TypeFox / xtext2langium

A tool for migrating an Xtext language to Langium
https://www.typefox.io/blog/xtext-to-langium
MIT License
7 stars 1 forks source link

Improve Usage directions #1

Closed steve-hickman-epistimis closed 1 year ago

steve-hickman-epistimis commented 1 year ago

The usage directions are spartan - so much so that I haven't gotten this to work yet. So far I've done:

  1. Used the p2 to add this to my Eclipse install - and restarted Eclipse
  2. Updated the Required-Bundle dependencies in the MANIFEST.MF of the base grammar project (the one with the .xtext file) to include io.typefox.xtext2langium;bundle-version="0.2.0"
  3. Updated the Generate....mwe2 file in base grammar project, adding the prescribed snippet
    fragment = io.typefox.xtext2langium.Xtext2LangiumFragment {
        outputPath = './langium'
    }

    to the StandardLanguage section as directed.

  4. Added the Maven dependency to the pom.xml of my base grammar project as below:
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>mwe2Launcher</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
                    <arguments>
                        <argument>/${project.basedir}/src/com/epistimis/face/GenerateFace.mwe2</argument>
                        <argument>-p</argument>
                        <argument>rootPath=/${project.basedir}/..</argument>
                    </arguments>
                    <classpathScope>compile</classpathScope>
                    <includePluginDependencies>true</includePluginDependencies>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads><!-- see https://bugs.eclipse.org/bugs/show_bug.cgi?id=475098#c3 -->
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.xtext</groupId>
                        <artifactId>xtext-antlr-generator</artifactId>
                        <version>2.1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>io.typefox.xtext2langium</groupId>
                        <artifactId>io.typefox.xtext2langium</artifactId>
                        <version>0.2.0</version>
                    </dependency>
                </dependencies>
            </plugin>
  5. Ran Maven > Update Project to sync everything.
  6. Ran Project > Clean to rebuild the project

I still get:

Couldn't resolve reference to JvmIdentifiableElement 'outputPath'.  
Couldn't resolve reference to JvmType 'io.typefox.xtext2langium.Xtext2LangiumFragment'.

errors in the .mwe2 file where I inserted the snippet.

I know there must be a simple fix to this - I just don't know what it is. I haven't discovered it by looking through the test code for this either. Or on StackOverflow/ Eclipse Forums via Google searches. I apologize that I just don't know Eclipse well enough to know the solution to this.

Could I trouble you to update the directions to make them more explicit?

dhuebner commented 1 year ago

@steve-hickman-epistimis

Updated the Required-Bundle dependencies in the MANIFEST.MF of the base grammar project (the one with the .xtext file) to include io.typefox.xtext2langium;bundle-version="0.2.0"

Normally this is enough to be able to resolve io.typefox.xtext2langium.Xtext2LangiumFragment in mwe2 file if you have a plug-in project. Are you using m2e? Is your DSL project somewhere in GitHub so I can take a look? Or better create a small Xtext project with the setup that reflects your project setup.

steve-hickman-epistimis commented 1 year ago

I'm using Eclipse 2022-09. The screenshot shows what I have installed. Screenshot 2022-12-20 at 1 49 39 PM

  1. I created a default XText 'Hello World' project using the defaults. I picked Maven / Fat Jar (see second screen shot) Screenshot 2022-12-20 at 1 52 16 PM

  2. I updated the Required-Bundle dependencies in the MANIFEST.MF of the base grammar project (the one with the .xtext file) to include io.typefox.xtext2langium;bundle-version="0.2.0"

  3. I updated the Generate....mwe2 file in base grammar project, adding the prescribed snippet

    fragment = io.typefox.xtext2langium.Xtext2LangiumFragment {
        outputPath = './langium'
    }

    to the StandardLanguage section as directed.

I still get:

Couldn't resolve reference to JvmIdentifiableElement 'outputPath'.  
Couldn't resolve reference to JvmType 'io.typefox.xtext2langium.Xtext2LangiumFragment'.

errors in the .mwe2 file where I inserted the snippet.

BTW: I see the same problem if I choose Gradle instead of Maven for builds. I also the the same result if I don't even go to the 'Advanced' dialog - so that I get the default of 'None' for the Preferred Build System.

spoenemann commented 1 year ago

If you build an Eclipse plug-in, you need to add the xtext2langium p2 repository to your target platform.

dhuebner commented 1 year ago

@steve-hickman-epistimis It looks like the p2 repository packaging is broken. I will fix that and report here

dhuebner commented 1 year ago

@steve-hickman-epistimis P2 jars are fixed now. Please try the following p2 repository https://typefox.github.io/xtext2langium/download/updates/v0.3.0/ Also don't forget to add it to your Language *.target file (should be in the <your-lang>.target project), otherwise maven-tycho build will fail:

<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
    <unit id="io.typefox.xtext2langium" version="0.0.0"/>
    <repository location="https://typefox.github.io/xtext2langium/download/updates/v0.3.0/"/>
</location>
dhuebner commented 1 year ago

@steve-hickman-epistimis I've release version v0.3.0, p2 repository is fixed now. In your runtime language project (with the Xtext grammar file) you should see this entries:

Bildschirm­foto 2022-12-22 um 16 11 00

Please re-open if something else is missing.

steve-hickman-epistimis commented 1 year ago

I have tested this for both Maven and Gradle using the default 'Hello' XText project. This eliminates the unresolved reference errors and the .langium files are generated as expected. Interestingly, on the Gradle project, I did not have to add this to the dependencies in the build.gradle file to build in Eclipse. Don't know why - maybe the Gradle file only matters when building from the command line?

One other thing: For my actual DSL, I found that recreating the XText project and adding the langium dependency before the first time I selected "Generate XText Artifacts" worked. For those who still have problems getting this to work, consider that.

Thanks!

steve-hickman-epistimis commented 1 year ago

NOTE: You need to update your blog post (https://www.typefox.io/blog/xtext-to-langium) to reference the 0.3.0 version.