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

The following examples show how to use org.apache.maven.model.Plugin#setArtifactId() . 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: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
private Plugin addControlBundleMavenPlugin() {

        Plugin plugin = new Plugin();

        plugin.setGroupId("org.apache.maven.plugins");
        plugin.setArtifactId("maven-jar-plugin");
        plugin.setVersion("3.0.2");

        plugin.setExtensions(true);

        Xpp3Dom configuration = new Xpp3Dom("configuration");
        Xpp3Dom archive = new Xpp3Dom("archive");
        Xpp3Dom manifest = new Xpp3Dom("manifestFile");
        manifest.setValue("${project.build.outputDirectory}/META-INF/MANIFEST.MF");
        archive.addChild(manifest);
        configuration.addChild(archive);
        plugin.setConfiguration(configuration);

        return plugin;
    }
 
Example 2
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void projectUnchangedWhenModeIsNone()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( none, model, null );
}
 
Example 3
Source File: PomAddPluginTest.java    From butterfly with MIT License 6 votes vote down vote up
@Test
public void addPluginWithVersionTest() throws IOException, XmlPullParserException {
	Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 3);
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

       PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin", "2.10.4").relative("pom.xml");
	TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext);
	assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);

	Model pomModelAfterChange = getTransformedPomModel("pom.xml");
	assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 4);
       Plugin plugin = new Plugin();
       plugin.setGroupId("org.apache.maven.plugins");
       plugin.setArtifactId("maven-javadoc-plugin");
       assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin));
       assertEquals(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion(), "2.10.4");
}
 
Example 4
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
/**
 * Skip clean control-bundle file in target folde, in case of using mvn clean + package goal
 *
 * @return plugin
 */
private Plugin addSkipMavenCleanPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.apache.maven.plugins");
    plugin.setArtifactId("maven-clean-plugin");
    plugin.setVersion("3.0.0");

    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom skipClean = new Xpp3Dom("skip");
    skipClean.setValue("true");
    configuration.addChild(skipClean);
    plugin.setConfiguration(configuration);

    return plugin;
}
 
Example 5
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
private Plugin addOsgiHelperMavenPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.talend.ci");
    plugin.setArtifactId("osgihelper-maven-plugin");
    plugin.setVersion(VersionUtils.getMojoVersion("osgihelper.version"));

    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue(PATH_FEATURE);
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("feature-helper");
    pluginExecution.setPhase("generate-sources");
    pluginExecution.addGoal("generate");
    pluginExecution.setConfiguration(configuration);
    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 6
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void projectDeploySkipTurnedOffWhenModeIsOff()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( off, model, model );
    assertSkip( model, null );
}
 
Example 7
Source File: PluginState.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
public void setRemoteRESTOverrides( Map<ArtifactRef, String> overrides )
{
    for ( ArtifactRef a : overrides.keySet() )
    {
        Plugin p = new Plugin();
        p.setGroupId( a.getGroupId() );
        p.setArtifactId( a.getArtifactId() );
        p.setVersion( overrides.get( a ) );
        remoteRESTplugins.add( p );
    }
}
 
Example 8
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private Plugin addFeaturesMavenPlugin(String finalNameValue) {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.apache.karaf.tooling");
    plugin.setArtifactId("karaf-maven-plugin");
    plugin.setVersion("4.2.4");

    Xpp3Dom configuration = new Xpp3Dom("configuration");

    Xpp3Dom finalName = new Xpp3Dom("finalName");

    finalName.setValue(finalNameValue);// "${talend.job.finalName}"

    Xpp3Dom resourcesDir = new Xpp3Dom("resourcesDir");
    resourcesDir.setValue("${project.build.directory}/bin");

    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue(PATH_FEATURE);

    configuration.addChild(finalName);
    configuration.addChild(resourcesDir);
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("create-kar");
    pluginExecution.addGoal("kar");
    pluginExecution.setConfiguration(configuration);

    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 9
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Plugin toPlugin( ReportPlugin reportPlugin )
{
    Plugin plugin = new Plugin();
    plugin.setGroupId( reportPlugin.getGroupId() );
    plugin.setArtifactId( reportPlugin.getArtifactId() );
    plugin.setVersion( reportPlugin.getVersion() );
    return plugin;
}
 
Example 10
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds those project plugins which are not inherited from the parent definitions to the list of plugins.
 *
 * @param plugins The list of plugins.
 * @param projectPlugins The project's plugins.
 * @param parentDefinitions The parent plugin definitions.
 * @since 1.0-alpha-1
 */
private void addProjectPlugins( Map<String, Plugin> plugins, Collection<Plugin> projectPlugins,
                                Map<String, String> parentDefinitions )
{
    for ( Plugin plugin : projectPlugins )
    {
        String coord = plugin.getKey();
        String version = plugin.getVersion();
        String parentVersion = parentDefinitions.get( coord );
        if ( version == null
            && ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null )
            && parentVersion != null )
        {
            Plugin parentPlugin = new Plugin();
            parentPlugin.setGroupId( plugin.getGroupId() );
            parentPlugin.setArtifactId( plugin.getArtifactId() );
            parentPlugin.setVersion( parentVersion );
            plugins.put( coord, parentPlugin );
        }
        else if ( parentVersion == null || !parentVersion.equals( version ) )
        {
            if ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null )
            {
                plugins.put( coord, plugin );
            }
        }
        if ( !plugins.containsKey( coord ) )
        {
            plugins.put( coord, plugin );
        }
    }
}
 
Example 11
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 5 votes vote down vote up
static Plugin newPlugin( String groupId, String artifactId, String version )
{
    Plugin plugin = new Plugin();
    plugin.setArtifactId( artifactId );
    plugin.setGroupId( groupId );
    plugin.setVersion( version );
    return plugin;
}
 
Example 12
Source File: MojoExecutionNameTest.java    From maven-buildtime-extension with MIT License 5 votes vote down vote up
@Test
public void getName() throws Exception {
    Plugin plugin = new Plugin();
    plugin.setArtifactId("artifact");
    MojoExecution execution = new MojoExecution(plugin, "goal", "id");

    MojoExecutionName executionName = new MojoExecutionName(execution);

    assertEquals("artifact:goal (id)", executionName.getName());
}
 
Example 13
Source File: BuildManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private Plugin createPlugin(String groupId, String artifactId, String version, boolean extension) {
	Plugin plugin = new Plugin();
	plugin.setGroupId(groupId);
	plugin.setArtifactId(artifactId);
	plugin.setVersion(version);
	if (extension) {
		plugin.setExtensions(true);
	}
	return plugin;
}
 
Example 14
Source File: ModelUtil.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
static Build prepareBuildWithSurefirePlugin(String version) {
    Plugin surefirePlugin = new Plugin();
    surefirePlugin.setArtifactId(ApplicablePlugins.SUREFIRE.getArtifactId());
    surefirePlugin.setVersion(version);

    Build build = new Build();
    build.addPlugin(surefirePlugin);

    return build;
}
 
Example 15
Source File: GenerateMojo.java    From karaf-boot with Apache License 2.0 4 votes vote down vote up
public void execute() throws MojoExecutionException {
    try {
        //
        // Felix Bundle plugin
        //

        Map<String, String> instructions = new LinkedHashMap<>();
        // Starters supplied instructions
        File bndInst = new File(mavenProject.getBasedir(), "target/classes/META-INF/org.apache.karaf.boot.bnd");
        if (bndInst.isFile()) {
            complete(instructions, bndInst);
            bndInst.delete();
        }
        // Verify and use defaults
        if (instructions.containsKey("Import-Package")) {
            instructions.put("Import-Package", instructions.get("Import-Package") + ",*");
        }
        // Build config
        StringBuilder config = new StringBuilder();
        config.append("<configuration>" +
                "<finalName>${project.build.finalName}</finalName>" +
                "<outputDirectory>${project.build.outputDirectory}</outputDirectory>" +
                "<m_mavenSession>${session}</m_mavenSession>" +
                "<project>${project}</project>" +
                "<buildDirectory>${project.build.directory}</buildDirectory>" +
                "<supportedProjectTypes>" +
                "<supportedProjectType>jar</supportedProjectType>" +
                "<supportedProjectType>bundle</supportedProjectType>" +
                "<supportedProjectType>war</supportedProjectType>" +
                "</supportedProjectTypes>" +
                "<instructions>" +
                "<_include>-bnd.bnd</_include>"); // include user bnd file if present
        for (Map.Entry<String, String> entry : instructions.entrySet()) {
            config.append("<").append(entry.getKey()).append(">")
                    .append(entry.getValue())
                    .append("</").append(entry.getKey()).append(">");
        }
        config.append("</instructions>" +
                "</configuration>");
        Xpp3Dom configuration = Xpp3DomBuilder.build(new StringReader(config.toString()));
        // Invoke plugin
        getLog().info("Invoking maven-bundle-plugin");
        Plugin felixBundlePlugin = new Plugin();
        felixBundlePlugin.setGroupId("org.apache.felix");
        felixBundlePlugin.setArtifactId("maven-bundle-plugin");
        felixBundlePlugin.setVersion("3.0.0");
        felixBundlePlugin.setInherited(true);
        felixBundlePlugin.setExtensions(true);
        PluginDescriptor felixBundlePluginDescriptor = pluginManager.loadPlugin(felixBundlePlugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession());
        MojoDescriptor felixBundleMojoDescriptor = felixBundlePluginDescriptor.getMojo("bundle");
        MojoExecution execution = new MojoExecution(felixBundleMojoDescriptor, configuration);
        pluginManager.executeMojo(mavenSession, execution);

    } catch (Exception e) {
        throw new MojoExecutionException("karaf-boot-maven-plugin failed", e);
    }
}
 
Example 16
Source File: SessionTimerTest.java    From maven-buildtime-extension with MIT License 4 votes vote down vote up
private MojoExecution createMojoExecution() {
    Plugin plugin = new Plugin();
    plugin.setArtifactId("plugin");
    return new MojoExecution(plugin, "goal", "executionId");
}
 
Example 17
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 18
Source File: BuildTimeEventSpyTest.java    From maven-buildtime-extension with MIT License 4 votes vote down vote up
private MojoExecution createMojoExecution() {
    Plugin plugin = new Plugin();
    plugin.setArtifactId("plugin");
    return new MojoExecution(plugin, "goal", "executionId");
}
 
Example 19
Source File: PropertiesUtilsTest.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
@Test
public void testCacheProperty() throws Exception
{
    Map<Project, Map<String, PropertyMapper>> propertyMap = new HashMap<>();
    CommonState state = new CommonState( new Properties() );
    Project project = getProject();
    Plugin dummy = new Plugin();
    dummy.setGroupId( "org.dummy" );
    dummy.setArtifactId( "dummyArtifactId" );

    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, "${foobar}${foobar2}", null, dummy,
                                                false ) );
    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, "suffix.${foobar}", null, dummy, false ) );
    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, null, "2.0", dummy, false ) );
    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, "1.0", "2.0", dummy, false ) );
    assertTrue( PropertiesUtils.cacheProperty( project, state, propertyMap, "${version.org.jboss}", "2.0", dummy,
                                               false ) );
    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, Version.PROJECT_VERSION, "2.0", dummy,
                                                false ) );

    // DependencyManipulator does dependency.getVersion(). This could return e.g. ${version.scala} which can
    // refer to <version.scala>${version.scala.major}.7</version.scala>. If we are attempting to change version.scala
    // to e.g. 2.11.7.redhat-1 then in this case we need to ignore the version.scala.major property and append the .redhat-1.

    // If the property is ${...}.foobar then we only want to append suffix to foobar to change the version
    // However we don't need to change the value of the property. If the property is foobar.${....} then
    // we want to append suffix to the property ... but we need to handle that part of the property is hardcoded.

    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, "${version.scala}.7", "2.0", null,
                                                false ) );
    assertFalse( PropertiesUtils.cacheProperty( project, state, propertyMap, "${version.foo}.${version.scala}.7",
                                                "2.0", null, false ) );

    try
    {
        PropertiesUtils.cacheProperty( project, state, propertyMap, "${version.scala}.7.${version.scala2}", "2.0",
                                       null, false );
    }
    catch ( ManipulationException e )
    {
        // Pass.
    }
}
 
Example 20
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private Plugin addSkipDeployFeatureMavenPlugin() {

        Plugin plugin = new Plugin();

        plugin.setGroupId("org.apache.maven.plugins");
        plugin.setArtifactId("maven-deploy-plugin");
        plugin.setVersion("2.7");

        Xpp3Dom configuration = new Xpp3Dom("configuration");

        Xpp3Dom skip = new Xpp3Dom("skip");
        skip.setValue("true");
        configuration.addChild(skip);
        plugin.setConfiguration(configuration);

        return plugin;

    }