From 4bfeadc789486a7e9e68eac62db86686d9b213e3 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Tue, 7 Apr 2020 10:16:03 +0200 Subject: [PATCH 1/2] fobiddenapis 3.0: Remove deprecations --- .../de/thetaphi/forbiddenapis/AntTask.java | 40 --------------- .../de/thetaphi/forbiddenapis/Constants.java | 4 -- .../thetaphi/forbiddenapis/ant/AntTask.java | 16 ------ .../thetaphi/forbiddenapis/cli/CliMain.java | 10 +--- .../gradle/CheckForbiddenApis.java | 50 ------------------- .../gradle/CheckForbiddenApisExtension.java | 1 - .../maven/AbstractCheckMojo.java | 14 ------ src/test/antunit/TestCli.xml | 4 +- src/test/antunit/TestDeprecatedTask.xml | 32 ------------ src/test/antunit/TestInternalRuntimeCalls.xml | 11 ---- src/test/gradle/build.gradle | 2 +- 11 files changed, 3 insertions(+), 181 deletions(-) delete mode 100644 src/main/java/de/thetaphi/forbiddenapis/AntTask.java delete mode 100644 src/test/antunit/TestDeprecatedTask.xml diff --git a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java deleted file mode 100644 index 8c74f441..00000000 --- a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (C) Copyright Uwe Schindler (Generics Policeman) and others. - * Parts of this work are licensed to the Apache Software Foundation (ASF) - * under one or more contributor license agreements. - * - * 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 de.thetaphi.forbiddenapis; - -import java.util.Locale; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * {@inheritDoc} - * @deprecated Use {@link de.thetaphi.forbiddenapis.ant.AntTask} instead. - */ -@Deprecated -public final class AntTask extends de.thetaphi.forbiddenapis.ant.AntTask { - - @Override - public void execute() throws BuildException { - log(String.format(Locale.ENGLISH, "DEPRECATED-WARNING: Please change your build.xml to use new task class '%s'", - getClass().getSuperclass().getName()), Project.MSG_WARN); - super.execute(); - } - -} diff --git a/src/main/java/de/thetaphi/forbiddenapis/Constants.java b/src/main/java/de/thetaphi/forbiddenapis/Constants.java index fc2bf6eb..5c3a9818 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Constants.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Constants.java @@ -18,7 +18,6 @@ package de.thetaphi.forbiddenapis; -import java.util.Locale; import java.util.regex.Pattern; import org.objectweb.asm.Type; @@ -29,9 +28,6 @@ public interface Constants { final Pattern JDK_SIG_PATTERN = Pattern.compile("(jdk\\-.*?\\-)(\\d+)(\\.\\d+)?(\\.\\d+)*"); - final String DEPRECATED_WARN_INTERNALRUNTIME = String.format(Locale.ENGLISH, - "The setting 'internalRuntimeForbidden' was deprecated and will be removed in next version. For backwards compatibility task/mojo is using '%s' bundled signatures instead.", BS_JDK_NONPORTABLE); - final Type DEPRECATED_TYPE = Type.getType(Deprecated.class); final String DEPRECATED_DESCRIPTOR = DEPRECATED_TYPE.getDescriptor(); diff --git a/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java index 9b160768..9eb2c0fa 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java +++ b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java @@ -64,7 +64,6 @@ public class AntTask extends Task implements Constants { private Path classpath = null; private boolean failOnUnsupportedJava = false; - @Deprecated private boolean internalRuntimeForbidden = false; private boolean restrictClassFilename = true; private boolean failOnMissingClasses = true; private boolean failOnUnresolvableSignatures = true; @@ -149,10 +148,6 @@ public void info(String msg) { } checker.addBundledSignatures(name, targetVersion); } - if (internalRuntimeForbidden) { - log.warn(DEPRECATED_WARN_INTERNALRUNTIME); - checker.addBundledSignatures(BS_JDK_NONPORTABLE, null); - } @SuppressWarnings("unchecked") final Iterator iter = apiSignatures.iterator(); @@ -338,17 +333,6 @@ public void setFailOnUnresolvableSignatures(boolean failOnUnresolvableSignatures this.failOnUnresolvableSignatures = failOnUnresolvableSignatures; } - /** - * Forbids calls to non-portable runtime APIs (like {@code sun.misc.Unsafe}). - * Please note: This enables {@code "jdk-non-portable"} bundled signatures for backwards compatibility. - * Defaults to {@code false}. - * @deprecated Use bundled signatures {@code "jdk-non-portable"} or {@code "jdk-internal"} instead. - */ - @Deprecated - public void setInternalRuntimeForbidden(boolean internalRuntimeForbidden) { - this.internalRuntimeForbidden = internalRuntimeForbidden; - } - /** Automatically restrict resource names included to files with a name ending in '.class'. * This makes filesets easier, as the includes="**/*.class" is not needed. * Defaults to {@code true}. diff --git a/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java b/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java index 27bb7c1b..b10ca5d3 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java +++ b/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java @@ -53,7 +53,7 @@ public final class CliMain implements Constants { private final Option classpathOpt, dirOpt, includesOpt, excludesOpt, signaturesfileOpt, bundledsignaturesOpt, suppressannotationsOpt, - internalruntimeforbiddenOpt, allowmissingclassesOpt, allowunresolvablesignaturesOpt, versionOpt, helpOpt; + allowmissingclassesOpt, allowunresolvablesignaturesOpt, versionOpt, helpOpt; private final CommandLine cmd; private static final Logger LOG = StdIoLogger.INSTANCE; @@ -125,10 +125,6 @@ public CliMain(String... args) throws ExitException { .valueSeparator(',') .argName("classname") .build()); - options.addOption(internalruntimeforbiddenOpt = Option.builder() - .desc(String.format(Locale.ENGLISH, "DEPRECATED: forbids calls to non-portable runtime APIs; use bundled signatures '%s' instead", BS_JDK_NONPORTABLE)) - .longOpt("internalruntimeforbidden") - .build()); options.addOption(allowmissingclassesOpt = Option.builder() .desc("don't fail if a referenced class is missing on classpath") .longOpt("allowmissingclasses") @@ -258,10 +254,6 @@ public void run() throws ExitException { if (bundledSignatures != null) for (String bs : new LinkedHashSet<>(Arrays.asList(bundledSignatures))) { checker.addBundledSignatures(bs, null); } - if (cmd.hasOption(internalruntimeforbiddenOpt.getLongOpt())) { - LOG.warn(DEPRECATED_WARN_INTERNALRUNTIME); - checker.addBundledSignatures(BS_JDK_NONPORTABLE, null); - } final String[] signaturesFiles = cmd.getOptionValues(signaturesfileOpt.getLongOpt()); if (signaturesFiles != null) for (String sf : new LinkedHashSet<>(Arrays.asList(signaturesFiles))) { diff --git a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java index 27a3cbc3..c4726229 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java +++ b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java @@ -133,32 +133,6 @@ public void setClassesDirs(FileCollection classesDirs) { this.classesDirs = classesDirs; } - /** - * Directory with the class files to check. - * Defaults to current sourseSet's output directory (Gradle 3 only). - * @deprecated use {@link #getClassesDirs()} instead. If there are more than one - * {@code classesDir} set by {@link #setClassesDirs(FileCollection)}, this getter may - * throw an exception! - */ - @Deprecated - @Internal - public File getClassesDir() { - final FileCollection col = getClassesDirs(); - return (col == null) ? null : col.getSingleFile(); - } - - /** Sets the directory where to look for classes. Overwrites any value set by {@link #setClassesDirs(FileCollection)}! - * @deprecated use {@link #setClassesDirs(FileCollection)} instead. - * @see #getClassesDir - */ - @Deprecated - public void setClassesDir(File classesDir) { - if (classesDir == null) throw new NullPointerException("classesDir"); - getLogger().warn("The 'classesDir' property on the '{}' task is deprecated. Use 'classesDirs' of type FileCollection instead!", - getName()); - setClassesDirs(getProject().files(classesDir)); - } - /** Returns the pattern set to match against class files in {@link #getClassesDir()}. */ @Internal public PatternSet getPatternSet() { @@ -252,26 +226,6 @@ public void setBundledSignatures(Set bundledSignatures) { data.bundledSignatures = bundledSignatures; } - /** - * Forbids calls to non-portable runtime APIs (like {@code sun.misc.Unsafe}). - * Please note: This enables {@code "jdk-non-portable"} bundled signatures for backwards compatibility. - * Defaults to {@code false}. - * @deprecated Use bundled signatures {@code "jdk-non-portable"} or {@code "jdk-internal"} instead. - */ - @Deprecated - @Input - public boolean getInternalRuntimeForbidden() { - return data.internalRuntimeForbidden; - } - - /** @see #getInternalRuntimeForbidden - * @deprecated Use bundled signatures {@code "jdk-non-portable"} or {@code "jdk-internal"} instead. - */ - @Deprecated - public void setInternalRuntimeForbidden(boolean internalRuntimeForbidden) { - data.internalRuntimeForbidden = internalRuntimeForbidden; - } - /** * Fail the build, if the bundled ASM library cannot read the class file format * of the runtime library or the runtime library cannot be discovered. @@ -575,10 +529,6 @@ public void info(String msg) { checker.addBundledSignatures(bs, bundledSigsJavaVersion); } } - if (getInternalRuntimeForbidden()) { - log.warn(DEPRECATED_WARN_INTERNALRUNTIME); - checker.addBundledSignatures(BS_JDK_NONPORTABLE, null); - } final FileCollection signaturesFiles = getSignaturesFiles(); if (signaturesFiles != null) for (final File f : signaturesFiles) { diff --git a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApisExtension.java b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApisExtension.java index ddc944d7..1113dae9 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApisExtension.java +++ b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApisExtension.java @@ -37,7 +37,6 @@ public class CheckForbiddenApisExtension { public List signatures = new ArrayList<>(); public Set bundledSignatures = new LinkedHashSet<>(), suppressAnnotations = new LinkedHashSet<>(); - @Deprecated public boolean internalRuntimeForbidden = false; public boolean failOnUnsupportedJava = false, failOnMissingClasses = true, failOnUnresolvableSignatures = true, diff --git a/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java index a93e9b26..d3cab6b1 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java @@ -111,16 +111,6 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant @Parameter(required = false) private String[] bundledSignatures; - /** - * Forbids calls to non-portable runtime APIs (like {@code sun.misc.Unsafe}). - * Please note: This enables {@code "jdk-non-portable"} bundled signatures for backwards compatibility. - * @deprecated Use bundled signatures {@code "jdk-non-portable"} or {@code "jdk-internal"} instead. - * @since 1.0 - */ - @Deprecated - @Parameter(required = false, defaultValue = "false") - private boolean internalRuntimeForbidden; - /** * Fail the build, if the bundled ASM library cannot read the class file format * of the runtime library or the runtime library cannot be discovered. @@ -377,10 +367,6 @@ public void info(String msg) { checker.addBundledSignatures(bs, targetVersion); } } - if (internalRuntimeForbidden) { - log.warn(DEPRECATED_WARN_INTERNALRUNTIME); - checker.addBundledSignatures(BS_JDK_NONPORTABLE, null); - } final Set sigFiles = new LinkedHashSet<>(); final Set sigUrls = new LinkedHashSet<>(); diff --git a/src/test/antunit/TestCli.xml b/src/test/antunit/TestCli.xml index 15c8763a..4f3d6721 100644 --- a/src/test/antunit/TestCli.xml +++ b/src/test/antunit/TestCli.xml @@ -42,19 +42,17 @@ - + - - diff --git a/src/test/antunit/TestDeprecatedTask.xml b/src/test/antunit/TestDeprecatedTask.xml deleted file mode 100644 index c58e8b13..00000000 --- a/src/test/antunit/TestDeprecatedTask.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/antunit/TestInternalRuntimeCalls.xml b/src/test/antunit/TestInternalRuntimeCalls.xml index 41b7cf6a..41cb56fb 100644 --- a/src/test/antunit/TestInternalRuntimeCalls.xml +++ b/src/test/antunit/TestInternalRuntimeCalls.xml @@ -31,17 +31,6 @@ - - - - - - - - - - - diff --git a/src/test/gradle/build.gradle b/src/test/gradle/build.gradle index 41e0bd7c..44eb7530 100644 --- a/src/test/gradle/build.gradle +++ b/src/test/gradle/build.gradle @@ -44,6 +44,6 @@ forbiddenApisMain { forbiddenApisTest { // use classesDir here to check backwards compatibility!: - classesDir = new File(forbiddenRootDir, 'build/test') + classesDirs = files(new File(forbiddenRootDir, 'build/test')) classpath = files(forbiddenTestClasspath.tokenize(File.pathSeparator)) } From 2fbfe203072ac23bb37af5ccb6031c088ecbcfbd Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Tue, 7 Apr 2020 10:24:28 +0200 Subject: [PATCH 2/2] Remove comment which is no longer applicable --- src/test/gradle/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/gradle/build.gradle b/src/test/gradle/build.gradle index 44eb7530..a45e1a78 100644 --- a/src/test/gradle/build.gradle +++ b/src/test/gradle/build.gradle @@ -43,7 +43,6 @@ forbiddenApisMain { } forbiddenApisTest { - // use classesDir here to check backwards compatibility!: classesDirs = files(new File(forbiddenRootDir, 'build/test')) classpath = files(forbiddenTestClasspath.tokenize(File.pathSeparator)) }