added ordering by internal usage in output files
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
index 840d0bc..b3bfaa1 100644
--- 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
@@ -19,12 +19,15 @@
 import java.io.IOException;
 import java.io.Writer;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+
 import org.eclipse.wtp.releng.tools.component.ILocation;
 import org.eclipse.wtp.releng.tools.component.api.ComponentXMLVisitor;
 import org.eclipse.wtp.releng.tools.component.internal.Location;
@@ -290,6 +293,19 @@
     generateHTMLFiles();
   }
   
+  private List getOrderedReferencedCountKeys(final TreeMap referenceCounts) {
+	  String[] keys = (String[]) referenceCounts.keySet().toArray(new String[referenceCounts.keySet().size()]);
+	  Comparator nonAPIComparator = new Comparator() {
+			public int compare(Object o1, Object o2) {
+				UsageCount usageCount1 = (UsageCount) referenceCounts.get(o1);
+				UsageCount usageCount2 = (UsageCount) referenceCounts.get(o2);
+				return usageCount2.nonAPIUse-usageCount1.nonAPIUse;
+			}
+	  };
+	  Arrays.sort(keys,nonAPIComparator);
+	  return Arrays.asList(keys);
+  }
+  
   /**
    * Helper method to update the passed in component team's cached usage counts based on the 
    * given class reference and known API's in the provided component.xml file.
@@ -492,9 +508,9 @@
    * @throws IOException
    */
   private void writeCompTeamCSV(ComponentTeam compTeam, Writer classWriter, Writer pkgWriter, Writer pluginWriter) throws IOException {
-    writeCompTeamCSV(compTeam,classWriter,CLASS_USAGE,compTeam.getClassReferenceCounts());
-    writeCompTeamCSV(compTeam,pkgWriter,PACKAGE_USAGE,compTeam.getPackageReferenceCounts());
-    writeCompTeamCSV(compTeam,pluginWriter,PLUGIN_USAGE,compTeam.getPluginReferenceCounts());
+    writeCompTeamCSV(compTeam,classWriter,compTeam.getClassReferenceCounts());
+    writeCompTeamCSV(compTeam,pkgWriter,compTeam.getPackageReferenceCounts());
+    writeCompTeamCSV(compTeam,pluginWriter,compTeam.getPluginReferenceCounts());
   }
   
   /**
@@ -503,29 +519,20 @@
    * 
    * @param compTeam
    * @param writer
-   * @param usage
    * @param referenceCounts
    * @throws IOException
    */
-  private void writeCompTeamCSV(ComponentTeam compTeam, Writer writer, int usage, TreeMap referenceCounts) throws IOException {
+  private void writeCompTeamCSV(ComponentTeam compTeam, Writer writer, TreeMap referenceCounts) throws IOException {
 	  // Write the team name
 	  writer.write(compTeam.getTeamName());
 	  writer.write(LINE_BREAK);
+	  // Order reference counts by usage type
+	  List orderedKeys = getOrderedReferencedCountKeys(referenceCounts);
 	  // For each name key, retrieve the corresponding usage count values
-	  for (Iterator it = referenceCounts.keySet().iterator(); it.hasNext();) {
+	  for (Iterator it = orderedKeys.iterator(); it.hasNext();) {
 	      String name = (String)it.next();
-	      UsageCount usageCount = null;
-	      switch (usage) {
-	      	case 0:
-	      		usageCount = (UsageCount)compTeam.getClassReferenceCounts().get(name);
-	      		break;
-	      	case 1:
-	      		usageCount = (UsageCount)compTeam.getPackageReferenceCounts().get(name);
-	      		break;
-	      	case 2:
-	      		usageCount = (UsageCount)compTeam.getPluginReferenceCounts().get(name);
-	      		break;
-		  }
+	      // Get the corresponding usage count for the name key
+	      UsageCount usageCount = (UsageCount)referenceCounts.get(name);
 	      // Write out the internal and api usages
 	      writer.write(name);
 	      writer.write(COMMA);
@@ -544,30 +551,33 @@
     try {
       // Create a new output stream	
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      baos.write(HTML_ROOT_BEGIN.getBytes());
+      baos.write(XML_ROOT_BEGIN.getBytes());
       // For each component team, write out the combined component team specific usage data
       for (int i=0; i<getComponentTeams().size(); i++) {
     	  ComponentTeam compTeam = (ComponentTeam) getComponentTeams().get(i);
-    	  writeCompTeam(compTeam, baos);
+    	  writeCompTeamXML(compTeam, baos);
       }
       // Close the output stream
-      baos.write(HTML_ROOT_END.getBytes());
+      baos.write(XML_ROOT_END.getBytes());
       baos.close();
       // Create a byte array from the output stream contents
       byte[] content = baos.toByteArray();
-      // Write out the byte array to a file output stream for the plugin references
+      // Write out the byte array xml to a html file output stream for the plugin references
+      // This transform will do a XSLT operation using the file combine-plugin2ref.xsl
       XSLUtil.transform (
         ClassLoader.getSystemResourceAsStream(COMBINE_PLUGINS_FILE),
         new ByteArrayInputStream(content),
         new FileOutputStream(getOutput() + PLUGIN_HTML_FILE_EXTENSION)
       );
-      // Write out the byte array to a file output stream for the package references
+      // Write out the byte array xml to a html file output stream for the package references
+      // This transform will do a XSLT operation using the file combine-pkg2ref.xsl
       XSLUtil.transform (
         ClassLoader.getSystemResourceAsStream(COMBINE_PACKAGES_FILE),
         new ByteArrayInputStream(content),
         new FileOutputStream(getOutput() + PACKAGE_HTML_FILE_EXTENSION)
       );
-      // Write out the byte array to a file output stream for the class references
+      // Write out the byte array xml to a html file output stream for the class references
+      // This transform will do a XSLT operation using the file combine-class2ref.xsl
       XSLUtil.transform (
         ClassLoader.getSystemResourceAsStream(COMBINE_CLASSES_FILE),
         new ByteArrayInputStream(content),
@@ -587,13 +597,13 @@
    * @param baos
    * @throws IOException
    */
-  private void writeCompTeam(ComponentTeam compTeam, ByteArrayOutputStream baos) throws IOException {
+  private void writeCompTeamXML(ComponentTeam compTeam, ByteArrayOutputStream baos) throws IOException {
     baos.write("<team lead=\"".getBytes()); //$NON-NLS-1$
     baos.write(compTeam.getTeamName().getBytes());
     baos.write("\">".getBytes()); //$NON-NLS-1$
-    writeCompTeam(compTeam,baos,CLASS_USAGE,compTeam.getClassReferenceCounts());
-    writeCompTeam(compTeam,baos,PACKAGE_USAGE,compTeam.getPackageReferenceCounts());
-    writeCompTeam(compTeam,baos,PLUGIN_USAGE,compTeam.getPluginReferenceCounts());
+    writeCompTeamXML(baos,CLASS_USAGE,compTeam.getClassReferenceCounts());
+    writeCompTeamXML(baos,PACKAGE_USAGE,compTeam.getPackageReferenceCounts());
+    writeCompTeamXML(baos,PLUGIN_USAGE,compTeam.getPluginReferenceCounts());
     baos.write("</team>".getBytes()); //$NON-NLS-1$
   }
   
@@ -602,33 +612,31 @@
    * the non API and API usage for the class usage file, the package usage file, and the plugin
    * usage file.
    * 
-   * @param compTeam ComponentTeam
    * @param baos ByteArrayOutputStream
    * @param usage class, package, or plugin?
    * @param referenceCounts TreeMap
    * @throws IOException
    */
-  private void writeCompTeam(ComponentTeam compTeam, ByteArrayOutputStream baos, int usage, TreeMap referenceCounts) throws IOException {
+  private void writeCompTeamXML(ByteArrayOutputStream baos, int usage, TreeMap referenceCounts) throws IOException {
+	  // Order reference counts by usage type
+	  List orderedKeys = getOrderedReferencedCountKeys(referenceCounts);
 	  // Iterate over the name keys of the references tree map
-	  for (Iterator it = referenceCounts.keySet().iterator(); it.hasNext();) {
+	  for (Iterator it = orderedKeys.iterator(); it.hasNext();) {
 	      String name = (String)it.next();
-	      UsageCount usageCount = null;
 	      // Retrieve the appropriate UsageCount from the map given the current name key
+	      UsageCount usageCount = (UsageCount) referenceCounts.get(name);
 	      switch (usage) {
 	        // Class reference
 	      	case 0:
-	      		usageCount = (UsageCount)compTeam.getClassReferenceCounts().get(name);
 	      		baos.write("<class name=\"".getBytes()); //$NON-NLS-1$
 	      		break;
 	        // Package reference
 			case 1:
-				usageCount = (UsageCount)compTeam.getPackageReferenceCounts().get(name);
 				baos.write("<package name=\"".getBytes()); //$NON-NLS-1$
 				break;
 			// Plugin reference
 			case 2:
-				usageCount = (UsageCount)compTeam.getPluginReferenceCounts().get(name);
-			    baos.write("<plugin id=\"".getBytes()); //$NON-NLS-1$
+				baos.write("<plugin id=\"".getBytes()); //$NON-NLS-1$
 				break;
 		  }
 	      // Write the api and internal usage for the current reference
@@ -643,7 +651,8 @@
 
   /**
    * This is the static main method used for launching this reference usage combination
-   * application.
+   * application.  It will create and set up the class instance and then invoke the execute
+   * method to do the combination.
    * 
    * @param args
    */
diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/IOutputConstants.java b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/IOutputConstants.java
index 671b595..58dbdbd 100644
--- a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/IOutputConstants.java
+++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/adopters/IOutputConstants.java
@@ -5,8 +5,8 @@
 	public static final String LINE_BREAK = "\n"; //$NON-NLS-1$
 	public static final String COMMA = ","; //$NON-NLS-1$
 	
-	public static final String HTML_ROOT_BEGIN = "<root>"; //$NON-NLS-1$
-	public static final String HTML_ROOT_END = "</root>" ; //$NON-NLS-1$
+	public static final String XML_ROOT_BEGIN = "<root>"; //$NON-NLS-1$
+	public static final String XML_ROOT_END = "</root>" ; //$NON-NLS-1$
 	
 	public static final String PRINT_SOURCE_LOCATION = "\t-src\t\t<src>\t\tlocation of your usage reports"; //$NON-NLS-1$
 	public static final String PRINT_OUTPUT_LOCATION = "\t-output\t<output>\t\tlocation of the output file"; //$NON-NLS-1$
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
index f1db2f6..40337e5 100644
--- 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
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+	
 	<xsl:template match="/">
 		<html>
 			<body>
@@ -23,7 +22,9 @@
 				</table>
 				<xsl:for-each select="root/team">
 					<xsl:sort select="@lead"/>
-					<xsl:apply-templates select="."/>
+					<xsl:apply-templates select=".">
+					    <xsl:sort select="@internal" order="descending"/>
+					</xsl:apply-templates>
 				</xsl:for-each>
 			</body>
 		</html>
@@ -38,7 +39,6 @@
 				<th>API usage count</th>
 			</tr>
 			<xsl:for-each select="class">
-				<xsl:sort select="@name"/>
 				<xsl:apply-templates select="."/>
 			</xsl:for-each>
 		</table>
diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-pkg2ref.xsl b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-pkg2ref.xsl
index 4617663..089f412 100644
--- a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-pkg2ref.xsl
+++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-pkg2ref.xsl
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 	<xsl:template match="/">
 		<html>
@@ -23,7 +22,9 @@
 				</table>
 				<xsl:for-each select="root/team">
 					<xsl:sort select="@lead"/>
-					<xsl:apply-templates select="."/>
+					<xsl:apply-templates select=".">
+					    <xsl:sort select="@internal" order="descending"/>
+					</xsl:apply-templates>
 				</xsl:for-each>
 			</body>
 		</html>
@@ -38,7 +39,6 @@
 				<th>API usage count</th>
 			</tr>
 			<xsl:for-each select="package">
-				<xsl:sort select="@name"/>
 				<xsl:apply-templates select="."/>
 			</xsl:for-each>
 		</table>
diff --git a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-plugin2ref.xsl b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-plugin2ref.xsl
index 9be8f81..7d598cb 100644
--- a/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-plugin2ref.xsl
+++ b/archive/releng.builder/tools/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/combine-plugin2ref.xsl
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 	<xsl:template match="/">
 		<html>
@@ -23,7 +22,9 @@
 				</table>
 				<xsl:for-each select="root/team">
 					<xsl:sort select="@lead"/>
-					<xsl:apply-templates select="."/>
+					<xsl:apply-templates select=".">
+					    <xsl:sort select="@internal" order="descending"/>
+					</xsl:apply-templates>
 				</xsl:for-each>
 			</body>
 		</html>
@@ -38,7 +39,6 @@
 				<th>API usage count</th>
 			</tr>
 			<xsl:for-each select="plugin">
-				<xsl:sort select="@id"/>
 				<xsl:apply-templates select="."/>
 			</xsl:for-each>
 		</table>