Bug 397604 - Add test for filtered use scan ant task
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/anttasks/tests/ApiToolingApiuseAntTaskTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/anttasks/tests/ApiToolingApiuseAntTaskTests.java
index 5abc705..0258176 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/anttasks/tests/ApiToolingApiuseAntTaskTests.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/anttasks/tests/ApiToolingApiuseAntTaskTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,22 +32,6 @@
return "apitooling.apiuse/";
}
- public void test1() throws Exception {
- IFolder reportFolder = runTaskAndVerify("test1");
- InputSource is = new InputSource(reportFolder.getFile("not_searched.xml").getContents());
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document doc = db.parse(is);
-
- NodeList elems = doc.getElementsByTagName("component");
- for (int index = 0; index < elems.getLength(); ++index) {
- String value = elems.item(index).getAttributes().getNamedItem("id").getNodeValue();
- boolean pass = false;
- if (value.startsWith("org.eclipse.osgi"))
- pass = true;
- assertTrue(value + " should have been filtered out.", pass);
- }
- }
-
private IFolder runTaskAndVerify(String resourceName) throws Exception,
CoreException, ParserConfigurationException, SAXException,
IOException {
@@ -69,6 +53,22 @@
}
+ public void test1() throws Exception {
+ IFolder reportFolder = runTaskAndVerify("test1");
+ InputSource is = new InputSource(reportFolder.getFile("not_searched.xml").getContents());
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = db.parse(is);
+
+ NodeList elems = doc.getElementsByTagName("component");
+ for (int index = 0; index < elems.getLength(); ++index) {
+ String value = elems.item(index).getAttributes().getNamedItem("id").getNodeValue();
+ boolean pass = false;
+ if (value.startsWith("org.eclipse.osgi"))
+ pass = true;
+ assertTrue(value + " should have been filtered out.", pass);
+ }
+ }
+
public void test2() throws Exception {
IFolder reportFolder = runTaskAndVerify("test2");
IResource[] members = reportFolder.members();
@@ -100,4 +100,37 @@
}
}
}
+
+ /**
+ * Tests that a use scan will find illegal use problems that can be filtered
+ * @throws Exception
+ */
+ public void testIllegalUse() throws Exception {
+ IFolder reportFolder = runTaskAndVerify("testIllegalUse");
+ IResource[] members = reportFolder.members();
+ for (int index = 0; index < members.length; index++) {
+ if (!members[index].getLocation().toFile().isDirectory())
+ continue;
+ boolean valid = members[index].getName().startsWith("org.eclipse.osgi");
+ assertTrue(members[index].getName() + " should have been filtered out", valid);
+ File[] dirs = members[index].getLocation().toFile().listFiles();
+ for (int i = 0; i < dirs.length; i++) {
+ boolean validDir = dirs[i].getName().startsWith("org.example.test.illegaluse");
+ assertTrue(dirs[i].getName() + " should have been filtered out", validDir);
+ }
+ }
+ }
+
+ /**
+ * Tests that a use scan will find illegal use problems that can be filtered
+ * @throws Exception
+ */
+ public void testIllegalUseFiltered() throws Exception {
+ IFolder reportFolder = runTaskAndVerify("testIllegalUseFiltered");
+ IResource[] members = reportFolder.members();
+ for (int index = 0; index < members.length; index++) {
+ if (members[index].getLocation().toFile().isDirectory())
+ fail(members[index].getName() + " should have been filtered using a .api_filters file");
+ }
+ }
}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/profile/OSGiProduct.zip b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/profile/OSGiProduct.zip
index 52577dc..ba5abea 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/profile/OSGiProduct.zip
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/profile/OSGiProduct.zip
Binary files differ
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUse/build.xml b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUse/build.xml
new file mode 100644
index 0000000..7977e1b
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUse/build.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+ Copyright (c) 2013 IBM Corporation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ IBM Corporation - initial API and implementation
+ -->
+
+<project name="apitooling.apiuse" default="run" basedir=".">
+ <target name="run">
+ <apitooling.apiuse
+ location="${baseline_location}"
+ report="${report_location}"
+ considerinternal="false"
+ considerapi="false"
+ considerillegaluse="true"
+ debug="true"
+ />
+ </target>
+</project>
\ No newline at end of file
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/build.xml b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/build.xml
new file mode 100644
index 0000000..d01359e
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/build.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+ Copyright (c) 2013 IBM Corporation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ IBM Corporation - initial API and implementation
+ -->
+
+<project name="apitooling.apiuse" default="run" basedir=".">
+ <target name="run">
+ <apitooling.apiuse
+ location="${baseline_location}"
+ report="${report_location}"
+ considerinternal="false"
+ considerapi="false"
+ considerillegaluse="true"
+ filters="${filter_location}"
+ debug="true"
+ />
+ </target>
+</project>
\ No newline at end of file
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/org.example.test.illegaluse/.api_filters b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/org.example.test.illegaluse/.api_filters
new file mode 100644
index 0000000..d8a5c98
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-anttasks/apitooling.apiuse/testIllegalUseFiltered/org.example.test.illegaluse/.api_filters
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <component id="org.example.test.illegaluse" version="2">
+ <resource type="org.example.test.illegaluse.HasIllegalUse">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="org.eclipse.osgi.framework.console.CommandInterpreter"/>
+ <message_argument value="org.example.test.illegaluse.HasIllegalUse"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ </component>
+
diff --git a/apitools/org.eclipse.pde.api.tools/scripts/usescan.xml b/apitools/org.eclipse.pde.api.tools/scripts/usescan.xml
new file mode 100644
index 0000000..592610f
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools/scripts/usescan.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) IBM Corporation and others 2009, 2012 This page is made available under license. For full details see the LEGAL in the documentation book that contains this page.
+
+ All Platform Debug contexts, those for org.eclipse.debug.ui, are located in this file
+ All contexts are grouped by their relation, with all relations grouped alphabetically.
+
+ General build file for running the API Ant tasks from the command line.
+
+ The tasks that can be run and their task names can be found in the api-tasks.properties file.
+ The supported tasks are:
+ - 'apiuse' from org.eclipse.pde.api.tools.internal.tasks.ApiUseTask
+ - 'apiuse_reportconversion' from org.eclipse.pde.api.tools.internal.tasks.ApiUseReportConversionTask
+ - 'apifreeze' from org.eclipse.pde.api.tools.internal.tasks.APIFreezeTask
+ - 'apifreeze_reportcoversion' from org.eclipse.pde.api.tools.internal.tasks.APIFreezeReportConversionTask
+ - 'apianalysis from org.eclipse.pde.api.tools.internal.tasks.APIToolsAnalysisTask
+ - 'apianalysis_reportconversion' from org.eclipse.pde.api.tools.internal.tasks.AnalysisReportConversionTask
+ - 'apimigration' from org.eclipse.pde.api.tools.internal.tasks.ApiMigrationTask
+ - 'apimigration_reportconversion' org.eclipse.pde.api.tools.internal.tasks.ApiMigrationReportConversionTask
+ - 'apigeneration' from org.eclipse.pde.api.tools.internal.tasks.ApiFileGenerationTask
+ - 'comparetask' from org.eclipse.pde.api.tools.internal.tasks.CompareTask
+ - 'apiconsumeruse_reportconversion' org.eclipse.pde.api.tools.internal.tasks.ApiConsumerUseReportConversionTask
+ - 'apiusescanproblems' org.eclipse.pde.api.tools.internal.tasks.MissingRefProblemsTask
+ - 'apiusescanproblem_reportconversion' org.eclipse.pde.api.tools.internal.tasks.MissingRefProblemsReportConversionTask
+-->
+<project name="apitask" basedir="." default="run">
+
+ <!--
+ The base install directory of a bare bones Eclipse SDK install, used to load dependent jars on the taskdef classpath
+ -->
+ <property name="eclipse.install.dir" value="C:\Users\windattc\Documents\Eclipse\Eclipse\plugins"/>
+ <!--
+ The directory to extract the apitooling-ant.jar jar file to, so it could be loaded on the taskdef classpath.
+
+ The apitooling-ant.jar file is located in the org.eclipse.pde.api.tools.jar file found in your base Eclipse
+ install specified above (in the eclipse.install.dir property)
+ -->
+ <property name="eclipse.lib.dir" value="C:\Users\windattc\Documents\Git\eclipse.pde.ui\apitools\org.eclipse.pde.api.tools\lib\"/>
+ <!--
+ Ant properties file that defines the API tools ant task names
+ -->
+ <property name="task.props" value="api-tasks.properties"/>
+
+ <!--
+ Initializes the API use task definition
+ -->
+ <target name="init">
+ <!--
+ We need to include all the dependencies for the api tooling jar and bundle on the classpath.
+ We do it here to avoid changes to the system-wide ant classpath variable.
+
+ This taskdef greedily inlcudes all jars from the eclipse install, in case there are unknown dependencies.
+ -->
+ <taskdef file="${task.props}">
+ <classpath>
+ <fileset dir="${eclipse.install.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${eclipse.lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </classpath>
+ </taskdef>
+ </target>
+
+ <!--
+ Main task
+ -->
+ <target name="run" depends="init">
+ <apiuse />
+ <apiuse_reportconversion/>
+ </target>
+</project>
+
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/FilterStore.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/FilterStore.java
index 724a1cb..6471800 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/FilterStore.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/FilterStore.java
@@ -353,6 +353,9 @@
typeName = null;
}
String path = element.getAttribute(IApiXmlConstants.ATTR_PATH);
+ if (path.trim().length() == 0){
+ path = null; // it is valid to have a filter without a path
+ }
NodeList filters = element.getElementsByTagName(IApiXmlConstants.ELEMENT_FILTER);
for(int j = 0; j < filters.getLength(); j++) {
element = (Element) filters.item(j);