Skip to content
Snippets Groups Projects
Commit a267c251 authored by jeffliu's avatar jeffliu
Browse files

All usage reports to be combined into one

parent f49d3070
No related branches found
No related tags found
No related merge requests found
...@@ -12,14 +12,21 @@ package org.eclipse.wtp.releng.tools.component.adopters; ...@@ -12,14 +12,21 @@ package org.eclipse.wtp.releng.tools.component.adopters;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
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;
import org.eclipse.wtp.releng.tools.component.model.ComponentXML;
import org.eclipse.wtp.releng.tools.component.model.Package;
import org.eclipse.wtp.releng.tools.component.model.Plugin;
import org.eclipse.wtp.releng.tools.component.model.Type;
import org.eclipse.wtp.releng.tools.component.util.CommandOptionParser; import org.eclipse.wtp.releng.tools.component.util.CommandOptionParser;
import org.eclipse.wtp.releng.tools.component.xsl.XSLUtil; import org.eclipse.wtp.releng.tools.component.xsl.XSLUtil;
...@@ -35,6 +42,7 @@ public class CombineClass2Reference ...@@ -35,6 +42,7 @@ public class CombineClass2Reference
ComponentLead unknown; ComponentLead unknown;
private Collection src; private Collection src;
private String output; private String output;
private Collection api;
private class ComponentLead private class ComponentLead
{ {
...@@ -102,8 +110,37 @@ public class CombineClass2Reference ...@@ -102,8 +110,37 @@ public class CombineClass2Reference
this.output = output; this.output = output;
} }
public Collection getApi()
{
return api;
}
public void setApi(Collection api)
{
this.api = api;
}
public void execute() public void execute()
{ {
// Collect component.xml files
Map pluginId2CompXML = new HashMap();
if (api != null)
{
for (Iterator i = api.iterator(); i.hasNext();)
{
ILocation apiLocation = Location.createLocation(new File((String)i.next()));
ComponentXMLVisitor compXMLVisitor = new ComponentXMLVisitor();
apiLocation.accept(compXMLVisitor);
for (Iterator it = compXMLVisitor.getCompXMLs().iterator(); it.hasNext();)
{
ComponentXML compXML = (ComponentXML)it.next();
for (Iterator it2 = compXML.getPlugins().iterator(); it2.hasNext();)
{
pluginId2CompXML.put(((Plugin)it2.next()).getId(), compXML);
}
}
}
}
for (Iterator it = src.iterator(); it.hasNext();) for (Iterator it = src.iterator(); it.hasNext();)
{ {
FileInputStream fis = null; FileInputStream fis = null;
...@@ -117,6 +154,7 @@ public class CombineClass2Reference ...@@ -117,6 +154,7 @@ public class CombineClass2Reference
int pluginRefTotal = 0; int pluginRefTotal = 0;
PluginRef pluginRef = (PluginRef)it2.next(); PluginRef pluginRef = (PluginRef)it2.next();
String pluginId = pluginRef.getId(); String pluginId = pluginRef.getId();
ComponentXML compXML = (ComponentXML)pluginId2CompXML.get(pluginId);
ComponentLead compLead = unknown; ComponentLead compLead = unknown;
for (Iterator it3 = plugin2complead.keySet().iterator(); it3.hasNext();) for (Iterator it3 = plugin2complead.keySet().iterator(); it3.hasNext();)
{ {
...@@ -131,6 +169,9 @@ public class CombineClass2Reference ...@@ -131,6 +169,9 @@ public class CombineClass2Reference
{ {
ClassRef classRef = (ClassRef)it3.next(); ClassRef classRef = (ClassRef)it3.next();
String name = classRef.getName(); String name = classRef.getName();
String pkgName = getPackageName(name);
if (isAPI(compXML, pkgName, name.substring(pkgName.length() + 1), classRef.getRefCount(), classRef.getSubclassCount(), classRef.getImplementCount(), classRef.getInstantiateCount()))
continue;
int refCount = classRef.getRefCount(); int refCount = classRef.getRefCount();
pluginRefTotal += refCount; pluginRefTotal += refCount;
Integer refTotal = (Integer)compLead.class2refCount.get(name); Integer refTotal = (Integer)compLead.class2refCount.get(name);
...@@ -140,7 +181,6 @@ public class CombineClass2Reference ...@@ -140,7 +181,6 @@ public class CombineClass2Reference
} }
refTotal = new Integer(refCount + refTotal.intValue()); refTotal = new Integer(refCount + refTotal.intValue());
compLead.class2refCount.put(name, refTotal); compLead.class2refCount.put(name, refTotal);
String pkgName = getPackageName(name);
Integer pkgRefTotal = (Integer)compLead.pkg2refCount.get(pkgName); Integer pkgRefTotal = (Integer)compLead.pkg2refCount.get(pkgName);
if (pkgRefTotal == null) if (pkgRefTotal == null)
{ {
...@@ -173,6 +213,34 @@ public class CombineClass2Reference ...@@ -173,6 +213,34 @@ public class CombineClass2Reference
genHTML(); genHTML();
} }
private boolean isAPI(ComponentXML compXML, String pkgName, String localName, int refCount, int subclassCount, int impleCount, int instantiateCount)
{
if (compXML == null)
return false;
Package pkg = compXML.getPackage(pkgName);
if (pkg == null)
return false;
else
{
Type type = pkg.getType(localName);
if (type == null)
return pkg.isApi();
else
{
if (refCount > 0 && !type.isReference())
return false;
else if (subclassCount > 0 && !type.isSubclass())
return false;
else if (impleCount > 0 && !type.isImplement())
return false;
else if (instantiateCount > 0 && !type.isInstantiate())
return false;
else
return true;
}
}
}
private String getPackageName(String className) private String getPackageName(String className)
{ {
int i = className.lastIndexOf('.'); int i = className.lastIndexOf('.');
...@@ -305,6 +373,7 @@ public class CombineClass2Reference ...@@ -305,6 +373,7 @@ public class CombineClass2Reference
Map options = optionParser.getOptions(); Map options = optionParser.getOptions();
Collection src = (Collection)options.get("src"); Collection src = (Collection)options.get("src");
Collection output = (Collection)options.get("output"); Collection output = (Collection)options.get("output");
Collection api = (Collection)options.get("api");
if (src == null || output == null || src.isEmpty() || output.isEmpty()) if (src == null || output == null || src.isEmpty() || output.isEmpty())
{ {
printUsage(); printUsage();
...@@ -314,6 +383,7 @@ public class CombineClass2Reference ...@@ -314,6 +383,7 @@ public class CombineClass2Reference
CombineClass2Reference class2Ref = new CombineClass2Reference(); CombineClass2Reference class2Ref = new CombineClass2Reference();
class2Ref.setSrc(src); class2Ref.setSrc(src);
class2Ref.setOutput((String)output.iterator().next()); class2Ref.setOutput((String)output.iterator().next());
class2Ref.setApi(api);
class2Ref.execute(); class2Ref.execute();
} }
...@@ -323,5 +393,6 @@ public class CombineClass2Reference ...@@ -323,5 +393,6 @@ public class CombineClass2Reference
System.out.println(""); System.out.println("");
System.out.println("\t-src\t\t<src>\t\tlocation of your usage reports"); 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"); System.out.println("\t-output\t<output>\t\tlocation of the output file");
System.out.println("\t-api\t\t<api>\t\tlocation of your component.xml");
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment