Java Code Examples for org.apache.maven.plugin.descriptor.MojoDescriptor

The following examples show how to use org.apache.maven.plugin.descriptor.MojoDescriptor. These examples are extracted from open source projects. 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 Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<String>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 2
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 3
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 4
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 5
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter(MojoDescriptor mojoDescriptor) {
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<String>(2);
    if (StringUtils.isNotEmpty(scopeToCollect)) {
        scopes.add(scopeToCollect);
    }
    if (StringUtils.isNotEmpty(scopeToResolve)) {
        scopes.add(scopeToResolve);
    }

    if (scopes.isEmpty()) {
        return null;
    } else {
        return new CumulativeScopeArtifactFilter(scopes);
    }
}
 
Example 6
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<String>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 7
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{
    String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
    String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

    List<String> scopes = new ArrayList<>( 2 );
    if ( StringUtils.isNotEmpty( scopeToCollect ) )
    {
        scopes.add( scopeToCollect );
    }
    if ( StringUtils.isNotEmpty( scopeToResolve ) )
    {
        scopes.add( scopeToResolve );
    }

    if ( scopes.isEmpty() )
    {
        return null;
    }
    else
    {
        return new CumulativeScopeArtifactFilter( scopes );
    }
}
 
Example 8
Source Project: helm-maven-plugin   Source File: MojoExtension.java    License: MIT License 6 votes vote down vote up
@Override
public void beforeAll(ExtensionContext context) throws Exception {

    // get plugin descriptor

    InputStream inputStream = AbstractHelmMojo.class.getResourceAsStream("/META-INF/maven/plugin.xml");
    assertNotNull(inputStream, "Plugin descriptor not found.");
    plugin = new PluginDescriptorBuilder().build(new InterpolationFilterReader(new BufferedReader(new XmlStreamReader(inputStream)), new HashMap<>()));

    // get mojos

    mojoDescriptors = new HashMap<>();
    for (MojoDescriptor mojoDescriptor : plugin.getMojos()) {
        mojoDescriptors.put((Class<? extends AbstractHelmMojo>) Class.forName(mojoDescriptor.getImplementation()), mojoDescriptor);
    }
}
 
Example 9
@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 10
Source Project: iterator-maven-plugin   Source File: IteratorMojo.java    License: 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 11
Source Project: wisdom   Source File: PluginExtractor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the subset of the given configuration containing only the values accepted by the plugin/goal. The
 * configuration is modified in-place. The the extraction fail the configuration stays unchanged.
 *
 * @param mojo          the Wisdom mojo
 * @param plugin        the plugin object
 * @param goal          the goal / mojo
 * @param configuration the global configuration
 */
public static void extractEligibleConfigurationForGoal(AbstractWisdomMojo mojo,
                                                       Plugin plugin, String goal, Xpp3Dom configuration) {
    try {
        MojoDescriptor descriptor = mojo.pluginManager.getMojoDescriptor(plugin, goal,
                mojo.remoteRepos, mojo.repoSession);
        final List<Parameter> parameters = descriptor.getParameters();
        Xpp3Dom[] children = configuration.getChildren();
        if (children != null) {
            for (int i = children.length - 1; i >= 0; i--) {
                Xpp3Dom child = children[i];
                if (!contains(parameters, child.getName())) {
                    configuration.removeChild(i);
                }
            }
        }
    } catch (Exception e) {
        mojo.getLog().warn("Cannot extract the eligible configuration for goal " + goal + " from the " +
                "configuration");
        mojo.getLog().debug(e);
        // The configuration is not changed.
    }

}
 
Example 12
Source Project: jkube   Source File: MojoExecutionService.java    License: 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 13
Source Project: jkube   Source File: MojoExecutionService.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private MojoExecution getMojoExecution(String executionId, MojoDescriptor mojoDescriptor) {
    if (executionId != null) {
        return new MojoExecution(mojoDescriptor, executionId);
    } else {
        return new MojoExecution(mojoDescriptor, toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
    }
}
 
Example 14
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 15
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 16
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 17
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 18
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements(Set<String> scopesToResolve, Set<String> scopesToCollect,
                                           Collection<MojoExecution> mojoExecutions) {
    for (MojoExecution mojoExecution : mojoExecutions) {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll(toScopes(mojoDescriptor.getDependencyResolutionRequired()));

        scopesToCollect.addAll(toScopes(mojoDescriptor.getDependencyCollectionRequired()));
    }
}
 
Example 19
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 20
Source Project: dew   Source File: MojoExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
                                            Collection<MojoExecution> mojoExecutions )
{
    for ( MojoExecution mojoExecution : mojoExecutions )
    {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );

        scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
    }
}
 
Example 21
Source Project: wildfly-swarm   Source File: MultiStartMojo.java    License: 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 22
Source Project: thorntail   Source File: MultiStartMojo.java    License: 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 23
Source Project: ARCHIVE-wildfly-swarm   Source File: MultiStartMojo.java    License: 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 24
Source Project: docker-maven-plugin   Source File: MojoExecutionService.java    License: 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 25
Source Project: docker-maven-plugin   Source File: MojoExecutionService.java    License: Apache License 2.0 5 votes vote down vote up
private MojoExecution getMojoExecution(String executionId, MojoDescriptor mojoDescriptor) {
    if (executionId != null) {
        return new MojoExecution(mojoDescriptor, executionId);
    } else {
        return new MojoExecution(mojoDescriptor, toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
    }
}
 
Example 26
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 27
Source Project: deadcode4j   Source File: An_UpdateChecker.java    License: 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 28
Source Project: helm-maven-plugin   Source File: MojoExtension.java    License: MIT License 4 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException {
    try {

        // get descriptor

        Class<? extends AbstractHelmMojo> mojoType = (Class<AbstractHelmMojo>) parameterContext.getParameter().getType();
        MojoDescriptor descriptor = mojoDescriptors.get(mojoType);
        assertNotNull(descriptor, "Plugin descriptor for " + mojoType.getSimpleName() + " not found, run 'maven-plugin-plugin:descriptor'.");

        // create mojo with default values

        AbstractHelmMojo mojo = spy(mojoType);
        for (Parameter parameter : descriptor.getParameters()) {
            if (parameter.getDefaultValue() == null || !parameter.isEditable() || parameter.getType().equals("boolean")) {
                continue;
            }
            getField(mojoType, parameter.getName()).set(mojo, resolve(context, parameter.getDefaultValue()));
        }

        // read mojo values from annotations

        MojoProperty[] mojoProperties = ArrayUtils.addAll(
                context.getRequiredTestClass().getAnnotationsByType(MojoProperty.class),
                context.getRequiredTestMethod().getAnnotationsByType(MojoProperty.class));
        for (MojoProperty mojoProperty : mojoProperties) {
            getField(mojoType, mojoProperty.name()).set(mojo, resolve(context, mojoProperty.value()));
        }

        // settings

        getField(mojoType, "settings").set(mojo, new Settings());
        
        // plexus SecDispatcher

        SecDispatcher secDispatcher = spy(DefaultSecDispatcher.class);
        FieldSetter.setField(secDispatcher, DefaultSecDispatcher.class.getDeclaredField("_cipher"), new DefaultPlexusCipher());
        getField(mojoType, "securityDispatcher").set(mojo, secDispatcher);

        // validate that every parameter is set

        for (Parameter paramter : descriptor.getParameters()) {
            if (paramter.isRequired()) {
                assertNotNull(
                        getField(mojoType, paramter.getName()).get(mojo),
                        "Parameter '" + paramter.getName() + "' not set for mojo '" + mojoType.getSimpleName() + "'.");
            }
        }

        return mojo;
    } catch (ReflectiveOperationException | PlexusCipherException e) {
        throw new ParameterResolutionException("Failed to setup mockito.", e);
    }
}
 
Example 29
public Goal(MojoDescriptor mojoDescriptor) {
    this.descriptor = mojoDescriptor;
}
 
Example 30
public VersionsExpressionEvaluator( MavenSession mavenSession, PathTranslator pathTranslator,
                                    MavenProject mavenProject )
{
    super( mavenSession, new MojoExecution( new MojoDescriptor() ), pathTranslator, null, mavenProject,
           mavenSession.getExecutionProperties() );
}