All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.net.causal.maven.plugins.boxdb.DependencyUtils Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package au.net.causal.maven.plugins.boxdb;

import au.net.causal.maven.plugins.boxdb.db.RunnerDependency;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.resolution.DependencyResult;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class DependencyUtils
{
    public static List resolveDependenciesFromStrings(List dependencySpecs,
                                                            RepositorySystem repositorySystem,
                                                            RepositorySystemSession repositorySystemSession,
                                                            List remoteRepositories)
    throws DependencyResolutionException
    {
        List dependencyList = dependencySpecs.stream()
                .map(DefaultArtifact::new)
                .map(artifact -> new Dependency(artifact, org.apache.maven.artifact.Artifact.SCOPE_COMPILE))
                .collect(Collectors.toList());

        DependencyRequest dRequest = new DependencyRequest();
        dRequest.setCollectRequest(new CollectRequest(dependencyList, Collections.emptyList(), remoteRepositories));

        DependencyResult dResult = repositorySystem.resolveDependencies(repositorySystemSession, dRequest);

        return dResult.getArtifactResults().stream()
                .map(ArtifactResult::getArtifact)
                .map(Artifact::getFile)
                .map(File::toPath)
                .collect(Collectors.toList());
    }

	public static List resolveDependencies(List dependencies,
	                                             RepositorySystem repositorySystem,
	                                             RepositorySystemSession repositorySystemSession,
	                                             List remoteRepositories)
	throws DependencyResolutionException
	{
		List dependencyList = dependencies.stream()
				.map(rd -> new DefaultArtifact(rd.getGroupId(), rd.getArtifactId(), rd.getClassifier(), rd.getType(), rd.getVersion()))
				.map(artifact -> new Dependency(artifact, org.apache.maven.artifact.Artifact.SCOPE_COMPILE))
				.collect(Collectors.toList());

		DependencyRequest dRequest = new DependencyRequest();
		dRequest.setCollectRequest(new CollectRequest(dependencyList, Collections.emptyList(), remoteRepositories));

		DependencyResult dResult = repositorySystem.resolveDependencies(repositorySystemSession, dRequest);

		return dResult.getArtifactResults().stream()
				.map(ArtifactResult::getArtifact)
				.map(Artifact::getFile)
				.map(File::toPath)
				.collect(Collectors.toList());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy