Example usage for org.apache.maven.artifact Artifact LATEST_VERSION

List of usage examples for org.apache.maven.artifact Artifact LATEST_VERSION

Introduction

In this page you can find the example usage for org.apache.maven.artifact Artifact LATEST_VERSION.

Prototype

String LATEST_VERSION

To view the source code for org.apache.maven.artifact Artifact LATEST_VERSION.

Click Source Link

Usage

From source file:com.googlecode.jndiresources.maven.ManageArtifact.java

License:Apache License

/**
 * Load the artifact in local repository, and return the file path.
 * /*from  ww w. j av  a 2  s . c  om*/
 * @param groupId The Maven group id.
 * @param artifactId The Maven artifact id.
 * @param version The Maven version.
 * @param repositories A list of String with remoteRepositories or null.
 * @return The path in local repository.
 * @throws MavenException If error when dowload or identify the maven jar
 *             file.
 */
public static String getArtifacts(final String groupId, final String artifactId, final String version,
        final List repositories) throws MavenException {
    try {
        final String scope = Artifact.LATEST_VERSION;
        final String type = "jar";

        final MavenEmbedder maven = new MavenEmbedder();
        maven.setClassLoader(Thread.currentThread().getContextClassLoader());
        maven.setAlignWithUserInstallation(true);
        maven.start();
        final ArtifactRepository localRepository = maven.getLocalRepository();

        Artifact artifact;
        artifact = maven.createArtifact(groupId, artifactId, version, scope, type);
        final List remoteRepositories = new ArrayList();
        if ((repositories == null) || repositories.isEmpty())
            remoteRepositories.add(maven.createRepository(CENTRAL_REPO, "central"));
        else {
            int id = 0;
            for (final Iterator i = repositories.iterator(); i.hasNext();) {
                remoteRepositories.add(maven.createRepository((String) i.next(), "central_" + id++));
            }
        }
        maven.resolveAll(artifact, remoteRepositories, localRepository);
        return null;
    } catch (Exception e) {
        throw new MavenException("Repository error", e);
    }
}

From source file:com.luke.maven.plugins.Dependencies.java

License:Apache License

private void resolveDependencies(MavenProject p) throws ProjectBuildingException {
    count++;/*from   w  ww  .  j av a2 s  . c  om*/
    Set<Artifact> artifacts = p.createArtifacts(factory, Artifact.LATEST_VERSION, null);
    for (Artifact a : artifacts) {
        System.out.println(
                tabGen(count) + "+- " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
        MavenProject pomProject = mavenProjectBuilder.buildFromRepository(a, remoteRepos, local);
        resolveDependencies(pomProject);
    }
    count--;
}

From source file:hudson.maven.artifact.transform.AbstractVersionTransformation.java

License:Apache License

protected String resolveVersion(Artifact artifact, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories) throws RepositoryMetadataResolutionException {
    RepositoryMetadata metadata;//from w  w  w .jav  a  2  s .  c o  m
    // Don't use snapshot metadata for LATEST (which isSnapshot returns true for)
    if (!artifact.isSnapshot() || Artifact.LATEST_VERSION.equals(artifact.getBaseVersion())) {
        metadata = new ArtifactRepositoryMetadata(artifact);
    } else {
        metadata = new SnapshotArtifactRepositoryMetadata(artifact);
    }

    repositoryMetadataManager.resolve(metadata, remoteRepositories, localRepository);

    artifact.addMetadata(metadata);

    Metadata repoMetadata = metadata.getMetadata();
    String version = null;
    if (repoMetadata != null && repoMetadata.getVersioning() != null) {
        version = constructVersion(repoMetadata.getVersioning(), artifact.getBaseVersion());
    }

    if (version == null) {
        // use the local copy, or if it doesn't exist - go to the remote repo for it
        version = artifact.getBaseVersion();
    }

    // TODO: also do this logging for other metadata?
    // TODO: figure out way to avoid duplicated message
    if (getLogger().isDebugEnabled()) {
        if (!version.equals(artifact.getBaseVersion())) {
            String message = artifact.getArtifactId() + ": resolved to version " + version;
            if (artifact.getRepository() != null) {
                message += " from repository " + artifact.getRepository().getId();
            } else {
                message += " from local repository";
            }
            getLogger().debug(message);
        } else {
            // Locally installed file is newer, don't use the resolved version
            getLogger().debug(artifact.getArtifactId() + ": using locally installed snapshot");
        }
    }
    return version;
}

From source file:org.codehaus.mojo.pomtools.helpers.MetadataHelper.java

License:Apache License

/** Simple wrapper for 
 * {@link ArtifactFactory#createArtifact(java.lang.String, java.lang.String, java.lang.String, 
 * java.lang.String, java.lang.String)}/*from ww w  .j a va2s .c o m*/
 * 
 */
public Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) {
    return artifactFactory.createArtifact(groupId, artifactId,
            StringUtils.defaultString(version, Artifact.LATEST_VERSION), scope,
            StringUtils.defaultString(type, "jar"));
}

From source file:org.maven.ide.eclipse.checkstyle.AbstractMavenPluginProjectConfigurator.java

License:Apache License

private Artifact resolvePluginArtifact(Plugin mavenPlugin, MavenProject mavenProject, IProgressMonitor monitor)
        throws CoreException {
    String groupId = mavenPlugin.getGroupId();
    String artifactId = mavenPlugin.getArtifactId();
    String version = mavenPlugin.getVersion();
    if (version == null) {
        version = Artifact.LATEST_VERSION;
    }/*from   w  ww.  java 2 s .c o  m*/
    return maven.resolve(groupId, artifactId, version, "compile", "maven-plugin",
            mavenProject.getRemoteArtifactRepositories(), monitor);

}

From source file:org.sonar.updatecenter.deprecated.UpdateCenter.java

License:Open Source License

private History<Plugin> resolvePluginHistory(String id) throws Exception {
    String groupId = StringUtils.substringBefore(id, ":");
    String artifactId = StringUtils.substringAfter(id, ":");

    Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, Artifact.LATEST_VERSION,
            Artifact.SCOPE_COMPILE, ARTIFACT_JAR_TYPE);

    List<ArtifactVersion> versions = filterSnapshots(
            metadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories));

    History<Plugin> history = new History<Plugin>();
    for (ArtifactVersion version : versions) {
        Plugin plugin = org.sonar.updatecenter.deprecated.Plugin
                .extractMetadata(resolve(artifact.getGroupId(), artifact.getArtifactId(), version.toString()));
        history.addArtifact(version, plugin);

        MavenProject project = mavenProjectBuilder
                .buildFromRepository(//w w  w  . ja  v a2  s .c o  m
                        artifactFactory.createArtifact(groupId, artifactId, version.toString(),
                                Artifact.SCOPE_COMPILE, ARTIFACT_POM_TYPE),
                        remoteRepositories, localRepository);

        if (plugin.getVersion() == null) {
            // Legacy plugin - set default values
            plugin.setKey(project.getArtifactId());
            plugin.setName(project.getName());
            plugin.setVersion(project.getVersion());

            String sonarVersion = "1.10"; // TODO Is it minimal version for all extension points ?
            for (Dependency dependency : project.getDependencies()) {
                if ("sonar-plugin-api".equals(dependency.getArtifactId())) { // TODO dirty hack
                    sonarVersion = dependency.getVersion();
                }
            }

            plugin.setRequiredSonarVersion(sonarVersion);
            plugin.setHomepage(project.getUrl());
        }
        plugin.setDownloadUrl(getPluginDownloadUrl(groupId, artifactId, plugin.getVersion()));
        // There is no equivalent for following properties in MANIFEST.MF
        if (project.getIssueManagement() != null) {
            plugin.setIssueTracker(project.getIssueManagement().getUrl());
        } else {
            System.out.println("Unknown Issue Management for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getScm() != null) {
            String scmUrl = project.getScm().getUrl();
            if (StringUtils.startsWith(scmUrl, "scm:")) {
                scmUrl = StringUtils.substringAfter(StringUtils.substringAfter(scmUrl, ":"), ":");
            }
            plugin.setSources(scmUrl);
        } else {
            System.out.println("Unknown SCM for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getLicenses() != null && project.getLicenses().size() > 0) {
            plugin.setLicense(project.getLicenses().get(0).getName());
        } else {
            System.out.println("Unknown License for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getDevelopers().size() > 0) {
            plugin.setDevelopers(project.getDevelopers());
        } else {
            System.out.println("Unknown Developers for " + plugin.getKey() + ":" + plugin.getVersion());
        }
    }
    return history;
}