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.List;
24 import java.util.Map;
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.Parameter;
32 import org.apache.maven.plugins.annotations.ResolutionScope;
33 import org.apache.maven.project.MavenProject;
34
35
36
37
38
39
40
41 @Mojo( name = "testCompile", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST )
42 public class SBTTestCompileMojo
43 extends AbstractSBTCompileMojo
44 {
45
46
47
48
49 @Parameter( property = "maven.test.skip" )
50 private boolean testCompileSkip;
51
52
53
54
55 @Parameter( defaultValue = "${project.testCompileSourceRoots}", readonly = true, required = true )
56 private List<String> compileSourceRoots;
57
58
59
60
61 @Parameter( defaultValue = "${project.testClasspathElements}", required = true, readonly = true )
62 private List<String> classpathElements;
63
64
65
66
67 @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true )
68 private File outputDirectory;
69
70 @Override
71 protected void internalExecute()
72 throws MojoExecutionException, MojoFailureException, IOException
73 {
74 if ( testCompileSkip )
75 {
76 getLog().info( "Not compiling test sources" );
77 }
78 else
79 {
80 super.internalExecute();
81 }
82 }
83
84 @Override
85 protected List<String> getCompileSourceRoots()
86 {
87 return compileSourceRoots;
88 }
89
90 @Override
91 protected List<String> getClasspathElements()
92 {
93 return classpathElements;
94 }
95
96 @Override
97 protected File getOutputDirectory()
98 {
99 return outputDirectory;
100 }
101
102 @Override
103 protected File getAnalysisCacheFile()
104 {
105 return defaultTestAnalysisCacheFile( project );
106 }
107
108 @Override
109 protected Map<File, File> getAnalysisCacheMap()
110 {
111 HashMap<File, File> map = new HashMap<File, File>();
112 for ( MavenProject reactorProject : reactorProjects )
113 {
114 if ( reactorProject != project )
115 {
116 File analysisCacheFile = defaultAnalysisCacheFile( reactorProject );
117 if ( analysisCacheFile.isFile() )
118 {
119 File reactorProjectArtifactFile = reactorProject.getArtifact().getFile();
120 if ( reactorProjectArtifactFile != null )
121 {
122 map.put( reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile() );
123 }
124 }
125
126 File testAnalysisCacheFile = defaultTestAnalysisCacheFile( reactorProject );
127 if ( testAnalysisCacheFile.isFile() )
128 {
129 List<Artifact> reactorProjectattachedArtifacts = reactorProject.getAttachedArtifacts();
130 for ( Artifact artifact: reactorProjectattachedArtifacts )
131 {
132 if ( "tests".equals( artifact.getClassifier() ) )
133 {
134 map.put( artifact.getFile().getAbsoluteFile(), testAnalysisCacheFile.getAbsoluteFile() );
135 break;
136 }
137 }
138 }
139 }
140 }
141 return map;
142 }
143
144 }