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 = "generateTestStubs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
24 public class GenerateTestStubsMojo extends AbstractGenerateStubsMojo {
25
26
27
28
29
30 @Parameter
31 protected FileSet[] testSources;
32
33
34
35
36 @Parameter(defaultValue = "${project.build.directory}/generated-sources/groovy-stubs/test")
37 protected File testStubsOutputDirectory;
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("Generation of test stubs is skipped.");
54 return;
55 }
56
57 minGroovyVersion = GROOVY_1_8_2;
58 try {
59 try {
60 getLog().debug("Project test classpath:\n" + project.getTestClasspathElements());
61 } catch (DependencyResolutionRequiredException e) {
62 getLog().debug("Unable to log project test classpath");
63 }
64
65 doStubGeneration(getTestFiles(testSources, false), project.getTestClasspathElements(), testStubsOutputDirectory);
66 logGeneratedStubs(testStubsOutputDirectory);
67 resetStubModifiedDates(getStubs(testStubsOutputDirectory));
68
69
70 project.addTestCompileSourceRoot(testStubsOutputDirectory.getAbsolutePath());
71 } catch (ClassNotFoundException e) {
72 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);
73 } catch (InvocationTargetException e) {
74 throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e);
75 } catch (InstantiationException e) {
76 throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
77 } catch (IllegalAccessException e) {
78 throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
79 } catch (DependencyResolutionRequiredException e) {
80 throw new MojoExecutionException("Test dependencies weren't resolved.", e);
81 } catch (MalformedURLException e) {
82 throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e);
83 }
84 }
85
86 }