Search in sources :

Example 1 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project buck by facebook.

the class Publisher method createDeployRequest.

private DeployRequest createDeployRequest(List<Artifact> toPublish) {
    DeployRequest deployRequest = new DeployRequest().setRepository(remoteRepo);
    for (Artifact artifact : toPublish) {
        File file = artifact.getFile();
        Preconditions.checkNotNull(file);
        Preconditions.checkArgument(file.exists(), "No such file: %s", file.getAbsolutePath());
        deployRequest.addArtifact(artifact);
    }
    return deployRequest;
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) File(java.io.File) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 2 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project buck by facebook.

the class Publisher method publish.

/**
   * @param toPublish each {@link Artifact} must contain a file, that will be published under maven
   *                  coordinates in the corresponding {@link Artifact}.
   * @see Artifact#setFile
   */
public DeployResult publish(List<Artifact> toPublish) throws DeploymentException {
    RepositorySystem repoSys = Preconditions.checkNotNull(locator.getService(RepositorySystem.class));
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setLocalRepositoryManager(repoSys.newLocalRepositoryManager(session, localRepo));
    session.setReadOnly();
    DeployRequest deployRequest = createDeployRequest(toPublish);
    if (dryRun) {
        return new DeployResult(deployRequest).setArtifacts(toPublish).setMetadata(deployRequest.getMetadata());
    } else {
        return repoSys.deploy(session, deployRequest);
    }
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DeployResult(org.eclipse.aether.deployment.DeployResult) DeployRequest(org.eclipse.aether.deployment.DeployRequest)

Example 3 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project camel by apache.

the class BOMResolver method retrieveUpstreamBOMVersions.

private void retrieveUpstreamBOMVersions() throws Exception {
    RepositorySystem system = newRepositorySystem();
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(LOCAL_REPO);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    String camelVersion = DependencyResolver.resolveCamelParentProperty("${project.version}");
    List<Artifact> neededArtifacts = new LinkedList<>();
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel:pom:" + camelVersion).setFile(camelRoot("pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-parent:pom:" + camelVersion).setFile(camelRoot("parent/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:spring-boot:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dm:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dependencies:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml")));
    Artifact camelSpringBootParent = new DefaultArtifact("org.apache.camel:camel-starter-parent:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-starter-parent/pom.xml"));
    neededArtifacts.add(camelSpringBootParent);
    RemoteRepository localRepoDist = new RemoteRepository.Builder("org.apache.camel.itest.springboot", "default", new File(LOCAL_REPO).toURI().toString()).build();
    for (Artifact artifact : neededArtifacts) {
        DeployRequest deployRequest = new DeployRequest();
        deployRequest.addArtifact(artifact);
        deployRequest.setRepository(localRepoDist);
        system.deploy(session, deployRequest);
    }
    RemoteRepository mavenCentral = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
    ArtifactDescriptorRequest dReq = new ArtifactDescriptorRequest(camelSpringBootParent, Arrays.asList(localRepoDist, mavenCentral), null);
    ArtifactDescriptorResult dRes = system.readArtifactDescriptor(session, dReq);
    this.versions = new TreeMap<>();
    for (Dependency dependency : dRes.getManagedDependencies()) {
        Artifact a = dependency.getArtifact();
        String key = a.getGroupId() + ":" + a.getArtifactId();
        versions.put(key, dependency.getArtifact().getVersion());
    }
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) LinkedList(java.util.LinkedList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest)

Example 4 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project bnd by bndtools.

the class AetherRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    DigestInputStream digestStream = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
    final File tmpFile = IO.createTempFile(cacheDir, "put", ".bnd");
    try {
        IO.copy(digestStream, tmpFile);
        byte[] digest = digestStream.getMessageDigest().digest();
        if (options.digest != null && !Arrays.equals(options.digest, digest))
            throw new IOException("Retrieved artifact digest doesn't match specified digest");
        // Get basic info about the bundle we're deploying
        Jar jar = new Jar(tmpFile);
        Artifact artifact = ConversionUtils.fromBundleJar(jar);
        artifact = artifact.setFile(tmpFile);
        // Setup the Aether repo session and create the deployment request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        final DeployRequest request = new DeployRequest();
        request.addArtifact(artifact);
        request.setRepository(remoteRepo);
        // Capture the result including remote resource URI
        final ResultHolder resultHolder = new ResultHolder();
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferSucceeded(TransferEvent event) {
                TransferResource resource = event.getResource();
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(resource.getFile())) {
                    PutResult result = new PutResult();
                    result.artifact = URI.create(resource.getRepositoryUrl() + resource.getResourceName());
                    resultHolder.result = result;
                    System.out.println("UPLOADED to: " + URI.create(resource.getRepositoryUrl() + resource.getResourceName()));
                }
            }

            @Override
            public void transferFailed(TransferEvent event) {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }

            @Override
            public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }
        });
        // Do the deploy and report results
        repoSystem.deploy(session, request);
        if (resultHolder.result != null) {
            if (indexedRepo != null)
                indexedRepo.reset();
            return resultHolder.result;
        } else if (resultHolder.error != null) {
            throw new Exception("Error during artifact upload", resultHolder.error);
        } else {
            throw new Exception("Artifact was not uploaded");
        }
    } finally {
        if (tmpFile != null && tmpFile.isFile())
            IO.delete(tmpFile);
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) DeployRequest(org.eclipse.aether.deployment.DeployRequest) AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) TransferResource(org.eclipse.aether.transfer.TransferResource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 5 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project drools by kiegroup.

the class MavenRepository method deployArtifact.

/**
 * Deploys a jar on a remote repository.
 *
 * @param repository The remote repository where the kjar will be deployed
 * @param releaseId The releaseId with which the deployment will be made
 * @param jar The jar to be deployed
 * @param pomfile The pom file to be deployed together with the kjar
 */
public void deployArtifact(RemoteRepository repository, ReleaseId releaseId, File jar, File pomfile) {
    Artifact jarArtifact = new DefaultArtifact(releaseId.getGroupId(), releaseId.getArtifactId(), "jar", releaseId.getVersion());
    jarArtifact = jarArtifact.setFile(jar);
    Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom");
    pomArtifact = pomArtifact.setFile(pomfile);
    DeployRequest deployRequest = new DeployRequest();
    deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact).setRepository(repository);
    try {
        aether.getSystem().deploy(aether.getSession(), deployRequest);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
Also used : SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DeployRequest(org.eclipse.aether.deployment.DeployRequest) DeploymentException(org.eclipse.aether.deployment.DeploymentException) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DeployRequest (org.eclipse.aether.deployment.DeployRequest)7 Artifact (org.eclipse.aether.artifact.Artifact)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 File (java.io.File)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)3 RepositorySystem (org.eclipse.aether.RepositorySystem)2 DeployResult (org.eclipse.aether.deployment.DeployResult)2 DeploymentException (org.eclipse.aether.deployment.DeploymentException)2 Jar (aQute.bnd.osgi.Jar)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 DigestInputStream (java.security.DigestInputStream)1 LinkedList (java.util.LinkedList)1 Dependency (org.eclipse.aether.graph.Dependency)1 LocalRepository (org.eclipse.aether.repository.LocalRepository)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 ArtifactDescriptorRequest (org.eclipse.aether.resolution.ArtifactDescriptorRequest)1 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)1