Skip to content
Open
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
21 changes: 21 additions & 0 deletions org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parentproject</artifactId>
<groupId>com.example</groupId>
<version>1.0</version>
</parent>

<artifactId>app</artifactId>
<name>app</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
79 changes: 79 additions & 0 deletions org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parentproject</artifactId>
<groupId>com.example</groupId>
<version>1.0</version>
</parent>

<artifactId>core</artifactId>

<name>core</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
<goal>add-test-source</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<sources>
<source>
${project.basedir}/../app/src/main/java
</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<annotationProcessorPaths></annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>java-test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
28 changes: 28 additions & 0 deletions org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parentproject</artifactId>
<version>1.0</version>
<name>parentproject</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>core</module>
<module>app</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -228,6 +229,36 @@ public void testMultiReleaseJar() throws CoreException, IOException, Interrupted
}
}

@Test
public void testNonDefaultCompile() throws CoreException, IOException, InterruptedException {
File baseDir = new File(FileLocator
.toFileURL(JavaConfigurationTest.class.getResource("/projects/nonedefaultcompile/pom.xml")).getFile())
.getParentFile().getParentFile();
waitForJobsToComplete();
IProject project = importProjects(
baseDir.getAbsolutePath(), new String[] { "nonedefaultcompile/pom.xml",
"nonedefaultcompile/core/pom.xml", "nonedefaultcompile/app/pom.xml" },
new ResolverConfiguration())[0];
waitForJobsToComplete();
project = ResourcesPlugin.getWorkspace().getRoot().getProject("core");
IJavaProject javaProject = JavaCore.create(project);
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_SOURCE, false));
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, false));
assertEquals("17", javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, false));
assertEquals(JavaCore.ENABLED, javaProject.getOption(JavaCore.COMPILER_RELEASE, false));

List<String> srcEntryPaths = Arrays.stream(javaProject.getRawClasspath())
.filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> !cp.isTest())
.map(IClasspathEntry::getPath).map(IPath::toString).toList();
assertEquals(Set.of("/core/src/main/java", "/core/src/main/resources"),
Set.copyOf(srcEntryPaths));
List<String> testEntryPaths = Arrays.stream(javaProject.getRawClasspath())
.filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> cp.isTest())
.map(IClasspathEntry::getPath).map(IPath::toString).toList();
assertEquals(Set.of("/core/src/test/java", "/core/src/test/resources",
"/core/.._app_src_main_java"),
Set.copyOf(testEntryPaths));
}
// --- utility methods ---

private static final Predicate<IClasspathEntry> TEST_SOURCES = cp -> cp.isTest()
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
Bundle-Version: 2.5.0.qualifier
Bundle-Version: 2.5.1.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.m2e.jdt,
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,11 @@ protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigu

boolean enablePreviewFeatures = false;

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

protected IContainer getFolder(IProject project, String path) throws CoreException {
Path projectLocation = project.getLocation().toPath().toAbsolutePath();
Path folderPath = Path.of(path);
Path folderPath = Path.of(path).normalize();
if(projectLocation.equals(folderPath)) {
return project;
}
Expand All @@ -1001,15 +1003,16 @@ protected IContainer getFolder(IProject project, String path) throws CoreExcepti
folderPath = projectLocation.resolve(path);
relativePath = IPath.fromOSString(path);
}
if(!project.exists(relativePath) && Files.exists(folderPath)
IFolder folder = project.getFolder(relativePath);
if((!project.exists(relativePath) || !folder.getProject().equals(project)) && Files.exists(folderPath)
&& !ResourcesPlugin.getWorkspace().getRoot().getLocation().toPath().equals(folderPath)) {
String linkName = projectLocation.relativize(folderPath).toString().replace("/", "_");
IFolder folder = project.getFolder(linkName);
folder = project.getFolder(linkName);
createLinkWithRetry(folder, folderPath.toUri());
folder.setPersistentProperty(LINKED_MAVEN_RESOURCE, "true");
return folder;
}
return project.getFolder(relativePath);
return folder;
}

/**
Expand Down
Loading