Skip to content

Commit

Permalink
First test of xtext-maven-plugin accessing a Java record
Browse files Browse the repository at this point in the history
Currently, we force the JDT version 3.37.0, the one supporting Java 21,
as an explicit dependency of the plugin in the IT project
  • Loading branch information
LorenzoBettini committed May 16, 2024
1 parent 64c02b0 commit a358d08
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.apache.maven.shared.utils.io.FileUtils;
import org.eclipse.xtext.maven.trace.ClassFileDebugSourceExtractor;
import org.eclipse.xtext.util.JavaRuntimeVersion;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -234,6 +236,15 @@ public void javaLangBiRef() throws Exception {
verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/JavaClazz.class");
}

@Test
public void javaLang21BiRef() throws Exception {
Assume.assumeTrue("Active only on Java 21 and later", JavaRuntimeVersion.isJava21OrLater());
Verifier verifier = verifyErrorFreeLog("java-lang-21-bi-ref");
verifier.verifyFilePresent(verifier.getBasedir() + "/src-gen/XbaseReferToJava.java");
verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/XbaseReferToJava.class");
verifier.verifyFilePresent(verifier.getBasedir() + "/target/xtext-temp/stub-classes/JavaRecord.class");
}

@Test
public void aggregation() throws Exception {
Verifier verifier = verifyErrorFreeLog("aggregate");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.xtext</groupId>
<artifactId>xtext-maven-plugin-it</artifactId>
<version>IT-SNAPSHOT</version>
</parent>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<artifactId>java-lang-21-bi-ref</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.xtext</groupId>
<artifactId>xtext-maven-plugin</artifactId>
<configuration>
<languages>
<language>
<setup>org.eclipse.xtext.purexbase.PureXbaseStandaloneSetup</setup>
</language>
</languages>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.purexbase</artifactId>
<version>${xtext-version}</version>
</dependency>
<!-- force the version of JDT that supports Java 21 -->
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.37.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.37.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public record JavaRecord(String name) {
public void useXbaseType(XbaseReferToJava xbaseType) throws Throwable {
xbaseType.myMethod();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val JavaRecord jr = new JavaRecord("test")
val name = jr.name()
jr.useXbaseType(this)

0 comments on commit a358d08

Please sign in to comment.