aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManu Sridharan <msridhar@gmail.com>2021-12-22 11:36:18 -0800
committerGitHub <noreply@github.com>2021-12-22 14:36:18 -0500
commit025ebf04c434a3d1b43738422b499a6628b9929d (patch)
tree8b361c01ce06c0152a3341588de7b79ecaaa862e
parentda577508a4f189cecf761026feddbe4e016a5109 (diff)
downloadnullaway-025ebf04c434a3d1b43738422b499a6628b9929d.tar.gz
Make jar-infer-lib tests pass on JDK 11 (#523)
Mostly, remove usage of internal APIs
-rw-r--r--.github/workflows/continuous-integration.yml2
-rw-r--r--jar-infer/jar-infer-lib/build.gradle20
-rw-r--r--jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/AnnotationChecker.java8
-rw-r--r--jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java44
4 files changed, 57 insertions, 17 deletions
diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 7d7a079..a96a148 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -54,7 +54,7 @@ jobs:
- name: Build and test using Gradle and Java 11
uses: eskatos/gradle-command-action@v1
with:
- arguments: build -x :sample-app:build -x :jar-infer:jar-infer-lib:build -x :jar-infer:nullaway-integration-test:build
+ arguments: build -x :sample-app:build -x :jar-infer:nullaway-integration-test:build
if: matrix.java == '11'
- name: Build and test using Gradle and Java 17
uses: eskatos/gradle-command-action@v1
diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle
index ea7c1d8..388a3be 100644
--- a/jar-infer/jar-infer-lib/build.gradle
+++ b/jar-infer/jar-infer-lib/build.gradle
@@ -30,7 +30,25 @@ dependencies {
test {
maxHeapSize = "1024m"
- jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
+ if (!JavaVersion.current().java9Compatible) {
+ jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
+ } else {
+ // to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer
+ jvmArgs += [
+ "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+ "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+ "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
+ // Accessed by Lombok tests
+ "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
+ ]
+ }
}
apply plugin: 'com.vanniktech.maven.publish'
diff --git a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/AnnotationChecker.java b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/AnnotationChecker.java
index f63a420..2098819 100644
--- a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/AnnotationChecker.java
+++ b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/AnnotationChecker.java
@@ -26,11 +26,11 @@ import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import jdk.internal.org.objectweb.asm.ClassReader;
-import jdk.internal.org.objectweb.asm.tree.AnnotationNode;
-import jdk.internal.org.objectweb.asm.tree.ClassNode;
-import jdk.internal.org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AnnotationNode;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.MethodNode;
/** Class to check if the methods in the given class / jar files have the expected annotations. */
public class AnnotationChecker {
diff --git a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java
index 4b89182..aa52049 100644
--- a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java
+++ b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java
@@ -27,7 +27,9 @@ import com.google.errorprone.bugpatterns.BugChecker;
import com.sun.tools.javac.main.Main;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
@@ -460,17 +462,7 @@ public class JarInferTest {
final String inputJarPath = workingFolderPath + "/" + baseJarName + ".jar";
final String outputJarPath = workingFolderPath + "/" + baseJarName + "-annotated.jar";
- // Copy Jar to workspace, and sign it
- Files.copy(
- Paths.get(baseJarPath), Paths.get(inputJarPath), StandardCopyOption.REPLACE_EXISTING);
- String ksPath =
- Thread.currentThread().getContextClassLoader().getResource("testKeyStore.jks").getPath();
- // JDK 8 only?
- sun.security.tools.jarsigner.Main jarSignerTool = new sun.security.tools.jarsigner.Main();
- jarSignerTool.run(
- new String[] {
- "-keystore", ksPath, "-storepass", "testPassword", inputJarPath, "testKeystore"
- });
+ copyAndSignJar(baseJarPath, inputJarPath);
// Test that this new jar fails if not run in --strip-jar-signatures mode
boolean signedJarExceptionThrown = false;
@@ -507,6 +499,36 @@ public class JarInferTest {
EntriesComparator.compareManifestContents(outputJarPath, baseJarPath));
}
+ /** copy the jar at {@code baseJarPath} to a signed jar at {@code signedJarPath} */
+ private void copyAndSignJar(String baseJarPath, String signedJarPath)
+ throws IOException, InterruptedException {
+ Files.copy(
+ Paths.get(baseJarPath), Paths.get(signedJarPath), StandardCopyOption.REPLACE_EXISTING);
+ String ksPath =
+ Thread.currentThread().getContextClassLoader().getResource("testKeyStore.jks").getPath();
+ // A public API for signing jars was added for Java 9+, but there is only an internal API on
+ // Java 8. And we need the test code to compile on Java 8. For simplicity and uniformity, we
+ // just run jarsigner as an executable (which slightly slows down test execution)
+ String jarsignerExecutable =
+ String.join(
+ FileSystems.getDefault().getSeparator(),
+ new String[] {System.getenv("JAVA_HOME"), "bin", "jarsigner"});
+ Process process =
+ Runtime.getRuntime()
+ .exec(
+ new String[] {
+ jarsignerExecutable,
+ "-keystore",
+ ksPath,
+ "-storepass",
+ "testPassword",
+ signedJarPath,
+ "testKeystore"
+ });
+ int exitCode = process.waitFor();
+ Assert.assertEquals("jarsigner process failed", 0, exitCode);
+ }
+
private byte[] sha1sum(String path) throws Exception {
File file = new File(path);
MessageDigest digest = MessageDigest.getInstance("SHA-1");