From 1187f335b04178ded3e16808cf3be3a81bd5a979 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 19 Nov 2023 17:14:34 -0800 Subject: [PATCH 01/24] added toJson function to AnalysisScope --- build.gradle.kts | 1 + cast/.settings/org.eclipse.jdt.core.prefs | 1 + .../java/.settings/org.eclipse.jdt.core.prefs | 1 + .../ecj/.settings/org.eclipse.jdt.core.prefs | 1 + .../data/.settings/org.eclipse.jdt.core.prefs | 1 + cast/js/.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + core/.settings/org.eclipse.jdt.core.prefs | 2 +- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 19 +++++++++++++++++++ dalvik/.settings/org.eclipse.jdt.core.prefs | 2 +- ide/.settings/org.eclipse.jdt.core.prefs | 1 + ide/jdt/.settings/org.eclipse.jdt.core.prefs | 1 + .../test/.settings/org.eclipse.jdt.core.prefs | 1 + ide/jsdt/.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + shrike/.settings/org.eclipse.jdt.core.prefs | 2 +- util/.settings/org.eclipse.jdt.core.prefs | 1 + 21 files changed, 39 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b789944d2c..b45d1dd908 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,6 +63,7 @@ val aggregatedJavadocClasspath: Configuration by configurations.creating { isCan val aggregatedJavadocSource: Configuration by configurations.creating { isCanBeConsumed = false } dependencies { + implementation 'com.google.code.gson:gson:2.8.6' subprojects { pluginManager.withPlugin("java-base") { aggregatedJavadocClasspath( diff --git a/cast/.settings/org.eclipse.jdt.core.prefs b/cast/.settings/org.eclipse.jdt.core.prefs index bf53eca489..46dc8478d7 100644 --- a/cast/.settings/org.eclipse.jdt.core.prefs +++ b/cast/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/.settings/org.eclipse.jdt.core.prefs b/cast/java/.settings/org.eclipse.jdt.core.prefs index 8f8e931c63..cb7184c292 100644 --- a/cast/java/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs index 5c12c8d1b0..bcfd2a8da2 100644 --- a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs index cf946c8de5..40411da3de 100644 --- a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/.settings/org.eclipse.jdt.core.prefs b/cast/js/.settings/org.eclipse.jdt.core.prefs index 463e28aa37..76347aee04 100644 --- a/cast/js/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs index 2b9d39c4ea..4f191ef2ac 100644 --- a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs index 3ad950dfca..9833c75b73 100644 --- a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs index 760d320e82..0d62206c7c 100644 --- a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs index 9b009e559e..d7762182a3 100644 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ b/core/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 5a36b459f2..b4be269d7f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -55,6 +55,8 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; +import com.google.gson.Gson; + /** * Base class that represents a set of files to analyze. * @@ -345,6 +347,23 @@ public String toString() { return result.toString(); } + public String toJson() { + StringBuilder result = new StringBuilder(); + for (ClassLoaderReference loader : loadersByName.values()) { + result.append(loader.getName()); + result.append('\n'); + for (Module m : getModules(loader)) { + result.append(' '); + result.append(m); + result.append('\n'); + } + } + result.append(getExclusionString()); + result.append('\n'); + Gson gson = new Gson(); + return gson.toJson(result.toString()); + } + /** * @return a String that describes exclusions from the analysis scope. */ diff --git a/dalvik/.settings/org.eclipse.jdt.core.prefs b/dalvik/.settings/org.eclipse.jdt.core.prefs index fff9860cf0..b136978268 100644 --- a/dalvik/.settings/org.eclipse.jdt.core.prefs +++ b/dalvik/.settings/org.eclipse.jdt.core.prefs @@ -7,7 +7,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/.settings/org.eclipse.jdt.core.prefs b/ide/.settings/org.eclipse.jdt.core.prefs index cd676248fe..1d033d1fa9 100644 --- a/ide/.settings/org.eclipse.jdt.core.prefs +++ b/ide/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/.settings/org.eclipse.jdt.core.prefs index 55d5744105..2939d58ea7 100644 --- a/ide/jdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs index 0d9a8a083e..861143ac53 100644 --- a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs index 1e908e2c71..2cbe9c1cdb 100644 --- a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs index fa9ef42774..c7caafc691 100644 --- a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/tests/.settings/org.eclipse.jdt.core.prefs b/ide/tests/.settings/org.eclipse.jdt.core.prefs index b9a5f6959b..a78ffab6a0 100644 --- a/ide/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/scandroid/.settings/org.eclipse.jdt.core.prefs b/scandroid/.settings/org.eclipse.jdt.core.prefs index c9942e9779..c225f50aa8 100644 --- a/scandroid/.settings/org.eclipse.jdt.core.prefs +++ b/scandroid/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/shrike/.settings/org.eclipse.jdt.core.prefs b/shrike/.settings/org.eclipse.jdt.core.prefs index 3150e13e55..74e011e600 100644 --- a/shrike/.settings/org.eclipse.jdt.core.prefs +++ b/shrike/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/util/.settings/org.eclipse.jdt.core.prefs b/util/.settings/org.eclipse.jdt.core.prefs index 1ae6eb0923..352ce4e43c 100644 --- a/util/.settings/org.eclipse.jdt.core.prefs +++ b/util/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull From 3a90899aa53b0c2bef40fd110b0392b35691c962 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 27 Nov 2023 19:47:50 -0800 Subject: [PATCH 02/24] added one successful test for toJson in Analysis Scope --- build.gradle.kts | 1 - core/build.gradle.kts | 1 + .../ibm/wala/ipa/callgraph/AnalysisScope.java | 4 +++- .../wala/core/tests/callGraph/CallGraphTest.java | 2 +- .../wala/core/tests/cha/AnalysisScopeTest.java | 16 ++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 14 +++++++------- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b45d1dd908..b789944d2c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,7 +63,6 @@ val aggregatedJavadocClasspath: Configuration by configurations.creating { isCan val aggregatedJavadocSource: Configuration by configurations.creating { isCanBeConsumed = false } dependencies { - implementation 'com.google.code.gson:gson:2.8.6' subprojects { pluginManager.withPlugin("java-base") { aggregatedJavadocClasspath( diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f032777f5c..4b66b1fb91 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -61,6 +61,7 @@ dependencies { api(projects.util) { because("public interface CallGraph extends interface NumberedGraph") } testFixturesImplementation(libs.ant) testFixturesImplementation(libs.junit.platform.launcher) + implementation(libs.gson) testImplementation(libs.assertj.core) testImplementation(libs.hamcrest) testRuntimeOnly(sourceSets["testSubjects"].output.classesDirs) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index b4be269d7f..95ae0d1ba5 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -54,9 +54,11 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; - import com.google.gson.Gson; + +// import com.google.gson.Gson; + /** * Base class that represents a set of files to analyze. * diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index a20853c202..9dcf85eb39 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -302,7 +302,7 @@ public void testPrimordial() if (useShortProfile()) { return; } - + AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope( "primordial.txt", diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 151b32dc4f..d8d0402e6b 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,5 +1,6 @@ package com.ibm.wala.core.tests.cha; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -18,8 +19,23 @@ import java.nio.file.Paths; import org.junit.jupiter.api.Test; +import com.google.gson.Gson; + public class AnalysisScopeTest { + @Test + public void toJsonTest() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + Gson gson = new Gson(); + String exp = gson.toJson(scope.toString()); + System.out.println(scope.toString()); + assertEquals(exp, scope.toJson()); + } + @Test public void testJarInputStream() throws IOException, ClassHierarchyException { AnalysisScope scope = diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 01f330a93e..41b59bedc4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1a53..1aa94a4269 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ From 6c815292fcb232c0413465cebbce735d95ffb9cb Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 4 Dec 2023 17:17:36 -0800 Subject: [PATCH 03/24] added json capability --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 8 +++++ .../core/tests/cha/AnalysisScopeTest.java | 6 ++-- z-out.java | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 z-out.java diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 95ae0d1ba5..82750572bb 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -351,18 +351,26 @@ public String toString() { public String toJson() { StringBuilder result = new StringBuilder(); + HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { + ArrayList arr = new ArrayList<>(); result.append(loader.getName()); result.append('\n'); for (Module m : getModules(loader)) { + arr.add(m.toString()); result.append(' '); result.append(m); result.append('\n'); } + hashMap.put(loader.getName().toString(), arr); } result.append(getExclusionString()); result.append('\n'); Gson gson = new Gson(); + // ArrayList arr2 = new ArrayList<>(); + // arr2.add(getJavaLibraryVersion()); + // hashMap.put(getExclusionString().toString(), arr2); + System.out.println(gson.toJson(hashMap)); return gson.toJson(result.toString()); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index d8d0402e6b..b48d0be7b1 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -28,11 +28,11 @@ public void toJsonTest() throws IOException { AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, - new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/core/src/test/java/com/ibm/wala/core/tests/cha/CodeDeletedTest.java"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); - String exp = gson.toJson(scope.toString()); - System.out.println(scope.toString()); + String exp = gson.toJson("scope.toString()"); assertEquals(exp, scope.toJson()); } diff --git a/z-out.java b/z-out.java new file mode 100644 index 0000000000..f4f67996fb --- /dev/null +++ b/z-out.java @@ -0,0 +1,35 @@ +// Example Code + +public class example { + public String convert_to_json(T dataStructure) throws IOException { + Gson gson = new Gson(); + System.out.println("gson"); + String json_format = gson.toJson(dataStructure); + FileWriter writer = new FileWriter("output2.json"); + writer.write(json_format); + writer.close(); + return json_format; + } + public String main() { + String out = convert_to_json("null"); + return out; + } + +} + +// example output + +{ + { + "Class_Name": "example", + "Functions": ["convert_to_json", "main"] + }, + { + "Class_Name": "convert_to_json", + "Functions": ["Gson", "toJson", "FileWriter", "write", "close"] + }, + { + "Class_Name": "main", + "Functions": ["convert_to_json"] + } +} From 163aa8e1272c42daa6e461cb947a1179c070dc0b Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 22 Dec 2023 23:07:28 -0800 Subject: [PATCH 04/24] implemented toJson functionality --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 82750572bb..0e34e2e52f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -51,6 +51,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.HashSet; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -351,26 +352,24 @@ public String toString() { public String toJson() { StringBuilder result = new StringBuilder(); + Set track = new HashSet<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); - result.append(loader.getName()); - result.append('\n'); for (Module m : getModules(loader)) { arr.add(m.toString()); - result.append(' '); - result.append(m); - result.append('\n'); } + if(!track.contains("Exclusions")) { + track.add("Exclusions"); + String newStr = getExclusionString().toString().substring(12); + ArrayList arr2 = new ArrayList<>(); + arr2.add(newStr); + hashMap.put("Exclusions", arr2); + } + track.add(loader.getName().toString()); hashMap.put(loader.getName().toString(), arr); } - result.append(getExclusionString()); - result.append('\n'); Gson gson = new Gson(); - // ArrayList arr2 = new ArrayList<>(); - // arr2.add(getJavaLibraryVersion()); - // hashMap.put(getExclusionString().toString(), arr2); - System.out.println(gson.toJson(hashMap)); return gson.toJson(result.toString()); } From 6f69ce9e0054e1a63263147a030fee54d0b9a159 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 22 Dec 2023 23:22:52 -0800 Subject: [PATCH 05/24] returned right value --- .../main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java | 4 ++-- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 0e34e2e52f..d052515495 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -351,7 +351,7 @@ public String toString() { } public String toJson() { - StringBuilder result = new StringBuilder(); + // StringBuilder result = new StringBuilder(); Set track = new HashSet<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { @@ -370,7 +370,7 @@ public String toJson() { hashMap.put(loader.getName().toString(), arr); } Gson gson = new Gson(); - return gson.toJson(result.toString()); + return gson.toJson(hashMap); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index b48d0be7b1..9b95c0ffa4 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -29,10 +29,11 @@ public void toJsonTest() throws IOException { AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/core/src/test/java/com/ibm/wala/core/tests/cha/CodeDeletedTest.java"), + new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/xvfb-gradle.sh"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); + System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From 307607af349576b7c26954655d3698df1f60f6fc Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 3 Jan 2024 13:29:56 -0800 Subject: [PATCH 06/24] added changes to toJson --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 20 ++++++++++++------- .../core/tests/cha/AnalysisScopeTest.java | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index d052515495..4997d74cb3 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -44,6 +44,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -353,22 +354,27 @@ public String toString() { public String toJson() { // StringBuilder result = new StringBuilder(); Set track = new HashSet<>(); + HashMap res = new HashMap<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { arr.add(m.toString()); } - if(!track.contains("Exclusions")) { - track.add("Exclusions"); - String newStr = getExclusionString().toString().substring(12); - ArrayList arr2 = new ArrayList<>(); - arr2.add(newStr); - hashMap.put("Exclusions", arr2); - } track.add(loader.getName().toString()); hashMap.put(loader.getName().toString(), arr); } + res.put("Loaders", hashMap); + String[] exclusions = getExclusions().toString().split("\\|"); + ArrayList arr2 = new ArrayList<>(); + for(int i = 0; i < exclusions.length; i++){ + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + res.put("Exclusions", arr2); + System.out.println(res); Gson gson = new Gson(); return gson.toJson(hashMap); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 9b95c0ffa4..a3d020a2e7 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -29,11 +29,11 @@ public void toJsonTest() throws IOException { AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/xvfb-gradle.sh"), + new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); - System.out.println(scope.toJson()); + // System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From cb5dd7bc7a53350fe0ee4f7d8fc78d84030bc5e5 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 3 Jan 2024 16:46:34 -0800 Subject: [PATCH 07/24] returned correct value --- .../com/ibm/wala/ipa/callgraph/AnalysisScope.java | 11 ++++------- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 4997d74cb3..d07017869d 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -353,18 +353,16 @@ public String toString() { public String toJson() { // StringBuilder result = new StringBuilder(); - Set track = new HashSet<>(); HashMap res = new HashMap<>(); - HashMap> hashMap = new HashMap<>(); + HashMap> loaders = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { arr.add(m.toString()); } - track.add(loader.getName().toString()); - hashMap.put(loader.getName().toString(), arr); + loaders.put(loader.getName().toString(), arr); } - res.put("Loaders", hashMap); + res.put("Loaders", loaders); String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); for(int i = 0; i < exclusions.length; i++){ @@ -374,9 +372,8 @@ public String toJson() { arr2.add(word); } res.put("Exclusions", arr2); - System.out.println(res); Gson gson = new Gson(); - return gson.toJson(hashMap); + return gson.toJson(res); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index a3d020a2e7..5a50500709 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -33,7 +33,7 @@ public void toJsonTest() throws IOException { AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); - // System.out.println(scope.toJson()); + System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From b489343b88f43a17d94e3ee8b1c29907d01bbccb Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sat, 13 Jan 2024 15:16:18 -0800 Subject: [PATCH 08/24] changes .settings --- cast/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/ecj/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/test/data/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/rhino/.settings/org.eclipse.jdt.core.prefs | 1 - core/.settings/org.eclipse.jdt.core.prefs | 2 +- dalvik/.settings/org.eclipse.jdt.core.prefs | 2 +- ide/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jdt/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jdt/test/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jsdt/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs | 1 - ide/tests/.settings/org.eclipse.jdt.core.prefs | 1 - scandroid/.settings/org.eclipse.jdt.core.prefs | 1 - shrike/.settings/org.eclipse.jdt.core.prefs | 2 +- util/.settings/org.eclipse.jdt.core.prefs | 1 - 19 files changed, 3 insertions(+), 19 deletions(-) diff --git a/cast/.settings/org.eclipse.jdt.core.prefs b/cast/.settings/org.eclipse.jdt.core.prefs index 46dc8478d7..bf53eca489 100644 --- a/cast/.settings/org.eclipse.jdt.core.prefs +++ b/cast/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/.settings/org.eclipse.jdt.core.prefs b/cast/java/.settings/org.eclipse.jdt.core.prefs index cb7184c292..8f8e931c63 100644 --- a/cast/java/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs index bcfd2a8da2..5c12c8d1b0 100644 --- a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs index 40411da3de..cf946c8de5 100644 --- a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/.settings/org.eclipse.jdt.core.prefs b/cast/js/.settings/org.eclipse.jdt.core.prefs index 76347aee04..463e28aa37 100644 --- a/cast/js/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs index 4f191ef2ac..2b9d39c4ea 100644 --- a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs index 9833c75b73..3ad950dfca 100644 --- a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs index 0d62206c7c..760d320e82 100644 --- a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs index d7762182a3..9b009e559e 100644 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ b/core/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/dalvik/.settings/org.eclipse.jdt.core.prefs b/dalvik/.settings/org.eclipse.jdt.core.prefs index b136978268..fff9860cf0 100644 --- a/dalvik/.settings/org.eclipse.jdt.core.prefs +++ b/dalvik/.settings/org.eclipse.jdt.core.prefs @@ -7,7 +7,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/.settings/org.eclipse.jdt.core.prefs b/ide/.settings/org.eclipse.jdt.core.prefs index 1d033d1fa9..cd676248fe 100644 --- a/ide/.settings/org.eclipse.jdt.core.prefs +++ b/ide/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/.settings/org.eclipse.jdt.core.prefs index 2939d58ea7..55d5744105 100644 --- a/ide/jdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs index 861143ac53..0d9a8a083e 100644 --- a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs index 2cbe9c1cdb..1e908e2c71 100644 --- a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs index c7caafc691..fa9ef42774 100644 --- a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/tests/.settings/org.eclipse.jdt.core.prefs b/ide/tests/.settings/org.eclipse.jdt.core.prefs index a78ffab6a0..b9a5f6959b 100644 --- a/ide/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/scandroid/.settings/org.eclipse.jdt.core.prefs b/scandroid/.settings/org.eclipse.jdt.core.prefs index c225f50aa8..c9942e9779 100644 --- a/scandroid/.settings/org.eclipse.jdt.core.prefs +++ b/scandroid/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/shrike/.settings/org.eclipse.jdt.core.prefs b/shrike/.settings/org.eclipse.jdt.core.prefs index 74e011e600..3150e13e55 100644 --- a/shrike/.settings/org.eclipse.jdt.core.prefs +++ b/shrike/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/util/.settings/org.eclipse.jdt.core.prefs b/util/.settings/org.eclipse.jdt.core.prefs index 352ce4e43c..1ae6eb0923 100644 --- a/util/.settings/org.eclipse.jdt.core.prefs +++ b/util/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull From a38c5b7099ccd6b51b527a60b633bc72b2e580e7 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 22 Jan 2024 16:59:05 -0800 Subject: [PATCH 09/24] removed unnecessary changes --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 1 - .../core/tests/callGraph/CallGraphTest.java | 4 +-- .../core/tests/cha/AnalysisScopeTest.java | 19 +--------- gradle/wrapper/gradle-wrapper.properties | 6 ++-- gradlew | 14 ++++---- z-out.java | 35 ------------------- 6 files changed, 13 insertions(+), 66 deletions(-) delete mode 100644 z-out.java diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index d07017869d..55f4b21af1 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -352,7 +352,6 @@ public String toString() { } public String toJson() { - // StringBuilder result = new StringBuilder(); HashMap res = new HashMap<>(); HashMap> loaders = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index 9dcf85eb39..cf60e65d01 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -302,7 +302,7 @@ public void testPrimordial() if (useShortProfile()) { return; } - + AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope( "primordial.txt", @@ -680,4 +680,4 @@ public boolean hasEdge(MethodReference src, MethodReference dst) { } }; } -} +} \ No newline at end of file diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 5a50500709..ad28a586e0 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,6 +1,5 @@ package com.ibm.wala.core.tests.cha; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -19,24 +18,8 @@ import java.nio.file.Paths; import org.junit.jupiter.api.Test; -import com.google.gson.Gson; - public class AnalysisScopeTest { - @Test - public void toJsonTest() throws IOException { - AnalysisScope scope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - Gson gson = new Gson(); - String exp = gson.toJson("scope.toString()"); - System.out.println(scope.toJson()); - assertEquals(exp, scope.toJson()); - } - @Test public void testJarInputStream() throws IOException, ClassHierarchyException { AnalysisScope scope = @@ -72,4 +55,4 @@ public void testBaseScope() throws IOException, ClassHierarchyException { ClassLoaderReference.Application, "Ljava/awt/AlphaComposite")), "found unexpected class"); } -} +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41b59bedc4..e1b846c9d5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,8 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionSha256Sum=c16d517b50dd28b3f5838f0e844b7520b8f1eb610f2f29de7e4e04a1b7c9c79b +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/gradlew b/gradlew index 1aa94a4269..0adc8e1a53 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/z-out.java b/z-out.java deleted file mode 100644 index f4f67996fb..0000000000 --- a/z-out.java +++ /dev/null @@ -1,35 +0,0 @@ -// Example Code - -public class example { - public String convert_to_json(T dataStructure) throws IOException { - Gson gson = new Gson(); - System.out.println("gson"); - String json_format = gson.toJson(dataStructure); - FileWriter writer = new FileWriter("output2.json"); - writer.write(json_format); - writer.close(); - return json_format; - } - public String main() { - String out = convert_to_json("null"); - return out; - } - -} - -// example output - -{ - { - "Class_Name": "example", - "Functions": ["convert_to_json", "main"] - }, - { - "Class_Name": "convert_to_json", - "Functions": ["Gson", "toJson", "FileWriter", "write", "close"] - }, - { - "Class_Name": "main", - "Functions": ["convert_to_json"] - } -} From 6d15461d769b9767a26cb45b0ce36d2802d29c95 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 30 Jan 2024 10:06:50 -0800 Subject: [PATCH 10/24] added linkedHashmap to AnalysisScope and created test for toJson --- .../com/ibm/wala/ipa/callgraph/AnalysisScope.java | 5 +++-- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 55f4b21af1..345754cc9f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -352,8 +352,9 @@ public String toString() { } public String toJson() { - HashMap res = new HashMap<>(); - HashMap> loaders = new HashMap<>(); + // make linked hashmap + LinkedHashMap res = new LinkedHashMap<>(); + LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index ad28a586e0..8c4095c189 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,5 +1,6 @@ package com.ibm.wala.core.tests.cha; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -55,4 +56,16 @@ public void testBaseScope() throws IOException, ClassHierarchyException { ClassLoaderReference.Application, "Ljava/awt/AlphaComposite")), "found unexpected class"); } + + @Test + public void testToJson() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + String exp = "{\"Loaders\":{\"Primordial\":[\"JarFileModule:/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/jmods/java.base.jmod\",\"Nested Jar File:primordial.jar.model\"],\"Extension\":[],\"Application\":[\"JarFileModule:/Users/aakgna/Documents/WALA-Research/WALA/core/build/resources/test/com.ibm.wala.core.testdata_1.0.0.jar\"],\"Synthetic\":[]},\"Exclusions\":[\"java\\\\/awt\\\\/.*\",\"javax\\\\/swing\\\\/.*\",\"sun\\\\/awt\\\\/.*\",\"sun\\\\/swing\\\\/.*\"]}"; + assertEquals(exp, scope.toJson().toString()); + } } \ No newline at end of file From e57b590763bb8a19de97ae22c741ae45d3268c5a Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 30 Jan 2024 11:35:41 -0800 Subject: [PATCH 11/24] deleted unnecessary lines --- .../main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 345754cc9f..3b682d671c 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -58,9 +58,6 @@ import java.util.jar.Manifest; import com.google.gson.Gson; - -// import com.google.gson.Gson; - /** * Base class that represents a set of files to analyze. * @@ -352,7 +349,6 @@ public String toString() { } public String toJson() { - // make linked hashmap LinkedHashMap res = new LinkedHashMap<>(); LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { From c237c76527032dd4da1090190f003b4ff5d84ea0 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 11 Feb 2024 20:03:11 -0800 Subject: [PATCH 12/24] implemented changes for toJson and added endlines --- .../core/tests/callGraph/CallGraphTest.java | 2 +- .../core/tests/cha/AnalysisScopeTest.java | 71 ++++++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index 193f0700c9..968e0b5462 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -723,4 +723,4 @@ public boolean hasEdge(MethodReference src, MethodReference dst) { } }; } -} \ No newline at end of file +} diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 8c4095c189..dedf08b929 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -17,7 +17,13 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.LinkedHashMap; + import org.junit.jupiter.api.Test; +import com.google.gson.Gson; +import java.lang.reflect.Type; +import com.google.gson.reflect.TypeToken; public class AnalysisScopeTest { @@ -65,7 +71,66 @@ public void testToJson() throws IOException { // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); - String exp = "{\"Loaders\":{\"Primordial\":[\"JarFileModule:/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/jmods/java.base.jmod\",\"Nested Jar File:primordial.jar.model\"],\"Extension\":[],\"Application\":[\"JarFileModule:/Users/aakgna/Documents/WALA-Research/WALA/core/build/resources/test/com.ibm.wala.core.testdata_1.0.0.jar\"],\"Synthetic\":[]},\"Exclusions\":[\"java\\\\/awt\\\\/.*\",\"javax\\\\/swing\\\\/.*\",\"sun\\\\/awt\\\\/.*\",\"sun\\\\/swing\\\\/.*\"]}"; - assertEquals(exp, scope.toJson().toString()); + Gson gson = new Gson(); + Type type = new TypeToken>(){}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + System.out.println(map); + if(map.containsKey("Exclusions")) { + String[] exclusions = scope.getExclusions().toString().split("\\|"); + ArrayList arr2 = new ArrayList<>(); + for(int i = 0; i < exclusions.length; i++){ + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + assertEquals(arr2, map.get("Exclusions")); + } + Type type2 = new TypeToken>>(){}.getType(); + LinkedHashMap> loaders = gson.fromJson(gson.toJson(map.get("Loaders")), type2); + if(loaders.containsKey("Primordial")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getPrimordialLoader()).size(); i++) { + String s1 = scope.getModules(scope.getPrimordialLoader()).get(i).toString(); + if (!loaders.get("Primordial").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Extension")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getExtensionLoader()).size(); i++) { + String s1 = scope.getModules(scope.getExtensionLoader()).get(i).toString(); + if (!loaders.get("Extension").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Application")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getApplicationLoader()).size(); i++) { + String s1 = scope.getModules(scope.getApplicationLoader()).get(i).toString(); + if (!loaders.get("Application").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Synthetic")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getSyntheticLoader()).size(); i++) { + String s1 = scope.getModules(scope.getSyntheticLoader()).get(i).toString(); + if (!loaders.get("Synthetic").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } } -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e1b846c9d5..a7a990ab2a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -5,4 +5,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists \ No newline at end of file +zipStorePath=wrapper/dists From fbe9c595baa34513250cc77bdca4f5567e5ffd47 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 13 Feb 2024 11:27:05 -0800 Subject: [PATCH 13/24] completed changes for AnalysisScopeTest and removed 1 import statement for AnalysisScope --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 1 + .../core/tests/cha/AnalysisScopeTest.java | 76 ++++++------------- 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 3b682d671c..6931e9af9b 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -353,6 +353,7 @@ public String toJson() { LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); + for (Module m : getModules(loader)) { arr.add(m.toString()); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index dedf08b929..1980907cff 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -13,12 +13,20 @@ import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; +import com.ibm.wala.util.collections.Iterator2Collection; + import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; import com.google.gson.Gson; @@ -68,69 +76,33 @@ public void testToJson() throws IOException { AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, - // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); Type type = new TypeToken>(){}.getType(); LinkedHashMap map = gson.fromJson(scope.toJson(), type); - System.out.println(map); if(map.containsKey("Exclusions")) { - String[] exclusions = scope.getExclusions().toString().split("\\|"); - ArrayList arr2 = new ArrayList<>(); - for(int i = 0; i < exclusions.length; i++){ - String word = exclusions[i]; - word = word.replace("(", ""); - word = word.replace(")", ""); - arr2.add(word); - } - assertEquals(arr2, map.get("Exclusions")); + assertEquals(List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); } - Type type2 = new TypeToken>>(){}.getType(); - LinkedHashMap> loaders = gson.fromJson(gson.toJson(map.get("Loaders")), type2); - if(loaders.containsKey("Primordial")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getPrimordialLoader()).size(); i++) { - String s1 = scope.getModules(scope.getPrimordialLoader()).get(i).toString(); - if (!loaders.get("Primordial").contains(s1)) { - flag = false; - break; - } + + if (map.get("Loaders") instanceof Map) { + Map> loaders = (Map>) map.get("Loaders"); + Set loadKey = new HashSet<>(Arrays.asList("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loadKey); + if(loaders.containsKey("Primordial")) { + assertEquals(2, loaders.get("Primordial").size()); + assertEquals(true, loaders.get("Primordial").contains("Nested Jar File:primordial.jar.model")); } - assertEquals(true, flag); - } - if(loaders.containsKey("Extension")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getExtensionLoader()).size(); i++) { - String s1 = scope.getModules(scope.getExtensionLoader()).get(i).toString(); - if (!loaders.get("Extension").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Application")) { + assertEquals(1, loaders.get("Application").size()); + assertEquals(true, loaders.get("Application").get(0).contains("com.ibm.wala.core.testdata_1.0.0.jar")); } - assertEquals(true, flag); - } - if(loaders.containsKey("Application")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getApplicationLoader()).size(); i++) { - String s1 = scope.getModules(scope.getApplicationLoader()).get(i).toString(); - if (!loaders.get("Application").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Extension")) { + assertEquals(0, loaders.get("Extension").size()); } - assertEquals(true, flag); - } - if(loaders.containsKey("Synthetic")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getSyntheticLoader()).size(); i++) { - String s1 = scope.getModules(scope.getSyntheticLoader()).get(i).toString(); - if (!loaders.get("Synthetic").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Synthetic")) { + assertEquals(0, loaders.get("Synthetic").size()); } - assertEquals(true, flag); } } } From 3cfff82faf87828d7e0add6faeea693fc8a0b58a Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 13 Feb 2024 17:50:53 -0800 Subject: [PATCH 14/24] Tune up test and fix formatting --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 6 +- .../core/tests/cha/AnalysisScopeTest.java | 73 ++++++++----------- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 6931e9af9b..9450a38498 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -10,6 +10,7 @@ */ package com.ibm.wala.ipa.callgraph; +import com.google.gson.Gson; import com.ibm.wala.classLoader.ArrayClassLoader; import com.ibm.wala.classLoader.BinaryDirectoryTreeModule; import com.ibm.wala.classLoader.ClassFileModule; @@ -44,7 +45,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -52,11 +52,9 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.HashSet; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import com.google.gson.Gson; /** * Base class that represents a set of files to analyze. @@ -362,7 +360,7 @@ public String toJson() { res.put("Loaders", loaders); String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); - for(int i = 0; i < exclusions.length; i++){ + for (int i = 0; i < exclusions.length; i++) { String word = exclusions[i]; word = word.replace("(", ""); word = word.replace(")", ""); diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 1980907cff..c860c0cace 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,9 +1,14 @@ package com.ibm.wala.core.tests.cha; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.ibm.wala.core.tests.util.TestConstants; import com.ibm.wala.core.util.config.AnalysisScopeReader; import com.ibm.wala.core.util.io.FileProvider; @@ -13,25 +18,17 @@ import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; -import com.ibm.wala.util.collections.Iterator2Collection; - import java.io.FileInputStream; import java.io.IOException; +import java.lang.reflect.Type; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; - import org.junit.jupiter.api.Test; -import com.google.gson.Gson; -import java.lang.reflect.Type; -import com.google.gson.reflect.TypeToken; public class AnalysisScopeTest { @@ -72,37 +69,29 @@ public void testBaseScope() throws IOException, ClassHierarchyException { } @Test - public void testToJson() throws IOException { - AnalysisScope scope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - Gson gson = new Gson(); - Type type = new TypeToken>(){}.getType(); - LinkedHashMap map = gson.fromJson(scope.toJson(), type); - if(map.containsKey("Exclusions")) { - assertEquals(List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); - } - - if (map.get("Loaders") instanceof Map) { - Map> loaders = (Map>) map.get("Loaders"); - Set loadKey = new HashSet<>(Arrays.asList("Primordial", "Extension", "Application", "Synthetic")); - assertEquals(loaders.keySet(), loadKey); - if(loaders.containsKey("Primordial")) { - assertEquals(2, loaders.get("Primordial").size()); - assertEquals(true, loaders.get("Primordial").contains("Nested Jar File:primordial.jar.model")); - } - if(loaders.containsKey("Application")) { - assertEquals(1, loaders.get("Application").size()); - assertEquals(true, loaders.get("Application").get(0).contains("com.ibm.wala.core.testdata_1.0.0.jar")); - } - if(loaders.containsKey("Extension")) { - assertEquals(0, loaders.get("Extension").size()); - } - if(loaders.containsKey("Synthetic")) { - assertEquals(0, loaders.get("Synthetic").size()); - } - } - } + public void testToJson() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + Gson gson = new Gson(); + Type type = new TypeToken>() {}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + assertEquals( + List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), + map.get("Exclusions")); + + Map> loaders = (Map>) map.get("Loaders"); + Set loaderKeys = + new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loaderKeys); + assertEquals(2, loaders.get("Primordial").size()); + assertThat(loaders.get("Primordial"), hasItem("Nested Jar File:primordial.jar.model")); + assertEquals(1, loaders.get("Application").size()); + assertThat( + loaders.get("Application").get(0), containsString("com.ibm.wala.core.testdata_1.0.0.jar")); + assertEquals(0, loaders.get("Extension").size()); + assertEquals(0, loaders.get("Synthetic").size()); + } } From ebd73aef3c06426074ab096e778380368a07ea79 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 13 Feb 2024 18:31:36 -0800 Subject: [PATCH 15/24] suppress a warning --- .../test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index c860c0cace..f7541dc3e3 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -82,6 +82,7 @@ public void testToJson() throws IOException { List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); + @SuppressWarnings("unchecked") Map> loaders = (Map>) map.get("Loaders"); Set loaderKeys = new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); From 89359aa664fb95a4cc583922a5633d5da202e554 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 27 Feb 2024 15:45:22 -0800 Subject: [PATCH 16/24] added custom analysisScope test --- .../core/tests/cha/AnalysisScopeTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index f7541dc3e3..49b6fa1b6f 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.jar.JarFile; +import com.ibm.wala.properties.WalaProperties; import org.junit.jupiter.api.Test; public class AnalysisScopeTest { @@ -95,4 +97,45 @@ public void testToJson() throws IOException { assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } + + @Test + public void testToJsonCustom() throws IOException { + AnalysisScope scope; + scope = AnalysisScope.createJavaAnalysisScope(); + AnalysisScope tempScope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + scope.setExclusions(tempScope.getExclusions()); + String[] stdlibs = WalaProperties.getJ2SEJarFiles(); + int cnt = 0; + for (String stdlib : stdlibs) { + scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); + scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); + cnt++; + if(cnt == 5) { + break; + } + } + Gson gson = new Gson(); + Type type = new TypeToken>() {}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + assertEquals( + List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), + map.get("Exclusions")); + + @SuppressWarnings("unchecked") + Map> loaders = (Map>) map.get("Loaders"); + Set loaderKeys = + new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loaderKeys); + assertEquals(5, loaders.get("Primordial").size()); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertEquals(5, loaders.get("Application").size()); + assertThat( + loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertEquals(0, loaders.get("Extension").size()); + assertEquals(0, loaders.get("Synthetic").size()); + } } From ed5500c21b377ac05909635f9adda37afdb57b74 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 27 Feb 2024 16:08:19 -0800 Subject: [PATCH 17/24] sorted stdlib --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 49b6fa1b6f..2cf4db9e17 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -23,6 +23,7 @@ import java.lang.reflect.Type; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -109,6 +110,7 @@ public void testToJsonCustom() throws IOException { AnalysisScopeTest.class.getClassLoader()); scope.setExclusions(tempScope.getExclusions()); String[] stdlibs = WalaProperties.getJ2SEJarFiles(); + Arrays.sort(stdlibs); int cnt = 0; for (String stdlib : stdlibs) { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); @@ -131,10 +133,10 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(5, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(5, loaders.get("Application").size()); assertThat( - loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 7036d90b79ddcd45717d50b20e8019b65fb6164d Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 27 Feb 2024 18:06:59 -0800 Subject: [PATCH 18/24] formatting --- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 2cf4db9e17..15ac0e1a5e 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -16,6 +16,7 @@ import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyFactory; +import com.ibm.wala.properties.WalaProperties; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; import java.io.FileInputStream; @@ -30,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.jar.JarFile; -import com.ibm.wala.properties.WalaProperties; import org.junit.jupiter.api.Test; public class AnalysisScopeTest { @@ -116,7 +116,7 @@ public void testToJsonCustom() throws IOException { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); cnt++; - if(cnt == 5) { + if (cnt == 5) { break; } } @@ -133,10 +133,15 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(5, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertThat( + loaders.get("Primordial"), + hasItem( + "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(5, loaders.get("Application").size()); assertThat( - loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + loaders.get("Application").get(0), + containsString( + "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 9b7b7e91d966c970ba6cd792948efc666088cfe6 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 28 Feb 2024 00:21:59 -0800 Subject: [PATCH 19/24] updated toJson custom test and added onto toJson method --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 27 ++++++++---- .../core/tests/cha/AnalysisScopeTest.java | 41 ++++++++----------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 9450a38498..b3e740925f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -346,27 +346,38 @@ public String toString() { return result.toString(); } + /** + * An AnalysisScope is converted to a JSON formatted variable using the loaders and exclusions + * hierarchy using ToJson. (Loaders) Primordial, Extension, Application, and Synthetic are the + * loaders keys; each one contains an arraylist of Strings. The exclusions contains an arraylist + * of strings. + * + * @return json variable containing contents of the AnalysisScope + */ public String toJson() { LinkedHashMap res = new LinkedHashMap<>(); LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); - for (Module m : getModules(loader)) { arr.add(m.toString()); } loaders.put(loader.getName().toString(), arr); } res.put("Loaders", loaders); - String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); - for (int i = 0; i < exclusions.length; i++) { - String word = exclusions[i]; - word = word.replace("(", ""); - word = word.replace(")", ""); - arr2.add(word); + if (getExclusions() == null) { + res.put("Exclusions", arr2); + } else { + String[] exclusions = getExclusions().toString().split("\\|"); + for (int i = 0; i < exclusions.length; i++) { + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + res.put("Exclusions", arr2); } - res.put("Exclusions", arr2); Gson gson = new Gson(); return gson.toJson(res); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 15ac0e1a5e..baefd5980c 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -103,45 +104,37 @@ public void testToJson() throws IOException { public void testToJsonCustom() throws IOException { AnalysisScope scope; scope = AnalysisScope.createJavaAnalysisScope(); - AnalysisScope tempScope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - scope.setExclusions(tempScope.getExclusions()); String[] stdlibs = WalaProperties.getJ2SEJarFiles(); Arrays.sort(stdlibs); - int cnt = 0; for (String stdlib : stdlibs) { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); - cnt++; - if (cnt == 5) { - break; - } } + scope.setExclusions(null); Gson gson = new Gson(); Type type = new TypeToken>() {}.getType(); LinkedHashMap map = gson.fromJson(scope.toJson(), type); - assertEquals( - List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), - map.get("Exclusions")); + assertEquals(List.of(), map.get("Exclusions")); @SuppressWarnings("unchecked") Map> loaders = (Map>) map.get("Loaders"); Set loaderKeys = new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); - assertEquals(5, loaders.get("Primordial").size()); - assertThat( - loaders.get("Primordial"), - hasItem( - "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); - assertEquals(5, loaders.get("Application").size()); - assertThat( - loaders.get("Application").get(0), - containsString( - "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertEquals(stdlibs.length, loaders.get("Primordial").size()); + assertTrue( + loaders + .get("Primordial") + .get(0) + .contains( + "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertEquals(stdlibs.length, loaders.get("Application").size()); + assertTrue( + loaders + .get("Application") + .get(0) + .contains( + "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From a41401a84fc21e770e10f01ff22864977a464104 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 1 Mar 2024 14:24:03 -0800 Subject: [PATCH 20/24] test out path for stdlibs --- .../test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index baefd5980c..65a68d884d 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,6 +122,7 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); + assertEquals(loaders.get("Primordial").get(0), stdlibs[0]); assertTrue( loaders .get("Primordial") From 8b9c04dee4fdbf1bc1f5185dc8ab5777f96c45aa Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 3 Mar 2024 15:11:27 -0800 Subject: [PATCH 21/24] modified file path to match all machines --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 65a68d884d..ceaedd7694 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,20 +122,19 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertEquals(loaders.get("Primordial").get(0), stdlibs[0]); assertTrue( loaders .get("Primordial") .get(0) .contains( - "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + "/Contents/Home/jmods/java.base.jmod")); assertEquals(stdlibs.length, loaders.get("Application").size()); assertTrue( loaders .get("Application") .get(0) .contains( - "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + "/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 15a4a1e7d7f91793377d1c7bd49f7b03ed730e64 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Mar 2024 11:34:35 -0800 Subject: [PATCH 22/24] formatting --- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index ceaedd7694..2d554dcc02 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,19 +122,9 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertTrue( - loaders - .get("Primordial") - .get(0) - .contains( - "/Contents/Home/jmods/java.base.jmod")); + assertTrue(loaders.get("Primordial").get(0).contains("/Contents/Home/jmods/java.base.jmod")); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertTrue( - loaders - .get("Application") - .get(0) - .contains( - "/Contents/Home/jmods/java.base.jmod")); + assertTrue(loaders.get("Application").get(0).contains("/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From f777f668f67f7058578c017744497ef9876f862d Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 4 Mar 2024 13:52:50 -0800 Subject: [PATCH 23/24] changed assertion in testToJsonCustom --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 2d554dcc02..7901243804 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -122,9 +121,9 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertTrue(loaders.get("Primordial").get(0).contains("/Contents/Home/jmods/java.base.jmod")); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertTrue(loaders.get("Application").get(0).contains("/Contents/Home/jmods/java.base.jmod")); + assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From efad1433d8a2f77d5981937d750ab5ffca73e2e2 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 5 Mar 2024 12:23:52 -0800 Subject: [PATCH 24/24] added for loop in testToJsonCustom (stdlibs) --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 7901243804..8c008c1703 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -121,9 +121,11 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[0])); + for (int i = 0; i < stdlibs.length; i++) { + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[i])); + assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[i])); + } assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); }