1 package org.codehaus.gmavenplus.mojo;
2
3 import org.apache.maven.artifact.DependencyResolutionRequiredException;
4 import org.apache.maven.plugin.MojoExecutionException;
5 import org.apache.maven.plugins.annotations.LifecyclePhase;
6 import org.apache.maven.plugins.annotations.Mojo;
7 import org.apache.maven.plugins.annotations.Parameter;
8 import org.apache.maven.plugins.annotations.ResolutionScope;
9 import org.apache.maven.shared.model.fileset.FileSet;
10
11 import java.io.File;
12 import java.lang.reflect.InvocationTargetException;
13 import java.net.MalformedURLException;
14
15
16
17
18
19
20
21
22
23 @Mojo(name = "compileTests", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
24 public class CompileTestsMojo extends AbstractCompileMojo {
25
26
27
28
29
30 @Parameter
31 protected FileSet[] testSources;
32
33
34
35
36 @Parameter(defaultValue = "${project.build.testOutputDirectory}")
37 protected File testOutputDirectory;
38
39
40
41
42 @Parameter(property = "maven.test.skip", defaultValue = "false")
43 protected boolean skipTests;
44
45
46
47
48
49
50 @Override
51 public void execute() throws MojoExecutionException {
52 if (skipTests) {
53 getLog().info("Compilation of tests is skipped.");
54 return;
55 }
56
57 try {
58 try {
59 getLog().debug("Project test classpath:\n" + project.getTestClasspathElements());
60 } catch (DependencyResolutionRequiredException e) {
61 getLog().debug("Unable to log project test classpath");
62 }
63 doCompile(getTestFiles(testSources, false), project.getTestClasspathElements(), testOutputDirectory);
64 } catch (ClassNotFoundException e) {
65 throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e);
66 } catch (InvocationTargetException e) {
67 throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e);
68 } catch (InstantiationException e) {
69 throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
70 } catch (IllegalAccessException e) {
71 throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
72 } catch (DependencyResolutionRequiredException e) {
73 throw new MojoExecutionException("Test dependencies weren't resolved.", e);
74 } catch (MalformedURLException e) {
75 throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e);
76 }
77 }
78
79 }