Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fobiddenapis 3.0: Remove deprecations #161

Merged
merged 2 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/main/java/de/thetaphi/forbiddenapis/AntTask.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/de/thetaphi/forbiddenapis/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package de.thetaphi.forbiddenapis;

import java.util.Locale;
import java.util.regex.Pattern;

import org.objectweb.asm.Type;
Expand All @@ -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();

Expand Down
16 changes: 0 additions & 16 deletions src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Resource> iter = apiSignatures.iterator();
Expand Down Expand Up @@ -338,17 +333,6 @@ public void setFailOnUnresolvableSignatures(boolean failOnUnresolvableSignatures
this.failOnUnresolvableSignatures = failOnUnresolvableSignatures;
}

/**
* Forbids calls to non-portable runtime APIs (like {@code sun.misc.Unsafe}).
* <em>Please note:</em> 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="**&#47;*.class" is not needed.
* Defaults to {@code true}.
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -252,26 +226,6 @@ public void setBundledSignatures(Set<String> bundledSignatures) {
data.bundledSignatures = bundledSignatures;
}

/**
* Forbids calls to non-portable runtime APIs (like {@code sun.misc.Unsafe}).
* <em>Please note:</em> This enables {@code "jdk-non-portable"} bundled signatures for backwards compatibility.
* Defaults to {@code false}.
* @deprecated Use <a href="bundled-signatures.html">bundled signatures</a> {@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.
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class CheckForbiddenApisExtension {
public List<String> signatures = new ArrayList<>();
public Set<String> bundledSignatures = new LinkedHashSet<>(),
suppressAnnotations = new LinkedHashSet<>();
@Deprecated public boolean internalRuntimeForbidden = false;
public boolean failOnUnsupportedJava = false,
failOnMissingClasses = true,
failOnUnresolvableSignatures = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}).
* <em>Please note:</em> This enables {@code "jdk-non-portable"} bundled signatures for backwards compatibility.
* @deprecated Use <a href="bundled-signatures.html">bundled signatures</a> {@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.
Expand Down Expand Up @@ -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<File> sigFiles = new LinkedHashSet<>();
final Set<URL> sigUrls = new LinkedHashSet<>();
Expand Down
4 changes: 1 addition & 3 deletions src/test/antunit/TestCli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@
<arg value="-b"/>
<arg value="jdk-unsafe-${jdk.version},jdk-deprecated-${jdk.version}"/>
<arg value="--bundledsignatures"/>
<arg value="jdk-system-out"/>
<arg value="jdk-system-out,jdk-non-portable"/>
<arg value="--includes"/>
<arg value="Java7*.class"/>
<arg value="--excludes"/>
<arg value="Java7ClassReferences.class"/>
<arg value="--internalruntimeforbidden"/>
</java>
<au:assertLogContains text=" 0 error(s)."/>
<au:assertLogContains text="Reading bundled API signatures: jdk-deprecated-${jdk.version}"/>
<au:assertLogContains text="Reading bundled API signatures: jdk-unsafe-${jdk.version}"/>
<au:assertLogContains text="Reading bundled API signatures: jdk-system-out"/>
<au:assertLogContains text="Reading bundled API signatures: jdk-non-portable"/>
<au:assertLogContains text="WARNING: The setting 'internalRuntimeForbidden' was deprecated"/>
</target>

<target name="testSuppressAnnotations">
Expand Down
32 changes: 0 additions & 32 deletions src/test/antunit/TestDeprecatedTask.xml

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/antunit/TestInternalRuntimeCalls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@
<au:assertLogContains level="error" text=" 2 error(s)"/>
</target>

<target name="testDeprecatedInternalRuntimeForbidden" if="has.sunmisc">
<au:expectfailure expectedMessage="Check for forbidden API calls failed, see log">
<forbiddenapis internalRuntimeForbidden="true" failOnMissingClasses="false">
<file file="OracleInternalRuntime.class"/>
</forbiddenapis>
</au:expectfailure>
<au:assertLogContains level="warn" text="The setting 'internalRuntimeForbidden' was deprecated"/>
<au:assertLogContains level="error" text="sun.misc.BASE64Encoder [non-portable or internal runtime class]"/>
<au:assertLogContains level="error" text=" 2 error(s)"/>
</target>

<!-- this should work also with non-Oracle runtimes, as no heuristics: -->
<target name="testInternalSignatures">
<au:expectfailure expectedMessage="Check for forbidden API calls failed, see log">
Expand Down
3 changes: 1 addition & 2 deletions src/test/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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))
}