List of usage examples for org.apache.maven.project.artifact AttachedArtifact AttachedArtifact
public AttachedArtifact(Artifact parent, String type, String classifier, ArtifactHandler artifactHandler)
From source file:de.hwbllmnn.maven.JSSourceArchiveMojo.java
License:GNU General Public License
@Override public void execute() throws MojoExecutionException, MojoFailureException { File dir = new File(project.getBasedir(), "src/main/javascript"); ZipOutputStream out = null;//from ww w . ja v a 2 s . c o m AttachedArtifact artifact = new AttachedArtifact(project.getArtifact(), "jslib", "source", new DefaultArtifactHandler("jslib")); List<File> list = new LinkedList<File>(); for (Object o : project.getDependencyArtifacts()) { Artifact a = (Artifact) o; if (a.getType().equals("jslib")) { Artifact source = artifactFactory.createArtifactWithClassifier(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jslib", "source"); try { artifactResolver.resolve(source, project.getRemoteArtifactRepositories(), localRepository); } catch (ArtifactResolutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ArtifactNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } list.add(source.getFile()); } } File target = new File(project.getBasedir(), "target"); if (!target.exists() && !target.mkdirs()) { throw new MojoFailureException("Could not create target directory!"); } File file = new File(project.getBasedir(), "target/" + project.getArtifactId() + "-" + project.getVersion() + "-source.jslib"); artifact.setFile(file); project.addAttachedArtifact(artifact); try { out = new ZipOutputStream(new FileOutputStream(file)); zip(dir, out, dir.toURI()); for (File f : list) { File tmp = new File(target, f.getName()); FileInputStream in = new FileInputStream(f); try { unzip(in, tmp); zip(tmp, out, tmp.getAbsoluteFile().toURI()); } finally { closeQuietly(in); } } } catch (IOException e) { getLog().error(e); } finally { closeQuietly(out); } }
From source file:org.codehaus.mojo.nbm.PopulateRepositoryMojo.java
License:Apache License
Artifact createAttachedArtifact(Artifact primary, File file, String type, String classifier) {
assert type != null;
ArtifactHandler handler = null;//ww w . j a va2 s . c o m
handler = artifactHandlerManager.getArtifactHandler(type);
if (handler == null) {
getLog().warn("No artifact handler for " + type);
handler = artifactHandlerManager.getArtifactHandler("jar");
}
Artifact artifact = new AttachedArtifact(primary, type, classifier, handler);
artifact.setFile(file);
artifact.setResolved(true);
return artifact;
}
From source file:org.gradle.api.publication.maven.internal.ant.AbstractMavenPublish.java
License:Apache License
private Artifact createAttachedArtifact(Artifact mainArtifact, String type, String classifier) { return new AttachedArtifact(mainArtifact, type, classifier, artifactHandler(type)); }
From source file:org.renjin.gcc.maven.GccBridgeHelper.java
License:Open Source License
public static void archiveHeaders(Log log, MavenProject project, File... includeDirectories) throws MojoExecutionException { File outputDir = new File(project.getBuild().getDirectory()); File archiveFile = new File(outputDir, project.getBuild().getFinalName() + "-headers.jar"); ensureDirExists(outputDir);/*from w w w.j av a 2 s . c o m*/ try (JarOutputStream output = new JarOutputStream(new FileOutputStream(archiveFile))) { for (File includeDirectory : includeDirectories) { if (includeDirectory.exists()) { log.info("Archiving headers from " + includeDirectory.getAbsolutePath()); archiveFiles(output, includeDirectory, ""); } } } catch (IOException e) { throw new MojoExecutionException("Failed to create headers archive", e); } Artifact artifact = new AttachedArtifact(project.getArtifact(), "jar", "headers", new HeaderArtifactHandler()); artifact.setFile(archiveFile); artifact.setResolved(true); project.addAttachedArtifact(artifact); }