Java Code Examples for org.apache.maven.model.Plugin#getArtifactId()

The following examples show how to use org.apache.maven.model.Plugin#getArtifactId() . 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
/**
 * 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 2
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 3
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 4
private Artifact toArtifact(Plugin plugin) {
    ArtifactType artifactType = typeRegistry.get(MAVEN_PLUGIN_ARTIFACT_TYPE);
    return new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), artifactType.getClassifier(), artifactType.getExtension(), plugin.getVersion(),
            artifactType);
}
 
Example 5
Source Project: versions-maven-plugin   File: PomHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Takes a list of {@link org.apache.maven.model.Plugin} instances and adds associations to properties used to
 * define versions of the plugin artifact or any of the plugin dependencies specified in the pom.
 *
 * @param helper Our helper.
 * @param expressionEvaluator Our expression evaluator.
 * @param result The map of {@link org.codehaus.mojo.versions.api.PropertyVersionsBuilder} keyed by property name.
 * @param plugins The list of {@link org.apache.maven.model.Plugin}.
 * @throws ExpressionEvaluationException if an expression cannot be evaluated.
 */
private static void addPluginAssociations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator,
                                           Map<String, PropertyVersionsBuilder> result, List<Plugin> plugins )
    throws ExpressionEvaluationException
{
    if ( plugins == null )
    {
        return;
    }
    for ( Plugin plugin : plugins )
    {
        String version = plugin.getVersion();
        if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 )
        {
            version = StringUtils.deleteWhitespace( version );
            for ( PropertyVersionsBuilder property : result.values() )
            {
                // any of these could be defined by a property
                final String propertyRef = "${" + property.getName() + "}";
                if ( version.contains( propertyRef ) )
                {
                    String groupId = plugin.getGroupId();
                    if ( groupId == null || groupId.trim().length() == 0 )
                    {
                        // group Id has a special default
                        groupId = APACHE_MAVEN_PLUGINS_GROUPID;
                    }
                    else
                    {
                        groupId = (String) expressionEvaluator.evaluate( groupId );
                    }
                    String artifactId = plugin.getArtifactId();
                    if ( artifactId == null || artifactId.trim().length() == 0 )
                    {
                        // malformed pom
                        continue;
                    }
                    else
                    {
                        artifactId = (String) expressionEvaluator.evaluate( artifactId );
                    }
                    // might as well capture the current value
                    VersionRange versionRange =
                        VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( plugin.getVersion() ) );
                    property.addAssociation( helper.createPluginArtifact( groupId, artifactId, versionRange ),
                                             true );
                    if ( !propertyRef.equals( version ) )
                    {
                        addBounds( property, version, propertyRef, versionRange.toString() );
                    }
                }
            }
        }
        addDependencyAssocations( helper, expressionEvaluator, result, plugin.getDependencies(), true );
    }
}
 
Example 6
Source Project: sundrio   File: GenerateBomMojo.java    License: Apache License 2.0 4 votes vote down vote up
private Artifact toArtifact(Plugin plugin) {
    return new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null, Constants.MAVEN_PLUGIN_TYPE, null, getArtifactHandler());
}
 
Example 7
public ArtifactPluginWrapper( Plugin p )
{
    super (p.getGroupId(), p.getArtifactId(), p.getVersion(), null, null, null);
    this.original = p;
}
 
Example 8
Source Project: ci.maven   File: ExecuteMojoUtil.java    License: Apache License 2.0 4 votes vote down vote up
private static Xpp3Dom validateConfiguration(Plugin plugin, String goal, Xpp3Dom config, Log log) {
    Xpp3Dom goalConfig;
    String executionGoal = plugin.getArtifactId() + ":" + goal;
    switch (executionGoal) {
    case "liberty-maven-plugin:create":
        config = convertLibertyAlias(config);
        goalConfig = stripConfigElements(config, CREATE_PARAMS);
        break;
    case "liberty-maven-plugin:deploy":
        config = convertLibertyAlias(config);
        goalConfig = stripConfigElements(config, DEPLOY_PARAMS);
        break;
    case "liberty-maven-plugin:install-feature":
        config = convertLibertyAlias(config);
        goalConfig = stripConfigElements(config, INSTALL_FEATURE_PARAMS);
        break;
    case "maven-compiler-plugin:compile":
        goalConfig = stripConfigElements(config, COMPILE_PARAMS);
        break;
    case "maven-compiler-plugin:testCompile":
        goalConfig = stripConfigElements(config, TEST_COMPILE_PARAMS);
        break;
    case "maven-resources-plugin:resources":
        goalConfig = stripConfigElements(config, RESOURCES_PARAMS);
        break;
    case "maven-resources-plugin:testResources":
        goalConfig = stripConfigElements(config, TEST_RESOURCES_PARAMS);
        break;
    case "maven-surefire-plugin:test":
        goalConfig = stripConfigElements(config, TEST_PARAMS);
        break;
    case "maven-failsafe-plugin:integration-test":
        goalConfig = stripConfigElements(config, INTEGRATION_TEST_PARAMS);
        break;
    case "maven-failsafe-plugin:verify":
        goalConfig = stripConfigElements(config, VERIFY_PARAMS);
        break;
    case "maven-surefire-report-plugin:report-only":
        goalConfig = stripConfigElements(config, REPORT_ONLY_PARAMS);
        break;
    case "maven-surefire-report-plugin:failsafe-report-only":
        goalConfig = stripConfigElements(config, FAILSAFE_REPORT_ONLY_PARAMS);
        break;
    default:
        goalConfig = config;
        log.info("skip execution goal configuration validation for " + executionGoal);
        break;
    }
    return goalConfig;
}