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  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  
25  /**
26   * Compile Scala test source into test-classes.  Corresponds roughly to testCompile
27   * in maven-compiler-plugin
28   *
29   * @phase test-compile
30   * @goal testCompile
31   * @requiresDependencyResolution test
32   */
33  public class ScalaTestCompileMojo extends ScalaCompilerSupport {
34  
35      /**
36       * Set this to 'true' to bypass unit tests entirely.
37       * Its use is NOT RECOMMENDED, but quite convenient on occasion.
38       *
39       * @parameter expression="${maven.test.skip}"
40       */
41      protected boolean skip;
42  
43      /**
44       * @parameter expression="${project.build.testOutputDirectory}
45       */
46      protected File testOutputDir;
47  
48      /**
49       * @parameter expression="${project.build.testSourceDirectory}/../scala"
50       */
51      protected File testSourceDir;
52  
53      @Override
54      public void execute() throws MojoExecutionException, MojoFailureException {
55          if (skip) {
56              return;
57          }
58          super.execute();
59      }
60  
61      @SuppressWarnings("unchecked")
62      @Override
63      protected List<String> getClasspathElements() throws Exception {
64          return project.getTestClasspathElements();
65      }
66  
67      @SuppressWarnings("unchecked")
68      @Override
69      protected List<Dependency> getDependencies() {
70          return project.getTestDependencies();
71      }
72  
73      @Override
74      protected File getOutputDir() throws Exception {
75          return testOutputDir.getAbsoluteFile();
76      }
77  
78      
79      
80  
81      protected List<String> getSourceDirectories() throws Exception {
82      	List<String> sources = project.getTestCompileSourceRoots();
83      	String scalaSourceDir = testSourceDir.getAbsolutePath();
84  		if(!sources.contains(scalaSourceDir)) {
85      		sources.add(scalaSourceDir);
86      	}
87      	return sources;
88      }
89  }