Skip to content

Commit d206d5c

Browse files
RussiaVkHannesWell
authored andcommittedOct 10, 2023
Update AbstractJavaProjectConfigurator.java
check --enable-preview flag in ${maven.compiler.enablePreview}
1 parent 8fe2220 commit d206d5c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>foo.bar</groupId>
8+
<artifactId>compilerEnablePreviewSettings</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<properties>
11+
<maven.compiler.enablePreview>true</maven.compiler.enablePreview>
12+
<maven.compiler.release>11</maven.compiler.release>
13+
</properties>
14+
</project>

‎org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public void testSkipNone() throws CoreException, IOException, InterruptedExcepti
124124
assertEquals(1, classpathEntriesCount(project, TEST_RESOURCES));
125125
}
126126

127+
128+
@Test
129+
public void testComplianceVsEnablePreviewSettings() throws CoreException, IOException, InterruptedException {
130+
IJavaProject project = importResourceProject("/projects/compilerEnablePreviewSettings/pom.xml");
131+
assertEquals("11", project.getOption(JavaCore.COMPILER_COMPLIANCE, false));
132+
assertEquals(JavaCore.ENABLED, project.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, false));
133+
assertEquals(JavaCore.IGNORE, project.getOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, false));
134+
}
127135
// --- utility methods ---
128136

129137
private static final Predicate<IClasspathEntry> TEST_SOURCES = cp -> cp.isTest()

‎org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java

+11
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,17 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution
765765
} catch(CoreException ex) {
766766
//ignore
767767
}
768+
769+
//3nd, check the --enable-preview flag in the ${maven.compiler.enablePreview}
770+
try {
771+
Boolean enablePreview = maven.getMojoParameterValue(mavenProject, execution, "enablePreview", Boolean.class, //$NON-NLS-1$
772+
monitor);
773+
if(Boolean.TRUE.equals(enablePreview)) {
774+
return true;
775+
}
776+
} catch(CoreException ex) {
777+
//ignore
778+
}
768779
return false;
769780
}
770781

0 commit comments

Comments
 (0)