Search in sources :

Example 51 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DefaultDependencyResolver method aggregateRemoteArtifactRepositories.

List<ArtifactRepository> aggregateRemoteArtifactRepositories(final List<ArtifactRepository> remoteRepositories, final Set<MavenProject> projects) {
    final List<List<ArtifactRepository>> repoLists = new ArrayList<List<ArtifactRepository>>();
    repoLists.add(remoteRepositories);
    for (final MavenProject project : projects) {
        repoLists.add(project.getRemoteArtifactRepositories());
    }
    final List<ArtifactRepository> remoteRepos = new ArrayList<ArtifactRepository>();
    final Set<String> encounteredUrls = new HashSet<String>();
    for (final List<ArtifactRepository> repositoryList : repoLists) {
        if ((repositoryList != null) && !repositoryList.isEmpty()) {
            for (final ArtifactRepository repo : repositoryList) {
                if (!encounteredUrls.contains(repo.getUrl())) {
                    remoteRepos.add(repo);
                    encounteredUrls.add(repo.getUrl());
                }
            }
        }
    }
    return remoteRepos;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 52 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DefaultDependencyResolver method resolve.

private void resolve(Assembly assembly, AssemblerConfigurationSource configSource, Map<DependencySet, Set<Artifact>> result, DependencySet dependencySet, ResolutionManagementInfo info) throws DependencyResolutionException {
    Set<Artifact> artifacts;
    if (info.isResolutionRequired()) {
        final List<ArtifactRepository> repos = aggregateRemoteArtifactRepositories(configSource.getRemoteRepositories(), info.getEnabledProjects());
        artifacts = info.getArtifacts();
        if (info.isResolvedTransitively()) {
            getLogger().debug("Resolving project dependencies transitively.");
            ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(info.getScopeFilter());
            artifacts = resolveTransitively(artifacts, repos, filter, configSource);
        } else {
            getLogger().debug("Resolving project dependencies ONLY. " + "Transitive dependencies WILL NOT be included in the results.");
            artifacts = resolveNonTransitively(assembly, artifacts, configSource, repos);
        }
    } else {
        artifacts = new HashSet<Artifact>();
    }
    result.put(dependencySet, artifacts);
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 53 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class MavenProject4CopyConstructor method initializeParentFields.

// to prevent the MavenProject copy constructor from blowing up
private void initializeParentFields() {
    // the pom should be located in the isolated dummy root         
    super.setFile(new File(getBasedir(), "pom.xml"));
    super.setDependencyArtifacts(new HashSet<Artifact>());
    super.setArtifacts(new HashSet<Artifact>());
    super.setExtensionArtifacts(new HashSet<Artifact>());
    super.setRemoteArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setPluginArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setCollectedProjects(new LinkedList<MavenProject>());
    super.setActiveProfiles(new LinkedList<Profile>());
    super.setOriginalModel(null);
    super.setExecutionProject(this);
    super.setBuild(getBuild());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Profile(org.apache.maven.model.Profile)

Example 54 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.

the class BundleInstallFileMojo method resolveBundleFileFromArtifact.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
    if (artifactId == null && artifact == null) {
        return null;
    }
    if (artifactId == null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
            throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        groupId = tokens[0];
        artifactId = tokens[1];
        version = tokens[2];
        if (tokens.length >= 4)
            packaging = tokens[3];
        if (tokens.length == 5)
            classifier = tokens[4];
    }
    Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    if (pomRemoteRepositories == null) {
        pomRemoteRepositories = new ArrayList();
    }
    List repoList = new ArrayList(pomRemoteRepositories);
    if (repositoryUrl != null) {
        ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
        ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
        repoList.add(remoteRepo);
    }
    try {
        artifactResolver.resolve(packageArtifact, repoList, localRepository);
        getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
    return packageArtifact.getFile().getAbsolutePath();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 55 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project bnd by bndtools.

the class DependencyResolver method resolve.

public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
    if (resolvedDependencies != null) {
        return resolvedDependencies;
    }
    DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
    request.setResolutionFilter(new DependencyFilter() {

        @Override
        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            if (node.getDependency() != null) {
                return scopes.contains(node.getDependency().getScope());
            }
            return false;
        }
    });
    DependencyResolutionResult result;
    try {
        result = resolver.resolve(request);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    Map<File, ArtifactResult> dependencies = new HashMap<>();
    DependencyNode dependencyGraph = result.getDependencyGraph();
    if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
        List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
        ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
        if (deployRepo != null) {
            remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
        }
        discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
    }
    return resolvedDependencies = dependencies;
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) File(java.io.File)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)56 File (java.io.File)22 Artifact (org.apache.maven.artifact.Artifact)17 MavenProject (org.apache.maven.project.MavenProject)14 ArrayList (java.util.ArrayList)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)10 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)7 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)6 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 IOException (java.io.IOException)5 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)5 HashMap (java.util.HashMap)4 ArtifactRepositoryFactory (org.apache.maven.artifact.repository.ArtifactRepositoryFactory)4 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)4 Model (org.apache.maven.model.Model)4 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)4 Repository (org.apache.maven.wagon.repository.Repository)4