geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pra...@apache.org
Subject svn commit: r476439 - in /geronimo/server/trunk/maven-plugins/testsuite-maven-plugin: pom.xml src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
Date Sat, 18 Nov 2006 05:03:48 GMT
Author: prasad
Date: Fri Nov 17 21:03:47 2006
New Revision: 476439

URL: http://svn.apache.org/viewvc?view=rev&rev=476439
Log:
* introducing testsuite-maven-plugin:fix-menu goal.
* goal is a hack for now to create a full menu in the surefire-report.html file generated
by the 'generate-surefire-report' goal.
* maven does not include full menu for reports run outside <reporting>
* have been unsuccessful getting maven to include custom reports with it's core reporting.

Added:
    geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/pom.xml

Modified: geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/pom.xml?view=diff&rev=476439&r1=476438&r2=476439
==============================================================================
--- geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/pom.xml Fri Nov 17 21:03:47
2006
@@ -53,6 +53,11 @@
           <artifactId>maven-reporting-impl</artifactId>
           <version>2.0</version>
         </dependency>
+        <dependency>
+          <groupId>jtidy</groupId>
+          <artifactId>jtidy</artifactId>
+          <version>8.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -65,6 +70,18 @@
             </plugin>
         </plugins>
     </build>
+
+     <repositories>
+        <repository>
+            <id>jtidy.sourceforge</id>
+            <url>http://jtidy.sourceforge.net/snapshots</url>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>ignore</checksumPolicy>
+            </snapshots>
+        </repository>
+    </repositories>
     
 </project>
 

Added: geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java?view=auto&rev=476439
==============================================================================
--- geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
(added)
+++ geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
Fri Nov 17 21:03:47 2006
@@ -0,0 +1,199 @@
+/*
+ * 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.geronimo.mavenplugins.testsuite;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.tidy.Tidy;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.dom.DOMSource; 
+import javax.xml.transform.stream.StreamResult; 
+
+
+import org.apache.geronimo.genesis.MojoSupport;
+
+import org.apache.maven.project.MavenProject;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * The surefire-report.html generated by the generate-surefire-report goal does not have
the full menu as other links.
+ * This is hack to fix the menu. This wouldn't be necessary when maven can start aggregating
surefire-reports.
+ * We shall fix the menu in this html by copying the full menu from index.html.
+ *
+ * @goal fix-menu
+ *
+ * @version $Rev$ $Date$
+ */
+public class SurefireReportMenuMojo
+    extends MojoSupport
+{
+    /**
+     * @parameter default-value="${project.build.directory}/site"
+     * @read-only
+     */
+     private File currentSiteDirectory;
+
+     /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project = null;
+
+    protected MavenProject getProject() {
+        return project;
+    }
+
+    protected void init() throws MojoExecutionException, MojoFailureException {
+        super.init();
+
+    }
+
+    protected void doExecute() throws Exception {
+
+        if (currentSiteDirectory == null) {
+            log.info("No site directory here");
+            return;
+        }
+
+        Tidy tidy = new Tidy(); // obtain a new Tidy instance
+        tidy.setQuiet(true);
+        tidy.setShowWarnings(false);
+
+        // Read index.html and get it's menu element
+        FileInputStream indexStream = new FileInputStream( new File(currentSiteDirectory,
"index.html") );
+        Document document = tidy.parseDOM(indexStream, null); 
+        indexStream.close();
+        Element navColumn1 = getNavColumn(document);
+
+        //FIXME: going into an endless loop
+        // navColumn1 = fixHref(navColumn1);
+
+        // Read surefire-report.html and get it's menu element
+        FileInputStream surefireStream = new FileInputStream( new File(currentSiteDirectory,
"surefire-report.html") );
+        document = tidy.parseDOM(surefireStream, null); 
+        surefireStream.close();
+        Element navColumn2 = getNavColumn(document);
+
+
+        // remove the menu from surefire-report.html and replace it with the menu from index.html
+        Element parent = (Element) navColumn2.getParentNode();
+        parent.removeChild(navColumn2);
+        parent.appendChild(navColumn1);
+        
+        // FIXME: tidy.pprint() is not working ! Have to use transform
+        // tidy.pprint(document, os);
+
+
+        // Use a Transformer for output
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        Transformer transformer = tFactory.newTransformer();
+
+        // write the document back into a temporary file.
+        FileOutputStream os = new FileOutputStream( new File(currentSiteDirectory, "surefire-report-2.html")
);
+        DOMSource source = new DOMSource(document);
+        StreamResult result = new StreamResult(os);
+        transformer.transform(source, result); 
+
+        os.flush();
+        os.close();
+
+        // tidy the document and replace the original surefire-report.html
+        File tempFile = new File(currentSiteDirectory, "surefire-report-2.html");
+        surefireStream = new FileInputStream( tempFile );
+        os = new FileOutputStream( new File(currentSiteDirectory, "surefire-report.html")
);
+        tidy.parse(surefireStream, os);
+        surefireStream.close();
+        os.close();
+
+        // delete the temp file.
+        tempFile.delete();
+    }
+
+
+
+    private Element getNavColumn(Document document) {
+        Element navColumn = null;
+        NodeList nodeList = document.getElementsByTagName("div");
+        for (int i=0; i<nodeList.getLength(); i++) {
+            Element node = (Element) nodeList.item(i);
+            String divID = node.getAttribute("id");
+            log.debug("id is " + divID);
+            if ("navcolumn".equals(divID)) {
+                navColumn = node;
+                break;
+            }
+        }
+        return navColumn;
+    }
+
+
+    /**
+     * Since we copy the menu from the index.html, we have to remove the 
+     * menu item "About" which is selected (<strong>) and make it a link
+     */
+    private Element fixHref(Element navColumn) {
+        log.info("fix href for About item");
+
+        NodeList nodeList = navColumn.getElementsByTagName("strong");
+        log.debug("node list size " + nodeList.getLength() );
+
+        Element strong = (Element) nodeList.item(0);
+        Element li = (Element) strong.getParentNode();
+
+        Element sibling = (Element) li.getNextSibling();
+
+        Element ul = (Element) li.getParentNode();
+
+        Element clone = (Element) sibling.cloneNode(false);
+
+        ul.removeChild(li);
+
+        ( (Element)clone.getFirstChild() ).setAttribute("href", "index.html");
+
+        clone.getFirstChild().setNodeValue("About");
+
+        ul.insertBefore(clone, sibling);
+
+        return navColumn;
+    }
+
+
+}
+

Propchange: geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/maven-plugins/testsuite-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/testsuite/SurefireReportMenuMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message