Skip to content

Commit f1be3f9

Browse files
committed
Merge pull request #70 from policeman-tools/issue68
Add Gradle plugin. This closes #68
2 parents ccfecc1 + d321804 commit f1be3f9

File tree

11 files changed

+710
-10
lines changed

11 files changed

+710
-10
lines changed

build.xml

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<target name="-init" depends="-install.ivy">
154154
<echo level="info" message="Detected Java runtime major version: ${build.java.runtime}"/>
155155
<echo level="info" message="Java runtime: ${build.java.info}"/>
156+
<ivy:configure file="ivy-settings.xml"/>
156157
<ivy:resolve log="${ivy.logging}"/>
157158
<local name="ivy.version-message"/>
158159
<condition property="ivy.version-message"

ivy-settings.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* (C) Copyright Uwe Schindler (Generics Policeman) and others.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
-->
17+
<ivysettings>
18+
<settings defaultResolver="default"/>
19+
20+
<include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
21+
<include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
22+
<include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
23+
<include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
24+
25+
<resolvers>
26+
<ibiblio name="gradle" root="http://repo.gradle.org/gradle/libs-releases-local" m2compatible="true" />
27+
<chain name="default" returnFirst="true" checkmodified="true" changingPattern=".*SNAPSHOT">
28+
<resolver ref="main"/>
29+
<resolver ref="gradle" />
30+
</chain>
31+
</resolvers>
32+
</ivysettings>

ivy.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<dependency org="org.apache.ant" name="ant" rev="1.7.0" conf="build"/>
2828
<dependency org="org.apache.maven" name="maven-plugin-api" rev="2.0" conf="build"/>
2929
<dependency org="org.apache.maven.plugin-tools" name="maven-plugin-annotations" rev="3.2" conf="build"/>
30+
<!-- we compile against older Gradle 1.12 version (latest of 1.x), because 1.x still works with Java 1.5: -->
31+
<dependency org="org.gradle" name="gradle-core" rev="1.12" conf="build"/>
32+
<dependency org="org.gradle" name="gradle-base-services" rev="1.12" conf="build"/>
33+
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="build"/>
34+
<!-- Gradle also needs Groovy, but we need it as build tool, too: -->
35+
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.2.2" conf="build,buildtools"/>
3036
<!-- ASM 5.0.4 minimal: -->
3137
<dependency org="org.ow2.asm" name="asm" rev="5.0.4" conf="build,bundle"/>
3238
<dependency org="org.ow2.asm" name="asm-commons" rev="5.0.4" conf="build,bundle"/>
@@ -39,7 +45,6 @@
3945
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="build,bundle"/>
4046
<dependency org="com.googlecode.jarjar" name="jarjar" rev="1.3" conf="buildtools"/>
4147
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.3" conf="buildtools"/>
42-
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.2.2" conf="buildtools"/>
4348
<dependency org="org.apache.ant" name="ant-antunit" rev="1.3" conf="test"/>
4449
<dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="test"/>
4550
<dependency org="junit" name="junit" rev="4.12" conf="test"/>

src/main/java/de/thetaphi/forbiddenapis/Checker.java

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.objectweb.asm.commons.Method;
2424

2525
import java.io.BufferedReader;
26+
import java.io.FileInputStream;
2627
import java.io.FileNotFoundException;
2728
import java.io.IOException;
2829
import java.io.InputStream;
@@ -351,6 +352,11 @@ public final void parseSignaturesFile(InputStream in) throws IOException,ParseEx
351352
parseSignaturesFile(in, false);
352353
}
353354

355+
/** Reads a list of API signatures from the given file. */
356+
public final void parseSignaturesFile(File f) throws IOException,ParseException {
357+
parseSignaturesFile(new FileInputStream(f));
358+
}
359+
354360
/** Reads a list of API signatures from a String. */
355361
public final void parseSignaturesString(String signatures) throws IOException,ParseException {
356362
parseSignaturesFile(new StringReader(signatures), false);
@@ -405,6 +411,11 @@ public final void addClassToCheck(final InputStream in) throws IOException {
405411
classesToCheck.put(reader.getClassName(), new ClassSignature(reader, false, true));
406412
}
407413

414+
/** Parses and adds a class from the given file to the list of classes to check. */
415+
public final void addClassToCheck(File f) throws IOException {
416+
addClassToCheck(new FileInputStream(f));
417+
}
418+
408419
public final boolean hasNoSignatures() {
409420
return forbiddenMethods.isEmpty() && forbiddenFields.isEmpty() && forbiddenClasses.isEmpty() && forbiddenClassPatterns.isEmpty() && (!options.contains(Option.INTERNAL_RUNTIME_FORBIDDEN));
410421
}

src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.Closeable;
2222
import java.io.File;
23-
import java.io.FileInputStream;
2423
import java.io.IOException;
2524
import java.util.Arrays;
2625
import java.util.EnumSet;
@@ -266,7 +265,7 @@ public void run() throws ExitException {
266265
if (signaturesFiles != null) for (String sf : signaturesFiles) {
267266
final File f = new File(sf).getAbsoluteFile();
268267
LOG.info("Reading API signatures: " + f);
269-
checker.parseSignaturesFile(new FileInputStream(f));
268+
checker.parseSignaturesFile(f);
270269
}
271270
} catch (IOException ioe) {
272271
throw new ExitException(EXIT_ERR_OTHER, "IO problem while reading files with API signatures: " + ioe);
@@ -284,7 +283,7 @@ public void run() throws ExitException {
284283
LOG.info("Loading classes to check...");
285284
try {
286285
for (String f : files) {
287-
checker.addClassToCheck(new FileInputStream(new File(classesDirectory, f)));
286+
checker.addClassToCheck(new File(classesDirectory, f));
288287
}
289288
} catch (IOException ioe) {
290289
throw new ExitException(EXIT_ERR_OTHER, "Failed to load one of the given class files: " + ioe);

0 commit comments

Comments
 (0)