Search in sources :

Example 1 with InvalidVersionSpecificationException

use of org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException in project galley by Commonjava.

the class VersionResolverImpl method addSnapshotFrom.

private void addSnapshotFrom(final MavenMetadataView metadata, final Location location, final ProjectVersionRef ref, final Map<SingleVersion, Location> available) throws GalleyMavenException {
    final String version = metadata.resolveSingleValue(SNAP_VERSION_XPATH);
    logger.debug("Latest snapshot version in metadata is: {}", version);
    if (version != null) {
        try {
            final SingleVersion ver = VersionUtils.createSingleVersion(version);
            if (!available.containsKey(ver)) {
                logger.debug("Found candidate snapshot: {}", ver);
                available.put(ver, location);
            }
        } catch (final InvalidVersionSpecificationException e) {
            debug("Unparsable version spec found in metadata: '%s' for: %s from: %s", e, version, ref, location);
        }
    }
}
Also used : InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion)

Example 2 with InvalidVersionSpecificationException

use of org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException in project galley by Commonjava.

the class MavenModelProcessor method addParentRelationship.

protected void addParentRelationship(final URI source, final Builder builder, final MavenPomView pomView, final ProjectVersionRef projectRef) {
    try {
        final ParentView parent = pomView.getParent();
        if (parent != null) {
            final ProjectVersionRef ref = parent.asProjectVersionRef();
            // force the InvalidVersionSpecificationException.
            ref.getVersionSpec();
            logger.info("Adding parent relationship for: {} to : {}", builder.getProjectRef(), ref);
            builder.withParent(new SimpleParentRelationship(source, builder.getProjectRef(), ref));
        } else {
            logger.info("Adding self-referential parent relationship for: {} to signify project has no parent, but is parsable.", builder.getProjectRef());
            builder.withParent(new SimpleParentRelationship(builder.getProjectRef()));
        }
    } catch (final GalleyMavenException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    } catch (final InvalidVersionSpecificationException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    } catch (final InvalidRefException e) {
        logger.error(String.format("%s: Parent reference is invalid! Reason: %s. Skipping.", projectRef, e.getMessage()), e);
    }
}
Also used : ParentView(org.commonjava.maven.galley.maven.model.view.ParentView) 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) SimpleParentRelationship(org.commonjava.maven.atlas.graph.rel.SimpleParentRelationship)

Example 3 with InvalidVersionSpecificationException

use of org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException 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 4 with InvalidVersionSpecificationException

use of org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException in project galley by Commonjava.

the class VersionResolverImpl method resolveLatestMultiRefWithLocation.

private ProjectVersionRefLocation resolveLatestMultiRefWithLocation(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref.asProjectRef(), Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final List<String> versions = metadata.resolveValues("/metadata/versioning/versions/version");
                if (versions != null) {
                    for (final String version : versions) {
                        try {
                            final SingleVersion spec = VersionUtils.createSingleVersion(version);
                            if (!available.containsKey(spec)) {
                                available.put(spec, location);
                            }
                        } catch (final InvalidVersionSpecificationException e) {
                            debug("Unparsable version spec found in metadata: '%s' for: %s from: %s.", e, version, ref, location);
                        }
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for variable version of: '%s' from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        final VersionSpec spec = ref.getVersionSpec();
        final List<SingleVersion> versions = new ArrayList<>(available.keySet());
        Collections.sort(versions);
        while (!versions.isEmpty()) {
            final SingleVersion selected = selectionStrategy.select(versions);
            if (selected == null) {
                return null;
            }
            versions.remove(selected);
            if (selected.isConcrete() && spec.contains(selected)) {
                return new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected));
            }
        }
    }
    return null;
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) VersionSpec(org.commonjava.maven.atlas.ident.version.VersionSpec) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 5 with InvalidVersionSpecificationException

use of org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException in project galley by Commonjava.

the class VersionResolverImpl method resolveAllSnapshotRefsWithLocations.

private List<ProjectVersionRefLocation> resolveAllSnapshotRefsWithLocations(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref, Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final String latest = metadata.resolveSingleValue("/metadata/versioning/latest");
                if (latest != null) {
                    try {
                        final SingleVersion ver = VersionUtils.createSingleVersion(latest);
                        if (ver.isSnapshot()) {
                            if (!available.containsKey(ver)) {
                                available.put(ver, location);
                            }
                        }
                    } catch (final InvalidVersionSpecificationException e) {
                        debug("Unparsable version spec found in metadata: '%s' for: %s from: %s", e, latest, ref, location);
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for snapshot version of: %s from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        return Collections.emptyList();
    }
    final List<SingleVersion> versions = new ArrayList<>(available.keySet());
    Collections.sort(versions);
    final List<ProjectVersionRefLocation> result = new ArrayList<>();
    while (!versions.isEmpty()) {
        final SingleVersion selected = selectionStrategy.select(versions);
        if (selected != null) {
            versions.remove(selected);
            result.add(new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected)));
        }
    }
    return result;
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) TreeMap(java.util.TreeMap) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)11 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)7 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)6 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)4 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)3 MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)3 Location (org.commonjava.maven.galley.model.Location)3 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)2 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)2 VersionSpec (org.commonjava.maven.atlas.ident.version.VersionSpec)2 DependencyView (org.commonjava.maven.galley.maven.model.view.DependencyView)2 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)1 Builder (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships.Builder)1 SimpleBomRelationship (org.commonjava.maven.atlas.graph.rel.SimpleBomRelationship)1