1 package org.apache.maven.plugin.jxr;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.maven.project.MavenProject;
23
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Locale;
29
30 /**
31 * Creates an html-based, cross referenced version of Java source code
32 * for a project.
33 *
34 * @author <a href="mailto:bellingard.NO-SPAM@gmail.com">Fabrice Bellingard</a>
35 * @version $Id: JxrReport.java 637378 2008-03-15 09:47:19Z bentmann $
36 * @goal jxr
37 */
38 public class JxrReport
39 extends AbstractJxrReport
40 {
41 /**
42 * Source directories of the project.
43 *
44 * @parameter expression="${project.compileSourceRoots}"
45 * @required
46 * @readonly
47 */
48 private List sourceDirs;
49
50 /**
51 * Specifies the source path where the java files are located.
52 * The paths are separated by '<code>;</code>'.
53 *
54 * @parameter expression="${sourcePath}"
55 */
56 private String sourcePath;
57
58 /**
59 * Folder where the Xref files will be copied to.
60 *
61 * @parameter expression="${project.reporting.outputDirectory}/xref"
62 */
63 private String destDir;
64
65 /**
66 * Folder where Javadoc is generated for this project.
67 *
68 * @parameter expression="${project.reporting.outputDirectory}/apidocs"
69 */
70 private File javadocDir;
71
72 /**
73 * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getDestinationDirectory()
74 */
75 protected String getDestinationDirectory()
76 {
77 return destDir;
78 }
79
80 /**
81 * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getSourceRoots()
82 */
83 protected List getSourceRoots()
84 {
85 if ( sourcePath != null )
86 {
87 String[] sourcePathArray = sourcePath.split( ";" );
88 if ( sourcePathArray.length > 0 )
89 {
90 return Arrays.asList( sourcePathArray );
91 }
92 }
93
94 List l = new ArrayList();
95
96 if ( !"pom".equals( getProject().getPackaging().toLowerCase() ) )
97 {
98 l.addAll( sourceDirs );
99 }
100
101 if ( getProject().getExecutionProject() != null )
102 {
103 if ( !"pom".equals( getProject().getExecutionProject().getPackaging().toLowerCase() ) )
104 {
105 l.addAll( getProject().getExecutionProject().getCompileSourceRoots() );
106 }
107 }
108
109 return l;
110 }
111
112 /**
113 * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getSourceRoots(org.apache.maven.project.MavenProject)
114 */
115 protected List getSourceRoots( MavenProject project )
116 {
117 List l = new ArrayList();
118
119 if ( !"pom".equals( project.getPackaging().toLowerCase() ) )
120 {
121 l.addAll( project.getCompileSourceRoots() );
122 }
123
124 if ( project.getExecutionProject() != null )
125 {
126 if ( !"pom".equals( project.getExecutionProject().getPackaging().toLowerCase() ) )
127 {
128 l.addAll( project.getExecutionProject().getCompileSourceRoots() );
129 }
130 }
131
132 return l;
133 }
134
135 /**
136 * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
137 */
138 public String getDescription( Locale locale )
139 {
140 return getBundle( locale ).getString( "report.xref.main.description" );
141 }
142
143 /**
144 * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
145 */
146 public String getName( Locale locale )
147 {
148 return getBundle( locale ).getString( "report.xref.main.name" );
149 }
150
151 /**
152 * @see org.apache.maven.reporting.MavenReport#getOutputName()
153 */
154 public String getOutputName()
155 {
156 return "xref/index";
157 }
158
159 /**
160 * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getJavadocDir()
161 */
162 protected File getJavadocDir()
163 {
164 return javadocDir;
165 }
166
167 /**
168 * @see org.apache.maven.reporting.AbstractMavenReport#setReportOutputDirectory(java.io.File)
169 */
170 public void setReportOutputDirectory( File reportOutputDirectory )
171 {
172 if ( ( reportOutputDirectory != null ) && ( !reportOutputDirectory.getAbsolutePath().endsWith( "xref" ) ) )
173 {
174 this.destDir = new File( reportOutputDirectory, "xref" ).getAbsolutePath();
175 }
176 else
177 {
178 this.destDir = reportOutputDirectory.getAbsolutePath();
179 }
180 }
181 }