use of org.apache.maven.plugin.descriptor.PluginDescriptor in project docker-maven-plugin by fabric8io.
the class MojoExecutionService method callPluginGoal.
// Call another goal after restart has finished
public void callPluginGoal(String fullGoal) throws MojoFailureException, MojoExecutionException {
String[] parts = splitGoalSpec(fullGoal);
Plugin plugin = project.getPlugin(parts[0]);
String goal = parts[1];
if (plugin == null) {
throw new MojoFailureException("No goal " + fullGoal + " found in pom.xml");
}
try {
String executionId = null;
if (goal != null && goal.length() > 0 && goal.indexOf('#') > -1) {
int pos = goal.indexOf('#');
executionId = goal.substring(pos + 1);
goal = goal.substring(0, pos);
}
PluginDescriptor pluginDescriptor = getPluginDescriptor(project, plugin);
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
if (mojoDescriptor == null) {
throw new MojoExecutionException("Could not find goal '" + goal + "' in plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion());
}
MojoExecution exec = getMojoExecution(executionId, mojoDescriptor);
pluginManager.executeMojo(session, exec);
} catch (Exception e) {
throw new MojoExecutionException("Unable to execute mojo", e);
}
}
use of org.apache.maven.plugin.descriptor.PluginDescriptor in project m2e-nar by maven-nar.
the class MavenUtils method getConfiguredMojo.
private static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class<T> asType, Log log) throws CoreException {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm().getWorld());
T mojo;
try {
mojo = asType.newInstance();
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating mojo", e));
}
mojo.setLog(log);
logger.debug("Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm);
Xpp3Dom dom = mojoExecution.getConfiguration();
PlexusConfiguration pomConfiguration;
if (dom == null) {
pomConfiguration = new XmlPlexusConfiguration("configuration");
} else {
pomConfiguration = new XmlPlexusConfiguration(dom);
}
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
populatePluginFields(mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator);
return mojo;
}
use of org.apache.maven.plugin.descriptor.PluginDescriptor in project syndesis by syndesisio.
the class ExtractConnectorDescriptorsMojo method execute.
@Override
@SuppressWarnings({ "PMD.EmptyCatchBlock", "PMD.CyclomaticComplexity" })
public void execute() throws MojoExecutionException, MojoFailureException {
ArrayNode root = new ArrayNode(JsonNodeFactory.instance);
URLClassLoader classLoader = null;
try {
PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
List<Artifact> artifacts = desc.getArtifacts();
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
for (Artifact artifact : artifacts) {
ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact);
File jar = result.getArtifact().getFile();
classLoader = createClassLoader(jar);
if (classLoader == null) {
throw new IOException("Can not create classloader for " + jar);
}
ObjectNode entry = new ObjectNode(JsonNodeFactory.instance);
addConnectorMeta(entry, classLoader);
addComponentMeta(entry, classLoader);
if (entry.size() > 0) {
addGav(entry, artifact);
root.add(entry);
}
}
if (root.size() > 0) {
saveCamelMetaData(root);
}
} catch (ArtifactResolverException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (classLoader != null) {
try {
classLoader.close();
} catch (IOException ignored) {
}
}
}
}
use of org.apache.maven.plugin.descriptor.PluginDescriptor in project tycho by eclipse.
the class PluginRealmHelper method execute.
public void execute(MavenSession session, MavenProject project, Runnable runnable, PluginFilter filter) throws MavenExecutionException {
for (Plugin plugin : project.getBuildPlugins()) {
if (plugin.isExtensions()) {
// https://cwiki.apache.org/MAVEN/maven-3x-class-loading.html
continue;
}
try {
lifecyclePluginResolver.resolveMissingPluginVersions(project, session);
PluginDescriptor pluginDescriptor;
try {
pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
} catch (PluginResolutionException e) {
// if the plugin really does not exist, the Maven build will fail later on anyway -> ignore for now (cf. bug #432957)
logger.debug("PluginResolutionException while looking for components from " + plugin, e);
continue;
}
if (pluginDescriptor != null) {
if (pluginDescriptor.getArtifactMap().isEmpty() && pluginDescriptor.getDependencies().isEmpty()) {
// force plugin descriptor reload to workaround http://jira.codehaus.org/browse/MNG-5212
// this branch won't be executed on 3.0.5+, where MNG-5212 is fixed already
PluginDescriptorCache.Key descriptorCacheKey = compatibilityHelper.createKey(plugin, project, session);
pluginDescriptorCache.put(descriptorCacheKey, null);
pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
}
if (filter == null || filter.accept(pluginDescriptor)) {
ClassRealm pluginRealm;
MavenProject oldCurrentProject = session.getCurrentProject();
session.setCurrentProject(project);
try {
pluginRealm = buildPluginManager.getPluginRealm(session, pluginDescriptor);
} finally {
session.setCurrentProject(oldCurrentProject);
}
if (pluginRealm != null) {
ClassLoader origTCCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(pluginRealm);
runnable.run();
} finally {
Thread.currentThread().setContextClassLoader(origTCCL);
}
}
}
}
} catch (PluginManagerException e) {
throw newMavenExecutionException(e);
} catch (PluginResolutionException e) {
throw newMavenExecutionException(e);
} catch (PluginVersionResolutionException e) {
throw newMavenExecutionException(e);
} catch (PluginDescriptorParsingException e) {
throw newMavenExecutionException(e);
} catch (InvalidPluginDescriptorException e) {
throw newMavenExecutionException(e);
}
}
}
use of org.apache.maven.plugin.descriptor.PluginDescriptor in project tycho by eclipse.
the class P2DependencyResolver method getDependencyMetadata.
protected Map<String, IDependencyMetadata> getDependencyMetadata(final MavenSession session, final MavenProject project, final List<TargetEnvironment> environments, final OptionalResolutionAction optionalAction) {
final Map<String, IDependencyMetadata> metadata = new LinkedHashMap<>();
metadata.put(null, generator.generateMetadata(new AttachedArtifact(project, project.getBasedir(), null), environments, optionalAction));
// let external providers contribute additional metadata
try {
pluginRealmHelper.execute(session, project, new Runnable() {
@Override
public void run() {
try {
for (P2MetadataProvider provider : plexus.lookupList(P2MetadataProvider.class)) {
Map<String, IDependencyMetadata> providedMetadata = provider.getDependencyMetadata(session, project, null, optionalAction);
if (providedMetadata != null) {
metadata.putAll(providedMetadata);
}
}
} catch (ComponentLookupException e) {
// have not found anything
}
}
}, new PluginFilter() {
@Override
public boolean accept(PluginDescriptor descriptor) {
return isTychoP2Plugin(descriptor);
}
});
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
}
return metadata;
}
Aggregations