diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ClassAPI.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ClassAPI.java index faf70cc93ba1b4e2abedcdb882af3de23fa27832..e8a297b5637ac276b9d99b4c5397584550891ed7 100644 --- a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ClassAPI.java +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ClassAPI.java @@ -18,6 +18,7 @@ import org.eclipse.wtp.releng.tools.component.model.Type; public class ClassAPI extends Type { + private String superClass; private int access; private List methodAPIs; private List fieldAPIs; @@ -28,6 +29,16 @@ public class ClassAPI extends Type access = -1; } + public String getSuperClass() + { + return superClass; + } + + public void setSuperClass(String superClass) + { + this.superClass = superClass; + } + /** * @return Returns the access. */ @@ -96,6 +107,7 @@ public class ClassAPI extends Type StringBuffer sb = new StringBuffer(); sb.append("<class-api"); sb.append(toAttribute("name", getName())); + sb.append(toAttribute("super", getSuperClass())); int access = getAccess(); if (access != -1) sb.append(toAttribute("access", String.valueOf(access))); diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ComponentAPIEmitter.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ComponentAPIEmitter.java index ee05f45af90ab23a945aa00f9126c01140b925c9..c73b49b6f52f54189618eb6492d2bfed7fa0bf37 100644 --- a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ComponentAPIEmitter.java +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/ComponentAPIEmitter.java @@ -205,6 +205,7 @@ public class ComponentAPIEmitter extends AbstractEmitter implements IClazzVisito private ClassAPI addClassAPI(ComponentXML compXML, IClazz clazz, ComponentAPI compAPI) { String typeName = clazz.getName(); + String superClass = clazz.getSuperClass(); int index = typeName.lastIndexOf('.'); String pkgName; String localName; @@ -222,6 +223,7 @@ public class ComponentAPIEmitter extends AbstractEmitter implements IClazzVisito { ClassAPI internalClassAPI = new ClassAPI(); internalClassAPI.setName(typeName); + internalClassAPI.setSuperClass(superClass); addClassAPI(compAPI, true, pkgName, internalClassAPI); } int access = clazz.getAccessFlags(); @@ -241,7 +243,7 @@ public class ComponentAPIEmitter extends AbstractEmitter implements IClazzVisito if (ref || subclass || implement || instantiate) { // at least one public usage - ClassAPI externalClassAPI = newClassAPI(typeName, access, new Boolean(ref), new Boolean(subclass), new Boolean(implement), new Boolean(instantiate)); + ClassAPI externalClassAPI = newClassAPI(typeName, superClass, access, new Boolean(ref), new Boolean(subclass), new Boolean(implement), new Boolean(instantiate)); addClassAPI(compAPI, false, pkgName, externalClassAPI); return externalClassAPI; } @@ -254,7 +256,7 @@ public class ComponentAPIEmitter extends AbstractEmitter implements IClazzVisito else if (pkg.isApi()) { // api == true means, by default, a non-listed type is an external API - ClassAPI externalClassAPI = newClassAPI(typeName, access, Boolean.TRUE, new Boolean(!isInterface), new Boolean(isInterface), new Boolean(!isInterface)); + ClassAPI externalClassAPI = newClassAPI(typeName, superClass, access, Boolean.TRUE, new Boolean(!isInterface), new Boolean(isInterface), new Boolean(!isInterface)); addClassAPI(compAPI, false, pkgName, externalClassAPI); return externalClassAPI; } @@ -330,10 +332,11 @@ public class ComponentAPIEmitter extends AbstractEmitter implements IClazzVisito return compAPI; } - private ClassAPI newClassAPI(String className, int access, Boolean ref, Boolean subclass, Boolean implement, Boolean instantiate) + private ClassAPI newClassAPI(String className, String superClass, int access, Boolean ref, Boolean subclass, Boolean implement, Boolean instantiate) { ClassAPI classAPI = new ClassAPI(); classAPI.setName(className); + classAPI.setSuperClass(superClass); classAPI.setAccess(access); classAPI.setReference(ref); classAPI.setSubclass(subclass); diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ClassViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ClassViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..f4a2fdf4c8d3a4e76f6a87d302ab10f97b436355 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ClassViolation.java @@ -0,0 +1,19 @@ +/********************************************************************** + * 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; + +public class ClassViolation extends ViolationContainer +{ + protected String getViolationName() + { + return "class"; + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..9c8fd9eb2603380810e905261351ba795491bc8a --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolation.java @@ -0,0 +1,20 @@ +/********************************************************************** + * 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; + +public class ComponentAPIViolation extends ViolationContainer +{ + protected String getViolationName() + { + return "component-api-violation"; + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolationEmitter.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolationEmitter.java new file mode 100644 index 0000000000000000000000000000000000000000..8688989bfa49a71ab07ff5e7d38494124802dd04 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ComponentAPIViolationEmitter.java @@ -0,0 +1,366 @@ +/********************************************************************** + * 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.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.eclipse.jdt.core.Signature; +import org.eclipse.jdt.core.util.IModifierConstants; +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.ComponentAPIEmitter; +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.internal.AbstractEmitter; +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.FileLocation; +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.Type; +import org.eclipse.wtp.releng.tools.component.util.CommandOptionParser; +import org.xml.sax.SAXException; + +public class ComponentAPIViolationEmitter extends AbstractEmitter +{ + private List compXMLDirs; + private List compXMLRefDirs; + private List eclipseDirs; + private List includes; + private List excludes; + private String outputDir; + private Map compLoc2CompXML; + private Map compLoc2CompRef; + private Map pluginId2Plugin; + private Map fragmentId2Fragment; + + public ComponentAPIViolationEmitter(List compXMLDirs, List compXMLRefDirs, List eclipseDirs, List includes, List excludes, String outputDir) + { + this.compXMLDirs = compXMLDirs; + this.compXMLRefDirs = compXMLRefDirs; + this.eclipseDirs = eclipseDirs; + this.includes = includes; + this.excludes = excludes; + this.outputDir = addTrailingSeperator(outputDir); + } + + public void genAPIViolations() throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException + { + compLoc2CompXML = new HashMap(); + compLoc2CompRef = new HashMap(); + pluginId2Plugin = new HashMap(); + fragmentId2Fragment = new HashMap(); + for (Iterator it = eclipseDirs.iterator(); it.hasNext();) + { + File eclipseFile = new File(addTrailingSeperator((String)it.next())); + if (eclipseFile.exists()) + harvestPlugins(eclipseFile, pluginId2Plugin, fragmentId2Fragment); + } + linkPluginsAndFragments(pluginId2Plugin, fragmentId2Fragment); + for (Iterator it = compXMLDirs.iterator(); it.hasNext();) + { + File compXMLFile = new File(addTrailingSeperator((String)it.next())); + if (compXMLFile.exists()) + harvestComponents(compXMLFile, compLoc2CompXML); + } + compLoc2CompRef.putAll(compLoc2CompXML); + if (compXMLRefDirs != null) + { + for (Iterator it = compXMLRefDirs.iterator(); it.hasNext();) + { + File compXMLRefFile = new File(addTrailingSeperator((String)it.next())); + if (compXMLRefFile.exists()) + harvestComponents(compXMLRefFile, compLoc2CompRef); + } + } + ComponentSummary summary = new ComponentSummary(); + for (Iterator it = compLoc2CompXML.keySet().iterator(); it.hasNext();) + { + String compLoc = (String)it.next(); + ComponentAPIEmitter compAPIEmitter = new ComponentAPIEmitter(null); + compAPIEmitter.init(compLoc2CompXML, pluginId2Plugin, fragmentId2Fragment); + ComponentAPI compAPI = compAPIEmitter.genComponentApiXml(compLoc); + ComponentAPIViolation v = genAPIViolation(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); + fos.write(v.toString().getBytes()); + fos.close(); + ComponentEntry entry = new ComponentEntry(); + entry.setCompName(compName); + sb = new StringBuffer("./"); + sb.append(compName); + sb.append("/component-api-violation.xml"); + entry.setRef(sb.toString()); + summary.add(entry); + } + summary.save(new FileLocation(new File(outputDir + "component-api-violation-all.xml"))); + xslt(summary.toString(), "org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl", outputDir + "component-api-violation-all.html"); + } + + private void xslt(String content, String xsl, String output) throws SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException, FileNotFoundException + { + File outputFile = new File(output); + outputFile.getParentFile().mkdirs(); + xslt(new ByteArrayInputStream(content.getBytes()), xsl, new FileOutputStream(outputFile)); + } + + private void xslt(InputStream is, String xsl, OutputStream os) throws SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException, FileNotFoundException + { + String user_dir = "user.dir"; + String currUserDir = System.getProperty(user_dir); + System.setProperty(user_dir, outputDir); + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xsl))); + transformer.transform(new StreamSource(is), new StreamResult(os)); + System.setProperty(user_dir, currUserDir); + } + + private ComponentAPIViolation genAPIViolation(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 = genAPIViolation((ClassAPI)it.next()); + if (classViolation != null) + classViolations.add(classViolation); + } + return classViolations; + } + + private ClassViolation genAPIViolation(ClassAPI classAPI) + { + ClassViolation classViolation = new ClassViolation(); + classViolation.setName(classAPI.getName()); + boolean isSuperClassAPI; + String superClassName = classAPI.getSuperClass(); + if (checkAccess(classAPI.getAccess(), IModifierConstants.ACC_INTERFACE)) + 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 checkAccess(int flag, int bit) + { + return ((flag & bit) == bit); + } + + 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 = compLoc2CompRef.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())) + { + for (Iterator typeIt = pkg.getTypes().iterator(); typeIt.hasNext();) + { + Type type = (Type)typeIt.next(); + if (typeName.equals(type.getName())) + { + 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; + } + } + return pkg.isApi(); + } + } + } + } + return false; + } + else + { + return true; + } + } + + private boolean include(String className) + { + if (excludes != null) + for (Iterator it = excludes.iterator(); it.hasNext();) + if (className.startsWith((String)it.next())) + return false; + if (includes != null && includes.size() > 0) + { + for (Iterator it = includes.iterator(); it.hasNext();) + if (className.startsWith((String)it.next())) + return true; + return false; + } + return true; + } + + public static void main(String[] args) + { + CommandOptionParser optionParser = new CommandOptionParser(args); + Map options = optionParser.getOptions(); + List compXMLDirs = (List)options.get("compXMLDirs"); + List compXMLRefDirs = (List)options.get("compXMLRefDirs"); + List eclipseDirs = (List)options.get("eclipseDirs"); + List outputDir = (List)options.get("outputDir"); + List includes = (List)options.get("includes"); + List excludes = (List)options.get("excludes"); + if (compXMLDirs == null || eclipseDirs == null || outputDir == null || compXMLDirs.size() < 1 || eclipseDirs.size() < 1 || outputDir.size() < 1) + { + printUsage(); + System.exit(-1); + } + ComponentAPIViolationEmitter emitter = new ComponentAPIViolationEmitter(compXMLDirs, compXMLRefDirs, eclipseDirs, includes, excludes, (String)outputDir.get(0)); + try + { + emitter.genAPIViolations(); + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + + private static void printUsage() + { + System.out.println("Usage: java org.eclipse.wtp.releng.tools.component.api.violation.APIViolationEmitter -compXMLDirs <compXMLDirs> -eclipseDirs <eclipseDirs> -outputDir <outputDir> [-options]"); + System.out.println(""); + System.out.println("\t-compXMLDirs\t<compXMLDirs>\tspace seperated list of directories containing component.xml files"); + System.out.println("\t-eclipseDirs\t<eclipseDirs>\tspace seperated list of directories containing Eclipse plugins"); + System.out.println("\t-outputDir\t<outputDir>\toutput directory"); + System.out.println(""); + System.out.println("where options include:"); + System.out.println(""); + System.out.println("\t-compXMLRefDirs\t<compXMLRefDirs>\tspace seperated list of directories containing component.xml files being referenced"); + System.out.println("\t-includes\t<includes>\tpackages to include"); + System.out.println("\t-excludes\t<excludes>\tpackages to exclude"); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/FieldViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/FieldViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..7f764e951ecb1960763366cf5209ee08e9203849 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/FieldViolation.java @@ -0,0 +1,42 @@ +/********************************************************************** + * 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; + +public class FieldViolation extends ViolationContainer +{ + private String type; + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + protected String getViolationName() + { + return "field"; + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + sb.append(getViolationName()); + sb.append(toAttribute("name", getName())); + sb.append(toAttribute("type", getType())); + sb.append("/>"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/MethodViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/MethodViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..d59fadb406ab54bca0446f88f8afa06d9c39a484 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/MethodViolation.java @@ -0,0 +1,46 @@ +/********************************************************************** + * 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; + +public class MethodViolation extends ViolationContainer +{ + protected String getViolationName() + { + return "method"; + } + + public String getName() + { + String name = super.getName(); + StringBuffer sb = new StringBuffer(name); + int index = name.indexOf('<'); + while (index != -1) + { + sb.deleteCharAt(index); + sb.insert(index, new char[] {'&', 'l', 't', ';'}, 0, 4); + index = sb.toString().indexOf('<'); + } + return sb.toString(); + } + + public void setName(String name) + { + StringBuffer sb = new StringBuffer(name); + int index = name.indexOf("<"); + while (index != -1) + { + sb.delete(index, index + 4); + sb.insert(index, '<'); + index = sb.toString().indexOf("<"); + } + super.setName(sb.toString()); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ParamViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ParamViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..87a907f3700d7bf994e1fe1d6ba3dfd2dac87bbb --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ParamViolation.java @@ -0,0 +1,43 @@ +/********************************************************************** + * 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; + +public class ParamViolation extends Violation +{ + private String type; + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + protected String getViolationName() + { + return "param"; + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + sb.append(getViolationName()); + sb.append(toAttribute("name", getName())); + sb.append(toAttribute("type", getType())); + sb.append("/>"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ReturnViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ReturnViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..91c096d40307c02c24f8eb5cb526455fc01a256f --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ReturnViolation.java @@ -0,0 +1,20 @@ +/********************************************************************** + * 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; + +public class ReturnViolation extends Violation +{ + protected String getViolationName() + { + return "return"; + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/SuperViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/SuperViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..d28057bc3ef89e2c67b88de8fbffc6f7d26b4dee --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/SuperViolation.java @@ -0,0 +1,20 @@ +/********************************************************************** + * 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; + +public class SuperViolation extends Violation +{ + protected String getViolationName() + { + return "super"; + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ThrowViolation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ThrowViolation.java new file mode 100644 index 0000000000000000000000000000000000000000..bb9ac839d7937c0b60b5d3f62910a9c4b5d16685 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ThrowViolation.java @@ -0,0 +1,20 @@ +/********************************************************************** + * 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; + +public class ThrowViolation extends Violation +{ + protected String getViolationName() + { + return "throw"; + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/Violation.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/Violation.java new file mode 100644 index 0000000000000000000000000000000000000000..d0d8d79626c8ad9a9523b6f6d84f3224648b6c6e --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/Violation.java @@ -0,0 +1,41 @@ +/********************************************************************** + * 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 org.eclipse.wtp.releng.tools.component.model.ComponentObject; + +public abstract class Violation extends ComponentObject +{ + private String name; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + protected abstract String getViolationName(); + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + sb.append(getViolationName()); + sb.append(toAttribute("name", getName())); + sb.append("/>"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ViolationContainer.java b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ViolationContainer.java new file mode 100644 index 0000000000000000000000000000000000000000..782ff51afbc59998fc855e14b916ab39c1a552f4 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/api/violation/ViolationContainer.java @@ -0,0 +1,59 @@ +/********************************************************************** + * 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.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public abstract class ViolationContainer extends Violation +{ + private List violations; + + public void addViolation(Violation violation) + { + if (violations == null) + violations = new ArrayList(); + violations.add(violation); + } + + public void addAllViolations(List violations) + { + if (this.violations == null) + this.violations = new ArrayList(); + this.violations.addAll(violations); + } + + public int countViolations() + { + if (violations == null) + return 0; + else + return violations.size(); + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + sb.append(getViolationName()); + sb.append(toAttribute("name", getName())); + sb.append(">"); + if (violations != null) + for (Iterator it = violations.iterator(); it.hasNext();) + sb.append(it.next().toString()); + sb.append("</"); + sb.append(getViolationName()); + sb.append(">"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl new file mode 100644 index 0000000000000000000000000000000000000000..ce594a23dac4636c0164c42ca8585a6a4fb5d3f2 --- /dev/null +++ b/archive/org.eclipse.wtp.releng/apitools/org.eclipse.wtp.releng.tools.component.core/src/org/eclipse/wtp/releng/tools/component/xsl/component-api-violation.xsl @@ -0,0 +1,164 @@ +<?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 showComponentsOnly() + { + toggleDiv("component::", false); + toggleDiv("class::", false); + } + function showClassesOnly() + { + toggleDiv("component::", true); + toggleDiv("class::", false); + } + function showAll() + { + toggleDiv("component::", true); + toggleDiv("class::", true); + } + function toggleDiv(prefix, show) + { + var divs = document.getElementsByTagName("div"); + for (var i = 0; i < divs.length; i++) + { + if (divs[i].id.indexOf(prefix) == 0) + { + var img = document.getElementById(divs[i].id + "::twist"); + if (show) + { + if (img != null) + { + img.src = "twistopened.gif"; + } + divs[i].style.display = ""; + } + else + { + if (img != null) + { + img.src = "twistclosed.gif"; + } + divs[i].style.display = "none"; + } + } + } + } + function toggle(id) + { + var div = document.getElementById(id); + var img = document.getElementById(id + "::twist"); + if (div.style.display == "") + { + img.src = "twistclosed.gif"; + div.style.display = "none"; + } + else + { + img.src = "twistopened.gif"; + div.style.display = ""; + } + } + </script> + <body> + <table width="100%" cellspacing="5" cellpadding="2" border="0"> + <tbody> + <tr> + <td width="60%" align="left"> + <font style="font-size: x-large;; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold">Eclipse WTP Component API Violation Report</font> + </td> + <td width="40%"> + <img width="120" hspace="50" height="86" align="middle" src="Idea.jpg"/> + </td> + </tr> + </tbody> + </table> + <table WIDTH="100%" CELLPADDING="2" CELLSPACING="5" BORDER="0"> + <tr> + <td BGCOLOR="#0080C0" COLSPAN="2" VALIGN="TOP" ALIGN="LEFT"><b><font face="Arial,Helvetica" color="#FFFFFF">Component API violation report</font></b></td> + </tr> + </table> + <table border="0"> + <tr><td><a href="javascript:showComponentsOnly()">Show components only</a></td></tr> + <tr><td><a href="javascript:showClassesOnly()">Show classes only</a></td></tr> + <tr><td><a href="javascript:showAll()">Show all</a></td></tr> + <tr><td> </td></tr> + </table> + <font face="Arial,Helvetica"> + <xsl:for-each select="component-summary/component"> + <xsl:sort select="@name"/> + <xsl:variable name="report" select="document(@ref)/component-api-violation"/> + <xsl:if test="$report/class"> + <xsl:apply-templates select="$report"/> + </xsl:if> + </xsl:for-each> + </font> + </body> + </html> + </xsl:template> + + <xsl:template match="component-api-violation"> + <table border="0"> + <tr> + <td> + <a href="javascript:toggle('component::{@name}')"><img id="component::{@name}::twist" border="0" src="twistopened.gif"/></a>  + <xsl:value-of select="@name"/>  + </td> + </tr> + <tr> + <td> + <div id="component::{@name}"> + <table border="0"> + <xsl:for-each select="class"> + <xsl:sort select="@name"/> + <xsl:apply-templates select="."/> + </xsl:for-each> + </table> + </div> + </td> + </tr> + </table> + </xsl:template> + + <xsl:template match="class"> + <tr> + <td> + <img border="0" src="space.gif"/> + <a href="javascript:toggle('class::{@name}')"><img id="class::{@name}::twist" border="0" src="twistopened.gif"/></a>  + <xsl:value-of select="@name"/>  + <div id="class::{@name}"> + <ol> + <xsl:if test="super"> + <li><b>Super class</b> <xsl:value-of select="super/@name"/> is not an API</li> + </xsl:if> + <xsl:for-each select="method"> + <xsl:sort select="@name"/> + <li> + <b>Method</b> <xsl:value-of select="@name"/> + <ul> + <xsl:for-each select="param"> + <li><b>Param type</b> <xsl:value-of select="@name"/> is not an API</li> + </xsl:for-each> + <xsl:if test="return"> + <li><b>Return type</b> <xsl:value-of select="return/@name"/> is not an API</li> + </xsl:if> + <xsl:for-each select="throw"> + <li><b>Throw type</b> <xsl:value-of select="@name"/> is not an API</li> + </xsl:for-each> + </ul> + </li> + </xsl:for-each> + <xsl:for-each select="field"> + <xsl:sort select="@name"/> + <li><b>Field</b> <xsl:value-of select="@name"/>: <xsl:value-of select="@type"/> is not an API</li> + </xsl:for-each> + </ol> + </div> + </td> + </tr> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file