org.eclipse.aether.deployment.DeploymentException Java Examples

The following examples show how to use org.eclipse.aether.deployment.DeploymentException. 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: DeployArtifacts.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
  this.log.info("Deploying the release artifacts into the distribution repository");

  try {
    Collection<Artifact> deployedArtifacts = this.deployer.deployArtifacts(this.metadata.getReleaseArtifacts());
    if (!deployedArtifacts.isEmpty()) {
      this.log.debug("\tDeployed the following release artifacts to the remote repository:");
      for (Artifact a : deployedArtifacts) {
        this.log.debug("\t\t" + a);
      }
    }
  } catch (DeploymentException e) {
    throw new MojoFailureException("Unable to deploy artifacts into remote repository.", e);
  }
}
 
Example #2
Source File: Publisher.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @param descriptor an {@link Artifact}, holding the maven coordinates for the published files
 *     less the extension that is to be derived from the files. The {@code descriptor} itself will
 *     not be published as is, and the {@link File} attached to it (if any) will be ignored.
 * @param toPublish {@link File}(s) to be published using the given coordinates. The filename
 *     extension of each given file will be used as a maven "extension" coordinate
 */
public DeployResult publish(Artifact descriptor, List<File> toPublish)
    throws DeploymentException {
  String providedExtension = descriptor.getExtension();
  if (!providedExtension.isEmpty()) {
    LOG.warn(
        "Provided extension %s of artifact %s to be published will be ignored. The extensions "
            + "of the provided file(s) will be used",
        providedExtension, descriptor);
  }
  List<Artifact> artifacts = new ArrayList<>(toPublish.size());
  for (File file : toPublish) {
    artifacts.add(
        new SubArtifact(
            descriptor,
            descriptor.getClassifier(),
            Files.getFileExtension(file.getAbsolutePath()),
            file));
  }
  return publish(artifacts);
}
 
Example #3
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 #4
Source File: ArtifactDeployer.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deploys the given artifacts to the configured remote Maven repositories.
 *
 * @param artifacts the artifacts to deploy.
 * @return the artifacts that have been deployed successfully.
 * @throws DeploymentException if anything goes wrong during the deployment process.
 */
public Collection<Artifact> deployArtifacts(Collection<Artifact> artifacts) throws DeploymentException {
  Collection<Artifact> result = deploy(artifacts, this.metadata.getDeploymentRepository());
  for (RemoteRepository repo : this.additonalDeploymentRepositories) {
    deploy(artifacts, repo);
  }
  return result;
}
 
Example #5
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 #6
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 #7
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 #8
Source File: Publisher.java    From buck with Apache License 2.0 4 votes vote down vote up
public ImmutableSet<DeployResult> publish(
    SourcePathResolverAdapter pathResolver, ImmutableSet<MavenPublishable> publishables)
    throws DeploymentException {
  ImmutableListMultimap<UnflavoredBuildTarget, UnflavoredBuildTarget> duplicateBuiltinBuileRules =
      checkForDuplicatePackagedDeps(publishables);
  if (duplicateBuiltinBuileRules.size() > 0) {
    StringBuilder sb = new StringBuilder();
    sb.append("Duplicate transitive dependencies for publishable libraries found!  This means");
    sb.append(StandardSystemProperty.LINE_SEPARATOR);
    sb.append("that the following libraries would have multiple copies if these libraries were");
    sb.append(StandardSystemProperty.LINE_SEPARATOR);
    sb.append("used together.  The can be resolved by adding a maven URL to each target listed");
    sb.append(StandardSystemProperty.LINE_SEPARATOR);
    sb.append("below:");
    for (UnflavoredBuildTarget unflavoredBuildTargetView : duplicateBuiltinBuileRules.keySet()) {
      sb.append(StandardSystemProperty.LINE_SEPARATOR);
      sb.append(unflavoredBuildTargetView.getFullyQualifiedName());
      sb.append(" (referenced by these build targets: ");
      Joiner.on(", ").appendTo(sb, duplicateBuiltinBuileRules.get(unflavoredBuildTargetView));
      sb.append(")");
    }
    throw new DeploymentException(sb.toString());
  }

  ImmutableSet.Builder<DeployResult> deployResultBuilder = ImmutableSet.builder();
  for (MavenPublishable publishable : publishables) {
    DefaultArtifact coords =
        new DefaultArtifact(
            Preconditions.checkNotNull(
                publishable.getMavenCoords().get(),
                "No maven coordinates specified for published rule ",
                publishable));
    Path relativePathToOutput =
        pathResolver.getRelativePath(
            Preconditions.checkNotNull(
                publishable.getSourcePathToOutput(),
                "No path to output present in ",
                publishable));
    File mainItem = publishable.getProjectFilesystem().resolve(relativePathToOutput).toFile();

    if (!coords.getClassifier().isEmpty()) {
      deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem)));
    }

    try {
      // If this is the "main" artifact (denoted by lack of classifier) generate and publish
      // pom alongside
      File pom = Pom.generatePomFile(pathResolver, publishable).toFile();
      deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem, pom)));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  return deployResultBuilder.build();
}
 
Example #9
Source File: Publisher.java    From buck with Apache License 2.0 4 votes vote down vote up
public DeployResult publish(
    String groupId, String artifactId, String version, List<File> toPublish)
    throws DeploymentException {
  return publish(new DefaultArtifact(groupId, artifactId, "", version), toPublish);
}
 
Example #10
Source File: PublishCommand.java    From buck with Apache License 2.0 4 votes vote down vote up
private void publishTargets(ImmutableSet<BuildTarget> buildTargets, CommandRunnerParams params) {
  ImmutableSet.Builder<MavenPublishable> publishables = ImmutableSet.builder();

  for (BuildTarget buildTarget : buildTargets) {
    BuildRule buildRule = getBuild().getGraphBuilder().requireRule(buildTarget);
    Objects.requireNonNull(buildRule);

    if (!(buildRule instanceof MavenPublishable)) {
      throw new HumanReadableException(
          "Cannot publish rule of type %s", buildRule.getClass().getName());
    }

    MavenPublishable publishable = (MavenPublishable) buildRule;
    if (!publishable.getMavenCoords().isPresent()) {
      throw new HumanReadableException(
          "No maven coordinates specified for %s",
          buildTarget.getUnflavoredBuildTarget().getFullyQualifiedName());
    }
    publishables.add(publishable);
  }

  // Assume validation passed.
  URL repoUrl = toMavenCentral ? Publisher.MAVEN_CENTRAL : Objects.requireNonNull(remoteRepo);

  Publisher publisher =
      new Publisher(
          params
              .getCells()
              .getRootCell()
              .getFilesystem()
              .getBuckPaths()
              .getTmpDir()
              .resolve(PUBLISH_GEN_PATH),
          repoUrl,
          Optional.ofNullable(username),
          Optional.ofNullable(password),
          dryRun);

  try {
    ImmutableSet<DeployResult> deployResults =
        publisher.publish(
            getBuild().getGraphBuilder().getSourcePathResolver(), publishables.build());
    for (DeployResult deployResult : deployResults) {
      printArtifactsInformation(params, deployResult);
    }
  } catch (DeploymentException e) {
    throw new HumanReadableException(e, e.getMessage());
  }
}
 
Example #11
Source File: PublisherTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void errorRaisedForDuplicateFirstOrderDeps()
    throws DeploymentException, NoSuchBuildTargetException {
  // Construct a graph that looks like this.  A and B have maven coordinates set.
  // A   B
  //  \ /
  //   C
  BuildTarget publishableTargetA =
      BuildTargetFactory.newInstance("//:a").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget publishableTargetB =
      BuildTargetFactory.newInstance("//:b").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget targetC = BuildTargetFactory.newInstance("//:c");

  TargetNode<?> depNode =
      JavaLibraryBuilder.createBuilder(targetC).addSrc(Paths.get("c.java")).build();
  TargetNode<?> publishableANode =
      JavaLibraryBuilder.createBuilder(publishableTargetA)
          .addSrc(Paths.get("a.java"))
          .setMavenCoords(MVN_COORDS_A)
          .addDep(targetC)
          .build();
  TargetNode<?> publishableBNode =
      JavaLibraryBuilder.createBuilder(publishableTargetB)
          .addSrc(Paths.get("b.java"))
          .setMavenCoords(MVN_COORDS_B)
          .addDep(targetC)
          .build();

  TargetGraph targetGraph =
      TargetGraphFactory.newInstance(depNode, publishableANode, publishableBNode);
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder(targetGraph);

  MavenPublishable publishableA = (MavenPublishable) graphBuilder.requireRule(publishableTargetA);
  MavenPublishable publishableB = (MavenPublishable) graphBuilder.requireRule(publishableTargetB);

  expectedException.expect(DeploymentException.class);
  expectedException.expectMessage(
      Matchers.containsString(targetC.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetA.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetB.getUnflavoredBuildTarget().getFullyQualifiedName()));

  publisher.publish(
      graphBuilder.getSourcePathResolver(), ImmutableSet.of(publishableA, publishableB));
}
 
Example #12
Source File: PublisherTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void errorRaisedForDuplicateFirstOrderAndTransitiveDep()
    throws DeploymentException, NoSuchBuildTargetException {
  // Construct a graph that looks like this.  A and B have maven coordinates set.
  // A   B
  // |   |
  // C   |
  //  \ /
  //   D
  BuildTarget publishableTargetA =
      BuildTargetFactory.newInstance("//:a").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget publishableTargetB =
      BuildTargetFactory.newInstance("//:b").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget targetC = BuildTargetFactory.newInstance("//:c");
  BuildTarget targetD = BuildTargetFactory.newInstance("//:d");

  TargetNode<?> transitiveDepNode =
      JavaLibraryBuilder.createBuilder(targetD).addSrc(Paths.get("d.java")).build();
  TargetNode<?> depNode =
      JavaLibraryBuilder.createBuilder(targetC)
          .addSrc(Paths.get("c.java"))
          .addDep(targetD)
          .build();
  TargetNode<?> publishableANode =
      JavaLibraryBuilder.createBuilder(publishableTargetA)
          .addSrc(Paths.get("a.java"))
          .setMavenCoords(MVN_COORDS_A)
          .addDep(targetC)
          .build();
  TargetNode<?> publishableBNode =
      JavaLibraryBuilder.createBuilder(publishableTargetB)
          .addSrc(Paths.get("b.java"))
          .setMavenCoords(MVN_COORDS_B)
          .addDep(targetD)
          .build();

  TargetGraph targetGraph =
      TargetGraphFactory.newInstance(
          transitiveDepNode, depNode, publishableANode, publishableBNode);
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder(targetGraph);

  MavenPublishable publishableA = (MavenPublishable) graphBuilder.requireRule(publishableTargetA);
  MavenPublishable publishableB = (MavenPublishable) graphBuilder.requireRule(publishableTargetB);

  expectedException.expect(DeploymentException.class);
  expectedException.expectMessage(
      Matchers.containsString(targetD.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetA.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetB.getUnflavoredBuildTarget().getFullyQualifiedName()));

  publisher.publish(
      graphBuilder.getSourcePathResolver(), ImmutableSet.of(publishableA, publishableB));
}
 
Example #13
Source File: PublisherTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void errorRaisedForDuplicateTransitiveDeps()
    throws DeploymentException, NoSuchBuildTargetException {
  // Construct a graph that looks like this.  A and B have maven coordinates set.
  // A   B
  // |   |
  // C   D
  //  \ /
  //   E
  BuildTarget publishableTargetA =
      BuildTargetFactory.newInstance("//:a").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget publishableTargetB =
      BuildTargetFactory.newInstance("//:b").withFlavors(JavaLibrary.MAVEN_JAR);
  BuildTarget targetC = BuildTargetFactory.newInstance("//:c");
  BuildTarget targetD = BuildTargetFactory.newInstance("//:d");
  BuildTarget targetE = BuildTargetFactory.newInstance("//:e");

  TargetNode<?> transitiveDepNode =
      JavaLibraryBuilder.createBuilder(targetE).addSrc(Paths.get("e.java")).build();
  TargetNode<?> dep1Node =
      JavaLibraryBuilder.createBuilder(targetC)
          .addSrc(Paths.get("c.java"))
          .addDep(targetE)
          .build();
  TargetNode<?> dep2Node =
      JavaLibraryBuilder.createBuilder(targetD)
          .addSrc(Paths.get("d.java"))
          .addDep(targetE)
          .build();
  TargetNode<?> publishableANode =
      JavaLibraryBuilder.createBuilder(publishableTargetA)
          .addSrc(Paths.get("a.java"))
          .setMavenCoords(MVN_COORDS_A)
          .addDep(targetC)
          .build();
  TargetNode<?> publishableBNode =
      JavaLibraryBuilder.createBuilder(publishableTargetB)
          .addSrc(Paths.get("b.java"))
          .setMavenCoords(MVN_COORDS_B)
          .addDep(targetD)
          .build();

  TargetGraph targetGraph =
      TargetGraphFactory.newInstance(
          transitiveDepNode, dep1Node, dep2Node, publishableANode, publishableBNode);
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder(targetGraph);

  MavenPublishable publishableA = (MavenPublishable) graphBuilder.requireRule(publishableTargetA);
  MavenPublishable publishableB = (MavenPublishable) graphBuilder.requireRule(publishableTargetB);

  expectedException.expect(DeploymentException.class);
  expectedException.expectMessage(
      Matchers.containsString(targetE.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetA.getUnflavoredBuildTarget().getFullyQualifiedName()));
  expectedException.expectMessage(
      Matchers.containsString(
          publishableTargetB.getUnflavoredBuildTarget().getFullyQualifiedName()));

  publisher.publish(
      graphBuilder.getSourcePathResolver(), ImmutableSet.of(publishableA, publishableB));
}