Search in sources :

Example 1 with DependencyView

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

the class MavenModelProcessorTest method resolveExpressionsBothInDepAndProfile.

@Test
public void resolveExpressionsBothInDepAndProfile() 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 + "resolve-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));
    String url = pomView.resolveExpressions("${repo.url}", "test.oracle");
    assertThat(url, equalTo("http://test.oracle.repository"));
    List<DependencyView> dvs = pomView.getAllDirectDependencies();
    assertThat(dvs.get(0).getVersion(), equalTo("2.5"));
    String version = pomView.resolveExpressions("${commons.lang.value}");
    assertThat(version, equalTo("2.5"));
}
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) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) LinkedHashMap(java.util.LinkedHashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) 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 DependencyView

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

the class MavenModelProcessor method addDependencyRelationships.

protected void addDependencyRelationships(final URI source, final Builder builder, final MavenPomView pomView, final ProjectVersionRef projectRef, final boolean includeManagedDependencies) {
    // regardless of whether we're processing managed info, this is STRUCTURAL, so always grab it!
    List<DependencyView> boms = null;
    try {
        boms = pomView.getAllBOMs();
    } catch (final GalleyMavenException e) {
        logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidVersionSpecificationException e) {
        logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidRefException e) {
        logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    }
    if (boms != null) {
        for (int i = 0; i < boms.size(); i++) {
            final DependencyView bomView = boms.get(i);
            try {
                builder.withBoms(new SimpleBomRelationship(source, projectRef, bomView.asProjectVersionRef(), i, bomView.getOriginInfo().isInherited(), bomView.getOriginInfo().isMixin()));
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
            }
        }
    }
    if (includeManagedDependencies) {
        List<DependencyView> deps = null;
        try {
            deps = pomView.getAllManagedDependencies();
        } catch (final GalleyMavenException e) {
            logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
        } catch (final InvalidVersionSpecificationException e) {
            logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
        } catch (final InvalidRefException e) {
            logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
        }
        addDependencies(deps, projectRef, builder, source, true);
    }
    List<DependencyView> deps = null;
    try {
        deps = pomView.getAllDirectDependencies();
    } catch (final GalleyMavenException e) {
        logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidVersionSpecificationException e) {
        logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidRefException e) {
        logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
    }
    addDependencies(deps, projectRef, builder, source, false);
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) SimpleBomRelationship(org.commonjava.maven.atlas.graph.rel.SimpleBomRelationship) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView)

Example 3 with DependencyView

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

the class ModelIO method getRemoteDependencyVersionOverrides.

public Map<ArtifactRef, String> getRemoteDependencyVersionOverrides(final ProjectVersionRef ref) throws ManipulationException {
    logger.debug("Resolving dependency management GAV: " + ref);
    final Map<ArtifactRef, String> versionOverrides = new LinkedHashMap<>();
    try {
        final MavenPomView pomView = galleyWrapper.readPomView(ref);
        // TODO: active profiles!
        final List<DependencyView> deps = pomView.getAllManagedDependencies();
        if (deps == null || deps.isEmpty()) {
            logger.warn("Attempting to align to a BOM that does not have a dependencyManagement section");
        } else {
            for (final DependencyView dep : deps) {
                versionOverrides.put(dep.asArtifactRef(), dep.getVersion());
                logger.debug("Added version override for: " + dep.asProjectRef().toString() + ":" + dep.getVersion());
            }
        }
    } catch (final GalleyMavenException e) {
        throw new ManipulationException("Unable to resolve: %s", e, ref);
    }
    return versionOverrides;
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DependencyView

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

the class MavenModelProcessor method addDependencies.

private void addDependencies(final List<DependencyView> deps, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (deps != null) {
        for (final DependencyView dep : deps) {
            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();
                Set<ProjectRefView> exclusionsView = dep.getExclusions();
                ProjectRef[] excludes;
                if (exclusionsView != null && !exclusionsView.isEmpty()) {
                    excludes = new ProjectRef[exclusionsView.size()];
                    int i = 0;
                    for (ProjectRefView exclusionView : exclusionsView) {
                        excludes[i] = exclusionView.asProjectRef();
                        i++;
                    }
                } else {
                    excludes = new ProjectRef[0];
                }
                builder.withDependencies(new SimpleDependencyRelationship(source, location, projectRef, artifactRef, dep.getScope(), builder.getNextDependencyIndex(managed), managed, dep.getOriginInfo().isInherited(), dep.isOptional(), excludes));
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            }
        }
    }
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectRefView(org.commonjava.maven.galley.maven.model.view.ProjectRefView) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) URI(java.net.URI) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleDependencyRelationship(org.commonjava.maven.atlas.graph.rel.SimpleDependencyRelationship) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef)

Example 5 with DependencyView

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

the class MavenPomReader method assembleImportedInformation.

private void assembleImportedInformation(final MavenPomView view, final List<? extends Location> locations) throws GalleyMavenException {
    final List<DependencyView> md = view.getAllBOMs();
    for (final DependencyView dv : md) {
        final ProjectVersionRef ref = dv.asProjectVersionRef();
        logger.debug("Found BOM: {} for: {}", ref, view.getRef());
        // This is a BOM, it's likely to be used in multiple locations...cache this.
        final MavenPomView imp = read(ref, locations, true);
        view.addMixin(new MavenXmlMixin<>(imp, MavenXmlMixin.DEPENDENCY_MIXIN));
    }
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Aggregations

DependencyView (org.commonjava.maven.galley.maven.model.view.DependencyView)5 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)3 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)3 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)3 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)3 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)2 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)2 SimpleBomRelationship (org.commonjava.maven.atlas.graph.rel.SimpleBomRelationship)1 SimpleDependencyRelationship (org.commonjava.maven.atlas.graph.rel.SimpleDependencyRelationship)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 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 ProjectRefView (org.commonjava.maven.galley.maven.model.view.ProjectRefView)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Location (org.commonjava.maven.galley.model.Location)1