1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.List;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.plugins.annotations.LifecyclePhase;
30 import org.apache.maven.plugins.annotations.Mojo;
31 import org.apache.maven.plugins.annotations.ResolutionScope;
32 import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
33 import org.codehaus.plexus.util.FileUtils;
34
35
36
37
38
39
40 @Mojo(name = "nar-assembly", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true,
41 requiresDependencyResolution = ResolutionScope.TEST)
42 public class NarAssemblyMojo extends AbstractDependencyMojo {
43
44
45
46 @Override
47 protected ScopeFilter getArtifactScopeFilter() {
48
49
50 return new ScopeFilter( Artifact.SCOPE_RUNTIME, null );
51 }
52
53
54
55
56 @Override
57 public final void narExecute() throws MojoExecutionException, MojoFailureException {
58
59 List<AttachedNarArtifact> attachedNarArtifacts = getAttachedNarArtifacts(libraries);
60 downloadAttachedNars(attachedNarArtifacts);
61
62
63
64
65
66
67
68
69
70
71
72 attachedNarArtifacts = getAttachedNarArtifacts(libraries);
73 unpackAttachedNars(attachedNarArtifacts);
74
75
76 for (final Object element : attachedNarArtifacts) {
77 final Artifact dependency = (Artifact) element;
78 getLog().debug("Assemble from " + dependency);
79
80
81
82
83 dependency.isSnapshot();
84
85 final File srcDir = getLayout().getNarUnpackDirectory(getUnpackDirectory(),
86 getNarManager().getNarFile(dependency));
87
88
89
90
91
92 final File dstDir = getTargetDirectory();
93 try {
94 FileUtils.mkdir(dstDir.getPath());
95 getLog().debug("SrcDir: " + srcDir);
96 if (srcDir.exists()) {
97 FileUtils.copyDirectoryStructureIfModified(srcDir, dstDir);
98 }
99 } catch (final IOException ioe) {
100 throw new MojoExecutionException("Failed to copy directory for dependency " + dependency + " from " + srcDir
101 + " to " + dstDir, ioe);
102 }
103 }
104 }
105 }