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 = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE )
44 public class SBTCompileMojo
45 extends AbstractSBTCompileMojo
46 {
47
48
49
50
51
52 @Parameter
53 private Set<String> includes = new HashSet<String>();
54
55
56
57
58
59
60 @Parameter
61 private Set<String> excludes = new HashSet<String>();
62
63
64
65
66
67 @Parameter ( property = "maven.main.skip" )
68 private boolean skipMain;
69
70
71
72
73 @Parameter( defaultValue = "${project.compileSourceRoots}", readonly = true, required = true )
74 private List<String> compileSourceRoots;
75
76
77
78
79 @Parameter( defaultValue = "${project.compileClasspathElements}", readonly = true, required = true )
80 private List<String> classpathElements;
81
82
83
84
85 @Parameter( defaultValue = "${project.build.outputDirectory}", required = true, readonly = true )
86 private File outputDirectory;
87
88
89
90
91 @Parameter( defaultValue = "${project.artifact}", readonly = true, required = true )
92 private Artifact projectArtifact;
93
94 @Override
95 protected void internalExecute()
96 throws MojoExecutionException, MojoFailureException, IOException
97 {
98 if ( skipMain )
99 {
100 getLog().info( "Not compiling main sources" );
101 return;
102 }
103
104 super.internalExecute();
105
106 if ( outputDirectory.isDirectory() )
107 {
108 projectArtifact.setFile( outputDirectory );
109 }
110 }
111
112 @Override
113 protected List<String> getCompileSourceRoots()
114 {
115 return compileSourceRoots;
116 }
117
118 @Override
119 protected Set<String> getSourceIncludes()
120 {
121 return includes;
122 }
123
124 @Override
125 protected Set<String> getSourceExcludes()
126 {
127 return excludes;
128 }
129
130 @Override
131 protected List<String> getClasspathElements()
132 {
133 return classpathElements;
134 }
135
136 @Override
137 protected File getOutputDirectory()
138 {
139 return outputDirectory;
140 }
141
142 @Override
143 protected File getAnalysisCacheFile()
144 {
145 return defaultAnalysisCacheFile( project );
146 }
147
148 @Override
149 protected Map<File, File> getAnalysisCacheMap()
150 {
151 HashMap<File, File> map = new HashMap<File, File>();
152 for ( MavenProject reactorProject : reactorProjects )
153 {
154 if ( reactorProject != project )
155 {
156 File analysisCacheFile = defaultAnalysisCacheFile( reactorProject );
157 if ( analysisCacheFile.isFile() )
158 {
159 File reactorProjectArtifactFile = reactorProject.getArtifact().getFile();
160 if ( reactorProjectArtifactFile != null )
161 {
162 map.put( reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile() );
163 }
164 }
165 }
166 }
167 return map;
168 }
169
170 }