List of usage examples for org.apache.maven.project MavenProject getAttachedArtifacts
public List<Artifact> getAttachedArtifacts()
From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java
License:Open Source License
/** * Checks to see if the specified artifact is available from the reactor. * * @param artifact The artifact we are looking for. * @return The resolved artifact that is the same as the one we were looking for or <code>null</code> if one could * not be found.//from w w w . ja v a2 s . c o m */ private Artifact getArtifactFomReactor(Artifact artifact) { // check project dependencies first off for (Artifact a : project.getArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } // check reactor projects for (MavenProject p : reactorProjects == null ? Collections.<MavenProject>emptyList() : reactorProjects) { // check the main artifact if (equals(artifact, p.getArtifact()) && hasFile(p.getArtifact())) { return p.getArtifact(); } // check any side artifacts for (Artifact a : (List<Artifact>) p.getAttachedArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } } // not available return null; }
From source file:com.github.panthers.maven.plugins.AbstractDependencyMojo.java
License:Apache License
/** * Checks to see if the specified artifact is available from the reactor. */*from w w w . ja va 2 s. c om*/ * @param artifact The artifact we are looking for. * @return The resolved artifact that is the same as the one we were looking for or <code>null</code> if one could * not be found. */ @SuppressWarnings("unchecked") private Artifact getArtifactFomReactor(Artifact artifact) { // check project dependencies first off for (Artifact a : (Set<Artifact>) project.getArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } // check reactor projects for (MavenProject p : reactorProjects == null ? Collections.<MavenProject>emptyList() : reactorProjects) { // check the main artifact if (equals(artifact, p.getArtifact()) && hasFile(p.getArtifact())) { return p.getArtifact(); } // check any side artifacts for (Artifact a : (List<Artifact>) p.getAttachedArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } } // not available return null; }
From source file:com.github.wix_maven.AbstractWixMojo.java
License:Apache License
/** * Copied from Maven-dependency-plugin Checks to see if the specified artifact is available from the reactor. * //from www. j a v a 2 s. c o m * @param artifact * The artifact we are looking for. * @return The resolved artifact that is the same as the one we were looking for or <code>null</code> if one could not be found. */ private Artifact getArtifactFomReactor(Artifact artifact) { // check project dependencies first off for (Artifact a : (Set<Artifact>) project.getArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } // check reactor projects for (MavenProject p : reactorProjects == null ? Collections.<MavenProject>emptyList() : reactorProjects) { // check the main artifact if (equals(artifact, p.getArtifact()) && hasFile(p.getArtifact())) { return p.getArtifact(); } // check any side artifacts for (Artifact a : (List<Artifact>) p.getAttachedArtifacts()) { if (equals(artifact, a) && hasFile(a)) { return a; } } } // not available return null; }
From source file:com.google.code.sbt.compiler.plugin.SBTTestCompileMojo.java
License:Apache License
/** * {@inheritDoc}/* w w w . j a v a 2s .c om*/ */ @Override protected Map<File, File> getAnalysisCacheMap() { HashMap<File, File> map = new HashMap<File, File>(); for (MavenProject reactorProject : reactorProjects) { File analysisCacheFile = defaultAnalysisCacheFile(reactorProject); if (analysisCacheFile.isFile()) { File reactorProjectArtifactFile = reactorProject.getArtifact().getFile(); if (reactorProjectArtifactFile != null) { map.put(reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile()); } } if (reactorProject != project) { File testAnalysisCacheFile = defaultTestAnalysisCacheFile(reactorProject); if (testAnalysisCacheFile.isFile()) { List<Artifact> reactorProjectattachedArtifacts = reactorProject.getAttachedArtifacts(); for (Artifact artifact : reactorProjectattachedArtifacts) { if ("tests".equals(artifact.getClassifier())) { map.put(artifact.getFile().getAbsoluteFile(), testAnalysisCacheFile.getAbsoluteFile()); break; } } } } } return map; }
From source file:com.webcohesion.enunciate.mojo.DeployArtifactBaseMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (this.enunciateArtifactId == null) { throw new MojoExecutionException("An enunciate artifact id must be supplied."); }/* w w w. ja v a 2s .c om*/ Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY); if (enunciate == null) { throw new MojoExecutionException("No enunciate mechanism found in the project!"); } com.webcohesion.enunciate.artifacts.Artifact enunciateArtifact = enunciate .findArtifact(this.enunciateArtifactId); if (enunciateArtifact == null) { throw new MojoExecutionException("Unknown Enunciate artifact: " + this.enunciateArtifactId + "."); } File mainArtifact = null; File sources = null; File javadocs = null; if (enunciateArtifact instanceof ClientLibraryArtifact) { for (com.webcohesion.enunciate.artifacts.Artifact childArtifact : ((ClientLibraryArtifact) enunciateArtifact) .getArtifacts()) { if (childArtifact instanceof FileArtifact) { ArtifactType artifactType = ((FileArtifact) childArtifact).getArtifactType(); if (artifactType != null) { switch (artifactType) { case binaries: mainArtifact = ((FileArtifact) childArtifact).getFile(); break; case sources: sources = ((FileArtifact) childArtifact).getFile(); break; case javadocs: javadocs = ((FileArtifact) childArtifact).getFile(); break; } } } } } else if (enunciateArtifact instanceof FileArtifact) { mainArtifact = ((FileArtifact) enunciateArtifact).getFile(); } else { try { mainArtifact = enunciate.createTempFile(this.enunciateArtifactId, "artifact"); enunciateArtifact.exportTo(mainArtifact, enunciate); } catch (IOException e) { throw new MojoExecutionException("Unable to create a temp file.", e); } } if (mainArtifact == null) { if (sources != null) { mainArtifact = sources; sources = null; } } if (mainArtifact == null) { throw new MojoExecutionException( "Unable to determine the file to deploy from enunciate artifact " + enunciateArtifactId + "."); } // Process the supplied POM (if there is one) Model model = null; if (pomFile != null) { generatePom = false; model = readModel(pomFile); processModel(model); } if (this.packaging == null) { String artifactName = mainArtifact.getName(); int dotIndex = artifactName.indexOf('.'); if (dotIndex > 0 && (dotIndex + 1 < artifactName.length())) { this.packaging = artifactName.substring(dotIndex + 1); } } if (this.packaging == null) { throw new MojoExecutionException("Unable to determine the packaging of enunciate artifact " + enunciateArtifactId + ". Please specify it in the configuration."); } if (this.version == null) { throw new MojoExecutionException("Null version."); } if (model == null) { model = new Model(); model.setModelVersion("4.0.0"); model.setGroupId(this.groupId); model.setArtifactId(this.artifactId); model.setVersion(this.version); model.setPackaging(this.packaging); model.setDescription(this.description); } ArtifactRepository repo = getDeploymentRepository(); String protocol = repo.getProtocol(); if (protocol.equals("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs(); } } Artifact artifact = this.artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier); // Upload the POM if requested, generating one if need be if (generatePom) { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, generatePomFile(model)); artifact.addMetadata(metadata); } else { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } try { getDeployer().deploy(mainArtifact, artifact, repo, this.localRepository); if (sources != null || javadocs != null) { MavenProject project = new MavenProject(model); project.setArtifact(artifact); if (sources != null) { //we have to do it this way because of classloading issues. this.projectHelper.attachArtifact(project, artifact.getType(), "sources", sources); getDeployer().deploy(sources, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository); } if (javadocs != null) { //we have to do it this way because of classloading issues. this.projectHelper.attachArtifact(project, artifact.getType(), "javadoc", javadocs); getDeployer().deploy(javadocs, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository); } } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:de.hwbllmnn.maven.DistMojo.java
License:GNU General Public License
public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog();//www . ja v a 2 s. co m File basedir = project.getBasedir(); File target = new File(basedir, "target/dist"); if (!target.isDirectory() && !target.mkdirs()) { log.warn("Could not create target directory: " + target); } List<Artifact> artifacts = new LinkedList<Artifact>(); @SuppressWarnings("unchecked") List<Object> modules = project.getCollectedProjects(); if (includeProjectArtifacts) { modules.add(project); } for (Object o : modules) { MavenProject module = (MavenProject) o; List<?> arts = module.getAttachedArtifacts(); for (Object obj : arts) { artifacts.add((Artifact) obj); } if (!includeOnlyAttachedArtifacts) { artifacts.add(module.getArtifact()); } } log.info("Collected artifacts: " + artifacts); for (Artifact a : artifacts) { File file = a.getFile(); if (file == null) { log.warn("Skipping non-existing artifact: " + a); continue; } try { copyFile(file, new File(target, file.getName())); log.info("Copied artifact " + file.getName()); } catch (IOException e) { log.warn("Could not copy artifact: " + file); } } }
From source file:hudson.gridmaven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(new FileInputStream(pom.getFile()))); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);/*from ww w . j a va2 s .c om*/ mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled - not archiving " + assembly); } else { FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } } return true; }
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
/** * Mojos perform different dependency resolution, so we need to check this for each mojo. *///from w ww .ja va 2s . c om public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { // TODO (kutzi, 2011/09/06): it should be perfectly safe to move all these records to the // postBuild method as artifacts should only be added by mojos, but never removed/modified. record(pom.getArtifacts(), used); record(pom.getArtifact(), produced); record(pom.getAttachedArtifacts(), produced); record(pom.getGroupId() + ":" + pom.getArtifactId(), pom.getFile(), produced); return true; }
From source file:hudson.maven.ReactorReader.java
License:Apache License
/** * Tries to resolve the specified artifact from the artifacts of the given project. * /*from w w w .j a v a 2 s .c o m*/ * @param project The project to try to resolve the artifact from, must not be <code>null</code>. * @param requestedArtifact The artifact to resolve, must not be <code>null</code>. * @return The matching artifact from the project or <code>null</code> if not found. */ private org.apache.maven.artifact.Artifact findMatchingArtifact(MavenProject project, Artifact requestedArtifact) { String requestedRepositoryConflictId = getConflictId(requestedArtifact); org.apache.maven.artifact.Artifact mainArtifact = project.getArtifact(); if (requestedRepositoryConflictId.equals(getConflictId(mainArtifact))) { mainArtifact.setFile(new File(workspaceRoot, project.getArtifactId())); return mainArtifact; } Collection<org.apache.maven.artifact.Artifact> attachedArtifacts = project.getAttachedArtifacts(); if (attachedArtifacts != null && !attachedArtifacts.isEmpty()) { for (org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts) { if (requestedRepositoryConflictId.equals(getConflictId(attachedArtifact))) { attachedArtifact.setFile(new File(workspaceRoot, project.getArtifactId())); return attachedArtifact; } } } return null; }
From source file:hudson.maven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(pom.getFile())); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);//from w ww .j ava2 s . co m mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled"); } else if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } return true; }