Search in sources :

Example 61 with Artifact

use of org.sonatype.aether.artifact.Artifact in project zeppelin by apache.

the class SparkDependencyResolver method loadFromMvn.

private List<String> loadFromMvn(String artifact, Collection<String> excludes, boolean addSparkContext) throws Exception {
    List<String> loadedLibs = new LinkedList<>();
    Collection<String> allExclusions = new LinkedList<>();
    allExclusions.addAll(excludes);
    allExclusions.addAll(Arrays.asList(exclusions));
    List<ArtifactResult> listOfArtifact;
    listOfArtifact = getArtifactsWithDep(artifact, allExclusions);
    Iterator<ArtifactResult> it = listOfArtifact.iterator();
    while (it.hasNext()) {
        Artifact a = it.next().getArtifact();
        String gav = a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion();
        for (String exclude : allExclusions) {
            if (gav.startsWith(exclude)) {
                it.remove();
                break;
            }
        }
    }
    List<URL> newClassPathList = new LinkedList<>();
    List<File> files = new LinkedList<>();
    for (ArtifactResult artifactResult : listOfArtifact) {
        logger.info("Load " + artifactResult.getArtifact().getGroupId() + ":" + artifactResult.getArtifact().getArtifactId() + ":" + artifactResult.getArtifact().getVersion());
        newClassPathList.add(artifactResult.getArtifact().getFile().toURI().toURL());
        files.add(artifactResult.getArtifact().getFile());
        loadedLibs.add(artifactResult.getArtifact().getGroupId() + ":" + artifactResult.getArtifact().getArtifactId() + ":" + artifactResult.getArtifact().getVersion());
    }
    global.new Run();
    if (sc.version().startsWith("1.1")) {
        updateRuntimeClassPath_1_x(newClassPathList.toArray(new URL[0]));
    } else {
        updateRuntimeClassPath_2_x(newClassPathList.toArray(new URL[0]));
    }
    updateCompilerClassPath(newClassPathList.toArray(new URL[0]));
    if (addSparkContext) {
        for (File f : files) {
            sc.addJar(f.getAbsolutePath());
        }
    }
    return loadedLibs;
}
Also used : LinkedList(java.util.LinkedList) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) URL(java.net.URL) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) AbstractFile(scala.reflect.io.AbstractFile) File(java.io.File)

Example 62 with Artifact

use of org.sonatype.aether.artifact.Artifact in project gradle by gradle.

the class MavenDeployAction method publishArtifacts.

@Override
protected void publishArtifacts(Collection<Artifact> artifacts, RepositorySystem repositorySystem, RepositorySystemSession session) throws DeploymentException {
    RemoteRepository gradleRepo = remoteRepository;
    if (artifacts.iterator().next().isSnapshot() && remoteSnapshotRepository != null) {
        gradleRepo = remoteSnapshotRepository;
    }
    if (gradleRepo == null) {
        throw new GradleException("Must specify a repository for deployment");
    }
    org.sonatype.aether.repository.RemoteRepository aetherRepo = createRepository(gradleRepo);
    DeployRequest request = new DeployRequest();
    request.setRepository(aetherRepo);
    for (Artifact artifact : artifacts) {
        request.addArtifact(artifact);
    }
    LOGGER.info("Deploying to {}", gradleRepo.getUrl());
    repositorySystem.deploy(session, request);
}
Also used : GradleException(org.gradle.api.GradleException) DeployRequest(org.sonatype.aether.deployment.DeployRequest) RemoteRepository(org.apache.maven.artifact.ant.RemoteRepository) Artifact(org.sonatype.aether.artifact.Artifact)

Example 63 with Artifact

use of org.sonatype.aether.artifact.Artifact in project karaf by apache.

the class Dependency30Helper method artifactToMvn.

@Override
public String artifactToMvn(Object _artifact, String versionOrRange) {
    Artifact artifact = (Artifact) _artifact;
    String bundleName;
    if (artifact.getExtension().equals("jar") && MavenUtil.isEmpty(artifact.getClassifier())) {
        bundleName = String.format("mvn:%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange);
    } else {
        if (MavenUtil.isEmpty(artifact.getClassifier())) {
            bundleName = String.format("mvn:%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension());
        } else {
            bundleName = String.format("mvn:%s/%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension(), artifact.getClassifier());
        }
    }
    return bundleName;
}
Also used : Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 64 with Artifact

use of org.sonatype.aether.artifact.Artifact in project gradle by gradle.

the class AbstractMavenPublishAction method publish.

public void publish() {
    List<Artifact> artifacts = new ArrayList<Artifact>();
    if (mainArtifact.getFile() != null) {
        artifacts.add(mainArtifact);
    }
    artifacts.add(pomArtifact);
    if (metadataArtifact != null) {
        artifacts.add(metadataArtifact);
    }
    for (Artifact artifact : attached) {
        File file = artifact.getFile();
        if (file != null && file.isFile()) {
            artifacts.add(artifact);
        }
    }
    try {
        publishArtifacts(artifacts, newRepositorySystem(), session);
    } catch (RepositoryException e) {
        throw new GradleException(e.getMessage(), e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) RepositoryException(org.sonatype.aether.RepositoryException) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 65 with Artifact

use of org.sonatype.aether.artifact.Artifact in project motech by motech.

the class ModuleAdminServiceImpl method getPropertyFromPom.

private String getPropertyFromPom(String propertyName, MavenRepositorySystemSession mvnRepository, RepositorySystem system, RemoteRepository remoteRepository, PomInformation pomInformation) throws ArtifactResolutionException {
    Properties properties = pomInformation.getProperties();
    String property = properties.getProperty(propertyName);
    if (property == null) {
        if (pomInformation.getParentPomInformation() == null) {
            if (pomInformation.getParent() != null) {
                Artifact artifact = new DefaultArtifact(pomInformation.getParent().getGroupId(), pomInformation.getParent().getArtifactId(), "pom", pomInformation.getParent().getVersion());
                ArtifactRequest artifactRequest = new ArtifactRequest();
                artifactRequest.setArtifact(artifact);
                if (pomInformation.getRepositories() != null) {
                    for (RemoteRepository repository : pomInformation.getRepositories()) {
                        artifactRequest.addRepository(repository);
                    }
                }
                artifactRequest.addRepository(remoteRepository);
                ArtifactResult artifactResult = system.resolveArtifact(mvnRepository, artifactRequest);
                File parentPOM = artifactResult.getArtifact().getFile();
                pomInformation.parseParentPom(parentPOM);
                return getPropertyFromPom(propertyName, mvnRepository, system, remoteRepository, pomInformation.getParentPomInformation());
            } else {
                return null;
            }
        } else {
            return getPropertyFromPom(propertyName, mvnRepository, system, remoteRepository, pomInformation.getParentPomInformation());
        }
    } else {
        return property;
    }
}
Also used : ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Properties(java.util.Properties) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Aggregations

Artifact (org.sonatype.aether.artifact.Artifact)116 Test (org.junit.Test)62 File (java.io.File)34 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)33 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)28 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)28 Dependency (org.sonatype.aether.graph.Dependency)21 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)17 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)16 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)15 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)15 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)13 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)13 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)12 ArrayList (java.util.ArrayList)11 RepositorySystem (org.sonatype.aether.RepositorySystem)10 Metadata (org.sonatype.aether.metadata.Metadata)10 CollectRequest (org.sonatype.aether.collection.CollectRequest)9 IOException (java.io.IOException)8