Search in sources :

Example 31 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class DefaultRepositoryAssembler method assembleRepositoryArtifacts.

private void assembleRepositoryArtifacts(ProjectBuildingRequest buildingRequest, Iterable<ArtifactResult> result, ArtifactFilter filter, Map<String, GroupVersionAlignment> groupVersionAlignments) throws RepositoryAssemblyException {
    try {
        for (ArtifactResult ar : result) {
            Artifact a = ar.getArtifact();
            if (filter.include(a)) {
                getLogger().debug("Re-resolving: " + a + " for repository assembly.");
                setAlignment(a, groupVersionAlignments);
                artifactResolver.resolveArtifact(buildingRequest, TransferUtils.toArtifactCoordinate(a));
                a.setVersion(a.getBaseVersion());
                File targetFile = new File(repositoryManager.getLocalRepositoryBasedir(buildingRequest), repositoryManager.getPathForLocalArtifact(buildingRequest, a));
                FileUtils.copyFile(a.getFile(), targetFile);
            // writeChecksums( targetFile );
            }
        }
    } catch (ArtifactResolverException e) {
        throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new RepositoryAssemblyException("Error writing artifact metdata.", e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) IOException(java.io.IOException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 32 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class GetMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    if (coordinate.getArtifactId() == null && artifact == null) {
        throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
    }
    if (artifact != null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length < 3 || tokens.length > 5) {
            throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        coordinate.setGroupId(tokens[0]);
        coordinate.setArtifactId(tokens[1]);
        coordinate.setVersion(tokens[2]);
        if (tokens.length >= 4) {
            coordinate.setType(tokens[3]);
        }
        if (tokens.length == 5) {
            coordinate.setClassifier(tokens[4]);
        }
    }
    ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
    if (pomRemoteRepositories != null) {
        repoList.addAll(pomRemoteRepositories);
    }
    if (remoteRepositories != null) {
        // Use the same format as in the deploy plugin id::layout::url
        List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
        for (String repo : repos) {
            repoList.add(parseRepository(repo, always));
        }
    }
    try {
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(repoList);
        if (transitive) {
            getLog().info("Resolving " + coordinate + " with transitive dependencies");
            dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
        } else {
            getLog().info("Resolving " + coordinate);
            artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
        }
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 33 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class PurgeLocalRepositoryMojo method reResolveArtifacts.

private void reResolveArtifacts(MavenProject project, Set<Artifact> artifacts, ArtifactFilter filter) throws ArtifactResolutionException, ArtifactNotFoundException {
    // because Maven 2 will not automatically re-resolve them when resolving the artifact
    for (Artifact artifact : artifacts) {
        try {
            // CHECKSTYLE_OFF: LineLength
            artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), org.apache.maven.shared.artifact.TransferUtils.toArtifactCoordinate(artifact));
        // CHECKSTYLE_ON: LineLength
        } catch (ArtifactResolverException e) {
            verbose(e.getMessage());
        }
    }
    List<Artifact> missingArtifacts = new ArrayList<Artifact>();
    for (Artifact artifact : artifacts) {
        verbose("Resolving artifact: " + artifact.getId());
        try {
            artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
        } catch (ArtifactResolverException e) {
            verbose(e.getMessage());
            missingArtifacts.add(artifact);
        }
    }
    if (missingArtifacts.size() > 0) {
        StringBuffer message = new StringBuffer("required artifacts missing:\n");
        for (Artifact missingArtifact : missingArtifacts) {
            message.append("  ").append(missingArtifact.getId()).append('\n');
        }
        message.append("\nfor the artifact:");
        throw new ArtifactResolutionException(message.toString(), project.getArtifact(), project.getRemoteArtifactRepositories());
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 34 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-archetype by apache.

the class IntegrationTestMojo method setupParentProjects.

private File setupParentProjects(File configFolder, File buildFolder) throws IOException, MojoExecutionException, IntegrationTestFailure {
    // look for 'archetype.pom.properties'
    File archetypePomPropertiesFile = new File(configFolder, "archetype.pom.properties");
    if (!archetypePomPropertiesFile.exists()) {
        getLog().debug("No 'archetype.pom.properties' file found in " + configFolder);
        return buildFolder;
    }
    // go up to the parent configuration folder
    buildFolder = setupParentProjects(configFolder.getParentFile(), buildFolder);
    Properties archetypePomProperties = loadProperties(archetypePomPropertiesFile);
    String groupId = archetypePomProperties.getProperty(Constants.GROUP_ID);
    if (StringUtils.isEmpty(groupId)) {
        throw new MojoExecutionException("Property " + Constants.GROUP_ID + " not set in " + archetypePomPropertiesFile);
    }
    String artifactId = archetypePomProperties.getProperty(Constants.ARTIFACT_ID);
    if (StringUtils.isEmpty(artifactId)) {
        throw new MojoExecutionException("Property " + Constants.ARTIFACT_ID + " not set in " + archetypePomPropertiesFile);
    }
    String version = archetypePomProperties.getProperty(Constants.VERSION);
    if (StringUtils.isEmpty(version)) {
        throw new MojoExecutionException("Property " + Constants.VERSION + " not set in " + archetypePomPropertiesFile);
    }
    File archetypeFile;
    try {
        archetypeFile = getArchetypeFile(groupId, artifactId, version);
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Could not resolve archetype artifact ", e);
    }
    Properties archetypeProperties = getProperties(archetypePomPropertiesFile);
    getLog().info("Setting up parent project in " + buildFolder);
    ArchetypeGenerationRequest request = generate(groupId, artifactId, version, archetypeFile, archetypeProperties, buildFolder.toString());
    return new File(buildFolder, request.getArtifactId());
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) Properties(java.util.Properties) File(java.io.File)

Example 35 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-archetype by apache.

the class DefaultDownloader method download.

public File download(String groupId, String artifactId, String version, ArtifactRepository archetypeRepository, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ProjectBuildingRequest buildingRequest) throws DownloadException, DownloadNotFoundException {
    DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
    jarCoordinate.setGroupId(groupId);
    jarCoordinate.setArtifactId(artifactId);
    jarCoordinate.setVersion(version);
    DefaultArtifactCoordinate pomCoordinate = new DefaultArtifactCoordinate();
    pomCoordinate.setGroupId(groupId);
    pomCoordinate.setArtifactId(artifactId);
    pomCoordinate.setVersion(version);
    pomCoordinate.setExtension("pom");
    List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(remoteRepositories);
    if (repositories.isEmpty() && archetypeRepository != null) {
        repositories.add(archetypeRepository);
    } else if (repositories.isEmpty() && localRepository != null) {
        repositories.add(localRepository);
    }
    ArtifactRepository localRepo = localRepository;
    buildingRequest.setLocalRepository(localRepo);
    buildingRequest.setRemoteRepositories(repositories);
    Artifact artifact;
    try {
        artifact = artifactResolver.resolveArtifact(buildingRequest, jarCoordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
    }
    // still required???
    try {
        artifactResolver.resolveArtifact(buildingRequest, pomCoordinate);
    } catch (ArtifactResolverException e) {
        throw new DownloadException("Error downloading POM for " + artifact.getId() + ".", e);
    }
    return artifact.getFile();
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)35 Artifact (org.apache.maven.artifact.Artifact)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)13 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)12 ArrayList (java.util.ArrayList)11 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)9 IOException (java.io.IOException)8 LinkedHashSet (java.util.LinkedHashSet)8 MavenReportException (org.apache.maven.reporting.MavenReportException)8 File (java.io.File)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)5 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)4 DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)3 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)3 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)3