开发自己的Maven插件之五:创建简单的report plugin
现在我来开发一个report plugin,我希望我的report plugin输出的hello world能够被集成到mvn site产生的站点中。
1.用向导创建一个report plugin工程:
package org.freebird;/* * Copyright 2001-2005 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 java.io.File;import org.apache.maven.reporting.AbstractMavenReport;import org.apache.maven.reporting.MavenReportException;import java.util.Locale;import org.apache.maven.doxia.sink.Sink;import org.apache.maven.doxia.siterenderer.Renderer;import org.apache.maven.project.MavenProject;/** * Goal which touches a timestamp file. * * @goal my-report * * @phase site */public class Report1 extends AbstractMavenReport { private Renderer siteRenderer; @Override protected Renderer getSiteRenderer() { return siteRenderer; } /** * The output directory. * * @parameter * expression="${project.build.directory}/generated-sources/myreport" * @required */ private File outputDirectory; @Override protected String getOutputDirectory() { return outputDirectory.getAbsolutePath(); } private MavenProject project; @Override protected MavenProject getProject() { return project; } @Override protected void executeReport(Locale locale) throws MavenReportException { Sink sink = getSink(); sink.paragraph(); sink.text("hello world"); sink.paragraph(); } public String getOutputName() { return "myreport-output"; } public String getName(Locale locale) { return "myreport-name"; } public String getDescription(Locale locale) { return "myreport-description"; }}