Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ public boolean apply(String filePath) {
/**
* Create Java Source Code that is compatible to this Java version.
*
* Supported values: 11, 17 and so forth
* Supported values: 11, 17, 21 and so forth
*/
@Parameter(property="maven.compiler.source", defaultValue="11")
private String javaSourceVersion;

/**
* Create Java Source Code that targets this Java release.
* <p>
* If set, this implies a {@link #javaSourceVersion} of the same value and any value explicitly configured for the latter is ignored.
* Nevertheless specifying this parameter does not enforce strict Java API checks like the {@code release} option for a Java compiler
* does. Still it is possible to enforce strict Java API checks by specifying the {@code release} option for the compiler-plugin.
* </p>
*
* Supported values: 11, 17, 21 and so forth
*/
@Parameter(property = "maven.compiler.release")
private String javaReleaseVersion;

/**
* The current build session instance. This is used for toolchain manager API calls.
*/
Expand Down Expand Up @@ -132,8 +145,9 @@ protected void compile(String classPath, List<String> sourcePaths, String output
return;
}
String baseDir = project.getBasedir().getAbsolutePath();
log.debug("Set Java Compliance Level: " + javaSourceVersion);
compiler.setJavaSourceVersion(javaSourceVersion);
String sourceVersion = javaReleaseVersion != null && !javaReleaseVersion.isBlank() ? javaReleaseVersion : javaSourceVersion;
log.debug("Set Java Compliance Level: " + sourceVersion);
compiler.setJavaSourceVersion(sourceVersion);
log.debug("Set generateSyntheticSuppressWarnings: " + generateSyntheticSuppressWarnings);
compiler.setGenerateSyntheticSuppressWarnings(generateSyntheticSuppressWarnings);
log.debug("Set useXbaseGenerated: " + useXbaseGenerated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</parent>
<artifactId>simple-java21</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.release>21</maven.compiler.release>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only adapted the test-cases in this directory because I expect them to be the only ones to 'use' the changed code immediately.

</properties>
<build>
<plugins>
Expand Down
3 changes: 1 addition & 2 deletions org.eclipse.xtend.maven.plugin/src/test/resources/it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<version>IT-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<xtextVersion>@project.version@</xtextVersion>
<xtextBOMVersion>${xtextVersion}</xtextBOMVersion>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.xtext.builder.standalone.LanguageAccessFactory;
import org.eclipse.xtext.builder.standalone.StandaloneBuilder;
import org.eclipse.xtext.builder.standalone.compiler.CompilerConfiguration;
import org.eclipse.xtext.builder.standalone.compiler.IJavaCompiler;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.persistence.IResourceStorageFacade;
import org.eclipse.xtext.resource.persistence.StorageAwareResource;
Expand Down Expand Up @@ -101,6 +100,21 @@ public String getEncoding() {

@Parameter(property = "maven.compiler.target", defaultValue = "11")
private String compilerTargetLevel;
/**
* Create Java Source Code that is compatible to this Java release.
* <p>
* If set, this implies a {@link #compilerSourceLevel} and
* {@link #compilerTargetLevel} of the same value and any value explicitly
* configured for the latter is ignored. Nevertheless specifying this parameter
* does not enforce strict Java API checks like the {@code release} option for a
* Java compiler does. Still it is possible to enforce strict Java API checks by
* specifying the {@code release} option for the compiler-plugin.
* </p>
*
* Supported values: 11, 17, 21 and so forth
*/
@Parameter(property = "maven.compiler.release")
private String compilerReleaseLevel;

@Parameter(defaultValue = "false")
private boolean compilerSkipAnnotationProcessing;
Expand Down Expand Up @@ -224,8 +238,9 @@ protected void internalExecute() throws MojoExecutionException {
if (clusteringConfig != null) {
builder.setClusteringConfig(clusteringConfig.convertToStandaloneConfig());
}
configureCompiler(builder.getCompiler());
logState();
CompilerConfiguration compilerConfiguration = builder.getCompiler().getConfiguration();
configureCompiler(compilerConfiguration);
logState(compilerConfiguration);
boolean errorDetected = !builder.launch();
if (errorDetected && failOnValidationError) {
throw new MojoExecutionException("Execution failed due to a severe validation error.");
Expand All @@ -236,20 +251,20 @@ protected void internalExecute() throws MojoExecutionException {

protected abstract List<String> getSourceRoots();

private void configureCompiler(IJavaCompiler compiler) {
CompilerConfiguration conf = compiler.getConfiguration();
conf.setSourceLevel(compilerSourceLevel);
conf.setTargetLevel(compilerTargetLevel);
private void configureCompiler(CompilerConfiguration conf) {
boolean isReleaseSet = compilerReleaseLevel != null && !compilerReleaseLevel.isBlank();
conf.setSourceLevel(isReleaseSet ? compilerReleaseLevel : compilerSourceLevel);
conf.setTargetLevel(isReleaseSet ? compilerReleaseLevel : compilerTargetLevel);
conf.setVerbose(getLog().isDebugEnabled());
conf.setSkipAnnotationProcessing(compilerSkipAnnotationProcessing);
conf.setPreserveInformationAboutFormalParameters(compilerPreserveInformationAboutFormalParameters);
}

private void logState() {
private void logState(CompilerConfiguration compilerConfiguration) {
getLog().info(
"Encoding: " + (getEncoding() == null ? "not set. Encoding provider will be used." : getEncoding()));
getLog().info("Compiler source level: " + compilerSourceLevel);
getLog().info("Compiler target level: " + compilerTargetLevel);
getLog().info("Compiler source level: " + compilerConfiguration.getSourceLevel());
getLog().info("Compiler target level: " + compilerConfiguration.getTargetLevel());
if (getLog().isDebugEnabled()) {
getLog().debug("Source dirs: " + IterableExtensions.join(getSourceRoots(), ", "));
getLog().debug("Java source dirs: " + IterableExtensions.join(javaSourceRoots, ", "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
</parent>

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

<artifactId>java-lang-21-bi-ref</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<properties>
<JENKINS_URL>https://ci.eclipse.org/xtext</JENKINS_URL>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<!-- The @...@ will be replaced during resource filtering with
the current version of our project -->
<xtext-version>@project.version@</xtext-version>
Expand Down
Loading