Skip to content

Commit

Permalink
Merge pull request #70 from policeman-tools/issue68
Browse files Browse the repository at this point in the history
Add Gradle plugin.
This closes #68
  • Loading branch information
uschindler committed Sep 9, 2015
2 parents ccfecc1 + d321804 commit f1be3f9
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<target name="-init" depends="-install.ivy">
<echo level="info" message="Detected Java runtime major version: ${build.java.runtime}"/>
<echo level="info" message="Java runtime: ${build.java.info}"/>
<ivy:configure file="ivy-settings.xml"/>
<ivy:resolve log="${ivy.logging}"/>
<local name="ivy.version-message"/>
<condition property="ivy.version-message"
Expand Down
32 changes: 32 additions & 0 deletions ivy-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* (C) Copyright Uwe Schindler (Generics Policeman) and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<ivysettings>
<settings defaultResolver="default"/>

<include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
<include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
<include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
<include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>

<resolvers>
<ibiblio name="gradle" root="http://repo.gradle.org/gradle/libs-releases-local" m2compatible="true" />
<chain name="default" returnFirst="true" checkmodified="true" changingPattern=".*SNAPSHOT">
<resolver ref="main"/>
<resolver ref="gradle" />
</chain>
</resolvers>
</ivysettings>
7 changes: 6 additions & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<dependency org="org.apache.ant" name="ant" rev="1.7.0" conf="build"/>
<dependency org="org.apache.maven" name="maven-plugin-api" rev="2.0" conf="build"/>
<dependency org="org.apache.maven.plugin-tools" name="maven-plugin-annotations" rev="3.2" conf="build"/>
<!-- we compile against older Gradle 1.12 version (latest of 1.x), because 1.x still works with Java 1.5: -->
<dependency org="org.gradle" name="gradle-core" rev="1.12" conf="build"/>
<dependency org="org.gradle" name="gradle-base-services" rev="1.12" conf="build"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="build"/>
<!-- Gradle also needs Groovy, but we need it as build tool, too: -->
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.2.2" conf="build,buildtools"/>
<!-- ASM 5.0.4 minimal: -->
<dependency org="org.ow2.asm" name="asm" rev="5.0.4" conf="build,bundle"/>
<dependency org="org.ow2.asm" name="asm-commons" rev="5.0.4" conf="build,bundle"/>
Expand All @@ -39,7 +45,6 @@
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="build,bundle"/>
<dependency org="com.googlecode.jarjar" name="jarjar" rev="1.3" conf="buildtools"/>
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.3" conf="buildtools"/>
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.2.2" conf="buildtools"/>
<dependency org="org.apache.ant" name="ant-antunit" rev="1.3" conf="test"/>
<dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="test"/>
<dependency org="junit" name="junit" rev="4.12" conf="test"/>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/thetaphi/forbiddenapis/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.objectweb.asm.commons.Method;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -351,6 +352,11 @@ public final void parseSignaturesFile(InputStream in) throws IOException,ParseEx
parseSignaturesFile(in, false);
}

/** Reads a list of API signatures from the given file. */
public final void parseSignaturesFile(File f) throws IOException,ParseException {
parseSignaturesFile(new FileInputStream(f));
}

/** Reads a list of API signatures from a String. */
public final void parseSignaturesString(String signatures) throws IOException,ParseException {
parseSignaturesFile(new StringReader(signatures), false);
Expand Down Expand Up @@ -405,6 +411,11 @@ public final void addClassToCheck(final InputStream in) throws IOException {
classesToCheck.put(reader.getClassName(), new ClassSignature(reader, false, true));
}

/** Parses and adds a class from the given file to the list of classes to check. */
public final void addClassToCheck(File f) throws IOException {
addClassToCheck(new FileInputStream(f));
}

public final boolean hasNoSignatures() {
return forbiddenMethods.isEmpty() && forbiddenFields.isEmpty() && forbiddenClasses.isEmpty() && forbiddenClassPatterns.isEmpty() && (!options.contains(Option.INTERNAL_RUNTIME_FORBIDDEN));
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.EnumSet;
Expand Down Expand Up @@ -266,7 +265,7 @@ public void run() throws ExitException {
if (signaturesFiles != null) for (String sf : signaturesFiles) {
final File f = new File(sf).getAbsoluteFile();
LOG.info("Reading API signatures: " + f);
checker.parseSignaturesFile(new FileInputStream(f));
checker.parseSignaturesFile(f);
}
} catch (IOException ioe) {
throw new ExitException(EXIT_ERR_OTHER, "IO problem while reading files with API signatures: " + ioe);
Expand All @@ -284,7 +283,7 @@ public void run() throws ExitException {
LOG.info("Loading classes to check...");
try {
for (String f : files) {
checker.addClassToCheck(new FileInputStream(new File(classesDirectory, f)));
checker.addClassToCheck(new File(classesDirectory, f));
}
} catch (IOException ioe) {
throw new ExitException(EXIT_ERR_OTHER, "Failed to load one of the given class files: " + ioe);
Expand Down
Loading

0 comments on commit f1be3f9

Please sign in to comment.