List of usage examples for org.apache.maven.artifact Artifact setRelease
void setRelease(boolean release);
From source file:com.soffid.maven.plugin.mda.Mda2Mojo.java
License:Apache License
private void attachArtifact(String directory, String classifier) throws ArchiverException, IOException { File dirFile = new File(directory); getLog().info("Attaching " + dirFile.getPath()); if (dirFile.isDirectory()) { File destFile = new File(project.getBuild().getOutputDirectory() + File.separator + project.getArtifactId() + "-" + classifier + ".zip"); zipArchiver.reset();//from ww w .j a va2 s.c om zipArchiver.addDirectory(dirFile); zipArchiver.setDestFile(destFile); zipArchiver.createArchive(); Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "zip", classifier); artifact.setFile(destFile); artifact.setRelease(true); project.addAttachedArtifact(artifact); } }
From source file:lu.softec.maven.mavenizer.FileDeployerMojo.java
License:Open Source License
public void deployFile(MavenFile mvnFile) throws MojoExecutionException, MojoFailureException { ArtifactRepositoryLayout layout = getLayout(repositoryLayout); ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, repositoryUrl, layout, uniqueVersion); String protocol = deploymentRepository.getProtocol(); if (StringUtils.isEmpty(protocol)) { throw new MojoExecutionException("No transfer protocol found."); }/*from w ww .j av a 2 s .c o m*/ // Create the artifact Artifact artifact = artifactFactory.createArtifactWithClassifier(mvnFile.getGroupId(), mvnFile.getArtifactId(), mvnFile.getVersion(), mvnFile.getPackaging(), mvnFile.getClassifier()); if (mvnFile.getFile().equals(getLocalRepoFile(artifact))) { throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + mvnFile.getFile()); } File pomFile = getPomFile(mvnFile); if (!pomFile.exists()) { throw new MojoExecutionException("No POM file found for: " + mvnFile.getFile()); } ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(pomMetadata); if (updateReleaseInfo) { artifact.setRelease(true); } try { deployer.deploy(mvnFile.getFile(), artifact, deploymentRepository, getLocalRepository()); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:lu.softec.maven.mavenizer.FileInstallerMojo.java
License:Open Source License
public void installFile(MavenFile mvnFile) throws MojoExecutionException { Artifact artifact = artifactFactory.createArtifactWithClassifier(mvnFile.getGroupId(), mvnFile.getArtifactId(), mvnFile.getVersion(), mvnFile.getPackaging(), mvnFile.getClassifier()); if (mvnFile.getFile().equals(getLocalRepoFile(artifact))) { getLog().warn("Cannot install artifact. " + "Artifact is already in the local repository.\n\nFile in question is: " + mvnFile.getFile() + "\n"); }/*from w w w .j ava 2 s .com*/ ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, getPomFile(mvnFile)); artifact.addMetadata(pomMetadata); if (updateReleaseInfo) { artifact.setRelease(true); } try { installer.install(mvnFile.getFile(), artifact, getLocalRepository()); } catch (ArtifactInstallationException e) { throw new MojoExecutionException( "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e); } }
From source file:net.md_5.specialsource.mavenplugin.InstallRemappedFileMojo.java
License:Apache License
private void installArtifact(Artifact artifact, File outJar) throws MojoExecutionException { // Install POM File generatedPomFile = generatePomFile(); ArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, generatedPomFile); if (!getLocalRepoFile(pomMetadata).exists()) { getLog().debug("Installing generated POM"); artifact.addMetadata(pomMetadata); } else {//from w w w .j a v a2 s. c o m getLog().debug("Skipping installation of generated POM, already present in local repository"); } if (updateReleaseInfo) { artifact.setRelease(true); } // Install artifact (based on maven-install-plugin) Collection metadataFiles = new LinkedHashSet(); try { installer.install(outJar, artifact, localRepository); installChecksums(artifact, metadataFiles); } catch (ArtifactInstallationException e) { throw new MojoExecutionException("Error installing artifact '" + artifact.getDependencyConflictId() + "' at " + outJar + ": " + e.getMessage(), e); } finally { if (generatedPomFile != null) { generatedPomFile.delete(); } } if (sources != null) { artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "jar", "sources"); try { installer.install(sources, artifact, localRepository); installChecksums(artifact, metadataFiles); } catch (ArtifactInstallationException e) { throw new MojoExecutionException("Error installing sources " + sources + ": " + e.getMessage(), e); } } if (javadoc != null) { artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "jar", "javadoc"); try { installer.install(javadoc, artifact, localRepository); installChecksums(artifact, metadataFiles); } catch (ArtifactInstallationException e) { throw new MojoExecutionException("Error installing API docs " + javadoc + ": " + e.getMessage(), e); } } installChecksums(metadataFiles); // Remove temporary file after it has been installed outJar.delete(); /* TODO: set as dependency? may not be feasible to add dynamically - instead, add in your pom.xml by hand then 'mvn initialize' & 'mvn package' mvn dependency:list http://maven.40175.n5.nabble.com/How-to-add-a-dependency-dynamically-during-the-build-in-a-plugin-td116484.html "How to add a dependency dynamically during the build in a plugin?" no solution https://gist.github.com/agaricusb/5073308/raw/aeae7738ec5da5274eab143d9f92c439f9b07f47/gistfile1.txt "Maven: A Developer's Notebook - Chapter 6. Writing Maven Plugins > Adding Dynamic Dependencies" adding to classpath.. // Add dependency Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); dependency.setScope("compile"); // TODO: system? //dependency.setSystemPath(); project.getDependencies().add(dependency);*/ }
From source file:org.codeartisans.javafx.maven.JavaFXInstallMojo.java
License:Apache License
private void install(String artifactId, String version, File file) throws MojoExecutionException { Artifact artifact = artifactFactory.createArtifactWithClassifier(GROUPID, artifactId, version, "jar", null); File pomFile = generatePomFile(GROUPID, artifactId, version, "jar"); artifact.addMetadata(new ProjectArtifactMetadata(artifact, pomFile)); artifact.setRelease(true); try {// ww w .jav a 2 s . com installer.install(file, artifact, localRepository); } catch (ArtifactInstallationException ex) { throw new MojoExecutionException("Unable to install " + artifactId, ex); } finally { pomFile.delete(); } }
From source file:org.opennms.maven.plugins.karaf.GenerateFeaturesMavenRepoMojo.java
License:Apache License
Artifact getPom(final Artifact artifact) { final Artifact pomArtifact = factory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom", null); pomArtifact.setOptional(artifact.isOptional()); pomArtifact.setRelease(artifact.isRelease()); final File dir = artifact.getFile().getParentFile(); pomArtifact.setFile(new File(dir, MavenUtil.getFileName(pomArtifact))); getLog().info("Artifact: " + artifact + " pom = " + pomArtifact); return pomArtifact; }
From source file:org.sonatype.nexus.maven.staging.deploy.DeployMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { if (skipNexusStagingDeployMojo) { getLog().info("Skipping Nexus Staging Deploy Mojo at user's demand."); return;//w w w . ja v a 2 s . c om } // StagingV2 cannot work offline, it needs REST calls to talk to Nexus even if not // deploying remotely (for example skipRemoteStaging equals true), but for stuff like profile selection, // matching, etc. failIfOffline(); // DEPLOY final ArrayList<DeployableArtifact> deployables = new ArrayList<DeployableArtifact>(2); // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { artifact.addMetadata(new ProjectArtifactMetadata(artifact, pomFile)); } if (updateReleaseInfo) { artifact.setRelease(true); } final Parameters parameters = buildParameters(); final DeployStrategy deployStrategy; final DeployPerModuleRequest request; try { if (isPomArtifact) { deployables.add(new DeployableArtifact(pomFile, artifact)); } else { final File file = artifact.getFile(); if (file != null && file.isFile()) { deployables.add(new DeployableArtifact(file, artifact)); } else if (!attachedArtifacts.isEmpty()) { getLog().info("No primary artifact to deploy, deploying attached artifacts instead."); final Artifact pomArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); pomArtifact.setFile(pomFile); if (updateReleaseInfo) { pomArtifact.setRelease(true); } deployables.add(new DeployableArtifact(pomFile, pomArtifact)); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion(pomArtifact.getVersion()); } else { throw new MojoExecutionException( "The packaging for this project did not assign a file to the build artifact"); } } for (Iterator<Artifact> i = attachedArtifacts.iterator(); i.hasNext();) { Artifact attached = i.next(); deployables.add(new DeployableArtifact(attached.getFile(), attached)); } if (skipLocalStaging) // totally skipped { deployStrategy = getDeployStrategy(Strategies.DIRECT); } else if (isSkipStaging() || artifact.isSnapshot()) // locally staging but uploading to deployment repo (no profiles and V2 used at all) { deployStrategy = getDeployStrategy(Strategies.DEFERRED); } else // for releases, everything used: profile selection, full V2, etc { deployStrategy = getDeployStrategy(Strategies.STAGING); } request = new DeployPerModuleRequest(getMavenSession(), parameters, deployables); deployStrategy.deployPerModule(request); } catch (ArtifactInstallationException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } // if local staging skipped, we even can't do remote staging at all (as nothing is staged locally) if (isThisLastProjectWithThisMojoInExecution()) { if (skipRemoteStaging) { getLog().info("Artifacts locally gathered under directory " + getWorkDirectoryRoot().getAbsolutePath() + ", skipping remote staging at user's demand."); return; } try { final FinalizeDeployRequest finalizeRequest = new FinalizeDeployRequest(getMavenSession(), parameters); finalizeRequest.setRemoteNexus(request.getRemoteNexus()); // pass over client deployStrategy.finalizeDeploy(finalizeRequest); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } } }
From source file:org.sonatype.nexus.plugin.deploy.DeployMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { if (skip) {/*from w w w .ja va2 s . c o m*/ getLog().info("Skipping artifact deployment"); return; } final File stagingDirectory = getStagingDirectory(); getLog().info("Using staging directory " + stagingDirectory.getAbsolutePath()); final ArtifactRepository repo = getStagingRepositoryFor(stagingDirectory); // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } if (isUpdateReleaseInfo()) { artifact.setRelease(true); } try { if (isPomArtifact) { stageArtifact(pomFile, artifact, repo, getLocalRepository()); } else { File file = artifact.getFile(); if (file != null && file.isFile()) { stageArtifact(file, artifact, repo, getLocalRepository()); } else if (!attachedArtifacts.isEmpty()) { getLog().info("No primary artifact to deploy, deploying attached artifacts instead."); Artifact pomArtifact = getArtifactFactory().createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); pomArtifact.setFile(pomFile); if (updateReleaseInfo) { pomArtifact.setRelease(true); } stageArtifact(pomFile, pomArtifact, repo, getLocalRepository()); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion(pomArtifact.getVersion()); } else { throw new MojoExecutionException( "The packaging for this project did not assign a file to the build artifact"); } } for (Iterator<Artifact> i = attachedArtifacts.iterator(); i.hasNext();) { Artifact attached = i.next(); stageArtifact(attached.getFile(), attached, repo, getLocalRepository()); } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } if (isThisLastProjectWithThisMojoInExecution()) { if (!skipUpload) { failIfOffline(); try { uploadStagedArtifacts(); } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } } else { getLog().info("Artifacts staged in directory " + stagingDirectory.getAbsolutePath() + ", skipping deploy."); } } }
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();/* w w w. j a v a 2 s. co m*/ } } // 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); } }
From source file:se.jiderhamn.promote.maven.plugin.PromoteArtifactsMojo.java
License:Apache License
public void execute() throws MojoExecutionException { File promotePropertiesFile = PromoteUtils.getPromotePropertiesFile(project); if (!promotePropertiesFile.exists()) { getLog().warn("Cannot find " + promotePropertiesFile + ". Remember to run the " + MakePromotableMojo.NAME + " goal after building the artifacts."); }// ww w . j a v a 2 s . co m Properties props = PropertyUtils.loadProperties(promotePropertiesFile); getLog().info("Artifact information read from " + promotePropertiesFile); getLog().debug("Read properties: " + props); URI targetURI = PromoteUtils.getTargetURI(project); Artifact artifact = PromoteUtils.fromProperties(props, "artifact", targetURI); if (artifact != null) { validateArtifact(artifact); // Set artifact as being artifact of project final String releasedVersion = getReleasedVersion(project, artifact); getLog().info("Setting artifact: " + artifact + "; released version " + releasedVersion); artifact.setVersion(releasedVersion != null ? releasedVersion : project.getVersion()); artifact.setRelease(true); project.setArtifact(artifact); } final List<Artifact> attachedArtifacts = PromoteUtils.attachedArtifactsFromProperties(props, targetURI); for (Artifact attachedArtifact : attachedArtifacts) { validateArtifact(attachedArtifact); // Attach artifact to project final String releasedVersion = getReleasedVersion(project, attachedArtifact); getLog().info("Attaching artifact: " + attachedArtifact + "; released version " + releasedVersion); attachedArtifact.setVersion(releasedVersion != null ? releasedVersion : project.getVersion()); attachedArtifact.setRelease(true); project.addAttachedArtifact(attachedArtifact); } }