1 | |
package org.apache.maven.plugins.site; |
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.artifact.Artifact; |
23 | |
import org.apache.maven.doxia.site.decoration.DecorationModel; |
24 | |
import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader; |
25 | |
import org.apache.maven.doxia.tools.SiteToolException; |
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.project.MavenProject; |
28 | |
import org.codehaus.plexus.util.IOUtil; |
29 | |
import org.codehaus.plexus.util.ReaderFactory; |
30 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
31 | |
|
32 | |
import java.io.File; |
33 | |
import java.io.IOException; |
34 | |
import java.io.StringReader; |
35 | |
import java.util.HashMap; |
36 | |
import java.util.Iterator; |
37 | |
import java.util.List; |
38 | |
import java.util.Locale; |
39 | |
import java.util.Map; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class SiteDescriptorAttachMojo |
50 | |
extends AbstractSiteMojo |
51 | |
{ |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
private Artifact artifact; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
private File basedir; |
65 | |
|
66 | |
public void execute() |
67 | |
throws MojoExecutionException |
68 | |
{ |
69 | 0 | List localesList = siteTool.getAvailableLocales( locales ); |
70 | |
|
71 | 0 | for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); ) |
72 | |
{ |
73 | 0 | Locale locale = (Locale) iterator.next(); |
74 | |
|
75 | 0 | File descriptorFile = siteTool.getSiteDescriptorFromBasedir( toRelative( project.getBasedir(), |
76 | |
siteDirectory.getAbsolutePath() ), |
77 | |
basedir, locale ); |
78 | |
|
79 | 0 | if ( descriptorFile.exists() ) |
80 | |
{ |
81 | 0 | Map props = new HashMap(); |
82 | 0 | props.put( "reports", "<menu ref=\"reports\"/>" ); |
83 | 0 | props.put( "modules", "<menu ref=\"modules\"/>" ); |
84 | |
|
85 | |
DecorationModel decoration; |
86 | |
try |
87 | |
{ |
88 | 0 | String siteDescriptorContent = IOUtil.toString( ReaderFactory.newXmlReader( descriptorFile ) ); |
89 | |
|
90 | 0 | siteDescriptorContent = |
91 | |
siteTool.getInterpolatedSiteDescriptorContent( props, project, siteDescriptorContent, |
92 | |
getInputEncoding(), getOutputEncoding() ); |
93 | |
|
94 | 0 | decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) ); |
95 | |
} |
96 | 0 | catch ( XmlPullParserException e ) |
97 | |
{ |
98 | 0 | throw new MojoExecutionException( "Error parsing site descriptor", e ); |
99 | |
} |
100 | 0 | catch ( IOException e ) |
101 | |
{ |
102 | 0 | throw new MojoExecutionException( "Error reading site descriptor", e ); |
103 | |
} |
104 | 0 | catch ( SiteToolException e ) |
105 | |
{ |
106 | 0 | throw new MojoExecutionException( "Error when interpoling site descriptor", e ); |
107 | 0 | } |
108 | |
|
109 | 0 | MavenProject parentProject = siteTool.getParentProject( project, reactorProjects, localRepository ); |
110 | 0 | if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null ) |
111 | |
{ |
112 | 0 | siteTool.populateParentMenu( decoration, locale, project, parentProject, true ); |
113 | |
} |
114 | |
try |
115 | |
{ |
116 | 0 | siteTool.populateModulesMenu( project, reactorProjects, localRepository, decoration, locale, true ); |
117 | |
} |
118 | 0 | catch ( SiteToolException e ) |
119 | |
{ |
120 | 0 | throw new MojoExecutionException( "Error when populating modules", e ); |
121 | 0 | } |
122 | |
|
123 | 0 | artifact.addMetadata( new SiteDescriptorArtifactMetadata( artifact, decoration, descriptorFile ) ); |
124 | |
} |
125 | 0 | } |
126 | 0 | } |
127 | |
} |