org.apache.maven.plugin.descriptor.PluginDescriptor Java Examples

The following examples show how to use org.apache.maven.plugin.descriptor.PluginDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java    From jax-maven-plugin with Apache License 2.0 6 votes vote down vote up
static Stream<String> getPluginRuntimeDependencyEntries(AbstractMojo mojo, MavenProject project, Log log,
        RepositorySystem repositorySystem, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories) {
    PluginDescriptor pluginDescriptor = (PluginDescriptor) mojo.getPluginContext().get(PLUGIN_DESCRIPTOR);
    Plugin plugin = project.getBuild().getPluginsAsMap().get(pluginDescriptor.getPluginLookupKey());

    List<ArtifactResolutionResult> artifactResolutionResults = plugin //
            .getDependencies() //
            .stream() //
            .map(repositorySystem::createDependencyArtifact) //
            .map(a -> Util.resolve(log, a, repositorySystem, localRepository, remoteRepositories)) //
            .collect(Collectors.toList());

    Stream<Artifact> originalArtifacts = artifactResolutionResults.stream()
            .map(ArtifactResolutionResult::getOriginatingArtifact);

    Stream<Artifact> childArtifacts = artifactResolutionResults.stream()
            .flatMap(resolutionResult -> resolutionResult.getArtifactResolutionNodes().stream())
            .map(ResolutionNode::getArtifact);

    return Stream.concat(originalArtifacts, childArtifacts).map(Artifact::getFile).map(File::getAbsolutePath);
}
 
Example #2
Source File: RepackageMojo.java    From sofa-ark with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws MojoExecutionException {
    if ("war".equals(this.project.getPackaging())) {
        getLog().debug("repackage goal could not be applied to war project.");
        return;
    }
    if ("pom".equals(this.project.getPackaging())) {
        getLog().debug("repackage goal could not be applied to pom project.");
        return;
    }
    if (StringUtils.isSameStr(this.arkClassifier, this.bizClassifier)) {
        getLog().debug("Executable fat jar should be different from 'plug-in' module jar.");
        return;
    }
    if (this.skip) {
        getLog().debug("skipping repackaging as configuration.");
        return;
    }

    /* version of ark container packaged into fat jar follows the plugin version */
    PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get(
        "pluginDescriptor");
    arkVersion = pluginDescriptor.getVersion();

    repackage();
}
 
Example #3
Source File: AgentDependencies.java    From promagent with Apache License 2.0 6 votes vote down vote up
static AgentDependencies init(PluginDescriptor pluginDescriptor) throws MojoExecutionException {

        String pluginGroupId = pluginDescriptor.getGroupId();
        String pluginArtifactId = pluginDescriptor.getArtifactId();

        List<ExpectedDependency> expectedDependencies = Arrays.asList(
                new ExpectedDependency(pluginGroupId, "promagent-agent"),
                new ExpectedDependency(pluginGroupId, "promagent-internal"),
                new ExpectedDependency(pluginGroupId, "promagent-api"),
                new ExpectedDependency("io.prometheus", "simpleclient_common"),
                new ExpectedDependency("io.prometheus", "simpleclient"),
                new ExpectedDependency("net.bytebuddy", "byte-buddy"),
                new ExpectedDependency("commons-io", "commons-io")
        );

        List<Artifact> actualDependencies = resolveVersions(pluginDescriptor, pluginArtifactId, expectedDependencies);
        failUnlessComplete(actualDependencies, expectedDependencies, pluginArtifactId);
        return new AgentDependencies(pluginGroupId, actualDependencies);
    }
 
Example #4
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Taken from MojoExecutor of Don Brown. Make it working with Maven 3.1.
 * 
 * @param plugin
 * @param goal
 * @param configuration
 * @param env
 * @throws MojoExecutionException
 * @throws PluginResolutionException
 * @throws PluginDescriptorParsingException
 * @throws InvalidPluginDescriptorException
 * @throws PluginManagerException
 * @throws PluginConfigurationException
 * @throws MojoFailureException
 */
private void executeMojo( Plugin plugin, String goal, Xpp3Dom configuration )
    throws MojoExecutionException, PluginResolutionException, PluginDescriptorParsingException,
    InvalidPluginDescriptorException, MojoFailureException, PluginConfigurationException, PluginManagerException
{

    if ( configuration == null )
    {
        throw new NullPointerException( "configuration may not be null" );
    }

    PluginDescriptor pluginDescriptor = getPluginDescriptor( 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 = mojoExecution( mojoDescriptor, configuration );
    pluginManager.executeMojo( getMavenSession(), exec );
}
 
Example #5
Source File: MojoConfigurationMergerTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void extractionOfMojoSpecificConfigurationAndMergingwithDefaultMojoConfiguration() throws Exception {
  InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml");
  assertNotNull(is);
  PluginDescriptor pluginDescriptor = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8"));
  String goal = merger.determineGoal("io.takari.maven.plugins.jar.Jar", pluginDescriptor);
  assertEquals("We expect the goal name to be 'jar'", "jar", goal);
  MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
  PlexusConfiguration defaultMojoConfiguration = mojoDescriptor.getMojoConfiguration();
  System.out.println(defaultMojoConfiguration);

  PlexusConfiguration configurationFromMaven = builder("configuration") //
      .es("jar") //
      .es("sourceJar").v("true").ee() //
      .ee() //
      .buildPlexusConfiguration();

  PlexusConfiguration mojoConfiguration = merger.extractAndMerge(goal, configurationFromMaven, defaultMojoConfiguration);

  String xml = mojoConfiguration.toString();
  assertXpathEvaluatesTo("java.io.File", "/configuration/classesDirectory/@implementation", xml);
  assertXpathEvaluatesTo("${project.build.outputDirectory}", "/configuration/classesDirectory/@default-value", xml);
  assertXpathEvaluatesTo("java.util.List", "/configuration/reactorProjects/@implementation", xml);
  assertXpathEvaluatesTo("${reactorProjects}", "/configuration/reactorProjects/@default-value", xml);
  assertXpathEvaluatesTo("true", "/configuration/sourceJar", xml);
}
 
Example #6
Source File: MojoExecutionService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public void callPluginGoal(String fullGoal) {
    String[] parts = splitGoalSpec(fullGoal);
    Plugin plugin = project.getPlugin(parts[0]);
    String goal = parts[1];

    if (plugin == null) {
        throw new IllegalStateException("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 IllegalStateException("Unable to execute mojo", e);
    }
}
 
Example #7
Source File: An_UpdateChecker.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
private void whenCheckingForUpdate() {
    PluginDescriptor pluginDescriptor = new PluginDescriptor();
    pluginDescriptor.setPluginArtifact(new DefaultArtifact("de.is24", "junit", "23", null, "maven-plugin", "", null));
    MojoDescriptor mojoDescriptor = new MojoDescriptor();
    mojoDescriptor.setPluginDescriptor(pluginDescriptor);
    result = objectUnderTest.checkForUpdate(new MojoExecution(mojoDescriptor));
}
 
Example #8
Source File: TestPropertiesMojoTest.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
private MojoExecution newMojoExecution(Xpp3Dom... parameters) throws IOException {
  MojoExecution execution = mojos.newMojoExecution("testProperties", parameters);
  PluginDescriptor pluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor();

  ArtifactHandler handler = new DefaultArtifactHandler("jar");
  DefaultArtifact workspaceResolver = new DefaultArtifact("io.takari.m2e.workspace", "org.eclipse.m2e.workspace.cli", "1", Artifact.SCOPE_COMPILE, ".jar", null, handler);
  workspaceResolver.setFile(new File("target/workspaceResolver.jar").getCanonicalFile());

  List<Artifact> pluginArtifacts = new ArrayList<>(pluginDescriptor.getArtifacts());
  pluginArtifacts.add(workspaceResolver);
  pluginDescriptor.setArtifacts(pluginArtifacts);

  return execution;
}
 
Example #9
Source File: MojoConfigurationMergerTest.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void determineGoalFromMojoImplementation() throws Exception {
  InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml");
  assertNotNull(is);
  PluginDescriptor pluginDescriptor = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8"));
  String goal = merger.determineGoal("io.takari.maven.plugins.jar.Jar", pluginDescriptor);
  assertEquals("We expect the goal name to be 'jar'", "jar", goal);
}
 
Example #10
Source File: AddPluginArtifactMetadataMojo.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the goal prefix parameter or the goal prefix from the Plugin artifactId.
 */
private String getGoalPrefix() {
  if (goalPrefix == null) {
    goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId());
  }

  return goalPrefix;
}
 
Example #11
Source File: MojoConfigurationProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
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();
    }
  }
  throw new ComponentConfigurationException("Cannot find the goal implementation with " + className);
}
 
Example #12
Source File: MojoConfigurationProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
public PlexusConfiguration mojoConfigurationFor(Object mojoInstance, PlexusConfiguration pluginConfigurationFromMaven) throws ComponentConfigurationException {
  try (InputStream is = mojoInstance.getClass().getResourceAsStream("/META-INF/maven/plugin.xml")) {
    PluginDescriptor pd = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8")); // closes input stream too
    String goal = determineGoal(mojoInstance.getClass().getName(), pd);
    PlexusConfiguration defaultMojoConfiguration = pd.getMojo(goal).getMojoConfiguration();
    PlexusConfiguration mojoConfiguration = extractAndMerge(goal, pluginConfigurationFromMaven, defaultMojoConfiguration);
    return mojoConfiguration;
  } catch (Exception e) {
    throw new ComponentConfigurationException(e);
  }
}
 
Example #13
Source File: MojoExecutionService.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #14
Source File: MavenHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Load the given plugin.
 *
 * @param plugin the plugin to load.
 * @return the descriptor of the plugin.
 * @throws MojoExecutionException if something bad append.
 */
public PluginDescriptor loadPlugin(Plugin plugin)
		throws MojoExecutionException {
	try {
		final Object repositorySessionObject = this.getRepositorySessionMethod.invoke(this.session);
		return (PluginDescriptor) this.loadPluginMethod.invoke(
				this.buildPluginManager,
				plugin,
				getSession().getCurrentProject().getRemotePluginRepositories(),
				repositorySessionObject);
	} catch (IllegalAccessException | IllegalArgumentException
			| InvocationTargetException e) {
		throw new MojoExecutionException(e.getLocalizedMessage(), e);
	}
}
 
Example #15
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
private Properties createGeneratorProperties() {
	final Properties props = new Properties();
	final PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); //$NON-NLS-1$
	props.put("generator.name", Strings.emptyIfNull(descriptor.getArtifactId())); //$NON-NLS-1$
	props.put("generator.version", Strings.emptyIfNull(descriptor.getVersion())); //$NON-NLS-1$
	return props;
}
 
Example #16
Source File: MultiStartMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #17
Source File: AbstractGeneratorTask.java    From gradle-plugins with MIT License 5 votes vote down vote up
/**
 * @see AbstractGeneratorMojo#execute()
 */
@TaskAction
public void generate() throws GeneratorException, IOException, XmlPullParserException, InvalidPluginDescriptorException, ExtractionException {
    PluginDescriptor pluginDescriptor = new PluginDescriptor();

    MavenProject project = new MavenProjectWrapper(getProject(), getPomFile().getAsFile().get());

    pluginDescriptor.setName(project.getName());
    pluginDescriptor.setDescription(project.getDescription());
    pluginDescriptor.setGroupId(project.getGroupId());
    pluginDescriptor.setVersion(project.getVersion());
    pluginDescriptor.setArtifactId(project.getArtifactId());
    pluginDescriptor.setGoalPrefix(goalPrefix.getOrElse(PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId())));

    List<ComponentDependency> deps = getRuntimeDependencies();
    pluginDescriptor.setDependencies(deps);

    DefaultPluginToolsRequest request = new DefaultPluginToolsRequest(project, pluginDescriptor);

    if (getEncoding().isPresent()) {
        request.setEncoding(getEncoding().getOrNull());
    }
    request.setSkipErrorNoDescriptorsFound(getSkipErrorNoDescriptorsFound().get());

    MojoScanner mojoScanner = getMojoScanner();
    mojoScanner.populatePluginDescriptor(request);

    getBaseDir().mkdirs();

    getGenerator().execute(
            getBaseDir(),
            request
    );
}
 
Example #18
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin(THORNTAIL_MAVEN_PLUGIN);

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(THORNTAIL_PROCESS);

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(THORNTAIL_PROCESS);

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put(THORNTAIL_PROCESS, procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #19
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #20
Source File: AbstractGeneratorTask.java    From gradle-plugins with MIT License 5 votes vote down vote up
/**
 * @see AbstractGeneratorMojo#execute()
 */
@TaskAction
public void generate() throws GeneratorException, IOException, XmlPullParserException, InvalidPluginDescriptorException, ExtractionException {
    PluginDescriptor pluginDescriptor = new PluginDescriptor();

    MavenProject project = new MavenProjectWrapper(getProject(), getPomFile().getAsFile().get());

    pluginDescriptor.setName(project.getName());
    pluginDescriptor.setDescription(project.getDescription());
    pluginDescriptor.setGroupId(project.getGroupId());
    pluginDescriptor.setVersion(project.getVersion());
    pluginDescriptor.setArtifactId(project.getArtifactId());
    pluginDescriptor.setGoalPrefix(goalPrefix.getOrElse(PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId())));

    List<ComponentDependency> deps = getRuntimeDependencies();
    pluginDescriptor.setDependencies(deps);

    DefaultPluginToolsRequest request = new DefaultPluginToolsRequest(project, pluginDescriptor);

    if (getEncoding().isPresent()) {
        request.setEncoding(getEncoding().getOrNull());
    }
    request.setSkipErrorNoDescriptorsFound(getSkipErrorNoDescriptorsFound().get());

    MojoScanner mojoScanner = getMojoScanner();
    mojoScanner.populatePluginDescriptor(request);

    getBaseDir().mkdirs();

    getGenerator().execute(
            getBaseDir(),
            request
    );
}
 
Example #21
Source File: AgentDependencies.java    From promagent with Apache License 2.0 5 votes vote down vote up
private static List<Artifact> resolveVersions(PluginDescriptor pluginDescriptor, String pluginArtifactId, List<ExpectedDependency> expectedDependencies) throws MojoExecutionException {
    List<Artifact> actualDependencies = new ArrayList<>();
    for (Artifact artifact : pluginDescriptor.getArtifacts()) {
        if (! isExpected(artifact, expectedDependencies)) {
            continue;
        }
        if (isKnown(artifact, actualDependencies)) {
            continue;
        }
        failOnVersionConflict(artifact, actualDependencies, pluginArtifactId);
        actualDependencies.add(artifact);
    }
    return actualDependencies;
}
 
Example #22
Source File: ConfluenceDeployMojo.java    From maven-confluence-plugin with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param pluginDescriptor
 * @param confluence
 * @param parentPage
 * @param site
 * @param locale
 * @return
 * @throws Exception
 */
public Model.Page processMojoDescriptors(
                        final PluginDescriptor pluginDescriptor,
                        final ConfluenceService confluence,
                        final Model.Page parentPage,
                        final Site site,
                        final Locale locale) throws Exception
{

    // issue#102
    //final String title = format( "%s-%s", pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion() );
    final String title = getPageTitle();

    getProperties().put("pageTitle",    title);
    getProperties().put("artifactId",   getProject().getArtifactId());
    getProperties().put("version",      getProject().getVersion());

    return
        removeSnaphot(confluence, parentPage, title)
        .thenCompose( deleted -> confluence.getPage(parentPage.getSpace(), parentPage.getTitle()) )
        .exceptionally( ex ->
            throwRTE( "cannot find parent page [%s] in space [%s]", parentPage.getTitle(), ex ))
        .thenApply( parent ->
            parent.orElseThrow( () -> RTE( "cannot find parent page [%s] in space [%s]", parentPage.getTitle())) )
        .thenCombine( confluence.getPage(parentPage.getSpace(), title), ParentChildTuple::of)
        .thenCompose( tuple -> ( tuple.getChild().isPresent() ) ?
            completedFuture(tuple.getChild().get()) :
            resetUpdateStatusForResource(site.getHome().getUri())
            .thenCompose( reset ->confluence.createPage(tuple.getParent(), title)))
        .thenCompose( p ->
            canProceedToUpdateResource( site.getHome().getUri())
            .thenCompose( update -> {
                if(update) return updateHomeContent(confluence, site, p, pluginDescriptor, locale) ;
                else {
                    getLog().info( String.format("page [%s] has not been updated (deploy skipped)",
                            getPrintableStringForResource(site.getHome().getUri()) ));
                    return confluence.storePage(p);
                }}))
        .join();

}
 
Example #23
Source File: ConfluenceDeployMojo.java    From maven-confluence-plugin with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void generatePluginReport( ConfluenceService confluence, final Site site, final Locale locale )  throws Exception
{

    final String goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId());
    final PluginDescriptor pluginDescriptor = new PluginDescriptor();
    pluginDescriptor.setGroupId(project.getGroupId());
    pluginDescriptor.setArtifactId(project.getArtifactId());
    pluginDescriptor.setVersion(project.getVersion());
    pluginDescriptor.setGoalPrefix(goalPrefix);

    final java.util.List<ComponentDependency> deps = new java.util.ArrayList<>();

    deps.addAll(toComponentDependencies(project.getRuntimeDependencies()));
    deps.addAll(toComponentDependencies(project.getCompileDependencies()));

    pluginDescriptor.setDependencies(deps);
    pluginDescriptor.setDescription(project.getDescription());

    PluginToolsRequest req = new DefaultPluginToolsRequest(project, pluginDescriptor);
    req.setEncoding(getEncoding());
    req.setLocal(local);
    req.setRemoteRepos(remoteRepos);
    req.setSkipErrorNoDescriptorsFound(false);
    req.setDependencies(dependencies);

    try {

        mojoScanner.populatePluginDescriptor(req);

    } catch (InvalidPluginDescriptorException e) {
        // this is OK, it happens to lifecycle plugins. Allow generation to proceed.
        getLog().warn(format("Plugin without mojos. %s\nMojoScanner:%s", e.getMessage(), mojoScanner.getClass()));

    }

    final Model.Page parentPage = loadParentPage(confluence, Optional.of(site)).join();

    outputDirectory.mkdirs();

    getLog().info( format("speceKey=%s parentPageTitle=%s", parentPage.getSpace(), parentPage.getTitle()) );

    final PluginGenerator generator = new PluginGenerator();

    final PluginToolsRequest request =
            new DefaultPluginToolsRequest(project, pluginDescriptor);

    final Model.Page confluenceHomePage = generator.processMojoDescriptors(
        request.getPluginDescriptor(),
        confluence,
        parentPage,
        site,
        locale );

    confluence.addLabelsByName(confluenceHomePage.getId(), site.getHome().getComputedLabels() ).join();

    final Map<String, Model.Page> varsToParentPageMap = new HashMap<>();

    generateChildren(   confluence,
                        site,
                        site.getHome(),
                        confluenceHomePage,
                        varsToParentPageMap);

    generator.generateGoalsPages(confluence, confluenceHomePage, varsToParentPageMap);


    //
    // Write the overview
    // PluginOverviewRenderer r = new PluginOverviewRenderer( getSink(), pluginDescriptor, locale );
    // r.render();
    //
}
 
Example #24
Source File: AbstractSarlMojo.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Execute another MOJO.
 *
 * @param groupId identifier of the MOJO plugin group.
 * @param artifactId identifier of the MOJO plugin artifact.
 * @param version version of the MOJO plugin version.
 * @param goal the goal to run.
 * @param configuration the XML code for the configuration.
 * @param dependencies the dependencies of the plugin.
 * @throws MojoExecutionException when cannot run the MOJO.
 * @throws MojoFailureException when the build failed.
 */
protected void executeMojo(
		String groupId, String artifactId,
		String version, String goal,
		String configuration,
		Dependency... dependencies) throws MojoExecutionException, MojoFailureException {
	final Plugin plugin = new Plugin();
	plugin.setArtifactId(artifactId);
	plugin.setGroupId(groupId);
	plugin.setVersion(version);
	plugin.setDependencies(Arrays.asList(dependencies));

	getLog().debug(MessageFormat.format(Messages.AbstractSarlMojo_0, plugin.getId()));

	final PluginDescriptor pluginDescriptor = this.mavenHelper.loadPlugin(plugin);
	if (pluginDescriptor == null) {
		throw new MojoExecutionException(MessageFormat.format(Messages.AbstractSarlMojo_1, plugin.getId()));
	}
	final MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
	if (mojoDescriptor == null) {
		throw new MojoExecutionException(MessageFormat.format(Messages.AbstractSarlMojo_2, goal));
	}

	final Xpp3Dom mojoXml;
	try {
		mojoXml = this.mavenHelper.toXpp3Dom(mojoDescriptor.getMojoConfiguration());
	} catch (PlexusConfigurationException e1) {
		throw new MojoExecutionException(e1.getLocalizedMessage(), e1);
	}
	Xpp3Dom configurationXml = this.mavenHelper.toXpp3Dom(configuration, getLog());
	if (configurationXml != null) {
		configurationXml = Xpp3DomUtils.mergeXpp3Dom(
				configurationXml,
				mojoXml);
	} else {
		configurationXml = mojoXml;
	}

	getLog().debug(MessageFormat.format(Messages.AbstractSarlMojo_3, plugin.getId(), configurationXml.toString()));

	final MojoExecution execution = new MojoExecution(mojoDescriptor, configurationXml);

	this.mavenHelper.executeMojo(execution);
}
 
Example #25
Source File: EmoStartMojo.java    From emodb with Apache License 2.0 4 votes vote down vote up
/** The version of this plugin used; is also the same version of the emodb server to use. */
private String pluginVersion() {
    return ((PluginDescriptor) getPluginContext().get("pluginDescriptor")).getVersion();
}
 
Example #26
Source File: AbstractUnleashMojo.java    From unleash-maven-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@MojoProduces
private PluginDescriptor getPluginDescriptor() {
  return (PluginDescriptor) getPluginContext().get("pluginDescriptor");
}
 
Example #27
Source File: ExtractConnectorDescriptorsMojo.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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) {

            }
        }
    }
}
 
Example #28
Source File: ManifestTransformer.java    From promagent with Apache License 2.0 4 votes vote down vote up
ManifestTransformer(PluginDescriptor pluginDescriptor) {
    pluginArtifactId = pluginDescriptor.getArtifactId();
    pluginVersion = pluginDescriptor.getVersion();
}
 
Example #29
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 4 votes vote down vote up
private PluginDescriptor getPluginDescriptor( Plugin plugin )
    throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
{
    return mavenPluginManagerHelper.getPluginDescriptor( plugin, getMavenProject().getRemotePluginRepositories(),
                                                         getMavenSession() );
}
 
Example #30
Source File: ActiveJdbcInstrumentationPlugin.java    From javalite with Apache License 2.0 4 votes vote down vote up
private void addUrlToPluginClasspath(URL url) {
    //Nice API, Maven :(
    PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
    ClassRealm realm = pluginDescriptor.getClassRealm();
    realm.addURL(url);
}