Skip to content

Apache Lucene open-source search software

LUCENE-4753: Run forbidden-apis Ant task per module. This allows more improvements and prevents OOMs after the number of class files raised recently

Uwe Schindler7315a90a7b83
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 731a8930b75..bfcec635a0a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -286,6 +286,10 @@ Build
* LUCENE-5322: Clean up / simplify Maven-related Ant targets.
(Steve Rowe)
+* LUCENE-4753: Run forbidden-apis Ant task per module. This allows more
+ improvements and prevents OOMs after the number of class files
+ raised recently. (Uwe Schindler)
+
Tests
* LUCENE-5278: Fix MockTokenizer to work better with more regular expression
diff --git a/lucene/analysis/build.xml b/lucene/analysis/build.xml
index 5ab5c8d10da..e77cfdfcf2a 100644
--- a/lucene/analysis/build.xml
+++ b/lucene/analysis/build.xml
@@ -147,4 +147,8 @@
<forall-analyzers target="-append-module-dependencies-properties"/>
</target>
+ <target name="check-forbidden-apis">
+ <forall-analyzers target="check-forbidden-apis"/>
+ </target>
+
</project>
diff --git a/lucene/analysis/stempel/build.xml b/lucene/analysis/stempel/build.xml
index 39bd7fdc1e2..6a2c17faaca 100644
--- a/lucene/analysis/stempel/build.xml
+++ b/lucene/analysis/stempel/build.xml
@@ -23,6 +23,11 @@
Analyzer for indexing Polish
</description>
+ <property name="forbidden-sysout-excludes" value="
+ org/egothor/stemmer/Compile.class
+ org/egothor/stemmer/DiffIt.class
+ "/>
+
<import file="../analysis-module-build.xml"/>
<path id="classpath">
diff --git a/lucene/benchmark/build.xml b/lucene/benchmark/build.xml
index f05399dd867..3fc2c628730 100644
--- a/lucene/benchmark/build.xml
+++ b/lucene/benchmark/build.xml
@@ -26,6 +26,9 @@
<import file="../module-build.xml"/>
<property name="working.dir" location="work"/>
+ <!-- benchmark creates lots of sysout stuff, so dont run forbidden! -->
+ <target name="-check-forbidden-sysout"/>
+
<target name="check-files">
<available file="temp/news20.tar.gz" property="news20.exists"/>
diff --git a/lucene/build.xml b/lucene/build.xml
index 74f40db8e55..bfc9d92f4f4 100644
--- a/lucene/build.xml
+++ b/lucene/build.xml
@@ -174,64 +174,15 @@
<lib-versions-check-macro dir="${common.dir}/.." centralized.versions.file="${common.dir}/ivy-versions.properties"/>
</target>
- <target name="check-forbidden-apis" depends="compile-tools,compile-test,install-forbidden-apis,-forbidden-apis-classpath,-check-forbidden-jdk-apis,-check-forbidden-test-apis,-check-system-out" description="Check forbidden API calls in compiled class files"/>
-
- <!-- TODO: Make the forbidden API checks per module! -->
- <target name="-forbidden-apis-classpath">
- <path id="forbidden-apis.classpath">
- <fileset dir="${basedir}" includes="**/lib/*.jar"/>
- <dirset dir="${basedir}/build" includes="**/classes/*"/>
- </path>
- </target>
-
- <target name="-check-forbidden-jdk-apis">
- <forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.classpath">
- <bundledSignatures name="jdk-unsafe-${javac.target}"/>
- <bundledSignatures name="jdk-deprecated-${javac.target}"/>
- <signaturesFileSet dir="${common.dir}/tools/forbiddenApis">
- <include name="base.txt" />
- </signaturesFileSet>
- <fileset dir="${basedir}/build" includes="**/*.class" />
- </forbidden-apis>
- </target>
-
- <target name="-check-forbidden-test-apis">
- <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/tests.txt" classpathref="forbidden-apis.classpath">
- <classpath refid="junit-path"/>
- <fileset dir="${basedir}/build" includes="**/classes/test/**/*.class,test-framework/**/*.class" />
- </forbidden-apis>
- </target>
-
- <target name="-check-system-out">
- <forbidden-apis bundledSignatures="jdk-system-out" classpathref="forbidden-apis.classpath">
- <fileset dir="${basedir}/build">
- <include name="**/classes/java/**/*.class"/>
- <!-- this is basically tests -->
- <exclude name="test-framework/**"/>
- <!-- exclude command line tools -->
- <exclude name="core/classes/java/org/apache/lucene/index/CheckIndex.class"/>
- <exclude name="core/classes/java/org/apache/lucene/index/IndexUpgrader.class"/>
- <exclude name="core/classes/java/org/apache/lucene/store/LockVerifyServer.class"/>
- <exclude name="core/classes/java/org/apache/lucene/store/LockStressTest.class"/>
- <exclude name="analysis/stempel/classes/java/org/egothor/stemmer/Compile.class"/>
- <exclude name="analysis/stempel/classes/java/org/egothor/stemmer/DiffIt.class"/>
- <exclude name="benchmark/**"/>
- <exclude name="demo/classes/java/org/apache/lucene/**"/>
- <exclude name="misc/classes/java/org/apache/lucene/index/CompoundFileExtractor.class"/>
- <exclude name="misc/classes/java/org/apache/lucene/index/IndexSplitter.class"/>
- <exclude name="misc/classes/java/org/apache/lucene/index/MultiPassIndexSplitter.class"/>
- <exclude name="misc/classes/java/org/apache/lucene/misc/GetTermInfo.class"/>
- <exclude name="misc/classes/java/org/apache/lucene/misc/HighFreqTerms.class"/>
- <exclude name="misc/classes/java/org/apache/lucene/misc/IndexMergeTool.class"/>
- <!-- not printing, just checking if its a system stream -->
- <exclude name="core/classes/java/org/apache/lucene/util/PrintStreamInfoStream.class"/>
- <!-- not printing, just generated code from javacc -->
- <exclude name="queryparser/classes/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.class"/>
- <exclude name="queryparser/classes/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.class"/>
- <exclude name="queryparser/classes/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.class"/>
- <exclude name="facet/classes/java/org/apache/lucene/facet/util/PrintTaxonomyStats.class"/>
- </fileset>
- </forbidden-apis>
+ <!-- -install-forbidden-apis is *not* a useless dependency. do not remove -->
+ <target name="check-forbidden-apis" depends="-install-forbidden-apis" description="Check forbidden API calls in compiled class files">
+ <subant target="check-forbidden-apis" failonerror="true" inheritall="false">
+ <propertyset refid="uptodate.and.compiled.properties"/>
+ <fileset dir="core" includes="build.xml"/>
+ <fileset dir="test-framework" includes="build.xml"/>
+ <fileset dir="tools" includes="build.xml"/>
+ </subant>
+ <modules-crawl target="check-forbidden-apis"/>
</target>
<target name="resolve">
diff --git a/lucene/common-build.xml b/lucene/common-build.xml
index 1da96ecc431..6ed36f4113b 100644
--- a/lucene/common-build.xml
+++ b/lucene/common-build.xml
@@ -2176,13 +2176,52 @@ ${ant.project.name}.test.dependencies=${test.classpath.list}
</target>
<!-- Forbidden API Task -->
- <target name="install-forbidden-apis" unless="forbidden-apis.loaded" depends="ivy-availability-check,ivy-configure">
+ <property name="forbidden-base-excludes" value=""/>
+ <property name="forbidden-tests-excludes" value=""/>
+ <property name="forbidden-sysout-excludes" value=""/>
+
+ <target name="-install-forbidden-apis" unless="forbidden-apis.loaded" depends="ivy-availability-check,ivy-configure">
<ivy:cachepath organisation="de.thetaphi" module="forbiddenapis" revision="1.3"
inline="true" conf="default" transitive="true" pathid="forbidden-apis.classpath"/>
<taskdef name="forbidden-apis" classname="de.thetaphi.forbiddenapis.AntTask" classpathref="forbidden-apis.classpath"/>
<property name="forbidden-apis.loaded" value="true"/>
+ </target>
+
+ <target name="-init-forbidden-apis" depends="-install-forbidden-apis">
+ <path id="forbidden-apis.allclasses.classpath">
+ <path refid="classpath"/>
+ <path refid="test.classpath"/>
+ <path refid="junit-path"/>
+ <!-- include the output directories, too (so we can still resolve excluded classes: -->
+ <pathelement path="${build.dir}/classes/java"/>
+ <pathelement path="${build.dir}/classes/test"/>
+ </path>
+ </target>
+
+ <target name="check-forbidden-apis" depends="-check-forbidden-base,-check-forbidden-tests,-check-forbidden-sysout" description="Check forbidden API calls in compiled class files"/>
+
+ <target name="-check-forbidden-base" depends="-init-forbidden-apis,compile-core,compile-test">
+ <forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.allclasses.classpath">
+ <bundledSignatures name="jdk-unsafe-${javac.target}"/>
+ <bundledSignatures name="jdk-deprecated-${javac.target}"/>
+ <signaturesFileSet file="${common.dir}/tools/forbiddenApis/base.txt"/>
+ <fileset dir="${build.dir}/classes/java" excludes="${forbidden-base-excludes}"/>
+ <fileset dir="${build.dir}/classes/test" excludes="${forbidden-tests-excludes}" erroronmissingdir="false"/>
+ </forbidden-apis>
</target>
+ <target name="-check-forbidden-tests" depends="-init-forbidden-apis,compile-test">
+ <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/tests.txt" classpathref="forbidden-apis.allclasses.classpath">
+ <fileset dir="${build.dir}/classes/test" excludes="${forbidden-tests-excludes}"/>
+ </forbidden-apis>
+ </target>
+
+ <target name="-check-forbidden-sysout" depends="-init-forbidden-apis,compile-core">
+ <forbidden-apis bundledSignatures="jdk-system-out" classpathref="forbidden-apis.allclasses.classpath">
+ <fileset dir="${build.dir}/classes/java" excludes="${forbidden-sysout-excludes}"/>
+ </forbidden-apis>
+ </target>
+
<!-- PEGDOWN macro: Before using depend on the target "resolve-pegdown,resolve-groovy" -->
<target name="resolve-pegdown" unless="pegdown.loaded" depends="ivy-availability-check,ivy-configure">
diff --git a/lucene/core/build.xml b/lucene/core/build.xml
index 8b137f1568e..c114bc7abe9 100644
--- a/lucene/core/build.xml
+++ b/lucene/core/build.xml
@@ -22,6 +22,14 @@
<property name="build.dir" location="../build/core"/>
+ <property name="forbidden-sysout-excludes" value="
+ org/apache/lucene/index/CheckIndex.class
+ org/apache/lucene/index/IndexUpgrader.class
+ org/apache/lucene/store/LockVerifyServer.class
+ org/apache/lucene/store/LockStressTest.class
+ org/apache/lucene/util/PrintStreamInfoStream.class
+ "/>
+
<import file="../common-build.xml"/>
<property name="moman.commit-hash" value="5c5c2a1e4dea" />
diff --git a/lucene/demo/build.xml b/lucene/demo/build.xml
index 0550660859a..c55529e9a1a 100644
--- a/lucene/demo/build.xml
+++ b/lucene/demo/build.xml
@@ -53,6 +53,9 @@
</invoke-module-javadoc>
</target>
+ <!-- we don't check for sysout in demo, because the demo is there to use sysout :-) -->
+ <target name="-check-forbidden-sysout"/>
+
<target name="compile-core" depends="jar-analyzers-common,jar-queryparser,jar-queries,jar-facet,jar-expressions,common.compile-core" />
<target name="default" depends="jar-core,build-web-demo"/>
diff --git a/lucene/facet/build.xml b/lucene/facet/build.xml
index 9c4ba59dce8..d6ed7dec27b 100644
--- a/lucene/facet/build.xml
+++ b/lucene/facet/build.xml
@@ -23,6 +23,10 @@
Faceted indexing and search capabilities
</description>
+ <property name="forbidden-sysout-excludes" value="
+ org/apache/lucene/facet/util/PrintTaxonomyStats.class
+ "/>
+
<import file="../module-build.xml"/>
<path id="classpath">
diff --git a/lucene/misc/build.xml b/lucene/misc/build.xml
index 7ed7fbcbb97..d49ccf77e19 100644
--- a/lucene/misc/build.xml
+++ b/lucene/misc/build.xml
@@ -23,6 +23,15 @@
Index tools and other miscellaneous code
</description>
+ <property name="forbidden-sysout-excludes" value="
+ org/apache/lucene/index/CompoundFileExtractor.class
+ org/apache/lucene/index/IndexSplitter.class
+ org/apache/lucene/index/MultiPassIndexSplitter.class
+ org/apache/lucene/misc/GetTermInfo.class
+ org/apache/lucene/misc/HighFreqTerms.class
+ org/apache/lucene/misc/IndexMergeTool.class
+ "/>
+
<import file="../module-build.xml"/>
<target name="install-cpptasks" unless="cpptasks.uptodate" depends="ivy-availability-check,ivy-fail,ivy-configure">
diff --git a/lucene/queryparser/build.xml b/lucene/queryparser/build.xml
index 4bd4711074b..a97c5553f55 100644
--- a/lucene/queryparser/build.xml
+++ b/lucene/queryparser/build.xml
@@ -20,6 +20,11 @@
Query parsers and parsing framework
</description>
+ <!-- TODO: remove the stupid debugStream in the JavaCC TokenManager classes with an additional regex below! -->
+ <property name="forbidden-sysout-excludes" value="
+ org/apache/lucene/queryparser/**/*TokenManager.class
+ "/>
+
<import file="../module-build.xml"/>
<path id="classpath">
diff --git a/lucene/test-framework/build.xml b/lucene/test-framework/build.xml
index 7fed9fe6645..eaa3d3701d4 100644
--- a/lucene/test-framework/build.xml
+++ b/lucene/test-framework/build.xml
@@ -42,6 +42,17 @@
<!-- redefine the clover setup, because we dont want to run clover for the test-framework -->
<target name="-clover.setup" if="run.clover"/>
+ <!-- redefine the test compilation, so its just a no-op -->
+ <target name="compile-test"/>
+
+ <!-- redefine the forbidden apis for tests, as we check ourselves - no sysout testing -->
+ <target name="-check-forbidden-tests" depends="-init-forbidden-apis,compile-core">
+ <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/tests.txt" classpathref="forbidden-apis.allclasses.classpath">
+ <fileset dir="${build.dir}/classes/java"/>
+ </forbidden-apis>
+ </target>
+ <target name="-check-forbidden-sysout"/>
+
<target name="javadocs-core" depends="javadocs"/>
<target name="javadocs" depends="init,javadocs-lucene-core,javadocs-lucene-codecs">
<sequential>
diff --git a/lucene/tools/build.xml b/lucene/tools/build.xml
index d9cbdc7dd1b..3a3e3d4071e 100644
--- a/lucene/tools/build.xml
+++ b/lucene/tools/build.xml
@@ -27,8 +27,19 @@
<import file="../common-build.xml"/>
<path id="classpath">
+ <!-- TODO: we need this for forbidden-apis to be happy, because it does not support "includeantruntime": -->
+ <path refid="ant-path"/>
</path>
+ <path id="test.classpath"/>
+
+ <!-- redefine the test compilation, so its just a no-op -->
+ <target name="compile-test"/>
+
+ <!-- redefine the forbidden apis to be no-ops -->
+ <target name="-check-forbidden-tests"/>
+ <target name="-check-forbidden-sysout"/>
+
<!--
Specialize compile-core to not depend on clover, to exclude a
classpath reference when compiling, and to not attempt to copy
diff --git a/solr/build.xml b/solr/build.xml
index baabb63213f..7092d3743a6 100644
--- a/solr/build.xml
+++ b/solr/build.xml
@@ -267,49 +267,14 @@
</license-check-macro>
</target>
- <target name="check-forbidden-apis" depends="compile-tools,compile-test,install-forbidden-apis,-forbidden-apis-classpath,-check-forbidden-java-apis,-check-forbidden-test-apis"
- description="Check forbidden API calls in compiled class files."/>
-
- <!-- TODO: Make the forbidden API checks per module! Also remove failOnMissingClasses="false" below!!! -->
- <target name="-forbidden-apis-classpath">
- <path id="forbidden-apis.classpath">
- <fileset dir="${basedir}" includes="**/lib/*.jar,**/test-lib/*.jar"/>
- <dirset dir="${basedir}/build" includes="**/classes/*"/>
- <path refid="solr.lucene.libs"/>
- <path refid="classpath"/>
- <path refid="test.classpath"/>
- </path>
- </target>
-
- <target name="-check-forbidden-java-apis">
- <property file="${common.dir}/ivy-versions.properties"/> <!-- for commons-io version -->
- <forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.classpath" failOnMissingClasses="false">
- <bundledSignatures name="jdk-unsafe-${javac.target}"/>
- <bundledSignatures name="jdk-deprecated-${javac.target}"/>
- <bundledSignatures name="commons-io-unsafe-${/commons-io/commons-io}"/>
- <signaturesFileSet dir="${common.dir}/tools/forbiddenApis">
- <include name="base.txt" />
- <include name="servlet-api.txt" />
- </signaturesFileSet>
- <fileset dir="${basedir}/build">
- <include name="**/*.class" />
- <!-- violates the servlet-api restrictions, but it is safe to do so in this test: -->
- <exclude name="solr-solrj/classes/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest$DebugServlet.class"/>
- </fileset>
- </forbidden-apis>
- </target>
-
- <target name="-check-forbidden-test-apis">
- <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/tests.txt" classpathref="forbidden-apis.classpath" failOnMissingClasses="false">
- <fileset dir="${basedir}/build">
- <include name="**/classes/test/**/*.class"/>
- <include name="solr-test-framework/**/*.class"/>
- <!-- not actually a test -->
- <exclude name="solr-core/classes/test/org/apache/solr/search/DocSetPerf.class"/>
- <!-- imported code -->
- <exclude name="solr-core/classes/test/org/apache/solr/internal/**/*.class"/>
- </fileset>
- </forbidden-apis>
+ <target name="check-forbidden-apis" depends="-install-forbidden-apis" description="Check forbidden API calls in compiled class files.">
+ <subant target="check-forbidden-apis" inheritall="false" >
+ <propertyset refid="uptodate.and.compiled.properties"/>
+ <fileset dir="core" includes="build.xml"/>
+ <fileset dir="solrj" includes="build.xml"/>
+ <fileset dir="test-framework" includes="build.xml"/>
+ </subant>
+ <contrib-crawl target="check-forbidden-apis" failonerror="true"/>
</target>
<!-- rat sources -->
diff --git a/solr/common-build.xml b/solr/common-build.xml
index 4ed25d722c6..614c2784212 100644
--- a/solr/common-build.xml
+++ b/solr/common-build.xml
@@ -466,6 +466,24 @@
<contrib-crawl target="add-to-war"/>
</target>
+ <!-- Forbidden API Task, customizations for Solr -->
+ <target name="-check-forbidden-base" depends="-init-forbidden-apis,compile-core,compile-test">
+ <property file="${common.dir}/ivy-versions.properties"/> <!-- for commons-io version -->
+ <forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.allclasses.classpath">
+ <bundledSignatures name="jdk-unsafe-${javac.target}"/>
+ <bundledSignatures name="jdk-deprecated-${javac.target}"/>
+ <bundledSignatures name="commons-io-unsafe-${/commons-io/commons-io}"/>
+ <signaturesFileSet dir="${common.dir}/tools/forbiddenApis">
+ <include name="base.txt" />
+ <include name="servlet-api.txt" />
+ </signaturesFileSet>
+ <fileset dir="${build.dir}/classes/java" excludes="${forbidden-base-excludes}"/>
+ <fileset dir="${build.dir}/classes/test" excludes="${forbidden-tests-excludes}" erroronmissingdir="false"/>
+ </forbidden-apis>
+ </target>
+
+ <target name="-check-forbidden-sysout"/>
+
<!-- hack for now to disable *all* Solr tests on Jenkins when "tests.disable-solr" property is set -->
<target name="test" unless="tests.disable-solr">
<antcall target="common.test" inheritrefs="true" inheritall="true"/>
diff --git a/solr/core/build.xml b/solr/core/build.xml
index 58a33116e76..e8c08b719dc 100644
--- a/solr/core/build.xml
+++ b/solr/core/build.xml
@@ -23,6 +23,11 @@
<property name="test.lib.dir" location="test-lib"/>
+ <property name="forbidden-tests-excludes" value="
+ org/apache/solr/internal/**
+ org/apache/solr/search/DocSetPerf.class
+ "/>
+
<import file="../common-build.xml"/>
<target name="compile-core" depends="compile-solrj,common-solr.compile-core"/>
diff --git a/solr/solrj/build.xml b/solr/solrj/build.xml
index 72f796114c8..8336e6b1f5a 100644
--- a/solr/solrj/build.xml
+++ b/solr/solrj/build.xml
@@ -18,6 +18,11 @@
<project name="solr-solrj" default="default">
<description>Solrj - Solr Java Client</description>
+ <!-- violates the servlet-api restrictions, but it is safe to do so in this test: -->
+ <property name="forbidden-tests-excludes" value="
+ org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest$DebugServlet.class
+ "/>
+
<import file="../common-build.xml"/>
<!-- Specialized compile classpath: to only depend on what solrj should depend on (e.g. not lucene) -->
diff --git a/solr/test-framework/build.xml b/solr/test-framework/build.xml
index 02c613dbffb..2f483803f2e 100644
--- a/solr/test-framework/build.xml
+++ b/solr/test-framework/build.xml
@@ -46,6 +46,16 @@
<!-- redefine the clover setup, because we dont want to run clover for the test-framework -->
<target name="-clover.setup" if="run.clover"/>
+ <!-- redefine the test compilation, so its just a no-op -->
+ <target name="compile-test"/>
+
+ <!-- redefine the forbidden apis for tests, as we check ourselves -->
+ <target name="-check-forbidden-tests" depends="-init-forbidden-apis,compile-core">
+ <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/tests.txt" classpathref="forbidden-apis.allclasses.classpath">
+ <fileset dir="${build.dir}/classes/java"/>
+ </forbidden-apis>
+ </target>
+
<!-- Override common-solr.javadocs to include JUnit links -->
<!-- and to copy the built javadocs to ${dest}/docs/api/test-framework -->
<target name="javadocs"