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