List of usage examples for org.apache.maven.artifact Artifact setResolvedVersion
void setResolvedVersion(String version);
From source file:hudson.maven.artifact.transform.SnapshotTransformation.java
License:Apache License
public void transformForDeployment(Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) throws ArtifactDeploymentException { if (artifact.isSnapshot()) { Snapshot snapshot = new Snapshot(); if (remoteRepository.isUniqueVersion()) { snapshot.setTimestamp(getDeploymentTimestamp()); }/*from w w w. ja va 2 s . c o m*/ // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect try { int buildNumber = resolveLatestSnapshotBuildNumber(artifact, localRepository, remoteRepository); snapshot.setBuildNumber(buildNumber + 1); } catch (RepositoryMetadataResolutionException e) { throw new ArtifactDeploymentException("Error retrieving previous build number for artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e); } RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(artifact, snapshot); artifact.setResolvedVersion( constructVersion(metadata.getMetadata().getVersioning(), artifact.getBaseVersion())); artifact.addMetadata(metadata); } }
From source file:io.fabric8.maven.DeployToProfileMojo.java
License:Apache License
@SuppressWarnings("unchecked") protected void uploadDeploymentUnit(J4pClient client, boolean newUserAdded) 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);//from ww w. jav a 2 s.c o m 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 (newUserAdded) { // make sure to set authentication if we just added new user 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(); // lets deploy the pom for the artifact first if (isFile(pomFile)) { deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount); } 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); } }
From source file:org.sourcepit.tools.mojo.DeployCopiedArtifactMojo.java
License:Apache License
private void deployProject(DeployRequest request) throws MojoExecutionException, MojoFailureException { Artifact artifact = ArtifactUtils.copyArtifact(request.getProject().getArtifact()); String packaging = request.getProject().getPackaging(); File pomFile = request.getProject().getFile(); @SuppressWarnings("unchecked") List<Artifact> attachedArtifacts = new ArrayList<Artifact>(); ArtifactUtils.copyArtifacts(request.getProject().getAttachedArtifacts(), attachedArtifacts); ArtifactRepository repo = getDeploymentRepository(request.getProject(), request.getAltDeploymentRepository(), request.getAltReleaseDeploymentRepository(), request.getAltSnapshotDeploymentRepository()); String protocol = repo.getProtocol(); if (protocol.equalsIgnoreCase("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs();/*from ww w . j a va2 s. c om*/ } } // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } if (request.isUpdateReleaseInfo()) { artifact.setRelease(true); } int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount(); try { if (isPomArtifact) { deploy(pomFile, artifact, repo, getLocalRepository(), retryFailedDeploymentCount); } else { File file = artifact.getFile(); if (file != null && file.isFile()) { deploy(file, artifact, repo, getLocalRepository(), 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); if (request.isUpdateReleaseInfo()) { pomArtifact.setRelease(true); } deploy(pomFile, pomArtifact, repo, getLocalRepository(), 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, getLocalRepository(), retryFailedDeploymentCount); } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }