View Javadoc

1   /*
2    * Copyright 2007 scala-tools.org
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 "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions
14   * and limitations under the License.
15   */
16   package org.scala_tools.maven;
17  
18  import java.io.File;
19  import java.util.List;
20  
21  import org.apache.maven.model.Dependency;
22  
23  /**
24   * Compiles a directory of Scala source. Corresponds roughly to the compile goal
25   * of the maven-compiler-plugin
26   *
27   * @phase compile
28   * @goal compile
29   * @requiresDependencyResolution compile
30   */
31  public class ScalaCompileMojo extends ScalaCompilerSupport {
32  
33      /**
34       * @parameter expression="${project.build.outputDirectory}"
35       */
36      protected File outputDir;
37  
38      /**
39       * @parameter expression="${project.build.sourceDirectory}/../scala"
40       */
41      protected File sourceDir;
42  
43      protected List<String> getSourceDirectories() throws Exception {
44      	List<String> sources = project.getCompileSourceRoots();
45      	//Quick fix in case the user has not added the "add-source" goal.
46      	String scalaSourceDir = sourceDir.getCanonicalPath();
47  		if(!sources.contains(scalaSourceDir)) {
48      		sources.add(scalaSourceDir);
49      	}
50      	return sources;
51      }
52      
53      @SuppressWarnings("unchecked")
54      @Override
55      protected List<String> getClasspathElements() throws Exception {
56          return project.getCompileClasspathElements();
57      }
58  
59      @SuppressWarnings("unchecked")
60      @Override
61      protected List<Dependency> getDependencies() {
62          return project.getCompileDependencies();
63      }
64  
65      @Override
66      protected File getOutputDir() throws Exception {
67          return outputDir.getAbsoluteFile();
68      }
69  }