diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/CombineClass2Reference.java b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/CombineClass2Reference.java new file mode 100644 index 0000000000000000000000000000000000000000..98d23cd9b2c3c397a43c36686c75e53f510363fd --- /dev/null +++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/CombineClass2Reference.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wtp.releng.tools.component.adopters; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.eclipse.wtp.releng.tools.component.util.CommandOptionParser; +import org.eclipse.wtp.releng.tools.component.xsl.XSLUtil; + +public class CombineClass2Reference +{ + private HashMap map; + private Collection src; + private String output; + + public Collection getSrc() + { + return src; + } + + public void setSrc(Collection src) + { + this.src = src; + } + + public String getOutput() + { + return output; + } + + public void setOutput(String output) + { + this.output = output; + } + + public void execute() + { + map = new HashMap(); + for (Iterator it = src.iterator(); it.hasNext();) + { + FileInputStream fis = null; + try + { + fis = new FileInputStream((String)it.next()); + References refs = new References(); + refs.load(fis); + for (Iterator it2 = refs.getPluginRefs().iterator(); it2.hasNext();) + { + PluginRef pluginRef = (PluginRef)it2.next(); + for (Iterator it3 = pluginRef.getClassRefs().iterator(); it3.hasNext();) + { + ClassRef classRef = (ClassRef)it3.next(); + String name = classRef.getName(); + int refCount = classRef.getRefCount(); + Integer refTotal = (Integer)map.get(name); + if (refTotal == null) + { + refTotal = new Integer(0); + } + refTotal = new Integer(refCount + refTotal.intValue()); + map.put(name, refTotal); + } + } + } + catch (Throwable t) + { + throw new RuntimeException(t); + } + finally + { + if (fis != null) + { + try + { + fis.close(); + } + catch (IOException ioe) + { + } + } + } + } + genCSV(); + genHTML(); + } + + public void genCSV() + { + FileWriter fw = null; + try + { + fw = new FileWriter(output); + for (Iterator it = map.keySet().iterator(); it.hasNext();) + { + String name = (String)it.next(); + fw.write(name); + fw.write(","); + fw.write(((Integer)map.get(name)).toString()); + fw.write("\n"); + } + } + catch (IOException ioe) + { + throw new RuntimeException(ioe); + } + finally + { + if (fw != null) + { + try + { + fw.close(); + } + catch (IOException ioe) + { + } + } + } + } + + public void genHTML() + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write("<root>".getBytes()); + for (Iterator it = map.keySet().iterator(); it.hasNext();) + { + String name = (String)it.next(); + baos.write("<class name=\"".getBytes()); + baos.write(name.getBytes()); + baos.write("\" ref=\"".getBytes()); + baos.write(((Integer)map.get(name)).toString().getBytes()); + baos.write("\"/>".getBytes()); + } + baos.write("</root>".getBytes()); + baos.close(); + XSLUtil.transform + ( + ClassLoader.getSystemResourceAsStream("org/eclipse/wtp/releng/tools/component/xsl/combine-class2ref.xsl"), + new ByteArrayInputStream(baos.toByteArray()), + new FileOutputStream(output + ".html") + ); + } + catch (Throwable t) + { + throw new RuntimeException(t); + } + } + + public static void main(String[] args) + { + CommandOptionParser optionParser = new CommandOptionParser(args); + Map options = optionParser.getOptions(); + Collection src = (Collection)options.get("src"); + Collection output = (Collection)options.get("output"); + if (src == null || output == null || src.isEmpty() || output.isEmpty()) + { + printUsage(); + System.exit(-1); + } + + CombineClass2Reference class2Ref = new CombineClass2Reference(); + class2Ref.setSrc(src); + class2Ref.setOutput((String)output.iterator().next()); + class2Ref.execute(); + } + + private static void printUsage() + { + System.out.println("Usage: java org.eclipse.wtp.releng.tools.component.adopters.CombineClass2Reference -src <src> -output <output>"); + System.out.println(""); + System.out.println("\t-src\t\t<src>\t\tlocation of your usage reports"); + System.out.println("\t-output\t<output>\t\tlocation of the output file"); + } +} \ 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/combine-class2ref.xsl b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-class2ref.xsl new file mode 100644 index 0000000000000000000000000000000000000000..1eedf0c153cbe76a07692426788191270056acfb --- /dev/null +++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-class2ref.xsl @@ -0,0 +1,86 @@ +<?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> + <script language="javascript"> + function sort(col) + { + var table = document.getElementById("data"); + for (var i = 2; i < table.rows.length; i++) + { + for (var j = i - 1; j > 0; j--) + { + var x = parseInt(table.rows[i].cells[col].childNodes[0].data); + var y = parseInt(table.rows[j].cells[col].childNodes[0].data); + if (x < y) + { + move(table, i, j + 1); + break; + } + if (j == 1) + { + move(table, i, 1); + break; + } + } + } + } + function move(table, src, target) + { + var td_name = document.createElement("td"); + var td_ref = document.createElement("td"); + + td_name.appendChild(document.createTextNode(table.rows[src].cells[0].childNodes[0].data)); + td_ref.appendChild(document.createTextNode(table.rows[src].cells[1].childNodes[0].data)); + + table.deleteRow(src); + var tr = table.insertRow(target); + tr.appendChild(td_name); + tr.appendChild(td_ref); + } + </script> + <body> + <table border="0" cellpadding="2" cellspacing="5" width="100%"> + <tr> + <td align="left" width="60%"> + <font style="font-size: x-large;; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold"> + API Usage Report + </font> + </td> + </tr> + </table> + <table border="0" cellpadding="2" cellspacing="5" width="100%"> + <tr> + <td ALIGN="LEFT" VALIGN="TOP" COLSPAN="2" BGCOLOR="#0080C0"><b><font color="#FFFFFF" face="Arial,Helvetica"> + API usage summary + </font></b></td> + </tr> + </table> + <br/> + <p> + Sort by: + <select name="sortby" onchange="javascript:sort(this.selectedIndex)"> + <option value="0">Class name</option> + <option value="1">Reference count</option> + </select> + </p> + <table id="data" border="1" width="80%"> + <tr> + <th width="95%">Class name</th> + <th>Reference count</th> + </tr> + <xsl:for-each select="root/class"> + <xsl:sort select="@name"/> + <tr> + <td><xsl:value-of select="@name"/></td> + <td><xsl:value-of select="@ref"/></td> + </tr> + </xsl:for-each> + </table> + </body> + </html> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file