Search in sources :

Example 6 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project byte-buddy by raphw.

the class ClassLoaderResolverTest method setUp.

@Before
public void setUp() throws Exception {
    classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
    when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
    when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
    when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
            dependencyVisitor.visitEnter(child);
            dependencyVisitor.visitLeave(child);
            return null;
        }
    });
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 7 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project spring-boot by spring-projects.

the class DependencyResolutionContext method addDependencyManagement.

public void addDependencyManagement(DependencyManagement dependencyManagement) {
    for (org.springframework.boot.cli.compiler.dependencies.Dependency dependency : dependencyManagement.getDependencies()) {
        List<Exclusion> aetherExclusions = new ArrayList<>();
        for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency.getExclusions()) {
            aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*"));
        }
        Dependency aetherDependency = new Dependency(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "jar", dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions);
        this.managedDependencies.add(0, aetherDependency);
        this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), aetherDependency);
    }
    this.dependencyManagement = this.dependencyManagement == null ? dependencyManagement : new CompositeDependencyManagement(dependencyManagement, this.dependencyManagement);
    this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver(this.dependencyManagement);
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) DependencyManagementArtifactCoordinatesResolver(org.springframework.boot.cli.compiler.dependencies.DependencyManagementArtifactCoordinatesResolver) Exclusion(org.eclipse.aether.graph.Exclusion) CompositeDependencyManagement(org.springframework.boot.cli.compiler.dependencies.CompositeDependencyManagement) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 8 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project bazel by bazelbuild.

the class ResultWriterTest method testBuildFile.

@Test
public void testBuildFile() throws Exception {
    Rule rule = new Rule(new DefaultArtifact("x:y:1.2.3"));
    Rule dep1 = new Rule(new DefaultArtifact("dep:dep1:4.5.6"));
    rule.addDependency(dep1);
    Rule dep2 = new Rule(new DefaultArtifact("dep:dep2:7.8.9"));
    rule.addDependency(dep2);
    Set<Rule> rules = ImmutableSet.of(rule, dep1, dep2);
    String content = getBuildFileContent(ImmutableList.<String>of(), rules);
    assertThat(content).contains("java_library(\n" + "    name = \"x_y\",\n" + "    visibility = [\"//visibility:public\"],\n" + "    exports = [\n" + "        \"@x_y//jar\",\n" + "        \"@dep_dep1//jar\",\n" + "        \"@dep_dep2//jar\",\n" + "    ],\n" + ")");
}
Also used : Rule(com.google.devtools.build.workspace.maven.Rule) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 9 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project bazel by bazelbuild.

the class ResultWriterTest method testParents.

@Test
public void testParents() throws Exception {
    Rule rule = new Rule(new DefaultArtifact("x:y:1.2.3"));
    rule.addParent("some parent");
    Set<Rule> rules = ImmutableSet.of(rule);
    String content = getWorkspaceFileContent(ImmutableList.<String>of(), rules);
    assertThat(content).contains("# some parent\n" + "maven_jar(\n" + "    name = \"x_y\",\n" + "    artifact = \"x:y:1.2.3\",\n" + ")");
}
Also used : Rule(com.google.devtools.build.workspace.maven.Rule) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 10 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project bazel by bazelbuild.

the class MavenDownloader method download.

/**
   * Download the Maven artifact to the output directory. Returns the path to the jar.
   */
public Path download(String name, WorkspaceAttributeMapper mapper, Path outputDirectory, MavenServerValue serverValue) throws IOException, EvalException {
    this.name = name;
    this.outputDirectory = outputDirectory;
    String url = serverValue.getUrl();
    Server server = serverValue.getServer();
    Artifact artifact;
    String artifactId = mapper.get("artifact", Type.STRING);
    String sha1 = mapper.isAttributeValueExplicitlySpecified("sha1") ? mapper.get("sha1", Type.STRING) : null;
    if (sha1 != null && !KeyType.SHA1.isValid(sha1)) {
        throw new IOException("Invalid SHA-1 for maven_jar " + name + ": '" + sha1 + "'");
    }
    try {
        artifact = new DefaultArtifact(artifactId);
    } catch (IllegalArgumentException e) {
        throw new IOException(e.getMessage());
    }
    boolean isCaching = repositoryCache.isEnabled() && KeyType.SHA1.isValid(sha1);
    if (isCaching) {
        Path downloadPath = getDownloadDestination(artifact);
        Path cachedDestination = repositoryCache.get(sha1, downloadPath, KeyType.SHA1);
        if (cachedDestination != null) {
            return cachedDestination;
        }
    }
    MavenConnector connector = new MavenConnector(outputDirectory.getPathString());
    RepositorySystem system = connector.newRepositorySystem();
    RepositorySystemSession session = connector.newRepositorySystemSession(system);
    RemoteRepository repository = new RemoteRepository.Builder(name, MavenServerValue.DEFAULT_ID, url).setAuthentication(new MavenAuthentication(server)).build();
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(ImmutableList.of(repository));
    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
        artifact = artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        throw new IOException("Failed to fetch Maven dependency: " + e.getMessage());
    }
    Path downloadPath = outputDirectory.getRelative(artifact.getFile().getAbsolutePath());
    // Verify checksum.
    if (!Strings.isNullOrEmpty(sha1)) {
        RepositoryCache.assertFileChecksum(sha1, downloadPath, KeyType.SHA1);
    }
    if (isCaching) {
        repositoryCache.put(sha1, downloadPath, KeyType.SHA1);
    }
    return downloadPath;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) Server(org.apache.maven.settings.Server) Builder(com.google.common.collect.ImmutableMap.Builder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 Artifact (org.eclipse.aether.artifact.Artifact)12 File (java.io.File)9 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)7 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)6 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)4 Dependency (org.eclipse.aether.graph.Dependency)4 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)4 Test (org.junit.Test)4 MavenVersion (aQute.bnd.version.MavenVersion)3 Rule (com.google.devtools.build.workspace.maven.Rule)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)3 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)3 Version (org.eclipse.aether.version.Version)3 Version (aQute.bnd.version.Version)2 ArrayList (java.util.ArrayList)2