Search in sources :

Example 1 with Authentication

use of org.apache.maven.artifact.repository.Authentication in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method uploadDeploymentUnit.

@SuppressWarnings("unchecked")
protected void uploadDeploymentUnit(J4pClient client, boolean customUsernameAndPassword) throws Exception {
    String uri = getMavenUploadUri(client);
    // lets resolve the artifact to make sure we get a local file
    Artifact artifact = project.getArtifact();
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    addNeededRemoteRepository();
    request.setRemoteRepositories(remoteRepositories);
    request.setLocalRepository(localRepository);
    resolver.resolve(request);
    String packaging = project.getPackaging();
    File pomFile = project.getFile();
    @SuppressWarnings("unchecked") List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
    DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
    ArtifactRepository repo = new DefaultArtifactRepository(serverId, uri, layout);
    if (customUsernameAndPassword) {
        repo.setAuthentication(new Authentication(fabricServer.getUsername(), fabricServer.getPassword()));
    }
    // Deploy the POM
    boolean isPomArtifact = "pom".equals(packaging);
    if (!isPomArtifact) {
        ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile);
        artifact.addMetadata(metadata);
    }
    try {
        if (isPomArtifact) {
            deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount);
        } else {
            File file = artifact.getFile();
            if (isFile(file)) {
                deploy(file, artifact, repo, localRepository, retryFailedDeploymentCount);
            } else if (!attachedArtifacts.isEmpty()) {
                getLog().info("No primary artifact to deploy, deploying attached artifacts instead.");
                Artifact pomArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
                pomArtifact.setFile(pomFile);
                deploy(pomFile, pomArtifact, repo, localRepository, retryFailedDeploymentCount);
                // propagate the timestamped version to the main artifact for the attached artifacts to pick it up
                artifact.setResolvedVersion(pomArtifact.getVersion());
            } else {
                String message = "The packaging for this project did not assign a file to the build artifact";
                throw new MojoExecutionException(message);
            }
        }
        for (Artifact attached : attachedArtifacts) {
            deploy(attached.getFile(), attached, repo, localRepository, retryFailedDeploymentCount);
        }
    } catch (ArtifactDeploymentException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) Authentication(org.apache.maven.artifact.repository.Authentication) File(java.io.File)

Aggregations

File (java.io.File)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactDeploymentException (org.apache.maven.artifact.deployer.ArtifactDeploymentException)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 Authentication (org.apache.maven.artifact.repository.Authentication)1 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)1 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)1 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ProjectArtifactMetadata (org.apache.maven.project.artifact.ProjectArtifactMetadata)1