1 | |
package org.apache.maven.plugin.jxr; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
|
27 | |
import javax.xml.parsers.DocumentBuilderFactory; |
28 | |
import javax.xml.parsers.FactoryConfigurationError; |
29 | |
import javax.xml.parsers.ParserConfigurationException; |
30 | |
import javax.xml.transform.TransformerException; |
31 | |
|
32 | |
import org.apache.maven.model.Plugin; |
33 | |
import org.apache.maven.model.ReportPlugin; |
34 | |
import org.apache.maven.model.Site; |
35 | |
import org.apache.maven.project.MavenProject; |
36 | |
import org.apache.maven.wagon.repository.Repository; |
37 | |
import org.apache.xpath.XPathAPI; |
38 | |
import org.apache.xpath.objects.XObject; |
39 | |
import org.codehaus.plexus.util.StringInputStream; |
40 | |
import org.codehaus.plexus.util.StringUtils; |
41 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
42 | |
import org.w3c.dom.Document; |
43 | |
import org.xml.sax.SAXException; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class JxrReportUtil |
52 | |
{ |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
protected static String getMavenJavadocPluginBasicOption( MavenProject project, String optionName, |
63 | |
String defaultValue ) |
64 | |
throws IOException |
65 | |
{ |
66 | 0 | List plugins = new ArrayList(); |
67 | 0 | for ( Iterator it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); ) |
68 | |
{ |
69 | 0 | plugins.add( it.next() ); |
70 | |
} |
71 | 0 | for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); ) |
72 | |
{ |
73 | 0 | plugins.add( it.next() ); |
74 | |
} |
75 | |
|
76 | 0 | String pluginArtifactId = "maven-javadoc-plugin"; |
77 | 0 | for ( Iterator it = plugins.iterator(); it.hasNext(); ) |
78 | |
{ |
79 | 0 | Object next = it.next(); |
80 | |
|
81 | 0 | Xpp3Dom pluginConf = null; |
82 | |
|
83 | 0 | if ( next instanceof Plugin ) |
84 | |
{ |
85 | 0 | Plugin plugin = (Plugin) next; |
86 | |
|
87 | |
|
88 | 0 | if ( !( ( plugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( plugin.getArtifactId() |
89 | |
.equals( pluginArtifactId ) ) ) ) |
90 | |
{ |
91 | 0 | continue; |
92 | |
} |
93 | |
|
94 | 0 | pluginConf = (Xpp3Dom) plugin.getConfiguration(); |
95 | |
} |
96 | |
|
97 | 0 | if ( next instanceof ReportPlugin ) |
98 | |
{ |
99 | 0 | ReportPlugin reportPlugin = (ReportPlugin) next; |
100 | |
|
101 | |
|
102 | 0 | if ( !( ( reportPlugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( reportPlugin |
103 | |
.getArtifactId().equals( pluginArtifactId ) ) ) ) |
104 | |
{ |
105 | 0 | continue; |
106 | |
} |
107 | |
|
108 | 0 | pluginConf = (Xpp3Dom) reportPlugin.getConfiguration(); |
109 | |
} |
110 | |
|
111 | 0 | if ( pluginConf == null ) |
112 | |
{ |
113 | 0 | continue; |
114 | |
} |
115 | |
|
116 | |
try |
117 | |
{ |
118 | 0 | Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() |
119 | |
.parse( new StringInputStream( pluginConf.toString() ) ); |
120 | |
|
121 | 0 | XObject obj = XPathAPI.eval( doc, "//configuration/" + optionName ); |
122 | |
|
123 | 0 | if ( StringUtils.isNotEmpty( obj.toString() ) ) |
124 | |
{ |
125 | 0 | return obj.toString(); |
126 | |
} |
127 | |
} |
128 | 0 | catch ( SAXException e ) |
129 | |
{ |
130 | 0 | throw new IOException( "SAXException: " + e.getMessage() ); |
131 | |
} |
132 | 0 | catch ( ParserConfigurationException e ) |
133 | |
{ |
134 | 0 | throw new IOException( "ParserConfigurationException: " + e.getMessage() ); |
135 | |
} |
136 | 0 | catch ( FactoryConfigurationError e ) |
137 | |
{ |
138 | 0 | throw new IOException( "FactoryConfigurationError: " + e.getMessage() ); |
139 | |
} |
140 | 0 | catch ( TransformerException e ) |
141 | |
{ |
142 | 0 | throw new IOException( "TransformerException: " + e.getMessage() ); |
143 | 0 | } |
144 | 0 | } |
145 | |
|
146 | 0 | return defaultValue; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
protected static String getStructure( MavenProject project, boolean ignoreMissingSiteUrl ) |
162 | |
throws IOException |
163 | |
{ |
164 | 0 | if ( project.getDistributionManagement() == null ) |
165 | |
{ |
166 | 0 | String hierarchy = project.getName(); |
167 | |
|
168 | 0 | MavenProject parent = project.getParent(); |
169 | 0 | while ( parent != null ) |
170 | |
{ |
171 | 0 | hierarchy = parent.getName() + "/" + hierarchy; |
172 | 0 | parent = parent.getParent(); |
173 | |
} |
174 | |
|
175 | 0 | return hierarchy; |
176 | |
} |
177 | |
|
178 | 0 | Site site = project.getDistributionManagement().getSite(); |
179 | 0 | if ( site == null ) |
180 | |
{ |
181 | 0 | if ( !ignoreMissingSiteUrl ) |
182 | |
{ |
183 | 0 | throw new IOException( |
184 | |
"Missing site information in the distribution management element in the project: '" |
185 | |
+ project.getName() + "'." ); |
186 | |
} |
187 | |
|
188 | 0 | return null; |
189 | |
} |
190 | |
|
191 | 0 | if ( StringUtils.isEmpty( site.getUrl() ) ) |
192 | |
{ |
193 | 0 | if ( !ignoreMissingSiteUrl ) |
194 | |
{ |
195 | 0 | throw new IOException( "The URL in the site is missing in the project descriptor." ); |
196 | |
} |
197 | |
|
198 | 0 | return null; |
199 | |
} |
200 | |
|
201 | 0 | Repository repository = new Repository( site.getId(), site.getUrl() ); |
202 | 0 | if ( StringUtils.isEmpty( repository.getBasedir() ) ) |
203 | |
{ |
204 | 0 | return repository.getHost(); |
205 | |
} |
206 | |
|
207 | 0 | if ( repository.getBasedir().startsWith( "/" ) ) |
208 | |
{ |
209 | 0 | return repository.getHost() + repository.getBasedir(); |
210 | |
} |
211 | |
|
212 | 0 | return repository.getHost() + "/" + repository.getBasedir(); |
213 | |
} |
214 | |
} |