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