Skip to content

Commit

Permalink
Issue #28: Print warning if targetVersion parameter or property is mi…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
uschindler committed Jun 30, 2014
1 parent 05a0f04 commit 5f305b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/thetaphi/forbiddenapis/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/test/antunit/TestMavenMojo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
<au:assertLogContains text="The class 'foo.bar.ForbiddenApis' referenced in a signature cannot be loaded, ignoring signature: foo.bar.ForbiddenApis#testMethod()"/>
</target>

<target name="testMissingTargetVersion">
<au:expectfailure>
<artifact:mvn pom="${antunit.fake-pom}" mavenVersion="${maven.version}" failonerror="true" fork="true">
<arg value="${groupId}:${artifactId}:${version}:check"/>
<syspropertyset refid="injected-properties"/>
<sysproperty key="maven.compiler.target" value=""/>
</artifact:mvn>
</au:expectfailure>
<au:assertLogContains text="The 'targetVersion' parameter or '${maven.compiler.target}' property is missing."/>
<au:assertLogContains text="Bundled signatures resource not found"/>
</target>

<target name="testMyselfMaven3">
<artifact:mvn pom="${antunit.fake-pom}" mavenVersion="${antunit.maven3.version}" failonerror="true" fork="true">
<arg value="${groupId}:${artifactId}:${version}:check"/>
Expand Down

0 comments on commit 5f305b8

Please sign in to comment.