Java tutorial
package org.jvnet.sorcerer.maven_plugin; /* * Copyright 2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.model.ReportPlugin; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.artifact.DependencyResolutionRequiredException; import java.io.File; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.ArrayList; /** * Creates an html-based, cross referenced version of Java source code * for a project. * * @author <a href="mailto:bellingard.NO-SPAM@gmail.com">Fabrice Bellingard</a> * @author Kohsuke Kawaguchi * * @goal sorcerer * @role org.apache.maven.reporting.MavenReport * @role-hint sorcerer * @instantiation-strategy per-lookup * @requiresDependencyResolution compile */ public class SorcererReport extends AbstractSorcererReport { /** * Source directories of the project. * * @parameter expression="${project.compileSourceRoots}" * @required * @readonly */ private List<String> sourceDirs; /** * Folder where the Xref files will be copied to. * * @parameter expression="${project.reporting.outputDirectory}/sorcerer" */ private String destDir; /** * Folder where Javadoc is generated for this project. * * @parameter expression="${project.reporting.outputDirectory}/apidocs" */ private File javadocDir; /** * Link the Javadoc from the Source XRef. Defaults to true and will link * automatically if javadoc plugin is being used. * * @parameter expression="${linkJavadoc}" default-value="true" */ private boolean linkJavadoc; protected String getDestinationDirectory() { return destDir; } protected List<String> getSourceRoots() { return this.sourceDirs; } protected List<String> getSourceRoots(MavenProject project) { return project.getCompileSourceRoots(); } public String getDescription(Locale locale) { return getBundle(locale).getString("report.sorcerer.main.description"); } public String getName(Locale locale) { return getBundle(locale).getString("report.sorcerer.main.name"); } public String getOutputName() { return "sorcerer/index"; } protected String getJavadocLocation() { String location = null; if (linkJavadoc) { // We don't need to do the whole translation thing like normal, because JXR does it internally. // It probably shouldn't. if (javadocDir.exists()) { // XRef was already generated by manual execution of a lifecycle binding location = javadocDir.getAbsolutePath(); } else { // Not yet generated - check if the report is on its way for (ReportPlugin report : (List<ReportPlugin>) getProject().getReportPlugins()) { String artifactId = report.getArtifactId(); if ("maven-javadoc-plugin".equals(artifactId)) { location = javadocDir.getAbsolutePath(); } } } if (location == null) { getLog().warn("Unable to locate Javadoc to link to - DISABLED"); } } return location; } protected List<String> getClasspathElements() throws DependencyResolutionRequiredException { if (!isAggregator()) return project.getCompileClasspathElements(); List<String> r = new ArrayList<String>(); for (MavenProject p : reactorProjects) r.addAll(p.getCompileClasspathElements()); return r; } }