Example usage for org.apache.maven.repository.legacy.metadata ArtifactMetadataSource retrieveAvailableVersions

List of usage examples for org.apache.maven.repository.legacy.metadata ArtifactMetadataSource retrieveAvailableVersions

Introduction

In this page you can find the example usage for org.apache.maven.repository.legacy.metadata ArtifactMetadataSource retrieveAvailableVersions.

Prototype

List<ArtifactVersion> retrieveAvailableVersions(Artifact artifact, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories) throws ArtifactMetadataRetrievalException;

Source Link

Document

Get a list of available versions for an artifact in the remote repository

Usage

From source file:org.jboss.tools.maven.core.internal.resolution.ArtifactResolutionService.java

License:Open Source License

List<String> getAvailableReleasedVersions(Artifact artifact, List<ArtifactRepository> repositories,
        IProgressMonitor monitor) throws CoreException {

    ArtifactMetadataSource source = getArtifactMetadataSource();

    IMaven maven = MavenPlugin.getMaven();
    ArtifactRepository localRepository = maven.getLocalRepository();
    try {/*from  ww w  .ja v a2s  .  c  o m*/
        String versionRangeSpec = artifact.getVersion() == null ? "[0,)" : artifact.getVersion(); //$NON-NLS-1$
        VersionRange versionRange = VersionRange.createFromVersionSpec(versionRangeSpec);
        artifact.setVersionRange(versionRange);
        List<ArtifactVersion> fullVersions = source.retrieveAvailableVersions(artifact, localRepository,
                repositories);
        List<String> versions = new ArrayList<String>(fullVersions.size());
        for (ArtifactVersion aVersion : fullVersions) {
            String version = aVersion.toString();
            if (version.endsWith("-SNAPSHOT")) { //$NON-NLS-1$
                continue;
            }
            if (versionRange.containsVersion(aVersion)) {
                versions.add(version);
            }
        }
        return versions;
    } catch (Exception e) {
        throw toCoreException(e);
    }
}

From source file:org.jboss.tools.maven.polyglot.poc.internal.core.ArtifactSearcher.java

License:Open Source License

public static String getLatestVersion(Artifact artifact, IProgressMonitor monitor) throws CoreException {
    monitor.beginTask("Getting latest version for " + artifact.getGroupId() + ":" + artifact.getArtifactId(),
            1);/*from   ww w  .jav  a 2 s .co  m*/
    try {
        final IMaven maven = MavenPlugin.getMaven();
        final ArtifactMetadataSource source = ((MavenImpl) maven).getPlexusContainer().lookup(
                ArtifactMetadataSource.class, "org.apache.maven.artifact.metadata.ArtifactMetadataSource", //$NON-NLS-1$
                "maven"); //$NON-NLS-2$
        List<ArtifactVersion> versions = source.retrieveAvailableVersions(artifact, maven.getLocalRepository(),
                maven.getArtifactRepositories());

        Collections.reverse(versions);
        for (ArtifactVersion artifactVersion : versions) {
            String version = artifactVersion.toString();
            if (!version.endsWith("-SNAPSHOT")) {
                return version;
            }
        }
    } catch (Exception e) {
        throw new CoreException(new Status(Status.ERROR, PolyglotSupportActivator.PLUGIN_ID,
                "Error resolving version range", e)); //$NON-NLS-1$
    }
    return null;
}

From source file:org.switchyard.tools.ui.M2EUtils.java

License:Open Source License

/**
 * Utility method for resolving the version range for a particular artifact.
 * /*from www  .  j  a  v a2 s .  c  o m*/
 * It would be nice if this were exposed directly from m2e.
 * 
 * @param artifact to resolve.
 * @param monitor the progress monitor
 * 
 * @return the version range for the artifact.
 * @throws CoreException if an error occurs.
 */
public static List<ArtifactVersion> resolveVersionRange(Artifact artifact, IProgressMonitor monitor)
        throws CoreException {
    try {
        final IMaven maven = MavenPlugin.getMaven();
        final ArtifactMetadataSource source = ((MavenImpl) maven).getPlexusContainer().lookup(
                ArtifactMetadataSource.class, "org.apache.maven.artifact.metadata.ArtifactMetadataSource", //$NON-NLS-1$
                "maven"); //$NON-NLS-2$
        return source.retrieveAvailableVersions(artifact, maven.getLocalRepository(),
                maven.getArtifactRepositories());
    } catch (Exception e) {
        throw new CoreException(
                new Status(Status.ERROR, Activator.PLUGIN_ID, "Error resolving version range", e)); //$NON-NLS-1$
    }
}