Search in sources :

Example 1 with DeployResult

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

the class PublishCommand method publishTargets.

private boolean publishTargets(ImmutableList<BuildTarget> buildTargets, CommandRunnerParams params) {
    ImmutableSet.Builder<MavenPublishable> publishables = ImmutableSet.builder();
    boolean success = true;
    for (BuildTarget buildTarget : buildTargets) {
        BuildRule buildRule = null;
        try {
            buildRule = getBuild().getRuleResolver().requireRule(buildTarget);
        } catch (NoSuchBuildTargetException e) {
            // This doesn't seem physically possible!
            throw new RuntimeException(e);
        }
        Preconditions.checkNotNull(buildRule);
        if (!(buildRule instanceof MavenPublishable)) {
            params.getBuckEventBus().post(ConsoleEvent.severe("Cannot publish rule of type %s", buildRule.getClass().getName()));
            success &= false;
            continue;
        }
        MavenPublishable publishable = (MavenPublishable) buildRule;
        if (!publishable.getMavenCoords().isPresent()) {
            params.getBuckEventBus().post(ConsoleEvent.severe("No maven coordinates specified for %s", buildTarget.getUnflavoredBuildTarget().getFullyQualifiedName()));
            success &= false;
            continue;
        }
        publishables.add(publishable);
    }
    Publisher publisher = new Publisher(params.getCell().getFilesystem(), Optional.ofNullable(remoteRepo), Optional.ofNullable(username), Optional.ofNullable(password), dryRun);
    try {
        ImmutableSet<DeployResult> deployResults = publisher.publish(new SourcePathResolver(new SourcePathRuleFinder(getBuild().getRuleResolver())), publishables.build());
        for (DeployResult deployResult : deployResults) {
            printArtifactsInformation(params, deployResult);
        }
    } catch (DeploymentException e) {
        params.getConsole().printBuildFailureWithoutStacktraceDontUnwrap(e);
        return false;
    }
    return success;
}
Also used : Publisher(com.facebook.buck.maven.Publisher) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) ImmutableSet(com.google.common.collect.ImmutableSet) DeployResult(org.eclipse.aether.deployment.DeployResult) BuildTarget(com.facebook.buck.model.BuildTarget) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) DeploymentException(org.eclipse.aether.deployment.DeploymentException)

Example 2 with DeployResult

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

the class Publisher method publish.

public ImmutableSet<DeployResult> publish(SourcePathResolver 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 unflavoredBuildTarget : duplicateBuiltinBuileRules.keySet()) {
            sb.append(StandardSystemProperty.LINE_SEPARATOR);
            sb.append(unflavoredBuildTarget.getFullyQualifiedName());
            sb.append(" (referenced by these build targets: ");
            Joiner.on(", ").appendTo(sb, duplicateBuiltinBuileRules.get(unflavoredBuildTarget));
            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();
}
Also used : Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) IOException(java.io.IOException) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) ImmutableSet(com.google.common.collect.ImmutableSet) DeployResult(org.eclipse.aether.deployment.DeployResult) DeploymentException(org.eclipse.aether.deployment.DeploymentException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 3 with DeployResult

use of org.eclipse.aether.deployment.DeployResult 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 4 with DeployResult

use of org.eclipse.aether.deployment.DeployResult in project unleash-maven-plugin by shillner.

the class ArtifactDeployer method deployArtifacts.

/**
 * 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 {
    DeployRequest request = new DeployRequest();
    request.setArtifacts(artifacts);
    request.setRepository(this.metadata.getDeploymentRepository());
    DeployResult result = this.deployer.deploy(this.repoSession, request);
    return result.getArtifacts();
}
Also used : DeployResult(org.eclipse.aether.deployment.DeployResult) DeployRequest(org.eclipse.aether.deployment.DeployRequest)

Aggregations

DeployResult (org.eclipse.aether.deployment.DeployResult)4 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DeployRequest (org.eclipse.aether.deployment.DeployRequest)2 DeploymentException (org.eclipse.aether.deployment.DeploymentException)2 Publisher (com.facebook.buck.maven.Publisher)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildRule (com.facebook.buck.rules.BuildRule)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 RepositorySystem (org.eclipse.aether.RepositorySystem)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1