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