Search in sources :

Example 36 with Artifact

use of org.apache.maven.artifact.Artifact in project intellij-community by JetBrains.

the class Maven30AetherModelConverter method convertAetherDependencyNodes.

public static List<MavenArtifactNode> convertAetherDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = RepositoryUtils.toArtifact(each.getDependency().getArtifact());
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        Map<?, ?> data = each.getData();
        //String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(each);
        //String premanagedScope = DependencyManagerUtils.getPremanagedScope(each);
        //Object winner = data.get(ConflictResolver.NODE_DATA_WINNER);
        //if(winner instanceof DependencyNode) {
        //  DependencyNode winnerNode = (DependencyNode)winner;
        //  if(!StringUtil.equals(each.getVersion().toString(), winnerNode.getVersion().toString())) {
        //    state = MavenArtifactState.CONFLICT;
        //    Artifact winnerArtifact = RepositoryUtils.toArtifact(winnerNode.getDependency().getArtifact());
        //    relatedArtifact = convertArtifact(winnerArtifact, nativeToConvertedMap, localRepository);
        //  }
        //}
        //
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, MavenArtifactState.ADDED, null, each.getDependency().getScope(), each.getPremanagedVersion(), each.getPremanagedScope());
        newNode.setDependencies(convertAetherDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 37 with Artifact

use of org.apache.maven.artifact.Artifact in project intellij-community by JetBrains.

the class Maven2ModelConverter method convertDependencyNodes.

public static List<MavenArtifactNode> convertDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = each.getArtifact();
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        MavenArtifactState state = MavenArtifactState.ADDED;
        switch(each.getState()) {
            case DependencyNode.INCLUDED:
                break;
            case DependencyNode.OMITTED_FOR_CONFLICT:
                state = MavenArtifactState.CONFLICT;
                break;
            case DependencyNode.OMITTED_FOR_DUPLICATE:
                state = MavenArtifactState.DUPLICATE;
                break;
            case DependencyNode.OMITTED_FOR_CYCLE:
                state = MavenArtifactState.CYCLE;
                break;
            default:
                assert false : "unknown dependency node state: " + each.getState();
        }
        MavenArtifact relatedMA = each.getRelatedArtifact() == null ? null : convertArtifact(each.getRelatedArtifact(), nativeToConvertedMap, localRepository);
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedMA, each.getOriginalScope(), each.getPremanagedVersion(), each.getPremanagedScope());
        newNode.setDependencies(convertDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 38 with Artifact

use of org.apache.maven.artifact.Artifact in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolveTransitively.

@NotNull
@Override
public List<MavenArtifact> resolveTransitively(@NotNull List<MavenArtifactInfo> artifacts, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException, MavenServerProcessCanceledException {
    try {
        Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
        for (MavenArtifactInfo each : artifacts) {
            toResolve.add(createArtifact(each));
        }
        Artifact project = getComponent(ArtifactFactory.class).createBuildArtifact("temp", "temp", "666", "pom");
        Set<Artifact> res = getComponent(ArtifactResolver.class).resolveTransitively(toResolve, project, Collections.EMPTY_MAP, myLocalRepository, convertRepositories(remoteRepositories), getComponent(ArtifactMetadataSource.class)).getArtifacts();
        return MavenModelConverter.convertArtifacts(res, new THashMap<Artifact, MavenArtifact>(), getLocalRepositoryFile());
    } catch (ArtifactResolutionException e) {
        Maven3ServerGlobals.getLogger().info(e);
    } catch (ArtifactNotFoundException e) {
        Maven3ServerGlobals.getLogger().info(e);
    } catch (Exception e) {
        throw rethrowException(e);
    }
    return Collections.emptyList();
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with Artifact

use of org.apache.maven.artifact.Artifact in project intellij-community by JetBrains.

the class MavenModelConverter method convertDependencyNodes.

public static List<MavenArtifactNode> convertDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = each.getArtifact();
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        MavenArtifactState state = MavenArtifactState.ADDED;
        switch(each.getState()) {
            case DependencyNode.INCLUDED:
                break;
            case DependencyNode.OMITTED_FOR_CONFLICT:
                state = MavenArtifactState.CONFLICT;
                break;
            case DependencyNode.OMITTED_FOR_DUPLICATE:
                state = MavenArtifactState.DUPLICATE;
                break;
            case DependencyNode.OMITTED_FOR_CYCLE:
                state = MavenArtifactState.CYCLE;
                break;
            default:
                assert false : "unknown dependency node state: " + each.getState();
        }
        MavenArtifact relatedMA = each.getRelatedArtifact() == null ? null : convertArtifact(each.getRelatedArtifact(), nativeToConvertedMap, localRepository);
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedMA, each.getOriginalScope(), each.getPremanagedVersion(), each.getPremanagedScope());
        newNode.setDependencies(convertDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) CustomMaven3Artifact(org.jetbrains.idea.maven.server.embedder.CustomMaven3Artifact) Artifact(org.apache.maven.artifact.Artifact)

Example 40 with Artifact

use of org.apache.maven.artifact.Artifact in project intellij-community by JetBrains.

the class Maven3AetherModelConverter method convertAetherDependencyNodes.

public static List<MavenArtifactNode> convertAetherDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = toArtifact(each.getDependency());
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        Map<?, ?> data = each.getData();
        String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(each);
        String premanagedScope = DependencyManagerUtils.getPremanagedScope(each);
        MavenArtifactState state = MavenArtifactState.ADDED;
        MavenArtifact relatedArtifact = null;
        String scope = each.getDependency().getScope();
        Object winner = data.get(ConflictResolver.NODE_DATA_WINNER);
        if (winner instanceof DependencyNode) {
            DependencyNode winnerNode = (DependencyNode) winner;
            scope = winnerNode.getDependency().getScope();
            Artifact winnerArtifact = toArtifact(winnerNode.getDependency());
            relatedArtifact = convertArtifact(winnerArtifact, nativeToConvertedMap, localRepository);
            nativeToConvertedMap.put(a, relatedArtifact);
            if (!StringUtil.equals(each.getVersion().toString(), winnerNode.getVersion().toString())) {
                state = MavenArtifactState.CONFLICT;
            } else {
                state = MavenArtifactState.DUPLICATE;
            }
        }
        ma.setScope(scope);
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedArtifact, each.getDependency().getScope(), premanagedVersion, premanagedScope);
        newNode.setDependencies(convertAetherDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16