Search in sources :

Example 41 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class DistributionEnforcingManipulatorTest method projectDeploySkipTurnedOffWhenModeIsOff.

@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, true, Boolean.FALSE);
}
Also used : Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) Plugin(org.apache.maven.model.Plugin) Test(org.junit.Test)

Example 42 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class Project method resolvePlugins.

private void resolvePlugins(MavenSessionHandler session, List<Plugin> plugins, HashMap<ProjectVersionRef, Plugin> resolvedPlugins) throws ManipulationException {
    ListIterator<Plugin> iterator = plugins.listIterator(plugins.size());
    // Iterate in reverse order so later plugins take precedence
    while (iterator.hasPrevious()) {
        Plugin p = iterator.previous();
        String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(p.getGroupId()) ? getGroupId() : p.getGroupId());
        String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(p.getArtifactId()) ? getArtifactId() : p.getArtifactId());
        String v = PropertyResolver.resolveInheritedProperties(session, this, p.getVersion());
        // comparison purposes.
        if (isEmpty(g)) {
            g = PLUGIN_DEFAULTS.getDefaultGroupId(a);
        }
        // this means managed plugins would be included which confuses things.
        if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) {
            SimpleProjectVersionRef spv = new SimpleProjectVersionRef(g, a, v);
            // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate.
            if (resolvedPlugins.containsKey(spv)) {
                logger.error("Found duplicate entry within plugin list. Key of {} and plugin {}", spv, p);
                iterator.remove();
            } else {
                Plugin old = resolvedPlugins.put(spv, p);
                if (old != null) {
                    logger.error("Internal project plugin resolution failure ; replaced {} in store by {}.", old, spv);
                    throw new ManipulationException("Internal project plugin resolution failure ; replaced " + old + " by " + spv);
                }
            }
        }
    }
}
Also used : ManipulationException(org.commonjava.maven.ext.common.ManipulationException) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Plugin(org.apache.maven.model.Plugin)

Example 43 with Plugin

use of org.apache.maven.model.Plugin in project maven-git-versioning-extension by qoomon.

the class VersioningPomReplacementMojo method asPlugin.

static Plugin asPlugin() {
    Plugin plugin = new Plugin();
    plugin.setGroupId(BuildProperties.projectGroupId());
    plugin.setArtifactId(BuildProperties.projectArtifactId());
    plugin.setVersion(BuildProperties.projectVersion());
    return plugin;
}
Also used : Plugin(org.apache.maven.model.Plugin)

Example 44 with Plugin

use of org.apache.maven.model.Plugin in project revapi by revapi.

the class ReportAggregateMojo method getRunConfig.

private ProjectVersions getRunConfig(MavenProject project) {
    ProjectVersions ret = new ProjectVersions();
    Plugin revapiPlugin = findRevapi(project);
    if (revapiPlugin == null) {
        return ret;
    }
    Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration();
    String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts");
    String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts");
    String oldVersion = getValueOfChild(pluginConfig, "oldVersion");
    if (oldVersion == null) {
        oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE);
    }
    String newVersion = getValueOfChild(pluginConfig, "newVersion");
    if (newVersion == null) {
        newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion());
    }
    String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion);
    String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion);
    if (oldArtifacts == null || oldArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        oldArtifacts = new String[] { defaultOldArtifact };
    }
    if (newArtifacts == null || newArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        newArtifacts = new String[] { defaultNewArtifact };
    }
    String versionRegexString = getValueOfChild(pluginConfig, "versionFormat");
    Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString);
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
    session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
    session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
    if (alwaysCheckForReleaseVersion) {
        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }
    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories());
    Function<String, Artifact> resolve = gav -> {
        try {
            return Analyzer.resolveConstrained(project, gav, versionRegex, resolver);
        } catch (VersionRangeResolutionException | ArtifactResolutionException e) {
            getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage());
            return null;
        }
    };
    ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    return ret;
}
Also used : Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Function(java.util.function.Function) Sink(org.apache.maven.doxia.sink.Sink) MessageFormat(java.text.MessageFormat) Execute(org.apache.maven.plugins.annotations.Execute) Mojo(org.apache.maven.plugins.annotations.Mojo) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ResourceBundle(java.util.ResourceBundle) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) SITE(org.apache.maven.plugins.annotations.LifecyclePhase.SITE) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) API(org.revapi.API) MavenSession(org.apache.maven.execution.MavenSession) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) MavenReportException(org.apache.maven.reporting.MavenReportException) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) Collectors(java.util.stream.Collectors) Revapi(org.revapi.Revapi) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) PACKAGE(org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE) List(java.util.List) Plugin(org.apache.maven.model.Plugin) Stream(java.util.stream.Stream) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) Pattern(java.util.regex.Pattern) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) Artifact(org.eclipse.aether.artifact.Artifact) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Plugin(org.apache.maven.model.Plugin) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector)

Example 45 with Plugin

use of org.apache.maven.model.Plugin in project custom-war-packager by jenkinsci.

the class MavenHPICustomWARPOMGenerator method generatePOM.

public Model generatePOM(Map<String, String> versionOverrides) throws IOException {
    Model model = new Model();
    model.setModelVersion("4.0.0");
    model.setGroupId(config.bundle.groupId);
    model.setArtifactId(config.bundle.artifactId);
    if (config.bundle.description != null) {
        model.setDescription(config.bundle.description);
    }
    model.setVersion(config.buildSettings.getVersion());
    // WAR Dependency
    Dependency dep = config.war.toDependency(versionOverrides);
    dep.setScope("test");
    dep.setType("war");
    model.addDependency(dep);
    // Plugins
    if (config.plugins != null) {
        for (DependencyInfo plugin : config.plugins) {
            Dependency pluginDep = plugin.toDependency(versionOverrides);
            pluginDep.setScope("runtime");
            model.addDependency(pluginDep);
        }
    }
    // Maven HPI Plugin
    /* Sample:
              <plugin>
                <groupId>≈/groupId>
                <artifactId>maven-hpi-plugin</artifactId>
                <version>2.2</version>
                <executions>
                  <execution>
                    <id>package-war</id>
                    <goals>
                      <goal>custom-war</goal>
                    </goals>
                    <configuration>
                      <outputFile>${build.directory}/tools-modified.war</outputFile>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
         */
    Repository jenkinsRepository = new Repository();
    jenkinsRepository.setId("repo.jenkins-ci.org");
    jenkinsRepository.setUrl("https://repo.jenkins-ci.org/public/");
    model.addPluginRepository(jenkinsRepository);
    model.addRepository(jenkinsRepository);
    Plugin mavenHPIPlugin = new Plugin();
    mavenHPIPlugin.setGroupId("org.jenkins-ci.tools");
    mavenHPIPlugin.setArtifactId("maven-hpi-plugin");
    // TODO: make configurable
    mavenHPIPlugin.setVersion("2.2");
    PluginExecution execution = new PluginExecution();
    execution.setId("package-war");
    execution.addGoal("custom-war");
    execution.setConfiguration(generateCustomWarGoalConfiguration());
    mavenHPIPlugin.addExecution(execution);
    Build build = new Build();
    build.addPlugin(mavenHPIPlugin);
    model.setBuild(build);
    return model;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Repository(org.apache.maven.model.Repository) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) DependencyInfo(io.jenkins.tools.warpackager.lib.config.DependencyInfo) Plugin(org.apache.maven.model.Plugin)

Aggregations

Plugin (org.apache.maven.model.Plugin)140 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)39 MavenProject (org.apache.maven.project.MavenProject)26 Build (org.apache.maven.model.Build)22 PluginExecution (org.apache.maven.model.PluginExecution)22 ArrayList (java.util.ArrayList)20 Dependency (org.apache.maven.model.Dependency)17 File (java.io.File)15 Model (org.apache.maven.model.Model)15 HashMap (java.util.HashMap)12 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)12 CoreException (org.eclipse.core.runtime.CoreException)11 IOException (java.io.IOException)9 List (java.util.List)8 PluginManagement (org.apache.maven.model.PluginManagement)8 Map (java.util.Map)7 MavenSession (org.apache.maven.execution.MavenSession)7 ReportPlugin (org.apache.maven.model.ReportPlugin)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6