Author: ito
Date: Thu Jan 28 17:24:18 2010
New Revision: 904173

URL: http://svn.apache.org/viewvc?rev=904173&view=rev
Log:
CLEREZZA-98: init project jaxrs resource report plugin

Added:
    incubator/clerezza/issues/CLEREZZA-98/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/pom.xml
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/
    
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/JaxRsReportMojo.java

Added: 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/pom.xml?rev=904173&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/pom.xml
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/pom.xml
 Thu Jan 28 17:24:18 2010
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>org.apache.clerezza.parent</artifactId>
+               <groupId>org.apache.clerezza</groupId>
+               <version>0.2-incubating-SNAPSHOT</version>
+       </parent>
+       <groupId>org.apache.clerezza</groupId>
+       <artifactId>org.apache.clerezza.maven-jaxrs-report-plugin</artifactId>
+       <packaging>maven-plugin</packaging>
+       <version>0.1-incubating-SNAPSHOT</version>
+       <name>Clerezza - Maven JaxRs Report Plugin</name>
+       <url>http://maven.apache.org</url>
+       <dependencies>
+               <dependency>
+                       <groupId>org.apache.maven</groupId>
+                       <artifactId>maven-plugin-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.maven.reporting</groupId>
+                       <artifactId>maven-reporting-api</artifactId>
+                       <version>2.0</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.maven.reporting</groupId>
+                       <artifactId>maven-reporting-impl</artifactId>
+                       <version>2.0</version>
+               </dependency>
+                <!-- JavaDoc Tags -->
+               <dependency>
+                       <groupId>com.thoughtworks.qdox</groupId>
+                       <artifactId>qdox</artifactId>
+                       <version>1.9.1</version>
+               </dependency>
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <artifactId>maven-site-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </build>
+       <reporting>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-plugin-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </reporting>
+</project>

Added: 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/JaxRsReportMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/JaxRsReportMojo.java?rev=904173&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/JaxRsReportMojo.java
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-98/org.apache.clerezza.maven-jaxrs-report-plugin/src/main/java/org/apache/clerezza/jaxrsreportplugin/JaxRsReportMojo.java
 Thu Jan 28 17:24:18 2010
@@ -0,0 +1,251 @@
+/*
+ *  Copyright 2009 trialox.org (trialox AG, Switzerland).
+ * 
+ *  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.
+ *  under the License.
+ */
+package org.apache.clerezza.jaxrsreportplugin;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.AbstractBaseJavaEntity;
+import com.thoughtworks.qdox.model.Annotation;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaSource;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.codehaus.doxia.sink.Sink;
+import org.codehaus.doxia.site.renderer.SiteRenderer;
+
+/**
+ * Generates a report about jaxrs resources. The report includes java doc 
descriptions
+ * about paths, http methods, comments and parameters of the methods. The 
report
+ * will be generated in the site phase, the default goal is jaxrs-report.
+ * 
+ * 
+ * @goal jaxrs-report
+ * 
+ * @phase site
+ */
+public class JaxRsReportMojo extends AbstractMavenReport {
+
+       /**
+        * Path to the root directory
+        *
+        * @parameter expression="${basedir}"
+        */
+       private String baseDir;
+       
+        /**
+     * Location where generated html will be created.
+     *
+     * @parameter expression="${project.reporting.outputDirectory}"
+     */
+    private String outputDirectory;
+
+    /**
+     * Doxia Site Renderer
+     *
+     * @parameter 
expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
+     * @required @readonly
+     */
+    private SiteRenderer siteRenderer;
+
+    /**
+     * Maven Project
+     *
+     * @parameter expression="${project}"
+     * @required @readonly
+     */
+    private MavenProject project;
+
+       @Override
+       protected SiteRenderer getSiteRenderer() {
+               return siteRenderer;
+       }
+
+       @Override
+       protected String getOutputDirectory() {
+               return outputDirectory;
+
+       }
+
+       @Override
+       protected MavenProject getProject() {
+               return project;
+       }
+
+       @Override
+       protected void executeReport(Locale arg0) throws MavenReportException {
+
+               Sink sink = getSink();
+               sink.head();
+               sink.title();
+               sink.text("JaxRs Report");
+               sink.title_();
+               sink.head_();
+               sink.body();
+
+               JavaClass[] classes =  getJavaClassesFromSources();
+               for(JavaClass clazz : classes) {
+                       if(hasPathAnnotation(clazz)) {
+                               sink.section1();
+                               sink.sectionTitle1();
+                               sink.text("Class: " + clazz.getName());
+                               sink.sectionTitle1_();
+                               sink.lineBreak();
+                               sink.text("Package: " + 
clazz.getPackage().getName());
+                               sink.lineBreak();
+                               sink.lineBreak();
+                               for(Annotation annotation : 
clazz.getAnnotations()) {
+                                       
if(annotation.getParameterValue().toString().contains("javax.ws.rs.Path")) {
+                                               sink.bold();
+                                               sink.text("Root Resource Path: 
" + annotation.getNamedParameter("value").toString());
+                                               sink.bold_();
+                                       }
+                               }
+                               sink.lineBreak();
+                               sink.lineBreak();
+                               sink.paragraph();
+                               sink.text(clazz.getComment());
+                               sink.paragraph_();
+                               sink.section1_();
+                               sink.horizontalRule();
+                               for(JavaMethod mth  : clazz.getMethods()) {
+                                       if(hasPathAnnotation(mth)) {
+                                               sink.section2();
+                                               sink.sectionTitle2();
+                                               sink.text("Method: " + 
mth.getName());
+                                               sink.sectionTitle2_();
+
+                                               for(Annotation annotation : 
mth.getAnnotations()) {
+                                                       
if(annotation.getParameterValue().toString().contains("javax.ws.rs.Path")) {
+                                                               sink.bold();
+                                                               
sink.text("Path: " + annotation.getNamedParameter("value"));
+                                                               sink.bold_();
+                                                               
sink.lineBreak();
+                                                               
sink.lineBreak();
+                                                       }  else 
if(annotation.getParameterValue().toString().contains("javax.ws.rs.Produces")) {
+                                                               sink.bold();
+                                                               
sink.text("Produces: " + annotation.getNamedParameter("value"));
+                                                               sink.bold_();
+                                                               
sink.lineBreak();
+                                                               
sink.lineBreak();
+                                                       }else 
if(annotation.getParameterValue().toString().contains("javax.ws.rs")) {
+                                                               sink.bold();
+                                                               sink.text("Http 
Method: " + annotation.getType().toString().substring("javax.ws.rs.".length()));
+                                                               sink.bold_();
+                                                               
sink.lineBreak();
+                                                               
sink.lineBreak();
+                                                       }
+                                               }
+                                               sink.paragraph();
+                                               sink.text(mth.getComment());
+                                               sink.paragraph_();
+                                               DocletTag[] params = 
mth.getTagsByName("param");
+                                               if(params != null) {
+                                                       
sink.numberedList(params.length);
+                                                       for(DocletTag param : 
params) {
+                                                               
sink.numberedListItem();
+                                                               
sink.text("param: " + param.getValue());
+                                                               
sink.numberedListItem_();
+                                                       }
+                                                       sink.numberedList_();
+                                               }
+                                               DocletTag returns = 
mth.getTagByName("return");
+                                               if(returns != null) {
+                                                       sink.text("Returns " + 
returns.getValue());
+                                               }
+                                               sink.lineBreak();
+                                               sink.lineBreak();
+                                               sink.paragraph();
+                                               sink.bold();
+                                               sink.text("Method Declaration 
Signature: ");
+                                               sink.bold_();
+                                               
sink.text(mth.getDeclarationSignature(true));
+                                               sink.paragraph_();
+                                               sink.section2_();
+                                       }
+                               }
+                               sink.section1_();
+                       }
+               }
+               
+               sink.body_();
+               sink.flush();
+               sink.close();
+       }
+
+       @Override
+       public String getOutputName() {
+               return "jaxrs-report";
+       }
+
+       @Override
+       public String getName(Locale locale) {  
+                return "JaxRs Report";
+       }
+
+
+       @Override
+       public String getDescription(Locale locale) {
+               return "Description of the REST webservices";
+       }
+
+       public boolean hasPathAnnotation(AbstractBaseJavaEntity entity) {
+
+               for(Annotation annotation : entity.getAnnotations()) {
+                       
if(annotation.getParameterValue().toString().contains("javax.ws.rs.Path")) {
+                               return true;
+                       }
+                       
+               }
+        return false;
+    }
+
+       public JavaSource[] getSources() {
+               String src =  baseDir + File.separator + "src";
+               File file = new File(src);
+        JavaDocBuilder builder = new JavaDocBuilder();
+               builder.addSourceTree(file);
+               return builder.getSources();
+
+       }
+
+    private JavaClass[] getJavaClassesFromSources()
+    {
+        final JavaSource[] sources = this.getSources();
+        final List<JavaClass> classes = new ArrayList<JavaClass>();
+        for ( int i = 0; i < sources.length; i++ )
+        {
+            for ( int j = 0; j < sources[i].getClasses().length; j++ )
+            {
+                final JavaClass clazz = sources[i].getClasses()[j];
+                classes.add( clazz );
+                for ( int k = 0; k < clazz.getNestedClasses().length; k++ )
+                {
+                    final JavaClass nestedClass = clazz.getNestedClasses()[k];
+                    classes.add( nestedClass );
+                }
+            }
+        }
+        return classes.toArray( new JavaClass[classes.size()] );
+    }
+}


Reply via email to