1 package org.codehaus.mojo.exec;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import java.io.File;
17 import java.util.List;
18
19 import org.apache.maven.plugin.AbstractMojo;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.project.MavenProject;
22 import org.codehaus.plexus.util.cli.CommandLineUtils;
23
24
25
26
27
28
29
30
31 public abstract class AbstractExecMojo extends AbstractMojo {
32
33
34
35
36
37
38
39 protected MavenProject project;
40
41
42
43
44
45 private File sourceRoot;
46
47
48
49
50
51 private File testSourceRoot;
52
53
54
55
56 private String commandlineArgs;
57
58
59
60
61
62 protected String classpathScope;
63
64
65
66
67
68
69
70 private boolean skip;
71
72
73
74
75
76
77
78
79
80
81 protected void collectProjectArtifactsAndClasspath(List artifacts, List theClasspathFiles) {
82
83 if ("compile".equals(classpathScope)) {
84 artifacts.addAll(project.getCompileArtifacts());
85 theClasspathFiles.add(new File(project.getBuild().getOutputDirectory()));
86 } else if ("test".equals(classpathScope)) {
87 artifacts.addAll(project.getTestArtifacts());
88 theClasspathFiles.add(new File(project.getBuild().getTestOutputDirectory()));
89 theClasspathFiles.add(new File(project.getBuild().getOutputDirectory()));
90 } else if ("runtime".equals(classpathScope)) {
91 artifacts.addAll(project.getRuntimeArtifacts());
92 theClasspathFiles.add(new File(project.getBuild().getOutputDirectory()));
93 } else if ("system".equals(classpathScope)) {
94 artifacts.addAll(project.getSystemArtifacts());
95 } else {
96 throw new IllegalStateException("Invalid classpath scope: " + classpathScope);
97 }
98
99 getLog().debug("Collected project artifacts " + artifacts);
100 getLog().debug("Collected project classpath " + theClasspathFiles);
101 }
102
103
104
105
106
107
108
109
110
111
112 protected String[] parseCommandlineArgs() throws MojoExecutionException {
113 if (commandlineArgs == null) {
114 return null;
115 } else {
116 try {
117 return CommandLineUtils.translateCommandline(commandlineArgs);
118 } catch (Exception e) {
119 throw new MojoExecutionException(e.getMessage());
120 }
121 }
122 }
123
124
125
126
127 protected boolean hasCommandlineArgs() {
128 return (commandlineArgs != null);
129 }
130
131
132
133
134 protected void registerSourceRoots() {
135 if (sourceRoot != null) {
136 getLog().info("Registering compile source root " + sourceRoot);
137 project.addCompileSourceRoot(sourceRoot.toString());
138 }
139
140 if (testSourceRoot != null) {
141 getLog().info("Registering compile test source root " + testSourceRoot);
142 project.addTestCompileSourceRoot(testSourceRoot.toString());
143 }
144 }
145
146
147
148
149
150
151 protected boolean isSkip() {
152 return skip;
153 }
154 }