Skip to content

Commit 0a34f9e

Browse files
committed
Fix Java Configurator
1 parent 9776a7f commit 0a34f9e

File tree

7 files changed

+168
-6
lines changed

7 files changed

+168
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>parentproject</artifactId>
6+
<groupId>com.example</groupId>
7+
<version>1.0</version>
8+
</parent>
9+
10+
<artifactId>app</artifactId>
11+
<name>app</name>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>junit</groupId>
16+
<artifactId>junit</artifactId>
17+
<version>4.13.1</version>
18+
<scope>test</scope>
19+
</dependency>
20+
</dependencies>
21+
</project>

org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/src/main/java/.gitkeep

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>parentproject</artifactId>
6+
<groupId>com.example</groupId>
7+
<version>1.0</version>
8+
</parent>
9+
10+
<artifactId>core</artifactId>
11+
12+
<name>core</name>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>4.13.1</version>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>org.codehaus.mojo</groupId>
26+
<artifactId>build-helper-maven-plugin</artifactId>
27+
<version>3.6.0</version>
28+
<executions>
29+
<execution>
30+
<goals>
31+
<goal>add-test-source</goal>
32+
</goals>
33+
<phase>generate-test-sources</phase>
34+
<configuration>
35+
<sources>
36+
<source>
37+
${project.basedir}/../app/src/main/java
38+
</source>
39+
</sources>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<version>3.14.0</version>
48+
<configuration>
49+
<annotationProcessorPaths></annotationProcessorPaths>
50+
</configuration>
51+
<executions>
52+
<execution>
53+
<id>default-compile</id>
54+
<phase>none</phase>
55+
</execution>
56+
<execution>
57+
<id>default-testCompile</id>
58+
<phase>none</phase>
59+
</execution>
60+
<execution>
61+
<id>java-compile</id>
62+
<goals>
63+
<goal>compile</goal>
64+
</goals>
65+
<phase>compile</phase>
66+
</execution>
67+
<execution>
68+
<id>java-test-compile</id>
69+
<goals>
70+
<goal>testCompile</goal>
71+
</goals>
72+
<phase>test-compile</phase>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
77+
</plugins>
78+
</build>
79+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.example</groupId>
5+
<artifactId>parentproject</artifactId>
6+
<version>1.0</version>
7+
<name>parentproject</name>
8+
<!-- FIXME change it to the project's website -->
9+
<url>http://www.example.com</url>
10+
<packaging>pom</packaging>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.release>17</maven.compiler.release>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>junit</groupId>
18+
<artifactId>junit</artifactId>
19+
<version>4.13.1</version>
20+
<scope>test</scope>
21+
</dependency>
22+
</dependencies>
23+
<modules>
24+
<module>core</module>
25+
<module>app</module>
26+
</modules>
27+
28+
</project>

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.core.resources.IProject;
3030
import org.eclipse.core.resources.IResource;
3131
import org.eclipse.core.resources.IncrementalProjectBuilder;
32+
import org.eclipse.core.resources.ResourcesPlugin;
3233
import org.eclipse.core.runtime.CoreException;
3334
import org.eclipse.core.runtime.FileLocator;
3435
import org.eclipse.core.runtime.IPath;
@@ -228,6 +229,36 @@ public void testMultiReleaseJar() throws CoreException, IOException, Interrupted
228229
}
229230
}
230231

232+
@Test
233+
public void testNonDefaultCompile() throws CoreException, IOException, InterruptedException {
234+
File baseDir = new File(FileLocator
235+
.toFileURL(JavaConfigurationTest.class.getResource("/projects/nonedefaultcompile/pom.xml")).getFile())
236+
.getParentFile().getParentFile();
237+
waitForJobsToComplete();
238+
IProject project = importProjects(
239+
baseDir.getAbsolutePath(), new String[] { "nonedefaultcompile/pom.xml",
240+
"nonedefaultcompile/core/pom.xml", "nonedefaultcompile/app/pom.xml" },
241+
new ResolverConfiguration())[0];
242+
waitForJobsToComplete();
243+
project = ResourcesPlugin.getWorkspace().getRoot().getProject("core");
244+
IJavaProject javaProject = JavaCore.create(project);
245+
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_SOURCE, false));
246+
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, false));
247+
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, false));
248+
assertEquals(JavaCore.ENABLED, javaProject.getOption(JavaCore.COMPILER_RELEASE, false));
249+
250+
List<String> srcEntryPaths = Arrays.stream(javaProject.getRawClasspath())
251+
.filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> !cp.isTest())
252+
.map(IClasspathEntry::getPath).map(IPath::toString).toList();
253+
assertEquals(Set.of("/core/src/main/java", "/core/src/main/resources"),
254+
Set.copyOf(srcEntryPaths));
255+
List<String> testEntryPaths = Arrays.stream(javaProject.getRawClasspath())
256+
.filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> cp.isTest())
257+
.map(IClasspathEntry::getPath).map(IPath::toString).toList();
258+
assertEquals(Set.of("/core/src/test/java", "/core/src/test/resources",
259+
"/core/.._app_src_main_java"),
260+
Set.copyOf(testEntryPaths));
261+
}
231262
// --- utility methods ---
232263

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

org.eclipse.m2e.jdt/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
5-
Bundle-Version: 2.5.0.qualifier
5+
Bundle-Version: 2.5.1.qualifier
66
Bundle-Localization: plugin
77
Export-Package: org.eclipse.m2e.jdt,
88
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,11 @@ protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigu
733733

734734
boolean enablePreviewFeatures = false;
735735

736+
boolean hasDefaultCompile = getCompilerMojoExecutions(request, monitor).stream()
737+
.filter(e -> "default-compile".equals(e.getExecutionId())).findAny().isPresent();
736738
for(MojoExecution execution : getCompilerMojoExecutions(request, monitor)) {
737739
String id = execution.getExecutionId();
738-
if(!"default-compile".equals(id)) {
740+
if(hasDefaultCompile && !"default-compile".equals(id)) {
739741
//Maven can have many but JDT only supports one config!
740742
continue;
741743
}
@@ -990,7 +992,7 @@ private void removeMavenClasspathContainer(IProject project) throws JavaModelExc
990992

991993
protected IContainer getFolder(IProject project, String path) throws CoreException {
992994
Path projectLocation = project.getLocation().toPath().toAbsolutePath();
993-
Path folderPath = Path.of(path);
995+
Path folderPath = Path.of(path).normalize();
994996
if(projectLocation.equals(folderPath)) {
995997
return project;
996998
}
@@ -1001,15 +1003,16 @@ protected IContainer getFolder(IProject project, String path) throws CoreExcepti
10011003
folderPath = projectLocation.resolve(path);
10021004
relativePath = IPath.fromOSString(path);
10031005
}
1004-
if(!project.exists(relativePath) && Files.exists(folderPath)
1006+
IFolder folder = project.getFolder(relativePath);
1007+
if((!project.exists(relativePath) || !folder.getProject().equals(project)) && Files.exists(folderPath)
10051008
&& !ResourcesPlugin.getWorkspace().getRoot().getLocation().toPath().equals(folderPath)) {
10061009
String linkName = projectLocation.relativize(folderPath).toString().replace("/", "_");
1007-
IFolder folder = project.getFolder(linkName);
1010+
folder = project.getFolder(linkName);
10081011
createLinkWithRetry(folder, folderPath.toUri());
10091012
folder.setPersistentProperty(LINKED_MAVEN_RESOURCE, "true");
10101013
return folder;
10111014
}
1012-
return project.getFolder(relativePath);
1015+
return folder;
10131016
}
10141017

10151018
/**

0 commit comments

Comments
 (0)