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 = "generateStubs", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
40 public class GenerateStubsMojo extends AbstractGenerateStubsMojo {
41
42
43
44
45
46 @Parameter
47 protected FileSet[] sources;
48
49
50
51
52 @Parameter(defaultValue = "${project.build.directory}/generated-sources/groovy-stubs/main")
53 protected File stubsOutputDirectory;
54
55
56
57
58
59
60 @Override
61 public void execute() throws MojoExecutionException {
62 minGroovyVersion = GROOVY_1_8_2;
63
64 try {
65 try {
66 getLog().debug("Project compile classpath:\n" + project.getCompileClasspathElements());
67 } catch (DependencyResolutionRequiredException e) {
68 getLog().debug("Unable to log project compile classpath");
69 }
70
71 doStubGeneration(getFiles(sources, false), project.getCompileClasspathElements(), stubsOutputDirectory);
72 logGeneratedStubs(stubsOutputDirectory);
73 resetStubModifiedDates(getStubs(stubsOutputDirectory));
74
75
76 project.addCompileSourceRoot(stubsOutputDirectory.getAbsolutePath());
77 } catch (ClassNotFoundException e) {
78 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);
79 } catch (InvocationTargetException e) {
80 throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e);
81 } catch (InstantiationException e) {
82 throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
83 } catch (IllegalAccessException e) {
84 throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
85 } catch (DependencyResolutionRequiredException e) {
86 throw new MojoExecutionException("Compile dependencies weren't resolved.", e);
87 } catch (MalformedURLException e) {
88 throw new MojoExecutionException("Unable to add project compile dependencies to classpath.", e);
89 }
90 }
91
92 }