List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getGoal
public String getGoal()
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//from w w w . ja v 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.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
protected Map<String, MojoDescriptor> getMojoDescriptors() { if (mojoDescriptors == null) { mojoDescriptors = new HashMap<String, MojoDescriptor>(); for (MojoDescriptor mojoDescriptor : getPluginDescriptor().getMojos()) { mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor); }/*from ww w . j a v a 2s . c o m*/ } return mojoDescriptors; }
From source file:io.takari.maven.plugins.configurator.MojoConfigurationProcessor.java
License:Open Source License
String determineGoal(String className, PluginDescriptor pluginDescriptor) throws ComponentConfigurationException { List<MojoDescriptor> mojos = pluginDescriptor.getMojos(); for (MojoDescriptor mojo : mojos) { if (className.equals(mojo.getImplementation())) { return mojo.getGoal(); }//w w w . j av a2 s . co m } throw new ComponentConfigurationException("Cannot find the goal implementation with " + className); }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
private Map<String, MojoDescriptor> readPluginXml(DefaultPlexusContainer container) throws Exception { Map<String, MojoDescriptor> mojoDescriptors = new HashMap<String, MojoDescriptor>(); Enumeration<URL> resources = getClass().getClassLoader().getResources(PATH_PLUGINXML); while (resources.hasMoreElements()) { InputStream is = resources.nextElement().openStream(); if (is == null) { return Collections.emptyMap(); }//from w w w .jav a 2 s . c o m XmlStreamReader reader = new XmlStreamReader(is); @SuppressWarnings("rawtypes") Map contextData = container.getContext().getContextData(); @SuppressWarnings("unchecked") InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( new BufferedReader(reader), contextData); PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationFilterReader); Artifact artifact = container.lookup(RepositorySystem.class) // .createArtifact(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), ".jar"); artifact.setFile(getPluginArtifactFile()); pluginDescriptor.setPluginArtifact(artifact); pluginDescriptor.setArtifacts(Arrays.asList(artifact)); for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) { container.addComponentDescriptor(desc); } for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) { // TODO decide how to handle duplicate goals // this is possible when one plugin extends another // for example, Tycho 'compile' goal is an extension of standard maven 'compile' mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor); } } return mojoDescriptors; }
From source file:org.jszip.maven.AbstractJSZipMojo.java
License:Apache License
protected MojoExecution createMojoExecution(Plugin plugin, PluginExecution pluginExecution, MojoDescriptor mojoDescriptor) { MojoExecution mojoExecution = new MojoExecution(plugin, mojoDescriptor.getGoal(), pluginExecution.getId()); mojoExecution.setConfiguration(convert(mojoDescriptor)); if (plugin.getConfiguration() != null || pluginExecution.getConfiguration() != null) { Xpp3Dom pluginConfiguration = plugin.getConfiguration() == null ? new Xpp3Dom("fake") : (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom mergedConfigurationWithExecution = Xpp3DomUtils .mergeXpp3Dom((Xpp3Dom) pluginExecution.getConfiguration(), pluginConfiguration); Xpp3Dom mergedConfiguration = Xpp3DomUtils.mergeXpp3Dom(mergedConfigurationWithExecution, convert(mojoDescriptor)); Xpp3Dom cleanedConfiguration = new Xpp3Dom("configuration"); if (mergedConfiguration.getChildren() != null) { for (Xpp3Dom parameter : mergedConfiguration.getChildren()) { if (mojoDescriptor.getParameterMap().containsKey(parameter.getName())) { cleanedConfiguration.addChild(parameter); }/*from w ww.j a v a 2 s .co m*/ } } if (getLog().isDebugEnabled()) { getLog().debug("mojoExecution mergedConfiguration: " + mergedConfiguration); getLog().debug("mojoExecution cleanedConfiguration: " + cleanedConfiguration); } mojoExecution.setConfiguration(cleanedConfiguration); } mojoExecution.setMojoDescriptor(mojoDescriptor); return mojoExecution; }
From source file:org.jszip.maven.AbstractJSZipMojo.java
License:Apache License
protected MojoDescriptor findMojoDescriptor(PluginDescriptor pluginDescriptor, Class<? extends Mojo> mojoClass) { MojoDescriptor mojoDescriptor = null; for (MojoDescriptor d : pluginDescriptor.getMojos()) { if (mojoClass.getName().equals(d.getImplementation())) { mojoDescriptor = pluginDescriptor.getMojo(d.getGoal()); break; }// w w w .ja v a 2 s.c o m } if (mojoDescriptor == null) { getLog().error("Cannot find goal that corresponds to " + mojoClass); throw new IllegalStateException("This plugin should always have the " + mojoClass.getName() + " goal"); } return mojoDescriptor; }
From source file:org.jszip.maven.RunMojo.java
License:Apache License
private void addOverlayResources(List<MavenProject> reactorProjects, List<Resource> _resources, Artifact a) throws PluginConfigurationException, PluginContainerException, IOException, MojoExecutionException { List<Resource> resources = new ArrayList<Resource>(); MavenProject fromReactor = findProject(reactorProjects, a); if (fromReactor != null) { MavenSession session = this.session.clone(); session.setCurrentProject(fromReactor); Plugin plugin = findThisPluginInProject(fromReactor); // we cheat here and use our version of the plugin... but this is less of a cheat than the only // other way which is via reflection. MojoDescriptor jszipDescriptor = findMojoDescriptor(pluginDescriptor, JSZipMojo.class); for (PluginExecution pluginExecution : plugin.getExecutions()) { if (!pluginExecution.getGoals().contains(jszipDescriptor.getGoal())) { continue; }/* w ww . j ava 2 s .co m*/ MojoExecution mojoExecution = createMojoExecution(plugin, pluginExecution, jszipDescriptor); JSZipMojo mojo = (JSZipMojo) mavenPluginManager.getConfiguredMojo(Mojo.class, session, mojoExecution); try { File contentDirectory = mojo.getContentDirectory(); if (contentDirectory.isDirectory()) { getLog().debug("Adding resource directory " + contentDirectory); resources.add(Resource.newResource(contentDirectory)); } // TODO filtering support // // The good news: // * resources:resources gets the list of resources from /project/build/resources *only* // The bad news: // * looks like maven-invoker is the only way to safely invoke it again // // probable solution // // 1. get the list of all resource directories, add on the scan for changes // 2. if a change to a non-filtered file, just copy it over // 3. if a change to a filtered file or a change to effective pom, use maven-invoker to run the // lifecycle up to 'compile' or 'process-resources' <-- preferred // File resourcesDirectory = mojo.getResourcesDirectory(); if (resourcesDirectory.isDirectory()) { getLog().debug("Adding resource directory " + resourcesDirectory); resources.add(Resource.newResource(resourcesDirectory)); } } finally { mavenPluginManager.releaseMojo(mojo, mojoExecution); } } } else { resources.add(Resource.newResource("jar:" + a.getFile().toURI().toURL() + "!/")); } // TODO support live reloading of mappings String path = ""; if (mappings != null) { for (Mapping mapping : mappings) { if (mapping.isMatch(a)) { path = StringUtils.clean(mapping.getPath()); break; } } } if (StringUtils.isBlank(path)) { _resources.addAll(resources); } else { ResourceCollection child = new ResourceCollection(resources.toArray(new Resource[resources.size()])); _resources.add(new VirtualDirectoryResource(child, path)); } }
From source file:org.jszip.maven.RunMojo.java
License:Apache License
private void addCssEngineResources(MavenProject project, List<MavenProject> reactorProjects, Mapping[] mappings, List<Resource> _resources) throws MojoExecutionException, IOException { List<PseudoFileSystem.Layer> layers = new ArrayList<PseudoFileSystem.Layer>(); layers.add(new PseudoFileSystem.FileLayer("/virtual", warSourceDirectory)); FilterArtifacts filter = new FilterArtifacts(); filter.addFilter(new ProjectTransitivityFilter(project.getDependencyArtifacts(), false)); filter.addFilter(new ScopeFilter("runtime", "")); filter.addFilter(new TypeFilter(JSZIP_TYPE, "")); // start with all artifacts. Set<Artifact> artifacts = project.getArtifacts(); // perform filtering try {/* w w w .ja v a2 s . c o m*/ artifacts = filter.filter(artifacts); } catch (ArtifactFilterException e) { throw new MojoExecutionException(e.getMessage(), e); } for (Artifact artifact : artifacts) { String path = Mapping.getArtifactPath(mappings, artifact); getLog().info("Adding " + ArtifactUtils.key(artifact) + " to virtual filesystem"); File file = artifact.getFile(); if (file.isDirectory()) { MavenProject fromReactor = findProject(reactorProjects, artifact); if (fromReactor != null) { MavenSession session = this.session.clone(); session.setCurrentProject(fromReactor); Plugin plugin = findThisPluginInProject(fromReactor); try { // we cheat here and use our version of the plugin... but this is less of a cheat than the only // other way which is via reflection. MojoDescriptor jszipDescriptor = findMojoDescriptor(this.pluginDescriptor, JSZipMojo.class); for (PluginExecution pluginExecution : plugin.getExecutions()) { if (!pluginExecution.getGoals().contains(jszipDescriptor.getGoal())) { continue; } MojoExecution mojoExecution = createMojoExecution(plugin, pluginExecution, jszipDescriptor); JSZipMojo mojo = (JSZipMojo) mavenPluginManager .getConfiguredMojo(org.apache.maven.plugin.Mojo.class, session, mojoExecution); try { File contentDirectory = mojo.getContentDirectory(); if (contentDirectory.isDirectory()) { getLog().debug("Merging directory " + contentDirectory + " into " + path); layers.add(new PseudoFileSystem.FileLayer(path, contentDirectory)); } File resourcesDirectory = mojo.getResourcesDirectory(); if (resourcesDirectory.isDirectory()) { getLog().debug("Merging directory " + contentDirectory + " into " + path); layers.add(new PseudoFileSystem.FileLayer(path, resourcesDirectory)); } } finally { mavenPluginManager.releaseMojo(mojo, mojoExecution); } } } catch (PluginConfigurationException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (PluginContainerException e) { throw new MojoExecutionException(e.getMessage(), e); } } else { throw new MojoExecutionException("Cannot find jzsip artifact: " + artifact.getId()); } } else { try { getLog().debug("Merging .zip file " + file + " into " + path); layers.add(new PseudoFileSystem.ZipLayer(path, file)); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } } final PseudoFileSystem fs = new PseudoFileSystem(layers); CssEngine engine = new LessEngine(fs, encoding == null ? "utf-8" : encoding, getLog(), lessCompress, customLessScript, showErrorExtracts); // look for files to compile PseudoDirectoryScanner scanner = new PseudoDirectoryScanner(); scanner.setFileSystem(fs); scanner.setBasedir(fs.getPseudoFile("/virtual")); if (lessIncludes != null && !lessIncludes.isEmpty()) { scanner.setIncludes(processIncludesExcludes(lessIncludes)); } else { scanner.setIncludes(new String[] { "**/*.less" }); } if (lessExcludes != null && !lessExcludes.isEmpty()) { scanner.setExcludes(processIncludesExcludes(lessExcludes)); } else { scanner.setExcludes(new String[0]); } scanner.scan(); for (String fileName : new ArrayList<String>(Arrays.asList(scanner.getIncludedFiles()))) { final CssEngineResource child = new CssEngineResource(fs, engine, "/virtual/" + fileName, new File(webappDirectory, engine.mapName(fileName))); final String path = FileUtils.dirname(fileName); if (StringUtils.isBlank(path)) { _resources.add( new VirtualDirectoryResource(new VirtualDirectoryResource(child, child.getName()), "")); } else { _resources.add( new VirtualDirectoryResource(new VirtualDirectoryResource(child, child.getName()), path)); } } engine = new SassEngine(fs, encoding == null ? "utf-8" : encoding); if (sassIncludes != null && !sassIncludes.isEmpty()) { scanner.setIncludes(processIncludesExcludes(sassIncludes)); } else { scanner.setIncludes(new String[] { "**/*.sass", "**/*.scss" }); } if (sassExcludes != null && !sassExcludes.isEmpty()) { scanner.setExcludes(processIncludesExcludes(sassExcludes)); } else { scanner.setExcludes(new String[] { "**/_*.sass", "**/_*.scss" }); } scanner.scan(); for (String fileName : new ArrayList<String>(Arrays.asList(scanner.getIncludedFiles()))) { final CssEngineResource child = new CssEngineResource(fs, engine, "/virtual/" + fileName, new File(webappDirectory, engine.mapName(fileName))); final String path = FileUtils.dirname(fileName); if (StringUtils.isBlank(path)) { _resources.add( new VirtualDirectoryResource(new VirtualDirectoryResource(child, child.getName()), "")); } else { _resources.add( new VirtualDirectoryResource(new VirtualDirectoryResource(child, child.getName()), path)); } } }
From source file:org.jszip.maven.UnpackMojo.java
License:Apache License
protected void unpack(Artifact artifact, File location, String includes, String excludes) throws MojoExecutionException { File file = artifact.getFile(); if (file.isDirectory()) { MavenProject fromReactor = findProject(reactorProjects, artifact); if (fromReactor != null) { MavenSession session = this.session.clone(); session.setCurrentProject(fromReactor); Plugin plugin = findThisPluginInProject(fromReactor); try { // we cheat here and use our version of the plugin... but this is less of a cheat than the only // other way which is via reflection. MojoDescriptor jszipDescriptor = findMojoDescriptor(this.pluginDescriptor, JSZipMojo.class); for (PluginExecution pluginExecution : plugin.getExecutions()) { if (!pluginExecution.getGoals().contains(jszipDescriptor.getGoal())) { continue; }/*from w w w .j a v a 2 s. c o m*/ MojoExecution mojoExecution = createMojoExecution(plugin, pluginExecution, jszipDescriptor); JSZipMojo mojo = (JSZipMojo) mavenPluginManager.getConfiguredMojo(Mojo.class, session, mojoExecution); try { File contentDirectory = mojo.getContentDirectory(); if (contentDirectory.isDirectory()) { FileUtils.copyDirectory(contentDirectory, location); } File resourcesDirectory = mojo.getResourcesDirectory(); if (resourcesDirectory.isDirectory()) { FileUtils.copyDirectory(resourcesDirectory, location); } } finally { mavenPluginManager.releaseMojo(mojo, mojoExecution); } } } catch (PluginConfigurationException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (PluginContainerException e) { throw new MojoExecutionException(e.getMessage(), e); } } else { throw new MojoExecutionException("Cannot find jzsip artifact: " + artifact.getId()); } } else { try { location.mkdirs(); zipUnArchiver.setSourceFile(file); zipUnArchiver.setDestDirectory(location); if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) { IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() }; if (StringUtils.isNotEmpty(excludes)) { selectors[0].setExcludes(excludes.split(",")); } if (StringUtils.isNotEmpty(includes)) { selectors[0].setIncludes(includes.split(",")); } zipUnArchiver.setFileSelectors(selectors); } zipUnArchiver.extract(); } catch (ArchiverException e) { e.printStackTrace(); throw new MojoExecutionException( "Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e); } } }
From source file:org.srcdeps.mvn.enforcer.SrcdepsEnforcer.java
License:Apache License
@Override public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException { final MavenProject project = event.getProject(); log.info("srcdeps enforcer checks for violations in {}:{}", project.getGroupId(), project.getArtifactId()); final Maven maven = configurationProducer.getConfiguration().getMaven(); final List<MojoExecution> mojoExecutions = event.getExecutionPlan(); final List<String> goals = new ArrayList<>(mojoExecutions.size()); for (MojoExecution mojoExecution : mojoExecutions) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); goals.add(mojoDescriptor.getFullGoalName()); goals.add(mojoDescriptor.getGoal()); }/* www .j a va 2 s.c om*/ final List<String> profiles = new ArrayList<>(); final List<Profile> activeProfiles = project.getActiveProfiles(); for (Profile profile : activeProfiles) { final String id = profile.getId(); profiles.add(id); } final Properties props = new Properties(); props.putAll(project.getProperties()); props.putAll(System.getProperties()); String[] firstViolation = assertFailWithout(maven.getFailWithout(), goals, profiles, props); if (firstViolation == null) { firstViolation = assertFailWith(maven.getFailWith(), goals, profiles, props); } if (firstViolation != null) { /* check if there are srcdeps */ Artifact parent = project.getParentArtifact(); if (parent != null) { assertNotSrcdeps(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), firstViolation); } DependencyManagement dm; List<Dependency> deps; if ((dm = project.getDependencyManagement()) != null && (deps = dm.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } if ((deps = project.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } } }