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

The following examples show how to use org.apache.maven.model.Plugin#setGroupId() . 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: PomUtils.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
private static boolean ensurePlugin(Model model) {
    org.apache.maven.model.Build build = model.getBuild();
    boolean isPresent = build.getPlugins()
                             .stream()
                             .anyMatch(p -> p.getGroupId().equals(BUILD_TOOLS_GROUP_ID)
                                     && p.getArtifactId().equals(BUILD_TOOLS_PLUGIN_ARTIFACT_ID));
    if (isPresent) {
        // Assume it is what we want rather than updating if not equal, since
        // that could undo future archetype changes.
        return false;
    } else {
        Plugin helidonPlugin = new Plugin();
        helidonPlugin.setGroupId(BUILD_TOOLS_GROUP_ID);
        helidonPlugin.setArtifactId(BUILD_TOOLS_PLUGIN_ARTIFACT_ID);
        helidonPlugin.setVersion("${" + HELIDON_PLUGIN_VERSION_PROPERTY + "}");
        helidonPlugin.setExtensions(true);
        build.addPlugin(helidonPlugin);
        return true;
    }
}
 
Example 2
Source File: CreateUtils.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Plugin resolvePluginInfo(Path pluginXml) throws MojoExecutionException {
    if (!Files.exists(pluginXml)) {
        throw new MojoExecutionException("Failed to locate " + pluginXml);
    }
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder db = dbf.newDocumentBuilder();
        try (InputStream is = Files.newInputStream(pluginXml)) {
            final Document doc = db.parse(is);
            final Node pluginNode = getElement(doc.getChildNodes(), "plugin");
            final Plugin plugin = new Plugin();
            plugin.setGroupId(getChildElementTextValue(pluginNode, "groupId"));
            plugin.setArtifactId(getChildElementTextValue(pluginNode, "artifactId"));
            plugin.setVersion(getChildElementTextValue(pluginNode, "version"));
            return plugin;
        }
    } catch (Throwable t) {
        throw new MojoExecutionException("Failed to parse " + pluginXml, t);
    }
}
 
Example 3
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 4
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
/**
 * Avoid clean control-bundle file in target folde, in case of using mvn clean package, TESB-22296
 *
 * @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: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Plugin createFakePlugin(String config) {
    Plugin plugin = new Plugin();
    plugin.setArtifactId("jkube-maven-plugin");
    plugin.setGroupId("org.eclipse.jkube");
    String content = "<configuration>"
        + config
        + "</configuration>";
    Xpp3Dom dom;
    try {
        dom = Xpp3DomBuilder.build(new StringReader(content));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    plugin.setConfiguration(dom);

    return plugin;
}
 
Example 6
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 7
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 8
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 9
Source File: CreateMavenDataServicePom.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("${basedir}/src/main/resources/feature/feature.xml");
    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 10
Source File: MojoToReportOptionsConverterTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  Plugin surefire = new Plugin();
  surefire.setGroupId("org.apache.maven.plugins");
  surefire.setArtifactId("maven-surefire-plugin");
  this.surefireConverter = Mockito.mock(SurefireConfigConverter.class);
  List<Plugin> mavenPlugins = Collections.singletonList(surefire);
  when(this.project.getBuildPlugins()).thenReturn(mavenPlugins);
  Build build = new Build();
  build.setOutputDirectory("");
  when(this.project.getBuild()).thenReturn(build);
}
 
Example 11
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 12
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 5 votes vote down vote up
private static Plugin toPlugin(Artifact artifact) {
    Plugin plugin = new Plugin();
    plugin.setGroupId(artifact.getGroupId());
    plugin.setArtifactId(artifact.getArtifactId());
    plugin.setVersion(artifact.getVersion());
    return plugin;
}
 
Example 13
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 14
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 15
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static Plugin createPluginEntry(MavenProject project, String groupId, String artifactId, String version,boolean isExtension){
	Plugin plugin = new Plugin();
	plugin.setGroupId(groupId);
	plugin.setArtifactId(artifactId);
	plugin.setVersion(version);
	if (isExtension){
		plugin.setExtensions(true);
	}
	MavenUtils.createMainConfigurationNode(plugin);
	project.getBuild().addPlugin(plugin);
	return plugin;
}
 
Example 16
Source File: PluginToStringTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static Plugin createPlugin(String gid, String aid, String version) {
  Plugin p = new Plugin();
  p.setGroupId(gid);
  p.setArtifactId(aid);
  p.setVersion(version);
  return p;
}
 
Example 17
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 18
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 19
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 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;

    }