Example usage for org.apache.maven.artifact.factory ArtifactFactory createProjectArtifact

List of usage examples for org.apache.maven.artifact.factory ArtifactFactory createProjectArtifact

Introduction

In this page you can find the example usage for org.apache.maven.artifact.factory ArtifactFactory createProjectArtifact.

Prototype

Artifact createProjectArtifact(String groupId, String artifactId, String version);

Source Link

Usage

From source file:org.wso2.maven.core.utils.MavenUtils.java

License:Open Source License

/**
 * Resolve maven POM of the given artifact
 * /*from   www  .j  av  a  2 s  .  com*/
 * @param dependency
 * @param artifactFactory
 * @param remoteRepositories
 * @param localRepository
 * @param resolver
 * @return resolved POM artifact
 * @throws MojoExecutionException
 */
public static Artifact getResolvedArtifactPom(Dependency dependency, ArtifactFactory artifactFactory,
        List<?> remoteRepositories, ArtifactRepository localRepository, ArtifactResolver resolver)
        throws MojoExecutionException {
    Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(),
            dependency.getArtifactId(), dependency.getVersion());
    if (null != dependency.getScope()) {
        artifact.setScope(dependency.getScope());
    }
    if (null != dependency.getSystemPath()) {
        artifact.setFile(new File(dependency.getSystemPath()));
    }

    try {
        resolver.resolve(artifact, remoteRepositories, localRepository);
    } catch (ArtifactResolutionException | ArtifactNotFoundException e) {
        throw new MojoExecutionException("Failed to resolve artifacts in specified repositories.", e);
    }
    return artifact;
}