From 67a935d30dd36f219f76666c37dc20f5d6eeaaee Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 26 Sep 2015 00:15:20 +0200 Subject: [PATCH 1/2] Allow arbitrary Ant resources as signatures --- .../thetaphi/forbiddenapis/ant/AntTask.java | 24 ++++++++++++------- src/test/antunit/TestFileSignatures.xml | 14 +++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java index 97358099..05cbc2c0 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java +++ b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java @@ -34,6 +34,7 @@ import org.apache.tools.ant.types.resources.FileResource; import org.apache.tools.ant.types.resources.Resources; import org.apache.tools.ant.types.resources.StringResource; +import org.apache.tools.ant.types.resources.Union; import de.thetaphi.forbiddenapis.Checker; import de.thetaphi.forbiddenapis.ForbiddenApiException; @@ -42,10 +43,10 @@ import java.io.IOException; import java.io.File; -import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.Iterator; -import java.util.List; +import java.util.LinkedHashSet; import java.util.Locale; /** @@ -56,10 +57,10 @@ */ public class AntTask extends Task { - private final Resources classFiles = new Resources(); - private final Resources apiSignatures = new Resources(); - private final List bundledSignatures = new ArrayList(); - private final List suppressAnnotations = new ArrayList(); + private final Union classFiles = new Union(); + private final Union apiSignatures = new Union(); + private final Collection bundledSignatures = new LinkedHashSet(); + private final Collection suppressAnnotations = new LinkedHashSet(); private Path classpath = null; private boolean failOnUnsupportedJava = false; @@ -155,7 +156,7 @@ public void info(String msg) { } if (checker.hasNoSignatures()) { - throw new BuildException("No API signatures found; use signaturesFile=, , or inner text to define those!"); + throw new BuildException("No API signatures found; use signaturesFile=, , or inner text to define those!"); } log.info("Loading classes to check..."); @@ -210,8 +211,8 @@ public void setDir(File dir) { classFiles.add(fs); } - private T addSignaturesResource(T res) { - ((ProjectComponent) res).setProject(getProject()); + private T addSignaturesResource(T res) { + res.setProject(getProject()); apiSignatures.add(res); return res; } @@ -236,6 +237,11 @@ public void setSignaturesFile(File file) { createSignaturesFile().setFile(file); } + /** Creates a collection of arbitrary Ant resources */ + public Resources createSignaturesResources() { + return addSignaturesResource(new Resources()); + } + /** Support for API signatures list as nested text */ public void addText(String text) { addSignaturesResource(new StringResource(text)); diff --git a/src/test/antunit/TestFileSignatures.xml b/src/test/antunit/TestFileSignatures.xml index b6a5e907..6e1dcc56 100644 --- a/src/test/antunit/TestFileSignatures.xml +++ b/src/test/antunit/TestFileSignatures.xml @@ -57,4 +57,18 @@ + + + + + + + java.util.Locale#ENGLISH @ We are speaking chinese here! + + + + + + + \ No newline at end of file From bb7e350c605bb1728b4ee5e2b6ac7b9919deb0a0 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 26 Sep 2015 00:22:22 +0200 Subject: [PATCH 2/2] Add documentation --- src/main/docs/ant-task.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/docs/ant-task.html b/src/main/docs/ant-task.html index 19900147..24950040 100644 --- a/src/main/docs/ant-task.html +++ b/src/main/docs/ant-task.html @@ -165,7 +165,8 @@

Parameters specified as nested elements

  • Use bundledSignatures element to pass a built-in signatures file, e.g. <bundledsignatures name="jdk-unsafe-1.7"/>
  • -
  • Use signaturesFileSet, signaturesFileList, signaturesFile elements to pass in collections of signatures files. Those elements behave like the corresponding standard Ant types.
  • +
  • Use signaturesResources element to wrap any valid Ant resource type (filesets,..).
  • +
  • Alternatively, use signaturesFileSet, signaturesFileList, signaturesFile elements to pass in collections of signatures files. Those elements behave like the corresponding standard Ant types.
  • Place signatures as plain text (use CDATA sections) inside the forbiddenapis element.