Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-09-14 14:12:58 +0000
committerIgor Fedorenko2011-10-17 17:38:12 +0000
commitcf46b596af16759eee91d147eab27f8f4ca15ecf (patch)
tree9838c0c91395117b554ec69d38d59cb9cb65d444
parent00d08e894558e0f081bb136b50b6b567234e4d06 (diff)
downloadm2e-core-cf46b596af16759eee91d147eab27f8f4ca15ecf.tar.gz
m2e-core-cf46b596af16759eee91d147eab27f8f4ca15ecf.tar.xz
m2e-core-cf46b596af16759eee91d147eab27f8f4ca15ecf.zip
335711 enforce embedded metadata and maven-plugin GAVs match
maven plugins should only be able to define mapping for their plugin goals. mappings for other plugins are ignored with a warning. also allowed mapping without GAV as it can be derived from plugin artifact. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
index 6539387b..d809a724 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
@@ -26,6 +26,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
@@ -73,6 +74,7 @@ import org.eclipse.m2e.core.internal.Messages;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadata;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
+import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionFilter;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.io.xpp3.LifecycleMappingMetadataSourceXpp3Reader;
import org.eclipse.m2e.core.internal.markers.MavenProblemInfo;
@@ -267,6 +269,12 @@ public class LifecycleMappingFactory {
}
LifecycleMappingMetadataSource metadata = readMavenPluginEmbeddedMetadata(artifact);
if(metadata != null) {
+ // enforce embedded metadata only contains mappings for this plugin and nothing else
+ for(LifecycleMappingMetadata lifecycleMetadta : metadata.getLifecycleMappings()) {
+ enforcePluginMapping(artifact, lifecycleMetadta.getPluginExecutions());
+ }
+ enforcePluginMapping(artifact, metadata.getPluginExecutions());
+
result.put(file, metadata);
}
}
@@ -274,6 +282,36 @@ public class LifecycleMappingFactory {
return new ArrayList<LifecycleMappingMetadataSource>(result.values());
}
+ private static void enforcePluginMapping(Artifact artifact, List<PluginExecutionMetadata> executions) {
+ if(executions == null) {
+ return;
+ }
+ ListIterator<PluginExecutionMetadata> iter = executions.listIterator();
+ while(iter.hasNext()) {
+ PluginExecutionMetadata execution = iter.next();
+ PluginExecutionFilter filter = execution.getFilter();
+ if(!isNullOrEqual(artifact.getGroupId(), filter.getGroupId())
+ || !isNullOrEqual(artifact.getArtifactId(), filter.getArtifactId())
+ || !isNullOrEqual(artifact.getBaseVersion(), filter.getVersionRange())) {
+ String mappingGAV = filter.getGroupId() + ":" + filter.getArtifactId() + ":" + filter.getVersionRange();
+ String pluginGAV = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+ log.warn(
+ "Ignoring plugin execution mapping {} defined in maven plugin {} because it matches other plugins and/or plugin versions",
+ mappingGAV, pluginGAV);
+ iter.remove();
+ } else {
+ // filter may have empty GAV elements
+ filter.setGroupId(artifact.getGroupId());
+ filter.setArtifactId(artifact.getArtifactId());
+ filter.setVersionRange(artifact.getBaseVersion());
+ }
+ }
+ }
+
+ private static boolean isNullOrEqual(String expected, String actual) {
+ return actual == null || actual.equals(expected);
+ }
+
private static LifecycleMappingMetadataSource readMavenPluginEmbeddedMetadata(Artifact artifact) {
File file = artifact.getFile();
try {

Back to the top