From 5f305b8eb7b9e8c48eb2278c0c2e5b8c6b738a79 Mon Sep 17 00:00:00 2001 From: uschindler Date: Mon, 30 Jun 2014 12:08:57 +0000 Subject: [PATCH] Issue #28: Print warning if targetVersion parameter or property is missing --- .../thetaphi/forbiddenapis/AbstractCheckMojo.java | 15 ++++++++++++--- .../java/de/thetaphi/forbiddenapis/Checker.java | 3 ++- src/test/antunit/TestMavenMojo.xml | 12 ++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java index ff9d9783..5c1f5ddc 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java @@ -217,9 +217,18 @@ protected void logInfo(String msg) { log.info("Reading inline API signatures..."); checker.parseSignaturesString(sig); } - if (bundledSignatures != null) for (String bs : bundledSignatures) { - log.info("Reading bundled API signatures: " + bs); - checker.parseBundledSignatures(bs, getTargetVersion()); + if (bundledSignatures != null) { + String targetVersion = getTargetVersion(); + if ("".equals(targetVersion)) targetVersion = null; + if (targetVersion == null) { + log.warn("The 'targetVersion' parameter or '${maven.compiler.target}' property is missing. " + + "Trying to read bundled JDK signatures without compiler target. " + + "You have to explicitely specify the version in the resource name."); + } + for (String bs : bundledSignatures) { + log.info("Reading bundled API signatures: " + bs); + checker.parseBundledSignatures(bs, targetVersion); + } } if (signaturesFiles != null) for (final File f : signaturesFiles) { log.info("Reading API signatures: " + f); diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index e13ae678..81e72924 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -295,7 +295,8 @@ public final void parseBundledSignatures(String name, String jdkTargetVersion) t InputStream in = this.getClass().getResourceAsStream("signatures/" + name + ".txt"); // automatically expand the compiler version in here (for jdk-* signatures without version): if (in == null && jdkTargetVersion != null && name.startsWith("jdk-") && !name.matches(".*?\\-\\d\\.\\d")) { - in = this.getClass().getResourceAsStream("signatures/" + name + "-" + jdkTargetVersion + ".txt"); + name = name + "-" + jdkTargetVersion; + in = this.getClass().getResourceAsStream("signatures/" + name + ".txt"); } if (in == null) { throw new FileNotFoundException("Bundled signatures resource not found: " + name); diff --git a/src/test/antunit/TestMavenMojo.xml b/src/test/antunit/TestMavenMojo.xml index 838cd5e6..bfe36bd8 100644 --- a/src/test/antunit/TestMavenMojo.xml +++ b/src/test/antunit/TestMavenMojo.xml @@ -66,6 +66,18 @@ + + + + + + + + + + + +