Search in sources :

Example 1 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class SparkDependencyContext method addRepoFromProperty.

private void addRepoFromProperty(String listOfRepo) {
    if (listOfRepo != null) {
        String[] repos = listOfRepo.split(";");
        for (String repo : repos) {
            String[] parts = repo.split(",");
            if (parts.length == 3) {
                String id = parts[0].trim();
                String url = parts[1].trim();
                boolean isSnapshot = Boolean.parseBoolean(parts[2].trim());
                if (id.length() > 1 && url.length() > 1) {
                    RemoteRepository rr = new RemoteRepository(id, "default", url);
                    rr.setPolicy(isSnapshot, null);
                    additionalRepos.add(rr);
                }
            }
        }
    }
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 2 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class AbstractDependencyResolver method setProxy.

public void setProxy(URL proxyUrl, String proxyUser, String proxyPassword) {
    Authentication auth = new Authentication(proxyUser, proxyPassword);
    Proxy proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            repo.setProxy(proxy);
        }
    }
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 3 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class DependencyContext method fetchArtifactWithDep.

private List<ArtifactResult> fetchArtifactWithDep(Dependency dep) throws DependencyResolutionException, ArtifactResolutionException {
    Artifact artifact = new DefaultArtifact(dep.getGroupArtifactVersion());
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(dep.getExclusions());
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(mavenCentral);
    collectRequest.addRepository(mavenLocal);
    for (Repository repo : repositories) {
        RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl());
        rr.setPolicy(repo.isSnapshot(), null);
        collectRequest.addRepository(rr);
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 4 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class SparkDependencyResolver method getArtifactsWithDep.

/**
   * @param dependency
   * @param excludes list of pattern can either be of the form groupId:artifactId
   * @return
   * @throws Exception
   */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws Exception {
    Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(inferScalaVersion(excludes));
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 5 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project motech by motech.

the class ModuleAdminServiceImpl method resolveDependencies.

private List<ArtifactResult> resolveDependencies(Dependency dependency, PomInformation pomInformation) throws RepositoryException {
    LOGGER.info("Resolving dependencies for {}", dependency);
    org.apache.maven.repository.internal.DefaultServiceLocator locator = new org.apache.maven.repository.internal.DefaultServiceLocator();
    locator.addService(RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class);
    locator.setServices(WagonProvider.class, new HttpWagonProvider());
    RepositorySystem system = locator.getService(RepositorySystem.class);
    MavenRepositorySystemSession mvnRepository = new MavenRepositorySystemSession();
    mvnRepository.setLocalRepositoryManager(system.newLocalRepositoryManager(new LocalRepository(System.getProperty("java.io.tmpdir") + "/repo")));
    RemoteRepository remoteRepository = new RemoteRepository("central", "default", "http://nexus.motechproject.org/content/repositories/public");
    CollectRequest collectRequest = new CollectRequest();
    if (pomInformation != null) {
        String version = parseDependencyVersion(dependency, mvnRepository, system, remoteRepository, pomInformation);
        String groupId = parseDependencyGroupId(dependency, mvnRepository, system, remoteRepository, pomInformation);
        Artifact artifact = dependency.getArtifact();
        Artifact updatedArtifact = new DefaultArtifact(groupId, artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
        // The method setArtifact instead of updating dependency object, creates new dependency object with the given artifact
        // NO CHECKSTYLE ParameterAssignmentCheck
        dependency = dependency.setArtifact(updatedArtifact);
        if (pomInformation.getRepositories() != null) {
            for (RemoteRepository repository : pomInformation.getRepositories()) {
                collectRequest.addRepository(repository);
            }
        }
    }
    collectRequest.setRoot(dependency);
    collectRequest.addRepository(remoteRepository);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
    try {
        LOGGER.debug("Sending dependency request");
        return system.resolveDependencies(mvnRepository, dependencyRequest).getArtifactResults();
    } catch (RuntimeException e) {
        LOGGER.error("Unable to resolve dependencies for {}", dependency.toString(), e);
        return Collections.emptyList();
    }
}
Also used : LocalRepository(org.sonatype.aether.repository.LocalRepository) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) MavenRepositorySystemSession(org.motechproject.admin.service.impl.MavenRepositorySystemSession) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) RepositorySystem(org.sonatype.aether.RepositorySystem) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Aggregations

RemoteRepository (org.sonatype.aether.repository.RemoteRepository)76 Artifact (org.sonatype.aether.artifact.Artifact)33 Test (org.junit.Test)27 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)22 File (java.io.File)16 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)15 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)13 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)13 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)13 Dependency (org.sonatype.aether.graph.Dependency)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)12 CollectRequest (org.sonatype.aether.collection.CollectRequest)11 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)11 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)10 RepositorySystem (org.sonatype.aether.RepositorySystem)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Authentication (org.sonatype.aether.repository.Authentication)8 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)8 Before (org.junit.Before)7