List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getId
public String getId()
From source file:com.github.sdedwards.m2e_nar.internal.MavenUtils.java
License:Apache License
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;// w w w . j a v a 2s . com 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; }
From source file:com.github.sdedwards.m2e_nar.internal.MavenUtils.java
License:Apache License
private static void populatePluginFields(Object mojo, MojoDescriptor mojoDescriptor, ClassRealm pluginRealm, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator) throws CoreException { ComponentConfigurator configurator = new BasicComponentConfigurator(); try {//from w w w. java2 s . c om configurator.configureComponent(mojo, configuration, expressionEvaluator, pluginRealm); } catch (ComponentConfigurationException e) { String message = "Unable to parse configuration of mojo " + mojoDescriptor.getId(); if (e.getFailedConfiguration() != null) { message += " for parameter " + e.getFailedConfiguration().getName(); } message += ": " + e.getMessage(); throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, message, e)); } catch (NoClassDefFoundError e) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); PrintStream ps = new PrintStream(os); ps.println("A required class was missing during configuration of mojo " + mojoDescriptor.getId() + ": " + e.getMessage()); pluginRealm.display(ps); throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, os.toString(), e)); } catch (LinkageError e) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); PrintStream ps = new PrintStream(os); ps.println("An API incompatibility was encountered during configuration of mojo " + mojoDescriptor.getId() + ": " + e.getClass().getName() + ": " + e.getMessage()); pluginRealm.display(ps); throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, os.toString(), e)); } }