List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getPluginDescriptor
public PluginDescriptor getPluginDescriptor()
From source file:com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator.java
License:Open Source License
public ClassRealm getPluginClassRealm(MavenSession session, MojoExecution mojoExecution) throws CoreException { IMaven maven = MavenPlugin.getMaven(); // call for side effect of ensuring that the realm is set in the descriptor. maven.getConfiguredMojo(session, mojoExecution, Mojo.class); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); return mojoDescriptor.getPluginDescriptor().getClassRealm(); }
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;/*from www. ja va 2s.c o m*/ 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.spyhunter99.pdf.plugin.PdfMojo.java
License:Apache License
/** * Generate all Maven reports defined in <code>${project.reporting}</code> part * only if <code>generateReports</code> is enabled. * * @param locale not null//w w w. jav a 2 s . c om * @throws MojoExecutionException if any * @throws IOException if any * @since 1.1 */ private void generateMavenReports(Locale locale) throws MojoExecutionException, IOException { if (!includeReports) { getLog().info("Skipped report generation."); return; } if (project.getReporting() == null) { getLog().info("No report was specified."); return; } for (final ReportPlugin reportPlugin : project.getReporting().getPlugins()) { final PluginDescriptor pluginDescriptor = getPluginDescriptor(reportPlugin); if (pluginDescriptor != null) { List<String> goals = new ArrayList<String>(8); for (final ReportSet reportSet : reportPlugin.getReportSets()) { for (String goal : reportSet.getReports()) { goals.add(goal); } } List mojoDescriptors = pluginDescriptor.getMojos(); for (Object mojoDescriptor1 : mojoDescriptors) { final MojoDescriptor mojoDescriptor = (MojoDescriptor) mojoDescriptor1; if (goals.isEmpty() || (!goals.isEmpty() && goals.contains(mojoDescriptor.getGoal()))) { MavenReport report = getMavenReport(mojoDescriptor); generateMavenReport(report, mojoDescriptor.getPluginDescriptor().getPluginArtifact(), locale); } } } } // generate project-info report if (!getGeneratedMavenReports(locale).isEmpty()) { File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc"); if (!locale.getLanguage().equals(defaultLocale.getLanguage())) { outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc"); } outDir.mkdirs(); File piReport = new File(outDir, "project-info.xml"); StringWriter sw = new StringWriter(); PdfSink sink = new PdfSink(sw); ProjectInfoRenderer r = new ProjectInfoRenderer(sink, getGeneratedMavenReports(locale), i18n, locale); r.render(); writeGeneratedReport(sw.toString(), piReport); } // copy generated site copySiteDir(getGeneratedSiteDirectoryTmp(), getSiteDirectoryTmp()); copySiteDir(generatedSiteDirectory, getSiteDirectoryTmp()); }
From source file:com.github.spyhunter99.pdf.plugin.PdfMojo.java
License:Apache License
/** * @param mojoDescriptor not null// www . j a v a 2 s . c om * @return the MavenReport instance for the given mojoDescriptor. * @throws MojoExecutionException if any * @since 1.1 */ private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread() .setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader()); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); return pluginManager.getReport(project, mojoExecution, session); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e); } catch (PluginConfigurationException e) { throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e); } catch (PluginManagerException e) { throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
private void finalizeMojoConfiguration(MojoExecution mojoExecution) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MavenProject project = getMavenSession().getCurrentProject(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); Plugin plugin = project.getPlugin(pluginDescriptor.getPluginLookupKey()); pluginDescriptor.setPlugin(plugin);/* www . j av a 2s . com*/ Xpp3Dom executionConfiguration = mojoExecution.getConfiguration(); if (executionConfiguration == null) executionConfiguration = new Xpp3Dom("configuration"); Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert(mojoDescriptor); Xpp3Dom finalConfiguration = new Xpp3Dom("configuration"); if (mojoDescriptor.getParameters() != null) { for (Parameter parameter : mojoDescriptor.getParameters()) { Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName()); if (parameterConfiguration == null) parameterConfiguration = executionConfiguration.getChild(parameter.getAlias()); Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName()); parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults, Boolean.TRUE); if (parameterConfiguration != null) { parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName()); if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation")) && StringUtils.isNotEmpty(parameter.getImplementation())) { parameterConfiguration.setAttribute("implementation", parameter.getImplementation()); } finalConfiguration.addChild(parameterConfiguration); } } } if (plugin != null) { String goal = mojoExecution.getGoal(); for (PluginExecution pe : plugin.getExecutions()) { if (pe.getGoals().contains(goal)) { Xpp3Dom execConfig = (Xpp3Dom) pe.getConfiguration(); if (execConfig != null) finalConfiguration = Xpp3Dom.mergeXpp3Dom(execConfig, finalConfiguration); break; } } } mojoExecution.setConfiguration(finalConfiguration); }
From source file:hudson.gridmaven.ExecutedMojo.java
License:Open Source License
public ExecutedMojo(MojoInfo mojo, long duration) { this.groupId = mojo.pluginName.groupId; this.artifactId = mojo.pluginName.artifactId; this.version = mojo.pluginName.version; this.goal = mojo.getGoal(); this.executionId = mojo.mojoExecution.getExecutionId(); this.duration = duration; String digest = null;// w w w.j a v a 2 s. c om MojoDescriptor md = mojo.mojoExecution.getMojoDescriptor(); PluginDescriptor pd = md.getPluginDescriptor(); try { Class<?> clazz = getMojoClass(md, pd); if (clazz != null) { File jarFile = Which.jarFile(clazz); if (jarFile.isFile()) { digest = Util.getDigestOf(new FileInputStream(jarFile)); } else { // Maybe mojo was loaded from a classes dir instead of from a jar (JENKINS-5044) LOGGER.log(Level.WARNING, "Cannot calculate digest of mojo class, because mojo wasn't loaded from a jar, but from: " + jarFile); } } else { LOGGER.log(Level.WARNING, "Failed to getClass for " + md.getImplementation()); } } catch (IllegalArgumentException e) { LOGGER.log(Level.WARNING, "Failed to locate jar for " + md.getImplementation(), e); } catch (ClassNotFoundException e) { // perhaps the plugin has failed to load. } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to calculate digest for " + md.getImplementation(), e); } this.digest = digest; }
From source file:hudson.maven.ExecutedMojo.java
License:Open Source License
public ExecutedMojo(MojoInfo mojo, long duration) { this.groupId = mojo.pluginName.groupId; this.artifactId = mojo.pluginName.artifactId; this.version = mojo.pluginName.version; this.goal = mojo.getGoal(); this.executionId = mojo.mojoExecution.getExecutionId(); this.duration = duration; String digest = null;/*from w ww. j ava2 s. co m*/ MojoDescriptor md = mojo.mojoExecution.getMojoDescriptor(); PluginDescriptor pd = md.getPluginDescriptor(); try { Class<?> clazz = getMojoClass(md, pd); if (clazz != null) { File jarFile = Which.jarFile(clazz); if (jarFile.isFile()) { digest = Util.getDigestOf(jarFile); } else { // Maybe mojo was loaded from a classes dir instead of from a jar (JENKINS-5044) LOGGER.log(Level.WARNING, "Cannot calculate digest of mojo class, because mojo wasn't loaded from a jar, but from: " + jarFile); } } else { LOGGER.log(Level.WARNING, "Failed to getClass for " + md.getImplementation()); } } catch (IllegalArgumentException e) { LOGGER.log(Level.WARNING, "Failed to locate jar for " + md.getImplementation(), e); } catch (ClassNotFoundException e) { // perhaps the plugin has failed to load. } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to calculate digest for " + md.getImplementation(), e); } this.digest = digest; }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
@Override public Mojo lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = container.lookup(Mojo.class, mojoDescriptor.getRoleHint()); ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null;//from ww w . j ava2 s . c o m Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } if (configuration == null) { configuration = new Xpp3Dom("configuration"); } configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); execution.setConfiguration(configuration); finalizeMojoConfiguration(execution); PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(execution.getConfiguration()); String configuratorHint = "basic"; if (mojoDescriptor.getComponentConfigurator() != null) { configuratorHint = mojoDescriptor.getComponentConfigurator(); } ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, configuratorHint); configurator.configureComponent(mojo, pluginConfiguration, evaluator, container.getContainerRealm()); return mojo; }
From source file:org.apache.tuscany.sdo.plugin.GeneratorMojo.java
License:Apache License
public void execute() throws MojoExecutionException { // check for schemaFiles parameter first, if properties are not set, use // global property if (null != schemaFiles) { for (int i = 0; i < schemaFiles.length; ++i) { SchemaFileOption sf = schemaFiles[i]; if (null == sf.getTargetDirectory()) { sf.setTargetDirectory(targetDirectory); }/*from ww w . ja v a 2 s . co m*/ if (null == sf.getJavaPackage()) { sf.setJavaPackage(javaPackage); } if (null == sf.getSchemaNamespace()) { sf.setSchemaNamespace(schemaNamespace); } if (null == sf.isNoInterfaces()) { sf.setNoInterfaces(noInterfaces); } if (null == sf.isNoContainment()) { sf.setNoContainment(noContainment); } if (null == sf.isNoNotification()) { sf.setNoNotification(noNotification); } if (null == sf.isNoUnsettable()) { sf.setNoUnsettable(noUnsettable); } if (null == sf.isGenerateLoader()) { sf.setGenerateLoader(generateLoader); } if (null == sf.isGenerateSwitch()) { sf.setGenerateSwitch(generateSwitch); } // if (null == sf.getCompilerSourceRoots()) { // sf.setCompilerSourceRoots(compileSourceRoots); // } if (null == sf.isInterfaceDataObject()) { sf.setInterfaceDataObject(interfaceDataObject); } if (sf.getFileName() == null || sf.getFileName().length() == 0) { throw new MojoExecutionException("no fileName specfied for schema."); } if (!sf.getFileName().canRead() || !sf.getFileName().isFile()) { throw new MojoExecutionException("file can not be read:" + sf.getFileName()); } } } else { if (schemaFile == null) { File[] files = new File(schemaDir).listFiles(FILTER); schemaFiles = new SchemaFileOption[files.length]; for (int i = files.length - 1; i > -1; --i) { schemaFiles[i] = new SchemaFileOption(); schemaFiles[i].setFileName(files[i]); schemaFiles[i].setJavaPackage(javaPackage); // schemaFiles[i].setCompilerSourceRoots(compileSourceRoots); schemaFiles[i].setGenerateLoader(generateLoader); schemaFiles[i].setGenerateSwitch(generateSwitch); schemaFiles[i].setNoContainment(noContainment); schemaFiles[i].setInterfaceDataObject(interfaceDataObject); schemaFiles[i].setNoInterfaces(noInterfaces); schemaFiles[i].setNoNotification(noNotification); schemaFiles[i].setNoUnsettable(noUnsettable); schemaFiles[i].setPrefix(prefix); schemaFiles[i].setTargetDirectory(targetDirectory); schemaFiles[i].setSchemaNamespace(schemaNamespace); } } else { schemaFiles = new SchemaFileOption[] { new SchemaFileOption() }; schemaFiles[0].setFileName(schemaFile); schemaFiles[0].setJavaPackage(javaPackage); // schemaFiles[0].setCompilerSourceRoots(compileSourceRoots); schemaFiles[0].setGenerateLoader(generateLoader); schemaFiles[0].setGenerateSwitch(generateSwitch); schemaFiles[0].setNoContainment(noContainment); schemaFiles[0].setInterfaceDataObject(interfaceDataObject); schemaFiles[0].setNoInterfaces(noInterfaces); schemaFiles[0].setNoNotification(noNotification); schemaFiles[0].setNoUnsettable(noUnsettable); schemaFiles[0].setPrefix(prefix); schemaFiles[0].setTargetDirectory(targetDirectory); schemaFiles[0].setSchemaNamespace(schemaNamespace); } } for (int i = 0; i < schemaFiles.length; i++) { File file = schemaFiles[i].getFileName(); File marker = new File(schemaFiles[i].getTargetDirectory(), ".gen#" + file.getName()); if (file.lastModified() > marker.lastModified()) { getLog().info("Generating SDO interfaces from " + file); int genOptions = 0; if (schemaFiles[i].isNoInterfaces() != null && schemaFiles[i].isNoInterfaces().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_INTERFACES; } if (schemaFiles[i].isNoContainment() != null && schemaFiles[i].isNoContainment().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT; } if (schemaFiles[i].isNoNotification() != null && schemaFiles[i].isNoNotification().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION; } if (schemaFiles[i].isGenerateLoader() != null && schemaFiles[i].isGenerateLoader().booleanValue()) { genOptions |= JavaGenerator.OPTION_GENERATE_LOADER; } if (schemaFiles[i].isNoUnsettable() != null && schemaFiles[i].isNoUnsettable().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE; } if (schemaFiles[i].isGenerateSwitch() != null && schemaFiles[i].isGenerateSwitch().booleanValue()) { genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH; } if (schemaFiles[i].isInterfaceDataObject() != null && schemaFiles[i].isInterfaceDataObject().booleanValue()) { genOptions |= JavaGenerator.OPTION_INTERFACE_DO; } XSD2JavaGenerator.generateFromXMLSchema(file.toString(), schemaFiles[i].getSchemaNamespace(), schemaFiles[i].getTargetDirectory(), schemaFiles[i].getJavaPackage(), schemaFiles[i].getPrefix(), genOptions); } try { marker.createNewFile(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage() + "'" + marker.getAbsolutePath() + "'", e); } marker.setLastModified(System.currentTimeMillis()); } targetDirectory = targetDirectory.replace('/', File.separatorChar); // FIXME: [rfeng] Workaround to figure out the current execution phase MojoDescriptor descriptor = (MojoDescriptor) mojos.get(0); PluginDescriptor pluginDescriptor = descriptor.getPluginDescriptor(); Map pluginMap = project.getBuild().getPluginsAsMap(); Plugin plugin = (Plugin) pluginMap .get(pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId()); // How to get the current execution id? for (Iterator i = plugin.getExecutions().iterator(); i.hasNext();) { PluginExecution execution = (PluginExecution) i.next(); String phase = execution.getPhase(); if (phase != null && phase.indexOf("-test-") != -1) { project.addTestCompileSourceRoot(targetDirectory); } else { project.addCompileSourceRoot(targetDirectory); } } }
From source file:org.codehaus.mojo.xml.test.AbstractXmlMojoTestCase.java
License:Apache License
@Override //In maven-plugin-testing-harnes 2.1, this method had a simple error in it which resulted in //the configuration being incorrectly generated. In later versions, the error has been corrected. //The error is annotated in the comments below. This method should be removed when upgrading to later //versions. protected Mojo lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception, ComponentConfigurationException { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = (Mojo) lookup(mojoDescriptor.getRole(), mojoDescriptor.getRoleHint()); ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null;// w w w . ja v a2s . c o m Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } if (configuration == null) { configuration = new Xpp3Dom("configuration"); } //FIX: the parameters were in the wrong order on this call - they have been reversed configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); //END FIX PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(configuration); getContainer().lookup(ComponentConfigurator.class, "basic").configureComponent(mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); return mojo; }