eclipse-xtext / eclipse-xtext/xtext

xtext-maven-plugin generate does not respect order of languages in pom.xml

Open
#2,967 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Hello everyone! I was trying to use my languages to generate code in another project, and I found out that the order in the pom.xml is not respected.

Instead, all grammars to be parsed are gathered together, some deltas are computed, and the end result is an arbitrary run of the languages.

For example, in my case:

<plugin>
  <groupId>org.eclipse.xtext</groupId>
  <artifactId>xtext-maven-plugin</artifactId>
  <version>${xtext-version}</version>
  <executions>
    <execution>
      <id>my-generate-prepare</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <languages>
          <language>
            <setup>my.generator.lang1StandaloneSetup</setup>
            <outputConfigurations>
              <outputConfiguration>
                <outputDirectory>${my-grammar-files}</outputDirectory>
              </outputConfiguration>
            </outputConfigurations>
          </language>
          <language>
            <setup>my.generator.lang2StandaloneSetup</setup>
            <outputConfigurations>
              <outputConfiguration>
                <outputDirectory>${my-grammar-files}</outputDirectory>
              </outputConfiguration>
            </outputConfigurations>
          </language>
          <language>
            <setup>my.generator.lang3StandaloneSetup</setup>
            <outputConfigurations>
              <outputConfiguration>
                <outputDirectory>${my-grammar-files}</outputDirectory>
              </outputConfiguration>
            </outputConfigurations>
          </language>
          <language>
            <setup>my.generator.lang4StandaloneSetup</setup>
            <outputConfigurations>
              <outputConfiguration>
                <outputDirectory>${my-grammar-files}</outputDirectory>
              </outputConfiguration>
            </outputConfigurations>
          </language>
          <language>
            <setup>my.generator.lang5StandaloneSetup</setup>
            <outputConfigurations>
              <outputConfiguration>
                <outputDirectory>${my-grammar-files}</outputDirectory>
              </outputConfiguration>
            </outputConfigurations>
          </language>
        </languages>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>my.generator</groupId>
      <artifactId>my.generator</artifactId>
      <version>1.0.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</plugin>

The pom above will validate and generate in this order:
lang3 lang1 lang5 lang2 lang4

Expected run:
lang1 lang2 lang3 lang4 lang5

This is necessary in my project as the first 2 languages are initializing some states/variables inside the generator which will be used by langs3-5.

I found the culprit code to be here:
https://github.com/eclipse/xtext/blob/1d83f8991764af318c917f5e2b34d86981742172/org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/StandaloneBuilder.java#L250-L273

This code should be modified to use the languages list to determine the parsing order of the files.
I tried to do the changes myself but I am having trouble building xtext locally.

Would there be another way to do this? I cannot use multiple execution entries as this would reinitialize the language model.

This language works perfectly fine inside Eclipse, I just have to manually run the generator on each file individually, in the order that I need.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with org.eclipse.xtext.builder.standalone/src/org/eclipse/xtext/builder/standalone/StandaloneBuilder.java at the linked lines 250-273, and trace how the configured languages and grammars are collected. Verify the Maven generation run preserves the language order from pom.xml, producing lang1 through lang5 in sequence rather than an arbitrary order.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.