Author: veithen
Date: Tue Nov 11 07:21:13 2008
New Revision: 713057

URL: http://svn.apache.org/viewvc?rev=713057&view=rev
Log:
Added a custom doclet to the testkit so that part of the Javadoc (dependencies 
between test resources) is generated automatically.

Added:
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java
   (with props)
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java
   (with props)
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java
   (with props)
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java
   (with props)
    
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java
   (with props)
Modified:
    webservices/commons/trunk/modules/transport/modules/testkit/pom.xml

Modified: webservices/commons/trunk/modules/transport/modules/testkit/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/pom.xml?rev=713057&r1=713056&r2=713057&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/testkit/pom.xml 
(original)
+++ webservices/commons/trunk/modules/transport/modules/testkit/pom.xml Tue Nov 
11 07:21:13 2008
@@ -116,6 +116,50 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>extract-resource-info</id>
+                        <phase>pre-site</phase>
+                        <goals>
+                            <goal>javadoc</goal>
+                        </goals>
+                        <configuration>
+                            <docletArtifacts>
+                                <docletArtifact>
+                                    <groupId>${pom.groupId}</groupId>
+                                    <artifactId>${pom.artifactId}</artifactId>
+                                    <version>${pom.version}</version>
+                                </docletArtifact>
+                            </docletArtifacts>
+                            
<doclet>org.apache.axis2.transport.testkit.doclet.ResourceInfoDoclet</doclet>
+                            <show>private</show>
+                            <additionalparam>-out 
${project.build.directory}/resource-info.dat</additionalparam>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
+
+    <reporting>
+        <plugins>
+            <plugin>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <docletArtifacts>
+                        <docletArtifact>
+                            <groupId>${pom.groupId}</groupId>
+                            <artifactId>${pom.artifactId}</artifactId>
+                            <version>${pom.version}</version>
+                        </docletArtifact>
+                    </docletArtifacts>
+                    
<doclet>org.apache.axis2.transport.testkit.doclet.TestkitJavadocDoclet</doclet>
+                    <useStandardDocletOptions>true</useStandardDocletOptions>
+                    <additionalparam>-resource-info 
${project.build.directory}/resource-info.dat</additionalparam>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
 </project>

Added: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java?rev=713057&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java
 Tue Nov 11 07:21:13 2008
@@ -0,0 +1,48 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.axis2.transport.testkit.doclet;
+
+import java.io.Serializable;
+
+public class Dependency implements Serializable {
+    private static final long serialVersionUID = -3576630956376161332L;
+    
+    private final String type;
+    private final String multiplicity;
+    private final String comment;
+
+    public Dependency(String type, String multiplicity, String comment) {
+        this.type = type;
+        this.multiplicity = multiplicity;
+        this.comment = comment;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public String getMultiplicity() {
+        return multiplicity;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Dependency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java?rev=713057&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java
 Tue Nov 11 07:21:13 2008
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.axis2.transport.testkit.doclet;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+public class Resource implements Serializable {
+    private static final long serialVersionUID = 8381629721839692917L;
+    
+    private final String type;
+    private List<Dependency> dependencies;
+    
+    public Resource(String type) {
+        this.type = type;
+    }
+
+    public String getType() {
+        return type;
+    }
+    
+    public void addDependency(String type, String multiplicity, String 
comment) {
+        if (dependencies == null) {
+            dependencies = new LinkedList<Dependency>();
+        }
+        dependencies.add(new Dependency(type, multiplicity, comment));
+    }
+
+    public List<Dependency> getDependencies() {
+        return dependencies;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/Resource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java?rev=713057&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java
 Tue Nov 11 07:21:13 2008
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.axis2.transport.testkit.doclet;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public class ResourceInfo implements Serializable {
+    private static final long serialVersionUID = -3590562573639276912L;
+    
+    private final Map<String,Resource> resources = new 
HashMap<String,Resource>();
+    
+    public void addResource(Resource resource) {
+        resources.put(resource.getType(), resource);
+    }
+    
+    public Resource getResource(String type) {
+        return resources.get(type);
+    }
+    
+    public List<Resource> getUsedBy(String type) {
+        List<Resource> result = null;
+        for (Resource resource : resources.values()) {
+            List<Dependency> dependencies = resource.getDependencies();
+            if (dependencies != null) {
+                for (Dependency dependency : dependencies) {
+                    if (dependency.getType().equals(type)) {
+                        if (result == null) {
+                            result = new LinkedList<Resource>();
+                        }
+                        result.add(resource);
+                        break;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java?rev=713057&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java
 Tue Nov 11 07:21:13 2008
@@ -0,0 +1,144 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.axis2.transport.testkit.doclet;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import com.sun.javadoc.AnnotationDesc;
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.Doc;
+import com.sun.javadoc.DocErrorReporter;
+import com.sun.javadoc.MethodDoc;
+import com.sun.javadoc.ParamTag;
+import com.sun.javadoc.Parameter;
+import com.sun.javadoc.ProgramElementDoc;
+import com.sun.javadoc.RootDoc;
+import com.sun.javadoc.SeeTag;
+import com.sun.javadoc.Tag;
+import com.sun.javadoc.Type;
+
+public class ResourceInfoDoclet {
+    private static File outFile;
+    
+    public static boolean start(RootDoc root) throws IOException {
+        parseOptions(root.options());
+        ResourceInfo resourceInfo = new ResourceInfo();
+        for (ClassDoc clazz : root.classes()) {
+            Resource resource = null;
+            for (MethodDoc method : clazz.methods()) {
+                if (getAnnotation(method, 
"org.apache.axis2.transport.testkit.tests.Setup") != null) {
+                    if (resource == null) {
+                        resource = new Resource(clazz.qualifiedName());
+                    }
+                    ParamTag[] paramTags = method.paramTags();
+                    for (Parameter parameter : method.parameters()) {
+                        Type type = parameter.type();
+                        String name = parameter.name();
+                        String comment = null;
+                        for (ParamTag paramTag : paramTags) {
+                            if (paramTag.parameterName().equals(name)) {
+                                comment = paramTag.parameterComment();
+                                break;
+                            }
+                        }
+                        if (comment == null) {
+                            comment = 
getFirstSentence(root.classNamed(type.qualifiedTypeName()));
+                        }
+                        resource.addDependency(type.qualifiedTypeName(),
+                                               type.dimension().equals("[]") ? 
"0..*" : "1", 
+                                               comment);
+                    }
+                }
+            }
+            if (resource != null) {
+                resourceInfo.addResource(resource);
+            }
+        }
+        ObjectOutputStream out = new ObjectOutputStream(new 
FileOutputStream(outFile));
+        out.writeObject(resourceInfo);
+        out.close();
+        return true;
+    }
+    
+    private static AnnotationDesc getAnnotation(ProgramElementDoc doc, String 
qualifiedName) {
+        for (AnnotationDesc annotation : doc.annotations()) {
+            if 
(annotation.annotationType().qualifiedName().equals(qualifiedName)) {
+                return annotation;
+            }
+        }
+        return null;
+    }
+    
+    private static String getFirstSentence(Doc doc) {
+        Tag[] tags = doc.firstSentenceTags();
+        if (tags.length == 0) {
+            return null;
+        }
+        StringBuilder buffer = new StringBuilder();
+        for (Tag tag : tags) {
+            if (tag instanceof SeeTag) {
+                buffer.append("{");
+                buffer.append(tag.name());
+                buffer.append(" ");
+                buffer.append(((SeeTag)tag).referencedClassName());
+                buffer.append("}");
+            } else {
+                buffer.append(tag.text());
+            }
+        }
+        return buffer.toString();
+    }
+
+    private static void parseOptions(String[][] options) {
+        for (String[] option : options) {
+            if (option[0].equals("-out")) {
+                outFile = new File(option[1]);
+                System.out.println("Output is going to " + outFile);
+            }
+        }
+    }
+
+    public static int optionLength(String option) {
+        if (option.equals("-out")) {
+            return 2;
+        } else {
+            return 0;
+        }
+    }
+    
+    public static boolean validOptions(String options[][], DocErrorReporter 
reporter) {
+        boolean hasOut = false;
+        for (String[] option : options) {
+            String opt = option[0];
+            if (opt.equals("-out")) {
+                hasOut = true;
+            }
+        }
+        if (!hasOut) {
+            reporter.printError("No output file specified: -out <output 
file>");
+            return false;
+        } else {
+            return true;
+        }
+    }
+}

Propchange: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/ResourceInfoDoclet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java?rev=713057&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java
 Tue Nov 11 07:21:13 2008
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.axis2.transport.testkit.doclet;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.ObjectInputStream;
+import java.util.List;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.DocErrorReporter;
+import com.sun.javadoc.RootDoc;
+import com.sun.tools.doclets.standard.Standard;
+
+public class TestkitJavadocDoclet {
+    private static File resourceInfoFile;
+    
+    public static int optionLength(String option) {
+        if (option.equals("-resource-info")) {
+            return 2;
+        } else {
+            return Standard.optionLength(option);
+        }
+    }
+    
+    public static boolean validOptions(String options[][], DocErrorReporter 
reporter) {
+        return Standard.validOptions(options, reporter);
+    }
+    
+    public static boolean start(RootDoc root) throws Exception {
+        parseOptions(root.options());
+        ObjectInputStream in = new ObjectInputStream(new 
FileInputStream(resourceInfoFile));
+        ResourceInfo resourceInfo = (ResourceInfo)in.readObject();
+        in.close();
+        for (ClassDoc clazz : root.classes()) {
+            String qualifiedName = clazz.qualifiedName();
+            List<Resource> usedBy = resourceInfo.getUsedBy(qualifiedName);
+            Resource resource = resourceInfo.getResource(qualifiedName);
+            List<Dependency> dependencies = resource == null ? null : 
resource.getDependencies();
+            if (dependencies != null || usedBy != null) {
+                StringBuilder buffer = new 
StringBuilder(clazz.getRawCommentText());
+                buffer.append("<h2>Resource information</h2>");
+                if (usedBy != null) {
+                    buffer.append("This resource is used by: ");
+                    boolean first = true;
+                    for (Resource r : usedBy) {
+                        if (first) {
+                            first = false;
+                        } else {
+                            buffer.append(", ");
+                        }
+                        buffer.append("[EMAIL PROTECTED] ");
+                        buffer.append(r.getType());
+                        buffer.append("}");
+                    }
+                }
+                if (dependencies != null) {
+                    buffer.append("<h3>Dependencies</h3>");
+                    buffer.append("<dl>");
+                    for (Dependency dependency : dependencies) {
+                        buffer.append("<dt>[EMAIL PROTECTED] ");
+                        buffer.append(dependency.getType());
+                        buffer.append("} (");
+                        buffer.append(dependency.getMultiplicity());
+                        buffer.append(")</dt><dd>");
+                        String comment = dependency.getComment();
+                        if (comment == null) {
+                            buffer.append("(no documentation available)");
+                        } else {
+                            buffer.append(comment);
+                        }
+                        buffer.append("</dd>");
+                    }
+                    buffer.append("</dl>");
+                }
+                clazz.setRawCommentText(buffer.toString());
+            }
+        }
+        return Standard.start(root);
+    }
+
+    private static void parseOptions(String[][] options) {
+        for (String[] option : options) {
+            if (option[0].equals("-resource-info")) {
+                resourceInfoFile = new File(option[1]);
+                System.out.println("Resource information is read from " + 
resourceInfoFile);
+            }
+        }
+    }
+}

Propchange: 
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/doclet/TestkitJavadocDoclet.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to