org.eclipse.aether.deployment.DeployRequest Java Examples

The following examples show how to use org.eclipse.aether.deployment.DeployRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Publisher.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @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 = Objects.requireNonNull(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);
  }
}
 
Example #2
Source File: ArtifactDeployer.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private Collection<Artifact> deploy(Collection<Artifact> artifacts, RemoteRepository repo)
    throws DeploymentException {
  DeployRequest request = new DeployRequest();
  request.setArtifacts(artifacts);
  request.setRepository(repo);
  DeployResult result = this.deployer.deploy(this.repoSession, request);
  return result.getArtifacts();
}
 
Example #3
Source File: MavenTest.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMvn1 () throws Exception
{
    final ChannelTester ct = ChannelTester.create ( getWebContext (), "m1" );
    ct.addAspect ( "mvn" );
    ct.addAspect ( "maven.repo" );
    ct.assignDeployGroup ( "m1" );

    final String key = ct.getDeployKeys ().iterator ().next (); // get first

    assertNotNull ( key );

    final RepositorySystem system = MavenUtil.newRepositorySystem ();
    final RepositorySystemSession session = MavenUtil.newRepositorySystemSession ( system );

    Artifact jarArtifact = new DefaultArtifact ( "org.eclipse.packagedrone.testing", "test.felix1", "", "jar", "0.0.1-SNAPSHOT" );
    jarArtifact = jarArtifact.setFile ( new File ( TEST_1_JAR ) );

    Artifact pomArtifact = new SubArtifact ( jarArtifact, "", "pom" );
    pomArtifact = pomArtifact.setFile ( new File ( TEST_1_POM ) );

    Artifact srcArtifact = new SubArtifact ( jarArtifact, "sources", "jar" );
    srcArtifact = srcArtifact.setFile ( new File ( TEST_1_SOURCES_JAR ) );

    final AuthenticationBuilder ab = new AuthenticationBuilder ();
    ab.addUsername ( "deploy" );
    ab.addPassword ( key );
    final Authentication auth = ab.build ();
    final RemoteRepository distRepo = new RemoteRepository.Builder ( "test", "default", resolve ( String.format ( "/maven/%s", ct.getId () ) ) ).setAuthentication ( auth ).build ();

    final DeployRequest deployRequest = new DeployRequest ();
    deployRequest.addArtifact ( jarArtifact ).addArtifact ( pomArtifact ).addArtifact ( srcArtifact );
    deployRequest.setRepository ( distRepo );

    system.deploy ( session, deployRequest );

    testUrl ( String.format ( "/maven/%s", ct.getId () ) ); // index page

    // FIXME: check more data
}
 
Example #4
Source File: DeployParticipant.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void afterSessionEnd(MavenSession session) throws MavenExecutionException {
  boolean errors = !session.getResult().getExceptions().isEmpty();

  if (!deployAtEndRequests.isEmpty()) {

    log.info("");
    log.info("------------------------------------------------------------------------");

    if (errors) {
      log.info("-- Not performing deploy at end due to errors                         --");
    } else {
      log.info("-- Performing deploy at end                                           --");
      log.info("------------------------------------------------------------------------");

      synchronized (deployAtEndRequests) {
        for (DeployRequest deployRequest : deployAtEndRequests) {
          try {
            deploy(session.getRepositorySession(), deployRequest);
          } catch (DeploymentException e) {
            log.error(e.getMessage(), e);
            throw new MavenExecutionException(e.getMessage(), e);
          }
        }
        deployAtEndRequests.clear();
      }
    }

    log.info("------------------------------------------------------------------------");
  }
}
 
Example #5
Source File: Publisher.java    From buck with Apache License 2.0 5 votes vote down vote up
private DeployRequest createDeployRequest(List<Artifact> toPublish) {
  DeployRequest deployRequest = new DeployRequest().setRepository(remoteRepo);
  for (Artifact artifact : toPublish) {
    File file = artifact.getFile();
    Objects.requireNonNull(file);
    Preconditions.checkArgument(file.exists(), "No such file: %s", file.getAbsolutePath());

    deployRequest.addArtifact(artifact);
  }
  return deployRequest;
}
 
Example #6
Source File: PublishCommand.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
private void publishToRepository(RepositorySystem system, RepositorySystemSession session,
        ArtifactSource source, Manifest manifest, Artifact zip, Artifact pom, Artifact metadata,
        org.eclipse.aether.repository.RemoteRepository deployRepository) {
    String artifactUrl = new ProgressReportingOperationRunner<String>(
            String.format("Publishing archive into repository %s", deployRepository.getId()))
                    .run(indicator -> {
                        String[] url = new String[1];
                        ((DefaultRepositorySystemSession) session).setTransferListener(
                                new ProgressReportingTransferListener(indicator, false) {

                                    @Override
                                    public void transferSucceeded(TransferEvent event) {
                                        super.transferSucceeded(event);
                                        if (event.getResource().getResourceName()
                                                .endsWith(".zip")) {
                                            url[0] = event.getResource().getRepositoryUrl()
                                                    + event.getResource().getResourceName();
                                        }
                                    }
                                });

                        DeployRequest deployRequest = new DeployRequest();
                        deployRequest.addArtifact(zip).addArtifact(pom).addArtifact(metadata);
                        deployRequest.setRepository(deployRepository);

                        system.deploy(session, deployRequest);

                        return url[0];
                    });

    log.newline();
    log.info(Style.cyan(Constants.DIVIDER) + " " + Style.bold("Archive"));
    log.info("  %s (%s in %s files)", Style.underline(FileUtils.relativize(zip.getFile())),
            FileUtils.sizeOf(zip.getFile()), source.allFiles().size());

    printTree(source);

    log.newline();
    log.info(Style.cyan(Constants.DIVIDER) + " " + Style.bold("URL"));
    log.info("  %s", Style.underline(artifactUrl));

    log.newline();
    log.info(Style.green("Successfully published archive for %s:%s (%s)", manifest.group(),
            manifest.artifact(), manifest.version()));
}
 
Example #7
Source File: DeployParticipant.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
List<DeployRequest> getDeployAtEndRequests() {
  return Collections.unmodifiableList(deployAtEndRequests);
}
 
Example #8
Source File: DeployParticipant.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public void deploy(RepositorySystemSession session, DeployRequest deployRequest) throws DeploymentException {
  repoSystem.deploy(session, deployRequest);
}
 
Example #9
Source File: DeployParticipant.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public void deployAtEnd(DeployRequest deployRequest) {
  checkSupport();
  deployAtEndRequests.add(deployRequest);
}