Search in sources :

Example 1 with PluginView

use of org.commonjava.maven.galley.maven.model.view.PluginView in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginVersionFromManagementExpression.

@Test
public void resolvePluginVersionFromManagementExpression() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "child.pom.xml");
    lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
    final String base = PROJ_BASE + "version-expression-managed-parent-plugin/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    assertThat(pv.getVersion(), equalTo("1.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 2 with PluginView

use of org.commonjava.maven.galley.maven.model.view.PluginView in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginVersionFromPropertyInProfile.

@Test
public void resolvePluginVersionFromPropertyInProfile() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "test-pom-1.0.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
    final String base = PROJ_BASE + "version-expression-in-a-profile/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    assertThat(pv.getVersion(), equalTo("2.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("2.0"));
        }
    }
    if (!seen) {
        fail("Plugin relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 3 with PluginView

use of org.commonjava.maven.galley.maven.model.view.PluginView in project pom-manipulation-ext by release-engineering.

the class ModelIO method getRemotePluginVersionOverrides.

private Set<Plugin> getRemotePluginVersionOverrides(final PluginType type, final ProjectVersionRef ref, final Properties userProperties) throws ManipulationException {
    logger.debug("Resolving remote {} POM: {}", type, ref);
    final Set<Plugin> pluginOverrides = new HashSet<>();
    final Map<ProjectRef, ProjectVersionRef> pluginOverridesPomView = new HashMap<>();
    final Model m = resolveRawModel(ref);
    try {
        final MavenPomView pomView = galleyWrapper.readPomView(ref);
        final List<PluginView> deps;
        if (type == PluginType.PluginMgmt) {
            deps = pomView.getAllManagedBuildPlugins();
        } else {
            deps = pomView.getAllBuildPlugins();
        }
        for (final PluginView p : deps) {
            pluginOverridesPomView.put(p.asProjectRef(), p.asProjectVersionRef());
        }
    } catch (GalleyMavenException e) {
        throw new ManipulationException("Unable to resolve: %s", e, ref);
    }
    logger.debug("Found pluginOverridesResolvedVersions {} ", pluginOverridesPomView);
    // set of plugins with versions to handle those.
    for (Map.Entry<ProjectRef, ProjectVersionRef> entry : pluginOverridesPomView.entrySet()) {
        Plugin p = new Plugin();
        p.setArtifactId(entry.getKey().getArtifactId());
        p.setGroupId(entry.getKey().getGroupId());
        p.setVersion(entry.getValue().getVersionString());
        pluginOverrides.add(p);
    }
    // TODO: active profiles!
    if (m.getBuild() != null && m.getBuild().getPluginManagement() != null) {
        Iterator<Plugin> plit = null;
        if (type == PluginType.PluginMgmt && m.getBuild().getPluginManagement() != null) {
            logger.debug("Returning override of " + m.getBuild().getPluginManagement().getPlugins());
            plit = m.getBuild().getPluginManagement().getPlugins().iterator();
        } else if (type == PluginType.Plugins && m.getBuild().getPlugins() != null) {
            logger.debug("Returning override of " + m.getBuild().getPlugins());
            plit = m.getBuild().getPlugins().iterator();
        }
        while (plit != null && plit.hasNext()) {
            Plugin p = plit.next();
            ProjectRef pr = new SimpleProjectRef(p.getGroupId(), p.getArtifactId());
            if ((isNotEmpty(p.getVersion()) && p.getVersion().startsWith("${")) || isEmpty(p.getVersion())) {
                // Property reference to something in the remote pom. Resolve and inline it now.
                String newVersion = resolveProperty(userProperties, m.getProperties(), p.getVersion());
                // TODO: Complete replacement with PomView
                if (newVersion.startsWith("${") || newVersion.length() == 0) {
                    // Use PomView as that contains a pre-resolved list of plugins.
                    newVersion = pluginOverridesPomView.get(pr).getVersionString();
                }
                logger.debug("Replacing plugin override version " + p.getVersion() + " with " + newVersion);
                p.setVersion(newVersion);
            }
            // Replacing the element with the fully parsed element from the Model.
            pluginOverrides.remove(p);
            pluginOverrides.add(p);
            // resolve any properties.
            if (p.getConfiguration() != null) {
                processChildren(userProperties, m, (Xpp3Dom) p.getConfiguration());
            }
            if (p.getExecutions() != null) {
                List<PluginExecution> exes = p.getExecutions();
                for (PluginExecution pe : exes) {
                    if (pe.getConfiguration() != null) {
                        processChildren(userProperties, m, (Xpp3Dom) pe.getConfiguration());
                    }
                }
            }
            if (p.getDependencies() != null) {
                for (Dependency d : p.getDependencies()) {
                    if (!isEmpty(d.getVersion()) && d.getVersion().startsWith("${")) {
                        logger.debug("Processing dependency {} and updating with {} ", d, resolveProperty(userProperties, m.getProperties(), d.getVersion()));
                        d.setVersion(resolveProperty(userProperties, m.getProperties(), d.getVersion()));
                    }
                }
            }
            logger.debug("Added plugin override for {} with configuration \n" + p.getConfiguration() + " and executions " + p.getExecutions() + " and dependencies " + p.getDependencies(), p.getId());
        }
    } else {
        throw new ManipulationException("Attempting to align to a BOM that does not have a " + type.toString() + " section");
    }
    return pluginOverrides;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Dependency(org.apache.maven.model.Dependency) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Model(org.apache.maven.model.Model) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) Plugin(org.apache.maven.model.Plugin) HashSet(java.util.HashSet)

Example 4 with PluginView

use of org.commonjava.maven.galley.maven.model.view.PluginView in project galley by Commonjava.

the class MavenModelProcessor method addPlugins.

private void addPlugins(final List<PluginView> plugins, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (plugins != null) {
        for (final PluginView plugin : plugins) {
            ProjectVersionRef pluginRef;
            try {
                if (plugin.getVersion() == null) {
                    logger.error("%s: Cannot find a version for plugin: {}. Skipping.", projectRef, plugin.toXML());
                    continue;
                }
                pluginRef = plugin.asProjectVersionRef();
                // force the InvalidVersionSpecificationException.
                pluginRef.getVersionSpec();
                final String profileId = plugin.getProfileId();
                final URI location = RelationshipUtils.profileLocation(profileId);
                boolean inherited = plugin.getOriginInfo().isInherited();
                boolean mixin = plugin.getOriginInfo().isMixin();
                builder.withPlugins(new SimplePluginRelationship(source, location, projectRef, pluginRef, builder.getNextPluginDependencyIndex(projectRef, managed, inherited), managed, inherited));
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            }
            List<PluginDependencyView> pluginDependencies = null;
            Set<PluginDependencyView> impliedPluginDependencies = null;
            try {
                pluginDependencies = plugin.getLocalPluginDependencies();
                impliedPluginDependencies = plugin.getImpliedPluginDependencies();
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            }
            addPluginDependencies(pluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
            logger.debug("{}: Adding implied dependencies for: {}\n\n  {}", projectRef, pluginRef, impliedPluginDependencies == null ? "-NONE-" : new JoinString("\n  ", impliedPluginDependencies));
            addPluginDependencies(impliedPluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
        }
    }
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) SimplePluginRelationship(org.commonjava.maven.atlas.graph.rel.SimplePluginRelationship) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) URI(java.net.URI) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView)

Example 5 with PluginView

use of org.commonjava.maven.galley.maven.model.view.PluginView in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginDependencyFromManagedInfo.

@Test
public void resolvePluginDependencyFromManagedInfo() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "child.pom.xml");
    lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
    final String base = PROJ_BASE + "dependency-in-managed-parent-plugin/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    final List<PluginDependencyView> deps = pv.getLocalPluginDependencies();
    assertThat(deps, notNullValue());
    assertThat(deps.size(), equalTo(1));
    final PluginDependencyView pdv = deps.get(0);
    assertThat(pdv, notNullValue());
    assertThat(pdv.asArtifactRef().getVersionString(), equalTo("1.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN_DEP && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugin dependencies found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin-dependency relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)5 URI (java.net.URI)4 LinkedHashMap (java.util.LinkedHashMap)4 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)4 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)4 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)3 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)3 Location (org.commonjava.maven.galley.model.Location)3 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)3 Test (org.junit.Test)3 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)2 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1