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);
}
}
Aggregations