View Javadoc
1   /**
2    * The Doxygen Maven Plugin (dmp)
3    *
4    * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 by SoftwareEntwicklung Beratung Schulung (SoEBeS)
5    * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 by Karl Heinz Marbaise
6    *
7    * Licensed to the Apache Software Foundation (ASF) under one or more
8    * contributor license agreements.  See the NOTICE file distributed with
9    * this work for additional information regarding copyright ownership.
10   * The ASF licenses this file to You under the Apache License, Version 2.0
11   * (the "License"); you may not use this file except in compliance with
12   * the License.  You may obtain a copy of the License at
13   *
14   *    http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   */
22  package com.soebes.maven.plugins.doxygen;
23  
24  import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
25  import org.apache.maven.doxia.siterenderer.Renderer;
26  import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugins.annotations.Component;
30  import org.apache.maven.plugins.annotations.LifecyclePhase;
31  import org.apache.maven.plugins.annotations.Mojo;
32  import org.apache.maven.plugins.annotations.Parameter;
33  import org.apache.maven.project.MavenProject;
34  import org.apache.maven.reporting.MavenReport;
35  import org.apache.maven.reporting.MavenReportException;
36  import org.codehaus.doxia.sink.Sink;
37  import java.io.File;
38  import java.util.Locale;
39  
40  
41  /**
42   * This part will create the report.
43   * 
44   */
45  @Mojo( name = "report", defaultPhase = LifecyclePhase.SITE, requiresProject = true, threadSafe = true )
46  public class DoxygenReport 
47      extends AbstractDoxygenMojo
48      implements MavenReport
49  {
50  
51      @Component
52      private Renderer siteRenderer;
53  	
54      /**
55  	 * Specifies the destination directory where javadoc saves the generated HTML files.
56  	 *
57  	 */
58      @Parameter(defaultValue = "${project.reporting.outputDirectory}", property = "reportOutputDirectory", required = true)
59  	private File reportOutputDirectory;
60  	
61      /**
62       * The name of the destination directory.
63       *
64       */
65      @Parameter(defaultValue = "doxygen", property = "destDir")
66      private String destDir;
67  
68      
69      /** {@inheritDoc} */
70      public void execute()
71          throws MojoExecutionException, MojoFailureException
72      {
73          if ( isSkip() )
74          {
75              getLog().info( "Skipping doxgenc generation" );
76              return;
77          }
78  
79          try
80          {
81              RenderingContext context = new RenderingContext( getOutputDirectory(), getOutputName() + ".html" );
82              SiteRendererSink sink = new SiteRendererSink( context );
83              Locale locale = Locale.getDefault();
84              generate( sink, locale );
85          }
86          catch ( MavenReportException e )
87          {
88  //            if ( failOnError )
89  //            {
90  //                throw new MojoExecutionException( "An error has occurred in " + getName( Locale.ENGLISH )
91  //                    + " report generation:" + e.getMessage(), e );
92  //            }
93  
94              getLog().error( "An error has occurred in " + getName( Locale.ENGLISH )
95                      + " report generation:" + e.getMessage(), e );
96          }
97          catch ( RuntimeException e )
98          {
99              getLog().error( e.getMessage(), e );
100         }
101     }
102     
103     /** {@inheritDoc} */
104     public void generate( Sink sink, Locale locale )
105         throws MavenReportException
106     {
107         setOutputDirectory(getReportOutputDirectory());
108 
109         executeReport( locale );
110     }
111 
112 
113     /** {@inheritDoc} */
114 	public File getReportOutputDirectory() {
115 		if (reportOutputDirectory == null) {
116 			return reportOutputDirectory;
117 		}
118 
119 		return reportOutputDirectory;
120 	}
121 	
122 
123 	protected MavenProject getProject() {
124 		return getProject();
125 	}
126 
127     /** {@inheritDoc} */
128 	public String getCategoryName()
129     {
130         return CATEGORY_PROJECT_REPORTS;
131     }
132 
133 
134     /** {@inheritDoc} */
135     public String getOutputName()
136     {
137         return "doxygen" + "/index";
138     }
139 
140     /** {@inheritDoc} */
141     public boolean isExternalReport()
142     {
143         return true;
144     }
145 
146     /** {@inheritDoc} */
147 	public String getDescription(Locale locale) {
148 		return "Doxygen Report";
149 	}
150 
151     /** {@inheritDoc} */
152 	public String getName(Locale locale) {
153 		return "Doxygen";
154 	}
155 
156 	public void setDestDir(String destDir) {
157 		this.destDir = destDir;
158 	}
159 
160 	public String getDestDir() {
161 		return destDir;
162 	}
163 
164 	public boolean canGenerateReport() {
165 		return true;
166 	}
167 
168 	public void setReportOutputDirectory(File reportOutputDirectory) {
169 		this.reportOutputDirectory = getOutputDirectory();
170 	}
171 }