1 package org.apache.maven.plugin.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugins.annotations.Component;
26 import org.apache.maven.plugins.annotations.LifecyclePhase;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.plugins.annotations.ResolutionScope;
30 import org.apache.maven.tools.plugin.generator.Generator;
31 import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
32 import org.codehaus.plexus.velocity.VelocityComponent;
33
34
35
36
37
38
39
40
41 @Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true,
42 requiresDependencyResolution = ResolutionScope.COMPILE )
43 public class HelpGeneratorMojo
44 extends AbstractGeneratorMojo
45 {
46
47
48
49 @Parameter( defaultValue = "${project.build.directory}/generated-sources/plugin" )
50 protected File outputDirectory;
51
52
53
54
55
56
57
58 @Parameter
59 private String helpPackageName;
60
61
62
63
64 @Component
65 private VelocityComponent velocity;
66
67
68
69
70 protected File getOutputDirectory()
71 {
72 return outputDirectory;
73 }
74
75
76
77
78 protected Generator createGenerator()
79 {
80 return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setVelocityComponent( this.velocity );
81 }
82
83
84
85
86 public void execute()
87 throws MojoExecutionException
88 {
89
90 skipErrorNoDescriptorsFound = true;
91
92 super.execute();
93
94 if ( !project.getCompileSourceRoots().contains( outputDirectory.getAbsolutePath() ) && !skip )
95 {
96 project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
97 }
98
99 }
100
101 }