[122833] Improve Test Automation
diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/classes/Class2Reference.java b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/classes/Class2Reference.java
index e58fdae..32e8dd8 100644
--- a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/classes/Class2Reference.java
+++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/classes/Class2Reference.java
@@ -13,6 +13,7 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -23,6 +24,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
+
 import org.eclipse.jdt.core.Signature;
 import org.eclipse.jdt.core.util.ClassFormatException;
 import org.eclipse.jdt.core.util.IClassFileReader;
@@ -35,6 +37,7 @@
 import org.eclipse.jdt.core.util.IMethodInfo;
 import org.eclipse.jdt.internal.core.util.ClassFileReader;
 import org.eclipse.wtp.releng.tools.component.ILocation;
+import org.eclipse.wtp.releng.tools.component.ILocationVisitor;
 import org.eclipse.wtp.releng.tools.component.internal.FieldRef;
 import org.eclipse.wtp.releng.tools.component.internal.FileLocation;
 import org.eclipse.wtp.releng.tools.component.internal.InternalByteCodeVisitor;
@@ -46,6 +49,7 @@
 import org.eclipse.wtp.releng.tools.component.use.MethodUse;
 import org.eclipse.wtp.releng.tools.component.use.Source;
 import org.eclipse.wtp.releng.tools.component.util.CommandOptionParser;
+import org.eclipse.wtp.releng.tools.component.xsl.XSLUtil;
 
 public class Class2Reference implements IClassVisitor
 {
@@ -57,11 +61,13 @@
   private Collection excludePlugins;
   private boolean classRefOnly;
   private boolean debug;
+  private boolean genHTML;
 
   public Class2Reference()
   {
     this.classRefOnly = false;
     this.debug = false;
+    this.genHTML = false;
   }
 
   public String getOutputDir()
@@ -144,6 +150,16 @@
     this.debug = debug;
   }
 
+  public boolean isGenHTML()
+  {
+    return genHTML;
+  }
+
+  public void setGenHTML(boolean genHTML)
+  {
+    this.genHTML = genHTML;
+  }
+
   public void execute()
   {
     ILocation srcLocation = Location.createLocation(new File(src));
@@ -160,6 +176,41 @@
     {
       throw new RuntimeException(e);
     }
+    if (isGenHTML())
+    {
+      genHTML();
+    }
+  }
+
+  public void genHTML()
+  {
+    ILocation outputLoc = Location.createLocation(new File(outputDir));
+    outputLoc.accept
+    (
+      new ILocationVisitor()
+      {
+        public boolean accept(ILocation location)
+        {
+          if (location.getName().equals("component-use.xml"))
+          {
+            try
+            {
+              XSLUtil.transform
+              (
+                ClassLoader.getSystemResourceAsStream("org/eclipse/wtp/releng/tools/component/xsl/component-use.xsl"),
+                location.getInputStream(),
+                new FileOutputStream(((FileLocation)location.createSibling("component-use.html")).getFile())
+              );
+            }
+            catch (Throwable t)
+            {
+              t.printStackTrace();
+            }
+          }
+          return true;
+        }
+      }
+    );
   }
 
   public boolean visit(String pluginId, ILocation classLoc)
@@ -581,6 +632,7 @@
     Collection excludePlugins = (Collection)options.get("excludePlugins");
     Collection classRefOnly = (Collection)options.get("classRefOnly");
     Collection debug = (Collection)options.get("debug");
+    Collection genHTML = (Collection)options.get("genHTML");
     if (src == null || outputDir == null || src.isEmpty() || outputDir.isEmpty())
     {
       printUsage();
@@ -595,6 +647,7 @@
     class2Ref.setExcludePlugins(excludePlugins);
     class2Ref.setClassRefOnly(classRefOnly != null);
     class2Ref.setDebug(debug != null);
+    class2Ref.setGenHTML(genHTML != null);
     class2Ref.execute();
   }
 
@@ -613,5 +666,6 @@
     System.out.println("\t-excludePlugins\t<excludePlugins>\tspace seperated plugins to exclude");
     System.out.println("\t-classRefOnly\t\t\ttreat all violations as class reference");
     System.out.println("\t-debug\t\t\t\tgenerate debug information (ex. line numbers)");
+    System.out.println("\t-genHTML\t\t\t\tgenerate HTML report");
   }
 }
\ No newline at end of file
diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-use.xsl b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-use.xsl
new file mode 100644
index 0000000..14f68ed
--- /dev/null
+++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-use.xsl
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+	<xsl:template match="/">
+		<html>
+			<body>
+				<table border="1">
+					<tr>
+						<th>Name</th>
+						<th>Reference</th>
+						<th>Subclass</th>
+						<th>Implement</th>
+						<th>Instantiate</th>
+					</tr>
+					<xsl:for-each select="component-use/source">
+						<xsl:sort select="@name"/>
+						<xsl:if test="class-use">
+							<xsl:apply-templates select="." />
+						</xsl:if>
+					</xsl:for-each>
+				</table>
+			</body>
+		</html>
+	</xsl:template>
+	<xsl:template match="source">
+		<tr>
+			<td><b>Source: <xsl:value-of select="@name"/></b></td>
+			<td bgcolor="c8c8c8" colspan="4">&#160;</td>
+		</tr>
+		<xsl:for-each select="class-use">
+			<xsl:sort select="@name"/>
+			<xsl:apply-templates select="." />
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template match="class-use">
+		<tr>
+			<td><b>&#160;&#160;&#160;Class: <xsl:value-of select="@name"/></b></td>
+			<td><xsl:value-of select="@reference"/></td>
+			<td><xsl:value-of select="@subclass"/></td>
+			<td><xsl:value-of select="@implement"/></td>
+			<td><xsl:value-of select="@instantiate"/></td>
+		</tr>
+		<xsl:for-each select="method-use">
+			<xsl:sort select="@name"/>
+			<xsl:apply-templates select="." />
+		</xsl:for-each>
+		<xsl:for-each select="field-use">
+			<xsl:sort select="@name"/>
+			<xsl:apply-templates select="." />
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template match="method-use">
+		<tr>
+			<td>&#160;&#160;&#160;&#160;&#160;&#160;Method: <xsl:value-of select="@name"/>&#160;<xsl:value-of select="@descriptor"/></td>
+			<td bgcolor="c8c8c8" colspan="4">&#160;</td>
+		</tr>
+	</xsl:template>
+	<xsl:template match="field">
+		<tr>
+			<td>&#160;&#160;&#160;&#160;&#160;&#160;Field: <xsl:value-of select="@name"/></td>
+			<td bgcolor="c8c8c8" colspan="4">&#160;</td>
+		</tr>
+	</xsl:template>
+</xsl:stylesheet>
\ No newline at end of file