1 | |
package org.apache.maven.plugin.javadoc; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.plugin.MojoExecutionException; |
23 | |
import org.apache.maven.plugin.MojoFailureException; |
24 | |
import org.apache.maven.plugin.javadoc.options.JavadocOptions; |
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.project.MavenProjectHelper; |
31 | |
import org.codehaus.plexus.archiver.Archiver; |
32 | |
import org.codehaus.plexus.archiver.ArchiverException; |
33 | |
import org.codehaus.plexus.archiver.manager.ArchiverManager; |
34 | |
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; |
35 | |
|
36 | |
import java.io.File; |
37 | |
import java.io.IOException; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@Mojo( name = "resource-bundle", defaultPhase = LifecyclePhase.PACKAGE, |
48 | |
requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true ) |
49 | 0 | public class ResourcesBundleMojo |
50 | |
extends AbstractJavadocMojo |
51 | |
{ |
52 | |
|
53 | |
public static final String BUNDLE_OPTIONS_PATH = "META-INF/maven/javadoc-options.xml"; |
54 | |
|
55 | |
public static final String RESOURCES_DIR_PATH = "resources"; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Parameter( defaultValue = "${project.build.finalName}", readonly = true ) |
63 | |
private String finalName; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Component |
70 | |
private MavenProjectHelper projectHelper; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
@Component |
76 | |
private ArchiverManager archiverManager; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void execute() |
89 | |
throws MojoExecutionException, MojoFailureException |
90 | |
{ |
91 | |
try |
92 | |
{ |
93 | 0 | buildJavadocOptions(); |
94 | |
} |
95 | 0 | catch ( IOException e ) |
96 | |
{ |
97 | 0 | throw new MojoExecutionException( "Failed to generate javadoc-options file: " + e.getMessage(), e ); |
98 | 0 | } |
99 | |
|
100 | |
Archiver archiver; |
101 | |
try |
102 | |
{ |
103 | 0 | archiver = archiverManager.getArchiver( "jar" ); |
104 | |
} |
105 | 0 | catch ( NoSuchArchiverException e ) |
106 | |
{ |
107 | 0 | throw new MojoExecutionException( "Failed to retrieve jar archiver component from manager.", e ); |
108 | 0 | } |
109 | |
|
110 | 0 | File optionsFile = getJavadocOptionsFile(); |
111 | 0 | File bundleFile = |
112 | |
new File( getProject().getBuild().getDirectory(), finalName + "-" + getAttachmentClassifier() + ".jar" ); |
113 | |
try |
114 | |
{ |
115 | 0 | archiver.addFile( optionsFile, BUNDLE_OPTIONS_PATH ); |
116 | |
|
117 | 0 | File javadocDir = getJavadocDirectory(); |
118 | 0 | if ( javadocDir.exists() && javadocDir.isDirectory() ) |
119 | |
{ |
120 | 0 | archiver.addDirectory( javadocDir, RESOURCES_DIR_PATH ); |
121 | |
} |
122 | |
|
123 | 0 | archiver.setDestFile( bundleFile ); |
124 | 0 | archiver.createArchive(); |
125 | |
} |
126 | 0 | catch ( ArchiverException e ) |
127 | |
{ |
128 | 0 | throw new MojoExecutionException( "Failed to assemble javadoc-resources bundle archive. Reason: " |
129 | |
+ e.getMessage(), e ); |
130 | |
} |
131 | 0 | catch ( IOException e ) |
132 | |
{ |
133 | 0 | throw new MojoExecutionException( "Failed to assemble javadoc-resources bundle archive. Reason: " |
134 | |
+ e.getMessage(), e ); |
135 | 0 | } |
136 | |
|
137 | 0 | projectHelper.attachArtifact( getProject(), bundleFile, getAttachmentClassifier() ); |
138 | 0 | } |
139 | |
} |