From bb473c32e29023b49992af7fa4ea76532d06ac0a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 29 Feb 2016 14:44:27 +0000 Subject: [PATCH] Enable Animal Sniffer checking of spring-boot-loader-tools Previously, Animal Sniffer checking of spring-boot-loader-tools was disabled as it failed with an NPE. This has been fixed in Animal Sniffer 1.15. This commit upgrades Animal Sniffer to 1.15 and adds the necessary annotations to suppress failures for safe usage of sun.* and Java 7 APIs. Note that UsesUnsafeJava has been copied from spring-boot and made package-private. This retains the clearer intent of the custom annotation (versus @IgnoreJRERequirement) while avoiding the change in the build order that would be necessary for spring-boot-loader-tools to use the annotation from spring-boot. Closes gh-5284 --- spring-boot-parent/pom.xml | 2 +- .../spring-boot-loader-tools/pom.xml | 6 ++-- .../boot/loader/tools/JarWriter.java | 3 ++ .../boot/loader/tools/SignalUtils.java | 1 + .../boot/loader/tools/UsesUnsafeJava.java | 34 +++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/UsesUnsafeJava.java diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index 82cdbc0b42..038fc4527b 100755 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -289,7 +289,7 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.14 + 1.15 org.codehaus.cargo diff --git a/spring-boot-tools/spring-boot-loader-tools/pom.xml b/spring-boot-tools/spring-boot-loader-tools/pom.xml index ba4e00f71b..cd40a0ad32 100644 --- a/spring-boot-tools/spring-boot-loader-tools/pom.xml +++ b/spring-boot-tools/spring-boot-loader-tools/pom.xml @@ -132,8 +132,10 @@ org.codehaus.mojo animal-sniffer-maven-plugin - - true + + org.springframework.boot.loader.tools.UsesUnsafeJava + org.springframework.lang.UsesJava7 + diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java index 0643a4afc9..5eb172b82a 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java @@ -42,6 +42,8 @@ import java.util.jar.Manifest; import java.util.zip.CRC32; import java.util.zip.ZipEntry; +import org.springframework.lang.UsesJava7; + /** * Writes JAR content, ensuring valid directory entries are always create and duplicate * items are ignored. @@ -86,6 +88,7 @@ public class JarWriter { this.jarOutput = new JarOutputStream(fileOutputStream); } + @UsesJava7 private void setExecutableFilePermission(File file) { try { Path path = file.toPath(); diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java index ad2c0c6db2..699fe2f1de 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java @@ -26,6 +26,7 @@ import sun.misc.SignalHandler; * @since 1.1.0 */ @SuppressWarnings("restriction") +@UsesUnsafeJava public final class SignalUtils { private static final Signal SIG_INT = new Signal("INT"); diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/UsesUnsafeJava.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/UsesUnsafeJava.java new file mode 100644 index 0000000000..102e87a5fc --- /dev/null +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/UsesUnsafeJava.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * 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. + */ + +package org.springframework.boot.loader.tools; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated element uses unsafe Java calls. + * + * @author Phillip Webb + */ +@Retention(RetentionPolicy.CLASS) +@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE }) +@Documented +@interface UsesUnsafeJava { +}