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

[115141] The API Scanner should be able to run from within the Eclipse workspace

parent dfa5d51e
No related branches found
No related tags found
No related merge requests found
Showing
with 1090 additions and 158 deletions
......@@ -24,5 +24,7 @@ Export-Package: org.eclipse.wtp.releng.tools.component,
org.eclipse.wtp.releng.tools.component.violation,
org.eclipse.wtp.releng.tools.component.xsl
Require-Bundle: org.eclipse.jdt.core,
org.eclipse.core.runtime
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.jface.text
Eclipse-AutoStart: true
......@@ -44,32 +44,45 @@ import org.eclipse.wtp.releng.tools.component.xsl.XSLUtil;
public class API2ComponentAPI implements IClassVisitor
{
private String api;
private String src;
private Collection api;
private Collection src;
private String outputDir;
private Collection includes;
private Collection excludes;
private boolean html;
private boolean readInterface = false;
private boolean readInterface = true;
private boolean skipAPIGen = false;
private Map interface2ImplClasses = new HashMap(0);
private Map super2SubClasses = new HashMap(0);
public String getApi()
public Collection getApi()
{
return api;
}
public void setApi(String api)
{
this.api = new ArrayList(1);
this.api.add(api);
}
public void setApi(Collection api)
{
this.api = api;
}
public String getSrc()
public Collection getSrc()
{
return src;
}
public void setSrc(String src)
{
this.src = new ArrayList(1);
this.src.add(src);
}
public void setSrc(Collection src)
{
this.src = src;
}
......@@ -136,32 +149,55 @@ public class API2ComponentAPI implements IClassVisitor
public List getImplClasses(String interfaceName)
{
List list = new ArrayList();
List implClasses = (List)interface2ImplClasses.get(interfaceName);
return implClasses != null ? new ArrayList(implClasses) : new ArrayList(0);
if (implClasses != null)
{
list.addAll(implClasses);
for (Iterator it = implClasses.iterator(); it.hasNext();)
getSubClasses((String)it.next(), list);
}
return list;
}
private void getSubClasses(String superClassName, List list)
{
List subClasses = (List)super2SubClasses.get(superClassName);
if (subClasses != null)
{
list.addAll(subClasses);
for (Iterator it = subClasses.iterator(); it.hasNext();)
getSubClasses((String)it.next(), list);
}
}
private Map pluginId2CompXML = new HashMap();
public void execute()
{
// Collection component.xml files
ILocation apiLocation = Location.createLocation(new File(api));
ComponentXMLVisitor compXMLVisitor = new ComponentXMLVisitor();
apiLocation.accept(compXMLVisitor);
for (Iterator it = compXMLVisitor.getCompXMLs().iterator(); it.hasNext();)
for (Iterator i = api.iterator(); i.hasNext();)
{
ComponentXML compXML = (ComponentXML)it.next();
for (Iterator it2 = compXML.getPlugins().iterator(); it2.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();)
{
pluginId2CompXML.put(((Plugin)it2.next()).getId(), compXML);
ComponentXML compXML = (ComponentXML)it.next();
for (Iterator it2 = compXML.getPlugins().iterator(); it2.hasNext();)
{
pluginId2CompXML.put(((Plugin)it2.next()).getId(), compXML);
}
}
}
// Generate api-info.xml files
ILocation srcLocation = Location.createLocation(new File(src));
LibVisitor libVisitor = new LibVisitor();
srcLocation.accept(libVisitor);
libVisitor.setClassVisitor(this);
srcLocation.accept(libVisitor);
for (Iterator it = src.iterator(); it.hasNext();)
{
ILocation srcLocation = Location.createLocation(new File((String)it.next()));
LibVisitor libVisitor = new LibVisitor();
srcLocation.accept(libVisitor);
libVisitor.setClassVisitor(this);
srcLocation.accept(libVisitor);
}
try
{
if (cachedCompAPI != null)
......@@ -199,13 +235,7 @@ public class API2ComponentAPI implements IClassVisitor
summary.append("</root>");
try
{
XSLUtil.transform
(
ClassLoader.getSystemResourceAsStream("org/eclipse/wtp/releng/tools/component/xsl/api-info-summary.xsl"),
new ByteArrayInputStream(summary.toString().getBytes()),
new FileOutputStream(new File(outputDir + "/api-info-summary.html")),
outputDir
);
XSLUtil.transform(ClassLoader.getSystemResourceAsStream("org/eclipse/wtp/releng/tools/component/xsl/api-info-summary.xsl"), new ByteArrayInputStream(summary.toString().getBytes()), new FileOutputStream(new File(outputDir + "/api-info-summary.html")), outputDir);
}
catch (Throwable e)
{
......@@ -215,54 +245,58 @@ public class API2ComponentAPI implements IClassVisitor
public boolean visit(String pluginId, ILocation classLoc)
{
String className = classLoc.getName();
className = className.substring(0, className.length() - ".class".length());
className = className.replace('/', '.');
className = className.replace('\\', '.');
if (include(className))
try
{
int i = className.lastIndexOf('.');
String packageName = (i != -1) ? className.substring(0, i) : "";
String localName = (i != -1) ? className.substring(i + 1) : className;
boolean isAPI;
ComponentXML compXML = (ComponentXML)pluginId2CompXML.get(pluginId);
if (compXML != null)
IClassFileReader reader = read(classLoc);
String className = new String(reader.getClassName()).replace('/', '.');
if (include(className))
{
Package pkg = compXML.getPackage(packageName);
if (pkg != null)
int i = className.lastIndexOf('.');
String packageName = (i != -1) ? className.substring(0, i) : "";
String localName = (i != -1) ? className.substring(i + 1) : className;
boolean isAPI;
ComponentXML compXML = (ComponentXML)pluginId2CompXML.get(pluginId);
if (compXML != null)
{
Type type = pkg.getType(localName);
if (type != null)
Package pkg = compXML.getPackage(packageName);
if (pkg != null)
{
if (!type.isReference() && !type.isSubclass() && !type.isImplement() && !type.isInstantiate())
Type type = pkg.getType(localName);
if (type != null)
{
isAPI = false;
if (!type.isReference() && !type.isSubclass() && !type.isImplement() && !type.isInstantiate())
{
isAPI = false;
}
else
{
isAPI = true;
}
}
else
{
isAPI = true;
isAPI = pkg.isApi();
}
}
else
{
isAPI = pkg.isApi();
isAPI = false;
}
}
else
{
isAPI = false;
}
}
else
{
isAPI = false;
}
IClassFileReader reader = null;
if (readInterface)
{
try
if (readInterface)
{
reader = read(classLoc);
String superClassName = new String(reader.getSuperclassName()).replace('/', '.');
List subClasses = (List)super2SubClasses.get(superClassName);
if (subClasses == null)
{
subClasses = new ArrayList(1);
super2SubClasses.put(superClassName, subClasses);
}
subClasses.add(className);
if (!reader.isInterface())
{
char[][] names = reader.getInterfaceNames();
......@@ -279,78 +313,78 @@ public class API2ComponentAPI implements IClassVisitor
}
}
}
catch (IOException ioe)
if (!isSkipAPIGen() && isAPI)
{
ioe.printStackTrace();
}
catch (ClassFormatException cfe)
{
cfe.printStackTrace();
}
}
if (!isSkipAPIGen() && isAPI)
{
try
{
ComponentAPI compAPI = getComponentAPI(pluginId);
PackageAPI pkgAPI = (PackageAPI)compAPI.getPackageAPI(packageName);
if (pkgAPI == null)
try
{
pkgAPI = new PackageAPI();
pkgAPI.setName(packageName);
compAPI.addPackageAPI(pkgAPI);
}
ClassAPI classAPI = pkgAPI.getClassAPI(localName);
if (classAPI == null)
{
if (reader == null)
reader = read(classLoc);
classAPI = new ClassAPI();
classAPI.setName(localName);
classAPI.setAccess(reader.getAccessFlags());
classAPI.setSuperClass(new String(reader.getSuperclassName()).replace('/', '.'));
pkgAPI.addClassAPI(classAPI);
IMethodInfo[] methods = reader.getMethodInfos();
for (int j = 0; j < methods.length; j++)
ComponentAPI compAPI = getComponentAPI(pluginId);
PackageAPI pkgAPI = (PackageAPI)compAPI.getPackageAPI(packageName);
if (pkgAPI == null)
{
pkgAPI = new PackageAPI();
pkgAPI.setName(packageName);
compAPI.addPackageAPI(pkgAPI);
}
ClassAPI classAPI = pkgAPI.getClassAPI(localName);
if (classAPI == null)
{
MethodAPI methodAPI = new MethodAPI();
methodAPI.setName(new String(methods[j].getName()));
methodAPI.setAccess(methods[j].getAccessFlags());
methodAPI.setDescriptor(new String(methods[j].getDescriptor()));
IExceptionAttribute exceptionAttr = methods[j].getExceptionAttribute();
if (exceptionAttr != null)
if (reader == null)
reader = read(classLoc);
classAPI = new ClassAPI();
classAPI.setName(localName);
classAPI.setAccess(reader.getAccessFlags());
classAPI.setSuperClass(new String(reader.getSuperclassName()).replace('/', '.'));
pkgAPI.addClassAPI(classAPI);
IMethodInfo[] methods = reader.getMethodInfos();
for (int j = 0; j < methods.length; j++)
{
char[][] exceptionNames = exceptionAttr.getExceptionNames();
List exceptions = new ArrayList(exceptionNames.length);
for (int k = 0; k < exceptionNames.length; k++)
MethodAPI methodAPI = new MethodAPI();
methodAPI.setName(new String(methods[j].getName()));
methodAPI.setAccess(methods[j].getAccessFlags());
methodAPI.setDescriptor(new String(methods[j].getDescriptor()));
IExceptionAttribute exceptionAttr = methods[j].getExceptionAttribute();
if (exceptionAttr != null)
{
exceptions.add(new String(exceptionNames[k]).replace('/', '.'));
char[][] exceptionNames = exceptionAttr.getExceptionNames();
List exceptions = new ArrayList(exceptionNames.length);
for (int k = 0; k < exceptionNames.length; k++)
{
exceptions.add(new String(exceptionNames[k]).replace('/', '.'));
}
methodAPI.addThrows(exceptions);
}
methodAPI.addThrows(exceptions);
classAPI.addMethodAPI(methodAPI);
}
IFieldInfo[] fields = reader.getFieldInfos();
for (int j = 0; j < fields.length; j++)
{
FieldAPI fieldAPI = new FieldAPI();
fieldAPI.setName(new String(fields[j].getName()));
fieldAPI.setAccess(fields[j].getAccessFlags());
fieldAPI.setDescriptor(new String(fields[j].getDescriptor()));
classAPI.addFieldAPI(fieldAPI);
}
classAPI.addMethodAPI(methodAPI);
}
IFieldInfo[] fields = reader.getFieldInfos();
for (int j = 0; j < fields.length; j++)
{
FieldAPI fieldAPI = new FieldAPI();
fieldAPI.setName(new String(fields[j].getName()));
fieldAPI.setAccess(fields[j].getAccessFlags());
fieldAPI.setDescriptor(new String(fields[j].getDescriptor()));
classAPI.addFieldAPI(fieldAPI);
}
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
catch (ClassFormatException e)
{
throw new RuntimeException(e);
catch (IOException e)
{
throw new RuntimeException(e);
}
catch (ClassFormatException e)
{
throw new RuntimeException(e);
}
}
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (ClassFormatException cfe)
{
cfe.printStackTrace();
}
return true;
}
......@@ -470,8 +504,8 @@ public class API2ComponentAPI implements IClassVisitor
System.exit(-1);
}
API2ComponentAPI api2CompAPI = new API2ComponentAPI();
api2CompAPI.setApi((String)api.iterator().next());
api2CompAPI.setSrc((String)src.iterator().next());
api2CompAPI.setApi(api);
api2CompAPI.setSrc(src);
api2CompAPI.setOutputDir((String)outputDir.iterator().next());
api2CompAPI.setIncludes(includes);
api2CompAPI.setExcludes(excludes);
......
......@@ -54,6 +54,7 @@ public class ComponentAPI extends ComponentObject
private static final String ELEMENT_THROW = "throw";
private static final String ATTR_ACCESS = "access";
private static final String ATTR_NAME = "name";
private static final String ATTR_SUPER = "super";
private static final String ATTR_TIMESTAMP = "timestamp";
private static final String ATTR_DESCRIPTOR = "descriptor";
private static final String ATTR_REFERENCE = "reference";
......@@ -282,6 +283,9 @@ public class ComponentAPI extends ComponentObject
{
classAPI = new ClassAPI();
classAPI.setName(attributes.getValue(ATTR_NAME));
String attrSuper = attributes.getValue(ATTR_SUPER);
if (attrSuper != null)
classAPI.setSuperClass(attrSuper);
String attrAccess = attributes.getValue(ATTR_ACCESS);
if (attrAccess != null)
classAPI.setAccess(Integer.parseInt(attrAccess));
......
......@@ -331,15 +331,15 @@ public class APICompatibilityScanner
String currOutputDir = od + "1/";
String refOutputDir = od + "2/";
API2ComponentAPI api2CompAPI = new API2ComponentAPI();
api2CompAPI.setApi((String)api.iterator().next());
api2CompAPI.setSrc((String)src.iterator().next());
api2CompAPI.setApi(api);
api2CompAPI.setSrc(src);
api2CompAPI.setOutputDir(currOutputDir);
api2CompAPI.setIncludes(includes);
api2CompAPI.setExcludes(excludes);
api2CompAPI.execute();
api2CompAPI = new API2ComponentAPI();
api2CompAPI.setApi((String)refapi.iterator().next());
api2CompAPI.setSrc((String)refsrc.iterator().next());
api2CompAPI.setApi(refapi);
api2CompAPI.setSrc(refsrc);
api2CompAPI.setOutputDir(refOutputDir);
api2CompAPI.setIncludes(includes);
api2CompAPI.setExcludes(excludes);
......
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.wtp.releng.tools.component.api.violation;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.util.IModifierConstants;
import org.eclipse.wtp.releng.tools.component.ILocation;
import org.eclipse.wtp.releng.tools.component.ILocationVisitor;
import org.eclipse.wtp.releng.tools.component.api.API2ComponentAPI;
import org.eclipse.wtp.releng.tools.component.api.ClassAPI;
import org.eclipse.wtp.releng.tools.component.api.ComponentAPI;
import org.eclipse.wtp.releng.tools.component.api.ComponentXMLVisitor;
import org.eclipse.wtp.releng.tools.component.api.FieldAPI;
import org.eclipse.wtp.releng.tools.component.api.MethodAPI;
import org.eclipse.wtp.releng.tools.component.api.PackageAPI;
import org.eclipse.wtp.releng.tools.component.images.ImagesUtil;
import org.eclipse.wtp.releng.tools.component.internal.ComponentEntry;
import org.eclipse.wtp.releng.tools.component.internal.ComponentSummary;
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.xsl.XSLUtil;
public class NonAPIDependencyScanner implements ILocationVisitor
{
private Collection src;
private Collection api;
private String outputDir;
private Collection includes;
private Collection excludes;
private Collection refapi;
private boolean skipAPIGen;
public Collection getApi()
{
return api;
}
public void setApi(Collection api)
{
this.api = api;
}
public String getOutputDir()
{
return outputDir;
}
public void setOutputDir(String outputDir)
{
this.outputDir = addTrailingSeperator(outputDir);
}
public Collection getIncludes()
{
return includes;
}
public void setIncludes(Collection includes)
{
this.includes = includes;
}
public Collection getExcludes()
{
return excludes;
}
public void setExcludes(Collection excludes)
{
this.excludes = excludes;
}
public Collection getRefapi()
{
return refapi;
}
public void setRefapi(Collection refapi)
{
this.refapi = refapi;
}
public Collection getSrc()
{
return src;
}
public void setSrc(Collection src)
{
this.src = src;
}
public boolean isSkipAPIGen()
{
return skipAPIGen;
}
public void setSkipAPIGen(boolean skipAPIGen)
{
this.skipAPIGen = skipAPIGen;
}
private API2ComponentAPI api2CompXML;
private ComponentSummary summary;
public void execute()
{
// Collect component.xml files
cacheCompXML(api);
cacheCompXML(refapi);
// Generate api-info.xml
api2CompXML = new API2ComponentAPI();
api2CompXML.setApi(api);
api2CompXML.setSrc(src);
api2CompXML.setOutputDir(outputDir);
api2CompXML.setReadInterface(true);
api2CompXML.setSkipAPIGen(skipAPIGen);
api2CompXML.execute();
// Generate non-API dependency report
summary = new ComponentSummary();
ILocation out = Location.createLocation(new File(outputDir));
out.accept(this);
// Generate HTML report
try
{
ImagesUtil.copyAll(outputDir);
XSLUtil.transform
(
ClassLoader.getSystemResourceAsStream("org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl"),
new ByteArrayInputStream(summary.toString().getBytes()),
new FileOutputStream(new File(outputDir + "component-api-violation-all.html")),
outputDir
);
}
catch (Throwable e)
{
try
{
XSLUtil.transform
(
Platform.getBundle("org.eclipse.wtp.releng.tools.component.core").getResource("org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl").openStream(),
new ByteArrayInputStream(summary.toString().getBytes()),
new FileOutputStream(new File(outputDir + "component-api-violation-all.html")),
outputDir
);
}
catch (Throwable e2)
{
e2.printStackTrace();
}
}
}
private Map pluginId2CompXML = new HashMap();
private void cacheCompXML(Collection locations)
{
for (Iterator i = locations.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);
}
}
}
}
public boolean accept(ILocation location)
{
if (location.getName().equals("api-info.xml"))
{
try
{
ComponentAPI compAPI = new ComponentAPI();
compAPI.setLocation(location);
compAPI.load();
ComponentAPIViolation violation = getViolations(compAPI);
String compName = compAPI.getName();
StringBuffer sb = new StringBuffer(outputDir);
sb.append(compName);
sb.append("/component-api-violation.xml");
File file = new File(sb.toString());
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
String content = violation.toString();
fos.write(content.getBytes());
fos.close();
ComponentEntry entry = new ComponentEntry();
entry.setCompName(compName);
entry.setRef(sb.toString());
summary.add(entry);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
return true;
}
private ComponentAPIViolation getViolations(ComponentAPI compAPI)
{
ComponentAPIViolation v = new ComponentAPIViolation();
v.setName(compAPI.getName());
for (Iterator it = compAPI.getPackageAPIs().iterator(); it.hasNext();)
v.addAllViolations(genAPIViolation((PackageAPI)it.next()));
return v;
}
private List genAPIViolation(PackageAPI pkgAPI)
{
List classViolations = new ArrayList();
for (Iterator it = pkgAPI.getClassAPIs().iterator(); it.hasNext();)
{
ClassViolation classViolation = getViolations((ClassAPI)it.next());
if (classViolation != null)
classViolations.add(classViolation);
}
return classViolations;
}
private ClassViolation getViolations(ClassAPI classAPI)
{
ClassViolation classViolation = new ClassViolation();
classViolation.setName(classAPI.getName());
boolean isSuperClassAPI;
String superClassName = classAPI.getSuperClass();
if (isInterface(classAPI.getAccess()))
isSuperClassAPI = isAPI(superClassName, false, false, true, false);
else
isSuperClassAPI = isAPI(superClassName, false, true, false, false);
if (!isSuperClassAPI)
{
SuperViolation superViolation = new SuperViolation();
superViolation.setName(superClassName);
classViolation.addViolation(superViolation);
}
for (Iterator it = classAPI.getMethodAPIs().iterator(); it.hasNext();)
{
MethodAPI methodAPI = (MethodAPI)it.next();
MethodViolation methodViolation = new MethodViolation();
methodViolation.setName(methodAPI.getName());
String desc = methodAPI.getDescriptor();
String returnTypeDesc = Signature.getReturnType(desc);
String returnType = toFullyQualifiedName(returnTypeDesc);
if (Signature.getTypeSignatureKind(returnTypeDesc) != Signature.BASE_TYPE_SIGNATURE && !isAPI(returnType, true, false, false, false))
{
ReturnViolation returnViolation = new ReturnViolation();
returnViolation.setName(returnType);
methodViolation.addViolation(returnViolation);
}
String[] params = Signature.getParameterTypes(desc);
for (int j = 0; j < params.length; j++)
{
String param = toFullyQualifiedName(params[j]);
if (Signature.getTypeSignatureKind(params[j]) != Signature.BASE_TYPE_SIGNATURE && !isAPI(param, true, false, false, false))
{
ParamViolation paramViolation = new ParamViolation();
paramViolation.setName(param);
methodViolation.addViolation(paramViolation);
}
}
String[] throwTypes = Signature.getThrownExceptionTypes(desc);
for (int j = 0; j < throwTypes.length; j++)
{
String throwType = toFullyQualifiedName(throwTypes[j]);
if (Signature.getTypeSignatureKind(throwTypes[j]) != Signature.BASE_TYPE_SIGNATURE && !isAPI(throwType, true, false, false, false))
{
ThrowViolation throwViolation = new ThrowViolation();
throwViolation.setName(throwType);
methodViolation.addViolation(throwViolation);
}
}
if (methodViolation.countViolations() > 0)
classViolation.addViolation(methodViolation);
}
for (Iterator it = classAPI.getFieldAPIs().iterator(); it.hasNext();)
{
FieldAPI fieldAPI = (FieldAPI)it.next();
String desc = new String(fieldAPI.getDescriptor());
String field = toFullyQualifiedName(desc);
if (Signature.getTypeSignatureKind(desc) != Signature.BASE_TYPE_SIGNATURE && !isAPI(field, true, false, false, false))
{
FieldViolation fieldViolation = new FieldViolation();
fieldViolation.setName(fieldAPI.getName());
fieldViolation.setType(field);
classViolation.addViolation(fieldViolation);
}
}
if (classViolation.countViolations() > 0)
return classViolation;
else
return null;
}
private String toFullyQualifiedName(String descriptor)
{
StringBuffer sb = new StringBuffer();
descriptor = descriptor.replace('/', '.');
sb.append(Signature.getSignatureQualifier(descriptor));
sb.append('.');
sb.append(Signature.getSignatureSimpleName(descriptor).replace('.', '$'));
return sb.toString();
}
private boolean isInterface(int access)
{
return ((access & IModifierConstants.ACC_INTERFACE) == IModifierConstants.ACC_INTERFACE);
}
protected boolean include(String name)
{
name = name.replace('/', '.');
name = name.replace('\\', '.');
if (excludes != null && !excludes.isEmpty())
for (Iterator it = excludes.iterator(); it.hasNext();)
if (name.matches((String)it.next()))
return false;
if (includes != null && !includes.isEmpty())
{
for (Iterator it = includes.iterator(); it.hasNext();)
if (name.matches((String)it.next()))
return true;
return false;
}
return true;
}
private boolean isAPI(String className, boolean ref, boolean subclass, boolean implement, boolean instantiate)
{
if (include(className))
{
String pkgName = null;
String typeName = null;
int dot = className.lastIndexOf('.');
if (dot != -1)
{
pkgName = className.substring(0, dot);
typeName = className.substring(dot + 1);
}
if (pkgName != null && typeName != null)
{
for (Iterator it = pluginId2CompXML.values().iterator(); it.hasNext();)
{
ComponentXML compXML = (ComponentXML)it.next();
for (Iterator pkgIt = compXML.getPackages().iterator(); pkgIt.hasNext();)
{
Package pkg = (Package)pkgIt.next();
if (pkgName.equals(pkg.getName()))
{
// if not overwritten, inner class inherits usages from base class
int index = typeName.indexOf('$');
String baseTypeName = (index != -1) ? typeName.substring(0, index) : null;
Type baseType = null;
for (Iterator typeIt = pkg.getTypes().iterator(); typeIt.hasNext();)
{
Type type = (Type)typeIt.next();
String name = type.getName();
if (typeName.equals(name))
{
if (ref && !type.isReference())
return false;
if (subclass && !type.isSubclass())
return false;
if (implement && !type.isImplement())
return false;
if (instantiate && !type.isInstantiate())
return false;
return true;
}
if (baseTypeName != null && baseType == null && baseTypeName.equals(name))
{
baseType = type;
}
}
if (baseType != null)
{
if (ref && !baseType.isReference())
return false;
if (subclass && !baseType.isSubclass())
return false;
if (implement && !baseType.isImplement())
return false;
if (instantiate && !baseType.isInstantiate())
return false;
return true;
}
return pkg.isApi();
}
}
}
}
return false;
}
else
{
return true;
}
}
protected String addTrailingSeperator(String s)
{
if (s != null && !s.endsWith("/") && !s.endsWith("\\"))
{
StringBuffer sb = new StringBuffer(s);
sb.append('/');
return sb.toString();
}
else
{
return s;
}
}
public static void main(String[] args)
{
CommandOptionParser optionParser = new CommandOptionParser(args);
Map options = optionParser.getOptions();
Collection src = (Collection)options.get("src");
Collection api = (Collection)options.get("api");
Collection outputDir = (Collection)options.get("outputDir");
Collection includes = (Collection)options.get("includes");
Collection excludes = (Collection)options.get("excludes");
Collection refapi = (Collection)options.get("refapi");
Collection skipAPIGen = (Collection)options.get("skipAPIGen");
if (src == null || api == null || outputDir == null || src.size() < 1 || api.size() < 1 || outputDir.size() < 1)
{
printUsage();
System.exit(-1);
}
NonAPIDependencyScanner scanner = new NonAPIDependencyScanner();
scanner.setSrc(src);
scanner.setApi(api);
scanner.setOutputDir((String)outputDir.iterator().next());
scanner.setIncludes(includes);
scanner.setExcludes(excludes);
scanner.setRefapi(refapi);
scanner.setSkipAPIGen(skipAPIGen != null);
scanner.execute();
}
private static void printUsage()
{
System.out.println("Usage: java org.eclipse.wtp.releng.tools.component.api.violation.NonAPIDependencyScanner -src <src> -api <api> -outputDir <outputDir> [-options]");
System.out.println("");
System.out.println("\t-src\t\t<src>\t\tlocation of a Eclipse-based product (requires SDK build)");
System.out.println("\t-api\t\t<api>\t\tlocation of your component.xml");
System.out.println("\t-outputDir\t<outputDir>\toutput directory of component.xml files");
System.out.println("");
System.out.println("where options include:");
System.out.println("");
System.out.println("\t-includes\t<includes>\tspace seperated packages to include");
System.out.println("\t-excludes\t<excludes>\tspace seperated packages to exclude");
System.out.println("\t-refapi\t<refapi>\tlocation of component.xml being referenced");
System.out.println("\t-skipAPIGen\t\t\tskip api-info.xml generation and use existing ones");
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import org.eclipse.jdt.core.util.ICodeAttribute;
import org.eclipse.jdt.core.util.IConstantPool;
import org.eclipse.jdt.core.util.IConstantPoolConstant;
import org.eclipse.jdt.core.util.IConstantPoolEntry;
import org.eclipse.jdt.core.util.IFieldInfo;
import org.eclipse.jdt.core.util.ILineNumberAttribute;
import org.eclipse.jdt.core.util.IMethodInfo;
import org.eclipse.jdt.internal.core.util.ClassFileReader;
......@@ -174,6 +175,8 @@ public class Class2Reference implements IClassVisitor
setClassUse(source, refClassName, Boolean.TRUE, null, null, null, null);
}
}
// method info & field info
setMethodAndFieldInfoUses(reader, source);
// method ref & field ref
if (!isClassRefOnly())
{
......@@ -228,13 +231,10 @@ public class Class2Reference implements IClassVisitor
}
fieldRefs = null;
// use: subclass
if (reader.isInterface())
String superClass = new String(reader.getSuperclassName()).replace('/', '.');
if (superClass != null && include(superClass))
{
String superClass = new String(reader.getSuperclassName()).replace('/', '.');
if (superClass != null && include(superClass))
{
setClassUse(source, superClass, null, Boolean.TRUE, null, null, null);
}
setClassUse(source, superClass, null, Boolean.TRUE, null, null, null);
}
// use: implement
char[][] interfaceNames = reader.getInterfaceNames();
......@@ -381,6 +381,60 @@ public class Class2Reference implements IClassVisitor
}
}
private void setMethodAndFieldInfoUses(IClassFileReader reader, Source source)
{
String className = new String(reader.getClassName()).replace('/', '.');
IMethodInfo[] methodInfos = reader.getMethodInfos();
for (int i = 0; i < methodInfos.length; i++)
{
String desc = new String(methodInfos[i].getDescriptor());
String returnTypeDesc = Signature.getReturnType(desc);
String returnType = toFullyQualifiedName(returnTypeDesc);
if (Signature.getTypeSignatureKind(returnTypeDesc) != Signature.BASE_TYPE_SIGNATURE && !className.equals(returnType) && include(returnType))
{
setClassUse(source, returnType, Boolean.TRUE, null, null, null, null);
}
String[] params = Signature.getParameterTypes(desc);
for (int j = 0; j < params.length; j++)
{
String param = toFullyQualifiedName(params[j]);
if (Signature.getTypeSignatureKind(params[j]) != Signature.BASE_TYPE_SIGNATURE && !className.equals(param) && include(param))
{
setClassUse(source, param, Boolean.TRUE, null, null, null, null);
}
}
String[] throwTypes = Signature.getThrownExceptionTypes(desc);
for (int j = 0; j < throwTypes.length; j++)
{
String throwType = toFullyQualifiedName(throwTypes[j]);
if (Signature.getTypeSignatureKind(throwTypes[j]) != Signature.BASE_TYPE_SIGNATURE && !className.equals(throwType) && include(throwType))
{
setClassUse(source, throwType, Boolean.TRUE, null, null, null, null);
}
}
}
IFieldInfo[] fieldInfos = reader.getFieldInfos();
for (int i = 0; i < fieldInfos.length; i++)
{
String desc = new String(fieldInfos[i].getDescriptor());
String field = toFullyQualifiedName(desc);
if (Signature.getTypeSignatureKind(desc) != Signature.BASE_TYPE_SIGNATURE && !className.equals(field) && include(field))
{
setClassUse(source, field, Boolean.TRUE, null, null, null, null);
}
}
}
private String toFullyQualifiedName(String descriptor)
{
StringBuffer sb = new StringBuffer();
descriptor = descriptor.replace('/', '.');
sb.append(Signature.getSignatureQualifier(descriptor));
sb.append('.');
sb.append(Signature.getSignatureSimpleName(descriptor).replace('.', '$'));
return sb.toString();
}
private IConstantPoolEntry[] getConstantPoolEntries(IClassFileReader reader, int kind)
{
List entries = new Vector();
......
......@@ -64,7 +64,7 @@ public class LibVisitor implements ILocationVisitor
}
else if (Location.isArchive(locationName))
{
acceptSingleJar(location);
return acceptSingleJar(location);
}
else if (locationName.endsWith(".classpath"))
{
......@@ -137,6 +137,8 @@ public class LibVisitor implements ILocationVisitor
if (path != null && path.length() > 0)
{
StringBuffer sb = new StringBuffer();
if (locationName.equalsIgnoreCase("plugin.xml"))
locationName = location.getAbsolutePath();
sb.append(locationName.substring(0, locationName.length() - "plugin.xml".length() - 1));
sb.append("/");
sb.append(path);
......@@ -178,6 +180,8 @@ public class LibVisitor implements ILocationVisitor
if (path != null && path.length() > 0)
{
StringBuffer sb = new StringBuffer();
if (locationName.equalsIgnoreCase("fragment.xml"))
locationName = location.getAbsolutePath();
sb.append(locationName.substring(0, locationName.length() - "fragment.xml".length() - 1));
sb.append("/");
sb.append(path);
......@@ -214,6 +218,8 @@ public class LibVisitor implements ILocationVisitor
if (path != null && path.length() > 0)
{
StringBuffer sb = new StringBuffer();
if (locationName.equalsIgnoreCase("MANIFEST.MF"))
locationName = location.getAbsolutePath();
sb.append(locationName.substring(0, locationName.length() - "META-INF/MANIFEST.MF".length() - 1));
sb.append("/");
sb.append(path);
......@@ -228,13 +234,13 @@ public class LibVisitor implements ILocationVisitor
}
}
private void acceptSingleJar(ILocation location)
private boolean acceptSingleJar(ILocation location)
{
ILocationChildrenIterator it = location.childIterator();
for (ILocation child = it.next(); child != null; child = it.next())
{
String name = child.getName();
if (name.endsWith("MANIFEST.MF"))
if (name.equalsIgnoreCase("META-INF/MANIFEST.MF"))
{
try
{
......@@ -245,7 +251,7 @@ public class LibVisitor implements ILocationVisitor
{
bundleName = (new StringTokenizer(bundleName, ";")).nextToken().trim();
lib2pluginId.put(location.getName().replace('\\', '/'), bundleName);
return;
return false;
}
}
catch (IOException e)
......@@ -266,7 +272,7 @@ public class LibVisitor implements ILocationVisitor
if (id != null && id.length() > 0)
{
lib2pluginId.put(location.getName().replace('\\', '/'), id);
return;
return false;
}
}
}
......@@ -288,7 +294,7 @@ public class LibVisitor implements ILocationVisitor
if (id != null && id.length() > 0)
{
lib2pluginId.put(location.getName().replace('\\', '/'), id);
return;
return false;
}
}
}
......@@ -297,6 +303,7 @@ public class LibVisitor implements ILocationVisitor
}
}
}
return true;
}
private void acceptDotClasspath(ILocation location)
......
......@@ -134,9 +134,9 @@ public class JavadocVisitor extends ASTVisitor
descriptor.append(Signature.C_PARAM_END);
// return type
boolean hasReturn = false;
boolean hasReturn = node.isConstructor();
org.eclipse.jdt.core.dom.Type returnType = node.getReturnType2();
if (returnType instanceof PrimitiveType)
if (!hasReturn && returnType instanceof PrimitiveType)
if (((PrimitiveType)returnType).getPrimitiveTypeCode() == PrimitiveType.VOID)
hasReturn = true;
descriptor.append(getDescriptor(returnType));
......
......@@ -44,7 +44,7 @@ import org.xml.sax.helpers.DefaultHandler;
public class CodeCoverageScanner implements ILocationVisitor
{
private String api;
private String src;
private Collection src;
private String trcxml;
private String outputDir;
private boolean skipAPIGen;
......@@ -73,12 +73,12 @@ public class CodeCoverageScanner implements ILocationVisitor
this.api = api;
}
public String getSrc()
public Collection getSrc()
{
return src;
}
public void setSrc(String src)
public void setSrc(Collection src)
{
this.src = src;
}
......@@ -440,10 +440,8 @@ public class CodeCoverageScanner implements ILocationVisitor
System.exit(-1);
}
CodeCoverageScanner scanner = new CodeCoverageScanner();
if (api != null)
scanner.setApi((String)api.iterator().next());
if (src != null)
scanner.setSrc((String)src.iterator().next());
scanner.setApi((String)api.iterator().next());
scanner.setSrc(src);
scanner.setTRCXML((String)trcxml.iterator().next());
scanner.setOutputDir((String)outputDir.iterator().next());
scanner.setSkipAPIGen(skipAPIGen != null);
......
......@@ -108,7 +108,7 @@
<xsl:value-of select="@name"/>
<p>
<div id="source::{@name}">
<xsl:if test="class-use/@subclass">
<xsl:if test="class-use/@subclass = 'true'">
<p>
<img src="../space.gif"/>
<b>Cannot subclass:</b><br/>
......@@ -123,7 +123,7 @@
</p>
</xsl:if>
<xsl:if test="class-use/@implement">
<xsl:if test="class-use/@implement = 'true'">
<p>
<img src="../space.gif"/>
<b>Cannot implement:</b><br/>
......@@ -138,7 +138,7 @@
</p>
</xsl:if>
<xsl:if test="class-use/@instantiate">
<xsl:if test="class-use/@instantiate = 'true'">
<p>
<img src="../space.gif"/>
<b>Cannot instantiate:</b><br/>
......@@ -159,7 +159,7 @@
</p>
</xsl:if>
<xsl:if test="class-use/@reference">
<xsl:if test="class-use/@reference = 'true'">
<p>
<img src="../space.gif"/>
<b>Cannot reference:</b><br/>
......@@ -168,28 +168,28 @@
<xsl:if test="@reference">
<img src="../space.gif"/>
<img src="../space.gif"/>
<xsl:value-of select="@name"/><br/>
<xsl:value-of select="@name"/>
<xsl:for-each select="method-use">
<xsl:if test="@name!='&lt;init&gt;'">
<i>
<br/><i>
<img src="../space.gif"/>
<img src="../space.gif"/>
<img src="../space.gif"/>
<xsl:value-of select="@name"/>(...)
<img src="../space.gif"/>
<xsl:value-of select="@lines"/><br/>
<xsl:value-of select="@lines"/>
</i>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="field-use">
<xsl:sort select="@name"/>
<i>
<br/><i>
<img src="../space.gif"/>
<img src="../space.gif"/>
<img src="../space.gif"/>
<xsl:value-of select="@name"/>
<img src="../space.gif"/>
<xsl:value-of select="@lines"/><br/>
<xsl:value-of select="@lines"/>
</i>
</xsl:for-each>
<br/>
......
LABEL_POPUP_MENU_API=API
LABEL_POPUP_ACTION_API_VIOLATION=Scan for API Violation
LABEL_POPUP_ACTION_SCAN_4_MISSING_JAVADOC=Scan for Missing javadoc
LABEL_POPUP_ACTION_SCAN_4_NON_API_DEPS=Scan for Non-API dependencies
EDITOR_COMPONENT_XML=Component.xml Editor
\ No newline at end of file
......@@ -34,6 +34,11 @@
class="org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4MissingJavadoc"
menubarPath="org.eclipse.wtp.releng.tools.component.ui.popupMenu/popupActions"
id="org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4MissingJavadoc"/>
<action
label="%LABEL_POPUP_ACTION_SCAN_4_NON_API_DEPS"
class="org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4NonAPIDependency"
menubarPath="org.eclipse.wtp.releng.tools.component.ui.popupMenu/popupActions"
id="org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4NonAPIDependency"/>
</objectContribution>
</extension>
......
......@@ -114,12 +114,12 @@ public class Scan4APIViolation extends Action implements IActionDelegate
srcs.add(workspace.append(project.getFullPath()).toFile().toURL().toString().substring(6));
}
String violationOutputDir = outputDir.append("_output_").toString();
delete(new File(violationOutputDir));
StringBuffer sb = new StringBuffer();
sb.append(violationOutputDir);
sb.append('/');
sb.append(selectedCompXML.getName());
reportDir = sb.toString();
(new File(reportDir + "/api-violation.xml")).delete();
String[] args = new String[srcs.size() + 13];
int i = 0;
args[i++] = "-src";
......@@ -169,4 +169,22 @@ public class Scan4APIViolation extends Action implements IActionDelegate
public void selectionChanged(IAction action, ISelection selection)
{
}
private boolean delete(File file)
{
String name = file.getName();
if (name.endsWith(".gif") || name.endsWith(".jpg") || name.endsWith(".html"))
return true;
else if (file.isDirectory())
{
boolean b = true;
File[] children = file.listFiles();
for (int i = 0; i < children.length; i++)
if (!delete(children[i]))
b = false;
return b;
}
else
return file.delete();
}
}
\ No newline at end of file
......@@ -44,6 +44,7 @@ public class Scan4MissingJavadoc extends Action implements IActionDelegate
public void run()
{
String outputDir = Platform.getPluginStateLocation(ComponentUIPlugin.getDefault()).append("_output_").toString();
delete(new File(outputDir));
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
......@@ -70,12 +71,6 @@ public class Scan4MissingJavadoc extends Action implements IActionDelegate
IProject project = workspaceRoot.getProject(plugin.getId());
if (project.exists())
{
StringBuffer sb = new StringBuffer();
sb.append(outputDir);
sb.append('/');
sb.append(project.getName());
sb.append("/api-info.xml");
new File(sb.toString()).delete();
srcs.add(workspace.append(project.getFullPath()).toFile().toURL().toString().substring(6));
}
}
......@@ -121,4 +116,22 @@ public class Scan4MissingJavadoc extends Action implements IActionDelegate
public void selectionChanged(IAction action, ISelection selection)
{
}
private boolean delete(File file)
{
String name = file.getName();
if (name.endsWith(".gif") || name.endsWith(".jpg") || name.endsWith(".html"))
return true;
else if (file.isDirectory())
{
boolean b = true;
File[] children = file.listFiles();
for (int i = 0; i < children.length; i++)
if (!delete(children[i]))
b = false;
return b;
}
else
return file.delete();
}
}
\ No newline at end of file
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.wtp.releng.tools.component.ui.internal.action;
import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.wtp.releng.tools.component.ILocation;
import org.eclipse.wtp.releng.tools.component.api.ComponentXMLVisitor;
import org.eclipse.wtp.releng.tools.component.api.violation.NonAPIDependencyScanner;
import org.eclipse.wtp.releng.tools.component.internal.Location;
import org.eclipse.wtp.releng.tools.component.java.Java2API;
import org.eclipse.wtp.releng.tools.component.model.ComponentXML;
import org.eclipse.wtp.releng.tools.component.model.Plugin;
import org.eclipse.wtp.releng.tools.component.ui.internal.ComponentUIPlugin;
import org.eclipse.wtp.releng.tools.component.ui.internal.WorkspaceFileLocation;
import org.osgi.service.prefs.Preferences;
public class Scan4NonAPIDependency extends Action implements IActionDelegate
{
public void run()
{
// Get src
IPreferencesService prefService = Platform.getPreferencesService();
IEclipsePreferences eclipsePref = prefService.getRootNode();
Preferences pdePref = eclipsePref.node("/instance/org.eclipse.pde.core");
String platformPath = pdePref.get("platform_path", null);
String src = platformPath != null ? platformPath : Platform.getInstallLocation().toString();
// Get outputDir
IPath outputDir = Platform.getPluginStateLocation(ComponentUIPlugin.getDefault());
String compXMLOutputDir = outputDir.addTrailingSeparator().append(src.replace(':', '_').replace('/', '_').replace('\\', '_')).toString();
if (!(new File(compXMLOutputDir).exists()))
{
// Get existing component.xml
List excludePlugins = new ArrayList();
ComponentXMLVisitor compXMLVisitor = new ComponentXMLVisitor();
Location.createLocation(new File(src)).accept(compXMLVisitor);
for (Iterator it = compXMLVisitor.getCompXMLs().iterator(); it.hasNext();)
{
ComponentXML compXML = (ComponentXML)it.next();
for (Iterator it2 = compXML.getPlugins().iterator(); it2.hasNext();)
{
Plugin plugin = (Plugin)it2.next();
excludePlugins.add(plugin.getId());
}
}
// Generate missing component.xml
List excludes = new ArrayList(1);
excludes.add(".*internal.*");
Java2API java2api = new Java2API();
java2api.setSrc(src);
java2api.setOutputDir(compXMLOutputDir);
java2api.setExcludes(excludes);
java2api.setExcludePlugins(excludePlugins);
java2api.execute();
}
// Generate Non-API dependency report
String reportOutputDir = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
IStructuredSelection selection = (IStructuredSelection)window.getSelectionService().getSelection();
if (selection != null && !selection.isEmpty())
{
Object firstElement = selection.getFirstElement();
if (firstElement != null && firstElement instanceof IFile)
{
try
{
IFile file = (IFile)firstElement;
ILocation compXMLLoc = new WorkspaceFileLocation(file);
ComponentXML selectedCompXML = new ComponentXML();
selectedCompXML.setLocation(compXMLLoc);
selectedCompXML.load();
Collection plugins = selectedCompXML.getPlugins();
List srcs = new ArrayList(plugins.size());
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath workspace = workspaceRoot.getLocation();
for (Iterator it = plugins.iterator(); it.hasNext();)
{
Plugin plugin = (Plugin)it.next();
IProject project = workspaceRoot.getProject(plugin.getId());
if (project.exists())
srcs.add(workspace.append(project.getFullPath()).toFile().toURL().toString().substring(6));
}
reportOutputDir = outputDir.append("_output_").toString();
delete(new File(reportOutputDir));
String[] args = new String[srcs.size() + 13];
int i = 0;
args[i++] = "-src";
for (Iterator it = srcs.iterator(); it.hasNext();)
args[i++] = (String)it.next();
args[i++] = "-api";
args[i++] = compXMLLoc.getAbsolutePath();
args[i++] = "-outputDir";
args[i++] = reportOutputDir;
args[i++] = "-refapi";
args[i++] = compXMLOutputDir;
args[i++] = "-includes";
args[i++] = "org.eclipse.*";
NonAPIDependencyScanner.main(args);
}
catch (Throwable ioe)
{
ioe.printStackTrace();
}
}
}
}
// Open report
try
{
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = browserSupport.createBrowser("org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4APIViolation");
browser.openURL(new File(reportOutputDir + "/component-api-violation-all.html").toURL());
}
catch (PartInitException e)
{
}
catch (MalformedURLException e)
{
}
}
public void run(IAction action)
{
run();
}
public void selectionChanged(IAction action, ISelection selection)
{
}
private boolean delete(File file)
{
String name = file.getName();
if (name.endsWith(".gif") || name.endsWith(".jpg") || name.endsWith(".html"))
return true;
else if (file.isDirectory())
{
boolean b = true;
File[] children = file.listFiles();
for (int i = 0; i < children.length; i++)
if (!delete(children[i]))
b = false;
return b;
}
else
return file.delete();
}
}
\ No newline at end of file
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.wtp.releng.tools.component.ui.internal.action;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.wtp.releng.tools.component.ILocation;
import org.eclipse.wtp.releng.tools.component.model.ComponentXML;
import org.eclipse.wtp.releng.tools.component.model.Plugin;
import org.eclipse.wtp.releng.tools.component.ui.internal.ComponentUIPlugin;
import org.eclipse.wtp.releng.tools.component.ui.internal.WorkspaceFileLocation;
public class Scan4UnitTestCoverage extends Action implements IActionDelegate
{
public void run()
{
String outputDir = Platform.getPluginStateLocation(ComponentUIPlugin.getDefault()).append("_output_").toString();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
IStructuredSelection selection = (IStructuredSelection)window.getSelectionService().getSelection();
if (selection != null && !selection.isEmpty())
{
Object firstElement = selection.getFirstElement();
if (firstElement != null && firstElement instanceof IFile)
{
try
{
IFile file = (IFile)firstElement;
ILocation compXMLLoc = new WorkspaceFileLocation(file);
ComponentXML selectedCompXML = new ComponentXML();
selectedCompXML.setLocation(compXMLLoc);
selectedCompXML.load();
Collection plugins = selectedCompXML.getPlugins();
List srcs = new ArrayList(plugins.size());
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath workspace = workspaceRoot.getLocation();
for (Iterator it = plugins.iterator(); it.hasNext();)
{
Plugin plugin = (Plugin)it.next();
IProject project = workspaceRoot.getProject(plugin.getId());
if (project.exists())
{
StringBuffer sb = new StringBuffer();
sb.append(outputDir);
sb.append('/');
sb.append(project.getName());
sb.append("/api-info.xml");
new File(sb.toString()).delete();
srcs.add(workspace.append(project.getFullPath()).toFile().toURL().toString().substring(6));
}
}
String[] args = new String[srcs.size() + 6];
int i = 0;
args[i++] = "-src";
for (Iterator it = srcs.iterator(); it.hasNext();)
args[i++] = (String)it.next();
args[i++] = "-api";
args[i++] = compXMLLoc.getAbsolutePath();
args[i++] = "-outputDir";
args[i++] = outputDir;
args[i++] = "-html";
JavadocScanner2.main(args);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}
// Open report
try
{
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = browserSupport.createBrowser("org.eclipse.wtp.releng.tools.component.ui.internal.action.Scan4MissingJavadoc");
browser.openURL(new File(outputDir + "/api-javadoc-summary.html").toURL());
}
catch (PartInitException e)
{
}
catch (MalformedURLException e)
{
}
}
public void run(IAction action)
{
run();
}
public void selectionChanged(IAction action, ISelection selection)
{
}
}
\ 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