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
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.plugins.annotations.LifecyclePhase;
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.codehaus.plexus.util.FileUtils;
31 import org.codehaus.plexus.util.SelectorUtils;
32
33
34
35
36
37
38
39 @Mojo(name = "nar-resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true)
40 public class NarResourcesMojo extends AbstractResourcesMojo {
41
42
43
44 @Parameter(property = "nar.resources.copy.aol", defaultValue = "true", required = true)
45 private boolean resourcesCopyAOL;
46
47
48
49
50 @Parameter(defaultValue = "${basedir}/src/nar/resources", required = true)
51 private File resourceDirectory;
52
53 @Override
54 public final void narExecute() throws MojoExecutionException, MojoFailureException {
55
56 try {
57 int copied = 0;
58 final File noarchDir = new File(this.resourceDirectory, NarConstants.NAR_NO_ARCH);
59 if (noarchDir.exists()) {
60 final File noarchDstDir = getLayout().getNoArchDirectory(getTargetDirectory(),
61 getMavenProject().getArtifactId(), getMavenProject().getVersion());
62 getLog().debug("Copying noarch from " + noarchDir + " to " + noarchDstDir);
63 copied += NarUtil.copyDirectoryStructure(noarchDir, noarchDstDir, null, NarUtil.DEFAULT_EXCLUDES);
64 }
65 getLog().info("Copied " + copied + " resources");
66 } catch (final IOException e) {
67 throw new MojoExecutionException("NAR: Could not copy resources", e);
68 }
69
70
71 final File aolDir = new File(this.resourceDirectory, NarConstants.NAR_AOL);
72 if (aolDir.exists()) {
73 final String[] aol = aolDir.list();
74 for (final String anAol : aol) {
75
76 if (this.resourcesCopyAOL && !anAol.equals(getAOL().toString())) {
77 continue;
78 }
79
80 boolean ignore = false;
81 for (final Object element : FileUtils.getDefaultExcludesAsList()) {
82 final String exclude = (String) element;
83 if (SelectorUtils.matchPath(exclude.replace('/', File.separatorChar), anAol)) {
84 ignore = true;
85 break;
86 }
87 }
88 if (!ignore) {
89 final File aolFile = new File(aolDir, anAol);
90 copyResources(aolFile, aolFile.getName());
91 }
92 }
93 }
94 }
95 }