Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-05-14 05:45:36 -0400
committerMickael Istria2019-05-14 10:20:00 -0400
commit9ad76e58f6c968bbd2c934202b0a404f052e0ad6 (patch)
treea421049297045c6c4c5aef8944f9e1fbc8c6b8b0
parentc345d47d4ac0d9e2335a0bb65e55ec02062acd60 (diff)
downloadm2e-core-9ad76e58f6c968bbd2c934202b0a404f052e0ad6.tar.gz
m2e-core-9ad76e58f6c968bbd2c934202b0a404f052e0ad6.tar.xz
m2e-core-9ad76e58f6c968bbd2c934202b0a404f052e0ad6.zip
Bug 547172 - Can't read project if parent coordinates don't match
Change-Id: I40708155607f026836bf541aaca83f3cc6240253 Signed-off-by: Mickael Istria <mistria@redhat.com>
m---------m2e-core-tests0
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/.classpath27
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/.project23
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.classpath27
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.project23
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/pom.xml12
-rw-r--r--org.eclipse.m2e.core.tests/resources/projects/invalidParent/pom.xml6
-rw-r--r--org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/RegistryTest.java19
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java15
9 files changed, 151 insertions, 1 deletions
diff --git a/m2e-core-tests b/m2e-core-tests
-Subproject 971d60b383f0579610ed0f4566e4d2f5f0ba21e
+Subproject 8c6b4f7f6e8f6d466c23568eb0afb4170ce886b
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.classpath b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.classpath
new file mode 100644
index 00000000..ebde5200
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.classpath
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="test" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.project b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.project
new file mode 100644
index 00000000..172d184d
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>potentialParent</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.classpath b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.classpath
new file mode 100644
index 00000000..5e8a55fe
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.classpath
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="test" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.project b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.project
new file mode 100644
index 00000000..ee87460a
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>invalidParent</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/pom.xml b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/pom.xml
new file mode 100644
index 00000000..68c4b9cc
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/child/pom.xml
@@ -0,0 +1,12 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <!-- Parent here is different from what's in parent folder -->
+ <groupId>io.takari</groupId>
+ <artifactId>takari</artifactId>
+ <version>28</version>
+ </parent>
+ <groupId>org.eclipse.m2e.tests.invalidParent</groupId>
+ <artifactId>invalidParent</artifactId>
+ <version>1</version>
+</project> \ No newline at end of file
diff --git a/org.eclipse.m2e.core.tests/resources/projects/invalidParent/pom.xml b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/pom.xml
new file mode 100644
index 00000000..e52fd636
--- /dev/null
+++ b/org.eclipse.m2e.core.tests/resources/projects/invalidParent/pom.xml
@@ -0,0 +1,6 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.m2e.tests.invalidParent</groupId>
+ <artifactId>potentialParent</artifactId>
+ <version>1</version>
+</project> \ No newline at end of file
diff --git a/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/RegistryTest.java b/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/RegistryTest.java
index 7572fb30..33ca03ec 100644
--- a/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/RegistryTest.java
+++ b/org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/RegistryTest.java
@@ -13,18 +13,24 @@ package org.eclipse.m2e.core.internal.project.registry;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Optional;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
@@ -73,4 +79,17 @@ public class RegistryTest extends AbstractMavenProjectTestCase {
}, monitor);
Assert.assertNotEquals(Collections.emptyMap(), state.requiredCapabilities);
}
+
+ @Ignore(value = "This test doesn't manage to reproduce Bug 547172 while similar manual steps do lead to an error")
+ public void testInvalidParent() throws IOException, CoreException, InterruptedException {
+ IProject childProject = importProject("invalidParent", "resources/projects/invalidParent/child/", new ProjectImportConfiguration());
+ waitForJobsToComplete(monitor);
+ Optional<IMarker> maybeErrorMarker = Arrays.stream(childProject.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE))
+ .filter(marker -> marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR)
+ .findAny();
+ assertEquals(Optional.empty(), maybeErrorMarker);
+ // The main difference between manual and unit test is that MavenImpl#readMavenProjects populates some "problems"
+ // for the manual case, but not in unit test. We didn't (yet?) manage to identify what cause this difference so
+ // we couldn't automate a good test
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
index 96b380cb..7a9864c3 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
@@ -71,11 +71,14 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.plugin.ExtensionRealmCache;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.PluginArtifactsCache;
import org.apache.maven.plugin.PluginRealmCache;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectRealmCache;
import org.apache.maven.project.artifact.MavenMetadataCache;
@@ -837,7 +840,7 @@ public class ProjectRegistryManager {
}
MavenExecutionResult result = results.values().iterator().next();
MavenProject mavenProject = result.getProject();
- if(mavenProject != null && result.getExceptions().isEmpty()) {
+ if(mavenProject != null && !hasError(result)) {
return mavenProject;
}
MultiStatus status = new MultiStatus(IMavenConstants.PLUGIN_ID, 0, Messages.MavenProjectFacade_error, null);
@@ -848,6 +851,16 @@ public class ProjectRegistryManager {
throw new CoreException(status);
}
+ private static boolean hasError(MavenExecutionResult mavenExecutionResult) {
+ return mavenExecutionResult.getExceptions().stream().anyMatch(ex -> !(ex instanceof ProjectBuildingException))
+ || mavenExecutionResult.getExceptions().stream()//
+ .map(ProjectBuildingException.class::cast)//
+ .flatMap(ex -> ex.getResults().stream())//
+ .flatMap(result -> result.getProblems().stream())//
+ .map(ModelProblem::getSeverity)//
+ .anyMatch(severity -> severity != Severity.WARNING);
+ }
+
Map<File, MavenExecutionResult> readProjectsWithDependencies(IProjectRegistry state, Collection<IFile> pomFiles,
ResolverConfiguration resolverConfiguration, IProgressMonitor monitor) {
try {

Back to the top