View Javadoc

1   /*
2    * Copyright 2013 Grzegorz Slowikowski (gslowikowski at gmail dot com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing,
11   * software distributed under the License is distributed on an
12   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13   * KIND, either express or implied.  See the License for the
14   * specific language governing permissions and limitations
15   * under the License.
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   * Compile Scala and Java sources
37   * 
38   * @author <a href="mailto:gslowikowski@gmail.com">Grzegorz Slowikowski</a>
39   * @since 1.0.0
40   */
41  @Mojo( name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE )
42  public class SBTCompileMojo
43      extends AbstractSBTCompileMojo
44  {
45      /**
46       * The source directories containing the sources to be compiled.
47       */
48      @Parameter( defaultValue = "${project.compileSourceRoots}", readonly = true, required = true )
49      private List<String> compileSourceRoots;
50  
51      /**
52       * Project classpath.
53       */
54      @Parameter( defaultValue = "${project.compileClasspathElements}", readonly = true, required = true )
55      private List<String> classpathElements;
56  
57      /**
58       * The directory for compiled classes.
59       */
60      @Parameter( defaultValue = "${project.build.outputDirectory}", required = true, readonly = true )
61      private File outputDirectory;
62  
63      /**
64       * Project's main artifact.
65       */
66      @Parameter( defaultValue = "${project.artifact}", readonly = true, required = true )
67      private Artifact projectArtifact;
68  
69      @Override
70      protected void internalExecute()
71          throws MojoExecutionException, MojoFailureException, IOException
72      {
73          super.internalExecute();
74  
75          if ( outputDirectory.isDirectory() )
76          {
77              projectArtifact.setFile( outputDirectory );
78          }
79      }
80  
81      @Override
82      protected List<String> getCompileSourceRoots()
83      {
84          return compileSourceRoots;
85      }
86  
87      @Override
88      protected List<String> getClasspathElements()
89      {
90          return classpathElements;
91      }
92  
93      @Override
94      protected File getOutputDirectory()
95      {
96          return outputDirectory;
97      }
98  
99      @Override
100     protected File getAnalysisCacheFile()
101     {
102         return defaultAnalysisCacheFile( project );
103     }
104 
105     @Override
106     protected Map<File, File> getAnalysisCacheMap()
107     {
108         HashMap<File, File> map = new HashMap<File, File>();
109         for ( MavenProject reactorProject : reactorProjects )
110         {
111             if ( reactorProject != project )
112             {
113                 File analysisCacheFile = defaultAnalysisCacheFile( reactorProject );
114                 if ( analysisCacheFile.isFile() )
115                 {
116                     File reactorProjectArtifactFile = reactorProject.getArtifact().getFile();
117                     if ( reactorProjectArtifactFile != null )
118                     {
119                         map.put( reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile() );
120                     }
121                 }
122             }
123         }
124         return map;
125     }
126 
127 }