Cacheability improvements for thirdparty audit task (#42085) (#42151)

This commit is contained in:
Mark Vieira 2019-05-15 08:11:55 -04:00 committed by GitHub
parent 70ea3cf847
commit a8aa818e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -28,11 +28,13 @@ import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.FileTree;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
@ -45,6 +47,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
@ -113,7 +116,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
this.javaHome = javaHome;
}
@OutputDirectory
@Internal
public File getJarExpandDir() {
return new File(
new File(getProject().getBuildDir(), "precommit/thirdPartyAudit"),
@ -121,6 +124,11 @@ public class ThirdPartyAuditTask extends DefaultTask {
);
}
@OutputFile
public File getSuccessMarker() {
return new File(getProject().getBuildDir(), "markers/" + getName());
}
public void ignoreMissingClasses(String... classesOrPackages) {
if (classesOrPackages.length == 0) {
missingClassExcludes = null;
@ -157,8 +165,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
return missingClassExcludes;
}
@InputFiles
@PathSensitive(PathSensitivity.NAME_ONLY)
@Classpath
@SkipWhenEmpty
public Set<File> getJarsToScan() {
// These are SelfResolvingDependency, and some of them backed by file collections, like the Gradle API files,
@ -241,6 +248,10 @@ public class ThirdPartyAuditTask extends DefaultTask {
}
assertNoJarHell(jdkJarHellClasses);
// Mark successful third party audit check
getSuccessMarker().getParentFile().mkdirs();
Files.write(getSuccessMarker().toPath(), new byte[]{});
}
private void logForbiddenAPIsOutput(String forbiddenApisOutput) {