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 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 List plugins = new ArrayList();
67 for ( Iterator it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); )
68 {
69 plugins.add( it.next() );
70 }
71 for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
72 {
73 plugins.add( it.next() );
74 }
75
76 String pluginArtifactId = "maven-javadoc-plugin";
77 for ( Iterator it = plugins.iterator(); it.hasNext(); )
78 {
79 Object next = it.next();
80
81 Xpp3Dom pluginConf = null;
82
83 if ( next instanceof Plugin )
84 {
85 Plugin plugin = (Plugin) next;
86
87
88 if ( !( ( plugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( plugin.getArtifactId()
89 .equals( pluginArtifactId ) ) ) )
90 {
91 continue;
92 }
93
94 pluginConf = (Xpp3Dom) plugin.getConfiguration();
95 }
96
97 if ( next instanceof ReportPlugin )
98 {
99 ReportPlugin reportPlugin = (ReportPlugin) next;
100
101
102 if ( !( ( reportPlugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( reportPlugin
103 .getArtifactId().equals( pluginArtifactId ) ) ) )
104 {
105 continue;
106 }
107
108 pluginConf = (Xpp3Dom) reportPlugin.getConfiguration();
109 }
110
111 if ( pluginConf == null )
112 {
113 continue;
114 }
115
116 try
117 {
118 Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
119 .parse( new StringInputStream( pluginConf.toString() ) );
120
121 XObject obj = XPathAPI.eval( doc, "//configuration/" + optionName );
122
123 if ( StringUtils.isNotEmpty( obj.toString() ) )
124 {
125 return obj.toString();
126 }
127 }
128 catch ( SAXException e )
129 {
130 throw new IOException( "SAXException: " + e.getMessage() );
131 }
132 catch ( ParserConfigurationException e )
133 {
134 throw new IOException( "ParserConfigurationException: " + e.getMessage() );
135 }
136 catch ( FactoryConfigurationError e )
137 {
138 throw new IOException( "FactoryConfigurationError: " + e.getMessage() );
139 }
140 catch ( TransformerException e )
141 {
142 throw new IOException( "TransformerException: " + e.getMessage() );
143 }
144 }
145
146 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 if ( project.getDistributionManagement() == null )
165 {
166 String hierarchy = project.getName();
167
168 MavenProject parent = project.getParent();
169 while ( parent != null )
170 {
171 hierarchy = parent.getName() + "/" + hierarchy;
172 parent = parent.getParent();
173 }
174
175 return hierarchy;
176 }
177
178 Site site = project.getDistributionManagement().getSite();
179 if ( site == null )
180 {
181 if ( !ignoreMissingSiteUrl )
182 {
183 throw new IOException(
184 "Missing site information in the distribution management element in the project: '"
185 + project.getName() + "'." );
186 }
187
188 return null;
189 }
190
191 if ( StringUtils.isEmpty( site.getUrl() ) )
192 {
193 if ( !ignoreMissingSiteUrl )
194 {
195 throw new IOException( "The URL in the site is missing in the project descriptor." );
196 }
197
198 return null;
199 }
200
201 Repository repository = new Repository( site.getId(), site.getUrl() );
202 if ( StringUtils.isEmpty( repository.getBasedir() ) )
203 {
204 return repository.getHost();
205 }
206
207 if ( repository.getBasedir().startsWith( "/" ) )
208 {
209 return repository.getHost() + repository.getBasedir();
210 }
211
212 return repository.getHost() + "/" + repository.getBasedir();
213 }
214 }