Search in sources :

Example 1 with PluginDependencyView

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

the class MavenModelProcessor method addPluginDependencies.

private void addPluginDependencies(final Collection<PluginDependencyView> pluginDependencies, final PluginView plugin, final ProjectVersionRef pluginRef, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (pluginDependencies != null) {
        for (final PluginDependencyView dep : pluginDependencies) {
            try {
                final ProjectVersionRef ref = dep.asProjectVersionRef();
                final String profileId = dep.getProfileId();
                final URI location = RelationshipUtils.profileLocation(profileId);
                final ArtifactRef artifactRef = new SimpleArtifactRef(ref, dep.getType(), dep.getClassifier());
                // force the InvalidVersionSpecificationException.
                artifactRef.getVersionSpec();
                boolean inherited = dep.getOriginInfo().isInherited();
                boolean mixin = dep.getOriginInfo().isMixin();
                builder.withPluginDependencies(new SimplePluginDependencyRelationship(source, location, projectRef, pluginRef, artifactRef, builder.getNextPluginDependencyIndex(pluginRef, managed, inherited), managed, inherited));
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            }
        }
    }
}
Also used : PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) SimplePluginDependencyRelationship(org.commonjava.maven.atlas.graph.rel.SimplePluginDependencyRelationship) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) URI(java.net.URI) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)

Example 2 with PluginDependencyView

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

the class AbstractMavenPluginImplications method getImpliedPluginDependencies.

@Override
public Set<PluginDependencyView> getImpliedPluginDependencies(final PluginView pv) throws GalleyMavenException {
    final Map<ProjectRef, Set<ProjectRef>> impliedDepMap = getImpliedRefMap();
    final ProjectRef ref = pv.asProjectRef();
    final Set<ProjectRef> implied = impliedDepMap.get(ref);
    if (implied == null || implied.isEmpty()) {
        return null;
    }
    final Set<PluginDependencyView> views = new HashSet<>(implied.size());
    for (final ProjectRef impliedRef : implied) {
        final PluginDependencyView pd = createPluginDependency(pv, impliedRef);
        views.add(pd);
    }
    return views;
}
Also used : PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) Set(java.util.Set) HashSet(java.util.HashSet) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) HashSet(java.util.HashSet)

Example 3 with PluginDependencyView

use of org.commonjava.maven.galley.maven.model.view.PluginDependencyView 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 4 with PluginDependencyView

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

the class AbstractMavenPluginImplications method createPluginDependency.

protected PluginDependencyView createPluginDependency(final PluginView pv, final ProjectRef ref) throws GalleyMavenException {
    final Map<String, String> map = new LinkedHashMap<>();
    map.put(G, ref.getGroupId());
    map.put(A, ref.getArtifactId());
    map.put(V, pv.getVersion());
    final Element element = pv.getElement();
    return new PluginDependencyView(pv.getPomView(), pv, xml.createElement(element, "dependencies/dependency", map), new OriginInfo());
}
Also used : PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) Element(org.w3c.dom.Element) OriginInfo(org.commonjava.maven.galley.maven.model.view.OriginInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with PluginDependencyView

use of org.commonjava.maven.galley.maven.model.view.PluginDependencyView 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

PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)5 URI (java.net.URI)3 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)3 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)3 LinkedHashMap (java.util.LinkedHashMap)2 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)2 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)2 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)2 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)1 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)1 SimplePluginDependencyRelationship (org.commonjava.maven.atlas.graph.rel.SimplePluginDependencyRelationship)1 SimplePluginRelationship (org.commonjava.maven.atlas.graph.rel.SimplePluginRelationship)1 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)1 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)1 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)1 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)1 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)1