Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 192868 Details for
Bug 332772
Support problem filters for API Use Scan Task
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Work In Progress
clipboard.txt (text/plain), 16.65 KB, created by
Curtis Windatt
on 2011-04-08 14:24:20 EDT
(
hide
)
Description:
Work In Progress
Filename:
MIME Type:
Creator:
Curtis Windatt
Created:
2011-04-08 14:24:20 EDT
Size:
16.65 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.api.tools >Index: src/org/eclipse/pde/api/tools/internal/problems/ApiProblemFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/problems/ApiProblemFactory.java,v >retrieving revision 1.52 >diff -u -r1.52 ApiProblemFactory.java >--- src/org/eclipse/pde/api/tools/internal/problems/ApiProblemFactory.java 6 Dec 2010 21:00:43 -0000 1.52 >+++ src/org/eclipse/pde/api/tools/internal/problems/ApiProblemFactory.java 8 Apr 2011 18:24:45 -0000 >@@ -632,10 +632,7 @@ > > /** > * Returns the problem severity id for the given problem parameters. >- * @param category >- * @param element >- * @param kind >- * @param flags >+ * @param problem the problem to get severity for > * @return the id of the preference to use to lookup the user specified severity level for the given {@link IApiProblem} > */ > public static String getProblemSeverityId(IApiProblem problem) { >@@ -707,4 +704,5 @@ > } > return null; > } >+ > } >Index: src/org/eclipse/pde/api/tools/internal/search/ReferenceFilterStore.java >=================================================================== >RCS file: src/org/eclipse/pde/api/tools/internal/search/ReferenceFilterStore.java >diff -N src/org/eclipse/pde/api/tools/internal/search/ReferenceFilterStore.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/api/tools/internal/search/ReferenceFilterStore.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,220 @@ >+package org.eclipse.pde.api.tools.internal.search; >+ >+import java.io.BufferedInputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Map; >+import java.util.Set; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.pde.api.tools.internal.IApiCoreConstants; >+import org.eclipse.pde.api.tools.internal.IApiXmlConstants; >+import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory; >+import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; >+import org.eclipse.pde.api.tools.internal.provisional.builder.IReference; >+import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; >+import org.eclipse.pde.api.tools.internal.util.Util; >+import org.w3c.dom.Element; >+import org.w3c.dom.NodeList; >+ >+ >+public class ReferenceFilterStore { >+ >+ class ReferenceFilter{ >+ public ReferenceFilter(IApiProblem apiProblem){ >+ initialize(apiProblem); >+ } >+ >+ private void initialize(IApiProblem apiProblem){ >+ >+ } >+ >+ >+ /** >+ * Returns a reference object created by parsing the message arguments, type and id of the given problem or >+ * <code>null</code> if the problem does not reflect a reference. The returned reference may be missing information >+ * and the type/method names may not be fully qualified. >+ * >+ * @param problem the problem to recover a reference from >+ * @return a reference containing all information collected from the problem or <code>null</code> if a reference cannot be recovered >+ */ >+ private IReference recoverReference(IApiProblem problem) { >+ if (problem.getCategory() == IApiProblem.CATEGORY_USAGE){ >+ String typeName = null; >+ String signature = null; >+// switch(problem.getKind()) { >+// case IApiProblem.ILLEGAL_IMPLEMENT: return IApiProblemTypes.ILLEGAL_IMPLEMENT; >+// case IApiProblem.ILLEGAL_EXTEND: return IApiProblemTypes.ILLEGAL_EXTEND; >+// case IApiProblem.ILLEGAL_INSTANTIATE: return IApiProblemTypes.ILLEGAL_INSTANTIATE; >+// case IApiProblem.ILLEGAL_OVERRIDE: return IApiProblemTypes.ILLEGAL_OVERRIDE; >+// case IApiProblem.ILLEGAL_REFERENCE: return IApiProblemTypes.ILLEGAL_REFERENCE; >+// case IApiProblem.API_LEAK: { >+// switch(problem.getFlags()) { >+// case IApiProblem.LEAK_EXTENDS : return IApiProblemTypes.LEAK_EXTEND; >+// case IApiProblem.LEAK_FIELD : return IApiProblemTypes.LEAK_FIELD_DECL; >+// case IApiProblem.LEAK_IMPLEMENTS : return IApiProblemTypes.LEAK_IMPLEMENT; >+// case IApiProblem.LEAK_CONSTRUCTOR_PARAMETER: >+// case IApiProblem.LEAK_METHOD_PARAMETER : return IApiProblemTypes.LEAK_METHOD_PARAM; >+// case IApiProblem.LEAK_RETURN_TYPE : return IApiProblemTypes.LEAK_METHOD_RETURN_TYPE; >+// } >+// break; >+// } >+// case IApiProblem.UNSUPPORTED_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG; >+// case IApiProblem.DUPLICATE_TAG_USE: return IApiProblemTypes.INVALID_JAVADOC_TAG; >+// case IApiProblem.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES: return IApiProblemTypes.INVALID_REFERENCE_IN_SYSTEM_LIBRARIES; >+// case IApiProblem.UNUSED_PROBLEM_FILTERS: return IApiProblemTypes.UNUSED_PROBLEM_FILTERS; >+// } >+// break; >+// } else if (problem.getCategory() == IApiProblem.CATEGORY_COMPATIBILITY){ >+// return Util.getDeltaPrefererenceKey(problem.getElementKind(), problem.getKind(), problem.getFlags()); >+// } >+ } >+ return null; >+ } >+ } >+ >+ /** >+ * Fully qualified type name to a IApiProblem >+ */ >+ private Map fFilterMap; >+ private int fFilterCount; >+ private boolean debug = false; >+ >+ public ReferenceFilterStore(String filterRoot, String componentID, boolean debug){ >+ this.debug = debug; >+ this.initialize(filterRoot, componentID); >+ } >+ >+ public void dispose(){ >+ } >+ >+ public boolean isFiltered(IReference reference){ >+ return false; >+ } >+ >+ public int getFilterCount(){ >+ return fFilterCount; >+ } >+ >+ /** >+ * Initialize the filter store using the given component id >+ */ >+ private void initialize(String filtersRoot, String componentID) { >+ if(fFilterMap != null) { >+ return; >+ } >+ fFilterCount = 0; >+ fFilterMap = new HashMap(5); >+ String xml = null; >+ InputStream contents = null; >+ try { >+ File filterFileParent = new File(filtersRoot, componentID); >+ if (!filterFileParent.exists()) { >+ if(this.debug) { >+ System.out.println("No filters found for component " + componentID); //$NON-NLS-1$ >+ } >+ return; >+ } >+ contents = new BufferedInputStream(new FileInputStream(new File(filterFileParent, IApiCoreConstants.API_FILTERS_XML_NAME))); >+ xml = new String(Util.getInputStreamAsCharArray(contents, -1, IApiCoreConstants.UTF_8)); >+ } >+ catch(IOException ioe) {} >+ finally { >+ if (contents != null) { >+ try { >+ contents.close(); >+ } catch(IOException e) { >+ // ignore >+ } >+ } >+ } >+ if(xml == null) { >+ return; >+ } >+ Element root = null; >+ try { >+ root = Util.parseDocument(xml); >+ } >+ catch(CoreException ce) { >+ ApiPlugin.log(ce); >+ } >+ if (root == null) { >+ return; >+ } >+ if (!root.getNodeName().equals(IApiXmlConstants.ELEMENT_COMPONENT)) { >+ return; >+ } >+ String component = root.getAttribute(IApiXmlConstants.ATTR_ID); >+ if(component.length() == 0) { >+ return; >+ } >+ >+ int version = loadIntegerAttribute(root, IApiXmlConstants.ATTR_VERSION); >+ if (version < 2) { >+ if(this.debug) { >+ System.out.println("All filters of versions earlier than 2 are discarded because there is no way to retrieve the type name"); //$NON-NLS-1$ >+ } >+ // we discard all filters since there is no way to retrieve the type name >+ return; >+ } >+ >+ NodeList resources = root.getElementsByTagName(IApiXmlConstants.ELEMENT_RESOURCE); >+ for(int i = 0; i < resources.getLength(); i++) { >+ Element element = (Element) resources.item(i); >+ String typeName = element.getAttribute(IApiXmlConstants.ATTR_TYPE); >+ if(typeName == null || typeName.length() == 0) { >+ // Only problems with types are used to filter references >+ continue; >+ } >+ NodeList filters = element.getElementsByTagName(IApiXmlConstants.ELEMENT_FILTER); >+ for(int j = 0; j < filters.getLength(); j++) { >+ element = (Element) filters.item(j); >+ int id = loadIntegerAttribute(element, IApiXmlConstants.ATTR_ID); >+ if(id <= 0) { >+ continue; >+ } >+ String[] messageargs = null; >+ NodeList elements = element.getElementsByTagName(IApiXmlConstants.ELEMENT_PROBLEM_MESSAGE_ARGUMENTS); >+ if (elements.getLength() != 1) continue; >+ Element messageArguments = (Element) elements.item(0); >+ NodeList arguments = messageArguments.getElementsByTagName(IApiXmlConstants.ELEMENT_PROBLEM_MESSAGE_ARGUMENT); >+ int length = arguments.getLength(); >+ messageargs = new String[length]; >+ for (int k = 0; k < length; k++) { >+ Element messageArgument = (Element) arguments.item(k); >+ messageargs[k] = messageArgument.getAttribute(IApiXmlConstants.ATTR_VALUE); >+ } >+ >+ Set filterSet = (Set) fFilterMap.get(typeName); >+ if(filterSet == null) { >+ filterSet = new HashSet(); >+ fFilterMap.put(typeName, filterSet); >+ } >+ filterSet.add(ApiProblemFactory.newApiProblem(null, typeName, messageargs, null, null, -1, -1, -1, id)); >+ fFilterCount++; >+ } >+ } >+ >+ if (debug){ >+ System.out.println(fFilterCount + " filters found for component " + componentID); //$NON-NLS-1$ >+ } >+ } >+ >+ private int loadIntegerAttribute(Element element, String name) { >+ String value = element.getAttribute(name); >+ if(value.length() == 0) { >+ return -1; >+ } >+ try { >+ int number = Integer.parseInt(value); >+ return number; >+ } >+ catch(NumberFormatException nfe) {} >+ return -1; >+ } >+ >+} >Index: src/org/eclipse/pde/api/tools/internal/search/UseSearchRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseSearchRequestor.java,v >retrieving revision 1.10 >diff -u -r1.10 UseSearchRequestor.java >--- src/org/eclipse/pde/api/tools/internal/search/UseSearchRequestor.java 30 Mar 2010 18:35:51 -0000 1.10 >+++ src/org/eclipse/pde/api/tools/internal/search/UseSearchRequestor.java 8 Apr 2011 18:24:45 -0000 >@@ -65,7 +65,22 @@ > * The default {@link ReferenceAnalyzer} for detecting illegal API use > * @see #includesIllegalUse() > */ >- ReferenceAnalyzer fAnalyzer = null; >+ private ReferenceAnalyzer fAnalyzer = null; >+ >+ /** >+ * The string root location of any api_filter files to apply, possbly <code>null</code> >+ */ >+ private String fFilterRoot = null; >+ >+ /** >+ * The filter store for the current component, only one is cached at a time >+ */ >+ private ReferenceFilterStore fCurrentFilterStore = null; >+ >+ /** >+ * Provide more verbose output if debug flag is set >+ */ >+ private boolean debug = false; > > /** > * Constructor >@@ -89,6 +104,22 @@ > * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#acceptComponent(org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent) > */ > public boolean acceptComponent(IApiComponent component) { >+ if (fFilterRoot != null){ >+ >+ >+ >+ // TODO Change debug value back from true >+ debug = true; >+ >+ >+ >+ fCurrentFilterStore = new ReferenceFilterStore(fFilterRoot, component.getSymbolicName(), debug); >+ if (fCurrentFilterStore.getFilterCount() == 0){ >+ // If no relevant filters are found, skip filtering >+ fCurrentFilterStore.dispose(); >+ fCurrentFilterStore = null; >+ } >+ } > try { > if(!component.isSystemComponent() && getScope().encloses(component)) { > if(includesIllegalUse()) { >@@ -156,23 +187,39 @@ > try { > IApiMember member = reference.getResolvedReference(); > if(member != null) { >+ // Check for component filtering > IApiComponent component = member.getApiComponent(); > if(!fComponentIds.contains(component.getSymbolicName()) || component.equals(reference.getMember().getApiComponent())) { > return false; > } >+ >+ // Check search type filtering >+ boolean searchTypeValid = false; > if(isIllegalUse(reference) || (includesAPI() && includesInternal())) { >- return true; >+ searchTypeValid = true; > } > IApiAnnotations annots = component.getApiDescription().resolveAnnotations(member.getHandle()); > if(annots != null) { > int vis = annots.getVisibility(); > if(VisibilityModifiers.isAPI(vis) && includesAPI()) { >- return true; >+ searchTypeValid = true; > } > else if(VisibilityModifiers.isPrivate(vis) && includesInternal()) { >- return true; >+ searchTypeValid = true; >+ } >+ } >+ if (!searchTypeValid){ >+ return false; >+ } >+ >+ // Check against api_filters file >+ if (fCurrentFilterStore != null){ >+ if (fCurrentFilterStore.isFiltered(reference)){ >+ return false; > } > } >+ >+ return true; > } > } > catch(CoreException ce) { >@@ -260,4 +307,20 @@ > public void setJarPatterns(String[] patterns) { > jarPatterns = patterns; > } >+ >+ /** >+ * Set the root directory location of api_filter files that should be used to filter the accepted references >+ * @param filterRoot string file location of any api_filter files to apply or <code>null</code> to not filter >+ */ >+ public void setFilterRoot(String filterRoot){ >+ this.fFilterRoot = filterRoot; >+ } >+ >+ /** >+ * Sets whether this requestor is in debug mode, with more verbose output. Default is <code>false</code>. >+ * @param debug new debug setting >+ */ >+ public void setDebug(boolean debug){ >+ this.debug = debug; >+ } > } >Index: src_ant/org/eclipse/pde/api/tools/internal/tasks/ApiUseTask.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/ApiUseTask.java,v >retrieving revision 1.24 >diff -u -r1.24 ApiUseTask.java >--- src_ant/org/eclipse/pde/api/tools/internal/tasks/ApiUseTask.java 17 Mar 2011 20:56:23 -0000 1.24 >+++ src_ant/org/eclipse/pde/api/tools/internal/tasks/ApiUseTask.java 8 Apr 2011 18:24:45 -0000 >@@ -108,6 +108,11 @@ > private FilteredElements includedElements = null; > > /** >+ * Root directory of api_filters files to apply >+ */ >+ private String filterRoot = null; >+ >+ /** > * Set the location of the current product you want to search. > * > * <p>It can be a .zip, .jar, .tgz, .tar.gz file, or a directory that corresponds to >@@ -292,11 +297,10 @@ > TreeSet scope = new TreeSet(Util.componentsorter); > getContext(baseline, ids, scope); > ApiSearchEngine engine = new ApiSearchEngine(); >- UseSearchRequestor requestor = new UseSearchRequestor( >- ids, >- (IApiElement[]) scope.toArray(new IApiElement[scope.size()]), >- getSearchFlags()); >+ UseSearchRequestor requestor = new UseSearchRequestor(ids, (IApiElement[]) scope.toArray(new IApiElement[scope.size()]), getSearchFlags()); >+ requestor.setFilterRoot(filterRoot); > requestor.setJarPatterns(archivePatterns); >+ requestor.setDebug(debug); > // override API descriptions as required > if (apiPatterns != null || internalPatterns != null) { > // modify API descriptions >@@ -491,15 +495,20 @@ > System.out.println("Searching for internal references : " + this.considerinternal); //$NON-NLS-1$ > System.out.println("Searching for illegal API use : "+ this.considerillegaluse); //$NON-NLS-1$ > if (this.excludeListLocation != null) { >- System.out.println("exclude list location : " + this.excludeListLocation); //$NON-NLS-1$ >+ System.out.println("Exclude list location : " + this.excludeListLocation); //$NON-NLS-1$ > } else { > System.out.println("No exclude list location"); //$NON-NLS-1$ > } > if (this.includeListLocation != null) { >- System.out.println("include list location : " + this.includeListLocation); //$NON-NLS-1$ >+ System.out.println("Include list location : " + this.includeListLocation); //$NON-NLS-1$ > } else { > System.out.println("No include list location"); //$NON-NLS-1$ > } >+ if (this.filterRoot != null) { >+ System.out.println("API Filter location : " + this.filterRoot); //$NON-NLS-1$ >+ } else { >+ System.out.println("No API filter location"); //$NON-NLS-1$ >+ } > if(this.scopepattern == null) { > System.out.println("No scope pattern defined - searching all bundles"); //$NON-NLS-1$ > } >@@ -571,4 +580,28 @@ > public void setIncludeList(String includeListLocation) { > this.includeListLocation = includeListLocation; > } >+ >+ /** >+ * Set the root directory of API filters to use during the use scan. >+ * >+ * The argument is the root directory of the .api_filters files that should be used to filter references. >+ * >+ * The .api_filters files specify specific problems to ignore during api analysis. During the use scan, the >+ * problem filters will be converted to a list of references that will be filtered from the use scan results. >+ * >+ * The root is specified using an absolute path. >+ * The root needs to contain the following structure: >+ * <pre> >+ * root >+ * | >+ * +-- component name (i.e. org.eclipse.jface) >+ * | >+ * +--- .api_filters >+ * </pre> >+ * >+ * @param filters the root of the .api_filters files >+ */ >+ public void setFilters(String filtersRoot) { >+ this.filterRoot = filtersRoot; >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 332772
:
192868
|
193404
|
221360