Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-09-12 17:11:08 -0400
committerIgor Fedorenko2011-09-12 17:11:08 -0400
commit06b4b717705ab2d46b8b0db3fc4cee40b558c414 (patch)
treeadfe5425e7283917623cca71358089057e2e8c49
parent6c58cc31d8061b6d6bcaa3689148de7bf6445def (diff)
downloadm2e-core-06b4b717705ab2d46b8b0db3fc4cee40b558c414.tar.gz
m2e-core-06b4b717705ab2d46b8b0db3fc4cee40b558c414.tar.xz
m2e-core-06b4b717705ab2d46b8b0db3fc4cee40b558c414.zip
335711 introduced mapping metadata configuration
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java3
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java94
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java18
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java8
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator2.java82
5 files changed, 134 insertions, 71 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
index 122d963c..e2ba2747 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java
@@ -19,6 +19,8 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionRequest;
@@ -122,6 +124,7 @@ public interface IMaven {
public <T> T getMojoParameterValue(MavenSession session, MojoExecution mojoExecution, String parameter,
Class<T> asType) throws CoreException;
+ @Deprecated
public <T> T getMojoParameterValue(String parameter, Class<T> type, MavenSession session, Plugin plugin,
ConfigurationContainer configuration, String goal) throws CoreException;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index 056a9d93..d593d08c 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -52,7 +52,6 @@ import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
-import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup;
@@ -96,16 +95,12 @@ import org.apache.maven.model.interpolation.ModelInterpolator;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.io.ModelWriter;
import org.apache.maven.plugin.BuildPluginManager;
-import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginContainerException;
-import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginManagerException;
-import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -787,31 +782,39 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
public <T> T getMojoParameterValue(MavenSession session, MojoExecution mojoExecution, String parameter,
Class<T> asType) throws CoreException {
- try {
- MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+ Xpp3Dom dom = mojoExecution.getConfiguration();
- ClassRealm pluginRealm = lookup(BuildPluginManager.class).getPluginRealm(session,
- mojoDescriptor.getPluginDescriptor());
+ if(dom == null) {
+ return null;
+ }
- ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
+ return getMojoParameterValue(session, mojoExecution, parameter, asType, new XmlPlexusConfiguration(dom));
+ }
- ConfigurationConverter typeConverter = converterLookup.lookupConverterForType(asType);
+ public <T> T getMojoParameterValue(MavenSession session, MojoExecution mojoExecution, String parameter, Class<T> asType,
+ PlexusConfiguration configuration) throws CoreException {
+ ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
- Xpp3Dom dom = mojoExecution.getConfiguration();
+ return getMojoParameterValue(session, mojoExecution, parameter, asType, configuration, expressionEvaluator);
+ }
- if(dom == null) {
- return null;
- }
+ public <T> T getMojoParameterValue(MavenSession session, MojoExecution mojoExecution, String parameter,
+ Class<T> asType, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator) throws CoreException {
+ PlexusConfiguration parameterConfiguration = configuration.getChild(parameter);
- PlexusConfiguration pomConfiguration = new XmlPlexusConfiguration(dom);
+ if(parameterConfiguration == null) {
+ return null;
+ }
+
+ try {
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
- PlexusConfiguration configuration = pomConfiguration.getChild(parameter);
+ ConfigurationConverter typeConverter = converterLookup.lookupConverterForType(asType);
- if(configuration == null) {
- return null;
- }
+ ClassRealm pluginRealm = lookup(BuildPluginManager.class).getPluginRealm(session,
+ mojoDescriptor.getPluginDescriptor());
- Object value = typeConverter.fromConfiguration(converterLookup, configuration, asType,
+ Object value = typeConverter.fromConfiguration(converterLookup, parameterConfiguration, asType,
mojoDescriptor.getImplementationClass(), pluginRealm, expressionEvaluator, null);
return asType.cast(value);
} catch(Exception e) {
@@ -820,12 +823,12 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
}
}
+ @SuppressWarnings("deprecation")
public <T> T getMojoParameterValue(String parameter, Class<T> type, MavenSession session, Plugin plugin,
ConfigurationContainer configuration, String goal) throws CoreException {
Xpp3Dom config = (Xpp3Dom) configuration.getConfiguration();
- config = (config != null) ? config.getChild(parameter) : null;
- PlexusConfiguration paramConfig = null;
+ PlexusConfiguration mojoConfiguration = null;
if(config == null) {
MojoDescriptor mojoDescriptor;
@@ -833,52 +836,19 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
try {
mojoDescriptor = lookup(BuildPluginManager.class).getMojoDescriptor(plugin, goal,
session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession());
- } catch(PluginNotFoundException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- } catch(PluginResolutionException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- } catch(PluginDescriptorParsingException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- } catch(MojoNotFoundException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- } catch(InvalidPluginDescriptorException ex) {
+ } catch(Exception ex) {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
Messages.MavenImpl_error_param, ex));
}
- PlexusConfiguration defaultConfig = mojoDescriptor.getMojoConfiguration();
- if(defaultConfig != null) {
- paramConfig = defaultConfig.getChild(parameter, false);
- }
+ mojoConfiguration = mojoDescriptor.getMojoConfiguration();
} else {
- paramConfig = new XmlPlexusConfiguration(config);
+ mojoConfiguration = new XmlPlexusConfiguration(config);
}
- if(paramConfig == null) {
- return null;
- }
-
- try {
- MojoExecution mojoExecution = new MojoExecution(plugin, goal, "default"); //$NON-NLS-1$
-
- ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
+ MojoExecution mojoExecution = new MojoExecution(plugin, goal, "default"); //$NON-NLS-1$
- ConfigurationConverter typeConverter = converterLookup.lookupConverterForType(type);
-
- Object value = typeConverter.fromConfiguration(converterLookup, paramConfig, type, Object.class,
- plexus.getContainerRealm(), expressionEvaluator, null);
- return type.cast(value);
- } catch(ComponentConfigurationException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- } catch(ClassCastException ex) {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
- Messages.MavenImpl_error_param, ex));
- }
+ return getMojoParameterValue(session, mojoExecution, parameter, type, mojoConfiguration);
}
/**
@@ -1125,7 +1095,7 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
}
}
- private <T> T lookup(Class<T> clazz) throws CoreException {
+ public <T> T lookup(Class<T> clazz) throws CoreException {
try {
return getPlexusContainer().lookup(clazz);
} catch(ComponentLookupException ex) {
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 0964eb32..85da7074 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
@@ -80,6 +80,7 @@ import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
+import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator2;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
import org.eclipse.m2e.core.project.configurator.ILifecycleMappingConfiguration;
import org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant;
@@ -134,6 +135,8 @@ public class LifecycleMappingFactory {
private static final String ELEMENT_RUN_ON_INCREMENTAL = "runOnIncremental";
+ private static final String ELEMENT_CONFIGURATION = "configuration"; //$NON-NLS-1$
+
private static final String ATTR_GROUPID = "groupId";
private static final String ATTR_ARTIFACTID = "artifactId";
@@ -145,7 +148,7 @@ public class LifecycleMappingFactory {
private static final String LIFECYCLE_MAPPING_METADATA_CLASSIFIER = "lifecycle-mapping-metadata";
private static List<LifecycleMappingMetadataSource> bundleMetadataSources = null;
-
+
public static LifecycleMappingResult calculateLifecycleMapping(MavenExecutionRequest templateRequest,
MavenProjectFacade projectFacade, IProgressMonitor monitor) {
long start = System.currentTimeMillis();
@@ -549,6 +552,14 @@ public class LifecycleMappingFactory {
String message = NLS.bind(Messages.ProjectConfiguratorNotAvailable, configuratorId);
throw new LifecycleMappingConfigurationException(message);
}
+ Xpp3Dom configuration = ((PluginExecutionMetadata) metadata).getConfiguration().getChild(ELEMENT_CONFIGURATION);
+ if(configuration != null) {
+ if(projectConfigurator instanceof AbstractProjectConfigurator2) {
+ ((AbstractProjectConfigurator2) projectConfigurator).setConfiguration(configuration);
+ } else {
+ log.warn("Project configurator {} does not support configuration injection", configuration);
+ }
+ }
return projectConfigurator;
}
@@ -607,7 +618,8 @@ public class LifecycleMappingFactory {
public static MojoExecutionBuildParticipant createMojoExecutionBuildParicipant(IMavenProjectFacade projectFacade,
MojoExecution mojoExecution, IPluginExecutionMetadata executionMetadata) {
boolean runOnIncremental = true;
- Xpp3Dom child = ((PluginExecutionMetadata) executionMetadata).getConfiguration().getChild(ELEMENT_RUN_ON_INCREMENTAL);
+ Xpp3Dom child = ((PluginExecutionMetadata) executionMetadata).getConfiguration().getChild(
+ ELEMENT_RUN_ON_INCREMENTAL);
if(child != null) {
runOnIncremental = Boolean.parseBoolean(child.getValue());
}
@@ -920,7 +932,7 @@ public class LifecycleMappingFactory {
public synchronized static List<LifecycleMappingMetadataSource> getBundleMetadataSources() {
if(bundleMetadataSources == null) {
bundleMetadataSources = new ArrayList<LifecycleMappingMetadataSource>();
-
+
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint configuratorsExtensionPoint = registry
.getExtensionPoint(EXTENSION_LIFECYCLE_MAPPING_METADATA_SOURCE);
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java
index 3d081ed7..1757dfce 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator.java
@@ -33,7 +33,6 @@ import org.eclipse.core.runtime.Status;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.apache.maven.execution.MavenSession;
-import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.m2e.core.MavenPlugin;
@@ -47,8 +46,8 @@ import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
/**
@@ -166,10 +165,7 @@ public abstract class AbstractProjectConfigurator implements IExecutableExtensio
protected <T> T getParameterValue(String parameter, Class<T> asType, MavenSession session, MojoExecution mojoExecution)
throws CoreException {
- PluginExecution execution = new PluginExecution();
- execution.setConfiguration(mojoExecution.getConfiguration());
- return maven.getMojoParameterValue(parameter, asType, session, mojoExecution.getPlugin(), execution,
- mojoExecution.getGoal());
+ return maven.getMojoParameterValue(session, mojoExecution, parameter, asType);
}
protected void assertHasNature(IProject project, String natureId) throws CoreException {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator2.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator2.java
new file mode 100644
index 00000000..30d0b470
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractProjectConfigurator2.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.project.configurator;
+
+import org.eclipse.core.runtime.CoreException;
+
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
+
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.embedder.MavenImpl;
+
+
+/**
+ * AbstractProjectConfigurator that allows configuration via lifecycle mapping metadata. This is particularly useful
+ * when the same generic configuration logic can be applied to several independent unrelated maven plugins. For example,
+ * most java code generation plugins can be supported by a single project configurator parametrised with input resources
+ * and generated sources directories.
+ * <p>
+ * Implementation supports most of ${properties} allowed in plugin execution configuration element of pom.xml file, i.e.
+ * ${project.basedir} and similar. Mojo configuration parameter values can be referenced via ${mojo.someParameter}.
+ *
+ * @since 1.1
+ */
+public abstract class AbstractProjectConfigurator2 extends AbstractProjectConfigurator {
+
+ private Xpp3Dom configuration;
+
+ protected <T> T getConfiguratorParameterValue(final String parameter, final Class<T> asType,
+ final MavenSession session, final MojoExecution mojoExecution) throws CoreException {
+ if(configuration == null) {
+ return null;
+ }
+
+ // if the parameter is not defined, make sure we don't use similarly-named mojo configuration parameter
+ if(configuration.getChild(parameter) == null) {
+ return null;
+ }
+
+ final MavenImpl maven = (MavenImpl) MavenPlugin.getMaven();
+
+ // TODO refactor PluginParameterExpressionEvaluator to allow easier customization
+ ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution) {
+ public Object evaluate(String expr, Class<?> type) throws ExpressionEvaluationException {
+ if(expr.startsWith("${mojo.") && expr.endsWith("}")) {
+ String paramName = expr.substring(7, expr.length() - 1);
+ try {
+ return maven.getMojoParameterValue(session, mojoExecution, paramName, asType);
+ } catch(CoreException ex) {
+ throw new ExpressionEvaluationException(ex.getMessage(), ex);
+ }
+ }
+ return super.evaluate(expr, type);
+ }
+ };
+
+ return maven.getMojoParameterValue(session, mojoExecution, parameter, asType, new XmlPlexusConfiguration(
+ configuration), expressionEvaluator);
+ }
+
+ /**
+ * @noreference
+ */
+ public void setConfiguration(Xpp3Dom configuration) {
+ this.configuration = configuration;
+ }
+}

Back to the top