1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.google.code.sbt;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.apache.maven.plugins.annotations.LifecyclePhase;
32 import org.apache.maven.plugins.annotations.Mojo;
33 import org.apache.maven.plugins.annotations.Parameter;
34 import org.apache.maven.plugins.annotations.ResolutionScope;
35 import org.apache.maven.project.MavenProject;
36
37
38
39
40
41
42
43 @Mojo( name = "testCompile", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST )
44 public class SBTTestCompileMojo
45 extends AbstractSBTCompileMojo
46 {
47
48
49
50
51
52 @Parameter
53 private Set<String> testIncludes = new HashSet<String>();
54
55
56
57
58
59
60 @Parameter
61 private Set<String> testExcludes = new HashSet<String>();
62
63
64
65
66
67
68
69 @Parameter( property = "maven.test.skip" )
70 private boolean skipTest;
71
72
73
74
75 @Parameter( defaultValue = "${project.testCompileSourceRoots}", readonly = true, required = true )
76 private List<String> compileSourceRoots;
77
78
79
80
81 @Parameter( defaultValue = "${project.testClasspathElements}", required = true, readonly = true )
82 private List<String> classpathElements;
83
84
85
86
87 @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true )
88 private File outputDirectory;
89
90 @Override
91 protected void internalExecute()
92 throws MojoExecutionException, MojoFailureException, IOException
93 {
94 if ( skipTest )
95 {
96 getLog().info( "Not compiling test sources" );
97 return;
98 }
99 super.internalExecute();
100 }
101
102 @Override
103 protected List<String> getCompileSourceRoots()
104 {
105 return compileSourceRoots;
106 }
107
108 @Override
109 protected Set<String> getSourceIncludes()
110 {
111 return testIncludes;
112 }
113
114 @Override
115 protected Set<String> getSourceExcludes()
116 {
117 return testExcludes;
118 }
119
120 @Override
121 protected List<String> getClasspathElements()
122 {
123 return classpathElements;
124 }
125
126 @Override
127 protected File getOutputDirectory()
128 {
129 return outputDirectory;
130 }
131
132 @Override
133 protected File getAnalysisCacheFile()
134 {
135 return defaultTestAnalysisCacheFile( project );
136 }
137
138 @Override
139 protected Map<File, File> getAnalysisCacheMap()
140 {
141 HashMap<File, File> map = new HashMap<File, File>();
142 for ( MavenProject reactorProject : reactorProjects )
143 {
144 if ( reactorProject != project )
145 {
146 File analysisCacheFile = defaultAnalysisCacheFile( reactorProject );
147 if ( analysisCacheFile.isFile() )
148 {
149 File reactorProjectArtifactFile = reactorProject.getArtifact().getFile();
150 if ( reactorProjectArtifactFile != null )
151 {
152 map.put( reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile() );
153 }
154 }
155
156 File testAnalysisCacheFile = defaultTestAnalysisCacheFile( reactorProject );
157 if ( testAnalysisCacheFile.isFile() )
158 {
159 List<Artifact> reactorProjectattachedArtifacts = reactorProject.getAttachedArtifacts();
160 for ( Artifact artifact: reactorProjectattachedArtifacts )
161 {
162 if ( "tests".equals( artifact.getClassifier() ) )
163 {
164 map.put( artifact.getFile().getAbsoluteFile(), testAnalysisCacheFile.getAbsoluteFile() );
165 break;
166 }
167 }
168 }
169 }
170 }
171 return map;
172 }
173
174 }