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

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

Introduction

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

Prototype

String RELEASE_VERSION

To view the source code for org.apache.maven.artifact Artifact RELEASE_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 a v a 2 s .co m
 * @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.
 * @throws ArtifactNotFoundException If artifact is not found.
 * @throws ResourceDoesNotExistException If error.
 */
public static String getArtifact(final String groupId, final String artifactId, final String version,
        final List repositories)
        throws MavenException, ArtifactNotFoundException, ResourceDoesNotExistException {
    // TODO : rcuperer la bonne version en cas de suprieur...
    try {
        if (maven_ == null) {
            maven_ = new MavenEmbedder();
            maven_.setClassLoader(Thread.currentThread().getContextClassLoader());
            maven_.setAlignWithUserInstallation(true);
            maven_.start();
        }

        final String scope = Artifact.RELEASE_VERSION;
        final String type = "jar";
        final ArtifactRepository localRepository = maven_.getLocalRepository();

        final 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_.resolve(artifact, remoteRepositories, localRepository);
        return localRepository.getBasedir() + File.separatorChar + localRepository.pathOf(artifact);
    } catch (ArtifactNotFoundException e) {
        throw (ArtifactNotFoundException) e.fillInStackTrace();
    } catch (Exception e) {
        throw new MavenException("Repository error", e);
    }
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.util.ReportUtils.java

License:Apache License

/**
 * Determines the version of the given skin. If the version is not set in the
 * skin, the {@link Artifact#RELEASE_VERSION} is returned.
 *
 * @param skin the skin whose version is requested.
 * @return the version of the skin or {@link Artifact#RELEASE_VERSION} as
 *         default.//  w w  w .  ja va2s .  c o  m
 */
private static String determineVersion(final Skin skin) {
    String version = skin.getVersion();
    if (version == null) {
        version = Artifact.RELEASE_VERSION;
    }
    return version;
}

From source file:org.apache.camel.maven.ConvertersMojo.java

License:Apache License

private File getSkinArtifactFile(DecorationModel decoration) throws MojoFailureException {

    Skin skin = decoration.getSkin();/*from  ww w. j a va 2 s.c  om*/
    if (skin == null) {
        skin = Skin.getDefaultSkin();
    }

    String version = skin.getVersion();
    Artifact artifact;
    try {
        if (version == null) {
            version = Artifact.RELEASE_VERSION;
        }

        VersionRange versionSpec = VersionRange.createFromVersionSpec(version);
        artifact = artifactFactory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(),
                versionSpec, "jar", null, null);

        artifactResolver.resolve(artifact, remoteArtifactRepositories, localRepository);
        return artifact.getFile();
    } catch (InvalidVersionSpecificationException e) {
        throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage());
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException("Unable to fink skin: " + e.getMessage());
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("The skin does not exist: " + e.getMessage());
    }
}

From source file:org.apache.rat.mp.RatReportMojo.java

License:Apache License

/**
 * Returns the skins artifact file.// w w  w .  j a va  2  s  .  c o  m
 *
 * @return Artifact file
 * @throws MojoFailureException   An error in the plugin configuration was detected.
 * @throws MojoExecutionException An error occurred while searching for the artifact file.
 */
private File getSkinArtifactFile() throws MojoFailureException, MojoExecutionException {
    final Skin skin = Skin.getDefaultSkin();

    String version = skin.getVersion();
    final Artifact artifact;
    try {
        if (version == null) {
            version = Artifact.RELEASE_VERSION;
        }
        VersionRange versionSpec = VersionRange.createFromVersionSpec(version);
        artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar",
                null, null);

        resolver.resolve(artifact, getProject().getRemoteArtifactRepositories(), localRepository);
    } catch (InvalidVersionSpecificationException e) {
        throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage());
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to find skin", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("The skin does not exist: " + e.getMessage());
    }

    return artifact.getFile();
}

From source file:org.codehaus.mojo.clirr.ClirrReport.java

License:Apache License

private File getSkinArtifactFile() throws MojoFailureException, MojoExecutionException {
    Skin skin = Skin.getDefaultSkin();//ww w. ja v  a  2 s . c  om

    String version = skin.getVersion();
    Artifact artifact;
    try {
        if (version == null) {
            version = Artifact.RELEASE_VERSION;
        }
        VersionRange versionSpec = VersionRange.createFromVersionSpec(version);
        artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar",
                null, null);

        resolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository);
    } catch (InvalidVersionSpecificationException e) {
        throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage());
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to find skin", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("The skin does not exist: " + e.getMessage());
    }

    return artifact.getFile();
}

From source file:org.codehaus.mojo.rat.RatReportMojo.java

License:Apache License

/**
 * Returns the skins artifact file./*  w w w .j  av a2  s.co m*/
 * 
 * @throws MojoFailureException
 *             An error in the plugin configuration was detected.
 * @throws MojoExecutionException
 *             An error occurred while searching for the artifact file.
 * @return Artifact file
 */
private File getSkinArtifactFile() throws MojoFailureException, MojoExecutionException {
    Skin skin = Skin.getDefaultSkin();

    String version = skin.getVersion();
    Artifact artifact;
    try {
        if (version == null) {
            version = Artifact.RELEASE_VERSION;
        }
        VersionRange versionSpec = VersionRange.createFromVersionSpec(version);
        artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar",
                null, null);

        resolver.resolve(artifact, getProject().getRemoteArtifactRepositories(), localRepository);
    } catch (InvalidVersionSpecificationException e) {
        throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage());
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to find skin", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("The skin does not exist: " + e.getMessage());
    }

    return artifact.getFile();
}

From source file:org.fedoraproject.maven.repository.internal.FossPluginVersionResolver.java

License:Open Source License

@Override
public PluginVersionResult resolve(PluginVersionRequest request) throws PluginVersionResolutionException {

    //        final PluginVersionRequest alternate =
    //                new DefaultPluginVersionRequest(plugin(request),
    //                        request.getRepositorySession(),
    //                        remotes()).setPom(request.getPom());

    logger.warn("No version specified for plugin " + request.getGroupId() + ":" + request.getArtifactId()
            + ", falling back to RELEASE");
    //final PluginVersionResult result = delegate.resolve(request);
    //        logger.warn("Would have been " + result.getVersion() + " from " +
    //                result.getRemoteRepository());
    return new PluginVersionResult() {
        @Override/*  www. ja v  a  2 s.c  o  m*/
        public String getVersion() {
            return Artifact.RELEASE_VERSION;
        }

        @Override
        public ArtifactRepository getRepository() {
            throw new RuntimeException("NYI: .getRemoteRepository");
        }
    };
}

From source file:org.sonatype.flexmojos.utilities.MavenUtils.java

License:Apache License

/**
 * Get dependency artifacts for a project using the local and remote repositories to resolve the artifacts
 * //from   w w w  . j a  va2s. c om
 * @param project maven project
 * @param resolver artifact resolver
 * @param localRepository artifact repository
 * @param remoteRepositories List of remote repositories
 * @param artifactMetadataSource artifactMetadataSource
 * @param artifactFactory TODO
 * @return all dependencies from the project
 * @throws MojoExecutionException thrown if an exception occured during artifact resolving
 */
@SuppressWarnings("unchecked")
public static Set<Artifact> getDependencyArtifacts(MavenProject project, ArtifactResolver resolver,
        ArtifactRepository localRepository, List remoteRepositories,
        ArtifactMetadataSource artifactMetadataSource, ArtifactFactory artifactFactory)
        throws MojoExecutionException {
    Set<Artifact> artifacts = project.getDependencyArtifacts();
    if (artifacts == null) {
        try {
            artifacts = project.createArtifacts(artifactFactory, null, null);
        } catch (InvalidDependencyVersionException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        project.setDependencyArtifacts(artifacts);
    }

    ArtifactResolutionResult arr;
    try {
        arr = resolver.resolveTransitively(project.getDependencyArtifacts(), project.getArtifact(),
                remoteRepositories, localRepository, artifactMetadataSource);
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    Set<Artifact> result = arr.getArtifacts();

    // ## 6/18/09 StoneRiver Change to resolve RELEASE Artifact version ##
    for (Artifact artifact : result) {
        if (artifact.getVersion().equals(Artifact.RELEASE_VERSION)) {
            getReleaseVersion(artifact, localRepository, remoteRepositories, artifactMetadataSource);
        }
    }

    return result;

}