Search in sources :

Example 6 with ArtifactVersion

use of org.apache.maven.artifact.versioning.ArtifactVersion in project intellij-community by JetBrains.

the class Maven3ServerEmbedder method retrieveAvailableVersions.

@NotNull
@Override
public List<String> retrieveAvailableVersions(@NotNull String groupId, @NotNull String artifactId, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException {
    try {
        Artifact artifact = new DefaultArtifact(groupId, artifactId, "", Artifact.SCOPE_COMPILE, "pom", null, new DefaultArtifactHandler("pom"));
        List<ArtifactVersion> versions = getComponent(ArtifactMetadataSource.class).retrieveAvailableVersions(artifact, getLocalRepository(), convertRepositories(remoteRepositories));
        return ContainerUtil.map(versions, new Function<ArtifactVersion, String>() {

            @Override
            public String fun(ArtifactVersion version) {
                return version.toString();
            }
        });
    } catch (Exception e) {
        Maven3ServerGlobals.getLogger().info(e);
    }
    return Collections.emptyList();
}
Also used : ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) RemoteException(java.rmi.RemoteException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ArtifactVersion

use of org.apache.maven.artifact.versioning.ArtifactVersion in project maven-plugins by apache.

the class AbstractJavadocMojo method populateCompileArtifactMap.

/**
     * Method to put the artifacts in the hashmap.
     *
     * @param compileArtifactMap the hashmap that will contain the artifacts
     * @param artifactList       the list of artifacts that will be put in the map
     * @throws MavenReportException if any
     */
private void populateCompileArtifactMap(Map<String, Artifact> compileArtifactMap, Collection<Artifact> artifactList) throws MavenReportException {
    if (artifactList == null) {
        return;
    }
    for (Artifact newArtifact : artifactList) {
        File file = newArtifact.getFile();
        if (file == null) {
            throw new MavenReportException("Error in plugin descriptor - " + "dependency was not resolved for artifact: " + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":" + newArtifact.getVersion());
        }
        if (compileArtifactMap.get(newArtifact.getDependencyConflictId()) != null) {
            Artifact oldArtifact = compileArtifactMap.get(newArtifact.getDependencyConflictId());
            ArtifactVersion oldVersion = new DefaultArtifactVersion(oldArtifact.getVersion());
            ArtifactVersion newVersion = new DefaultArtifactVersion(newArtifact.getVersion());
            if (newVersion.compareTo(oldVersion) > 0) {
                compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
            }
        } else {
            compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
        }
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) File(java.io.File) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 8 with ArtifactVersion

use of org.apache.maven.artifact.versioning.ArtifactVersion in project maven-plugins by apache.

the class DependencyManagementRenderer method getDependencyRow.

@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
    Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
    StringBuilder licensesBuffer = new StringBuilder();
    String url = null;
    try {
        VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
        if (range.getRecommendedVersion() == null) {
            // MPIR-216: no direct version but version range: need to choose one precise version
            log.debug("Resolving range for DependencyManagement on " + artifact.getId());
            List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
            // only use versions from range
            for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
                if (!range.containsVersion(iter.next())) {
                    iter.remove();
                }
            }
            // select latest, assuming pom information will be the most accurate
            if (versions.size() > 0) {
                ArtifactVersion maxArtifactVersion = Collections.max(versions);
                artifact.setVersion(maxArtifactVersion.toString());
                log.debug("DependencyManagement resolved: " + artifact.getId());
            }
        }
        url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
        MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
        List<License> licenses = artifactProject.getLicenses();
        for (License license : licenses) {
            String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
            if (licensesBuffer.length() > 0) {
                licensesBuffer.append(", ");
            }
            licensesBuffer.append(licenseCell);
        }
    } catch (InvalidVersionSpecificationException e) {
        log.warn("Unable to parse version for " + artifact.getId(), e);
    } catch (ArtifactMetadataRetrievalException e) {
        log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
    } catch (ProjectBuildingException e) {
        log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
    }
    String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
    if (hasClassifier) {
        return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
    }
    return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
Also used : ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) License(org.apache.maven.model.License) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) MavenProject(org.apache.maven.project.MavenProject)

Example 9 with ArtifactVersion

use of org.apache.maven.artifact.versioning.ArtifactVersion in project sling by apache.

the class AbstractBundleListMojo method getArtifact.

/**
     * Get a resolved Artifact from the coordinates provided
     *
     * @return the artifact, which has been resolved.
     * @throws MojoExecutionException
     */
protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier) throws MojoExecutionException {
    Artifact artifact;
    VersionRange vr;
    try {
        vr = VersionRange.createFromVersionSpec(version);
    } catch (InvalidVersionSpecificationException e) {
        vr = VersionRange.createFromVersion(version);
    }
    if (StringUtils.isEmpty(classifier)) {
        artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE);
    } else {
        artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier, Artifact.SCOPE_COMPILE);
    }
    // This code kicks in when the version specifier is a range.
    if (vr.getRecommendedVersion() == null) {
        try {
            List<ArtifactVersion> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos);
            ArtifactVersion resolvedVersion = vr.matchVersion(availVersions);
            artifact.setVersion(resolvedVersion.toString());
        } catch (ArtifactMetadataRetrievalException e) {
            throw new MojoExecutionException("Unable to find version for artifact", e);
        }
    }
    try {
        resolver.resolve(artifact, remoteRepos, local);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to resolve artifact.", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Unable to find artifact.", e);
    }
    return artifact;
}
Also used : ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VersionRange(org.apache.maven.artifact.versioning.VersionRange) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)9 Artifact (org.apache.maven.artifact.Artifact)5 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)4 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 File (java.io.File)2 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)2 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 MavenProject (org.apache.maven.project.MavenProject)2 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 OverConstrainedVersionException (org.apache.maven.artifact.versioning.OverConstrainedVersionException)1