Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

analysisScope toJson function #1355

Merged
merged 29 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1187f33
added toJson function to AnalysisScope
aakgna Nov 20, 2023
3a90899
added one successful test for toJson in Analysis Scope
aakgna Nov 28, 2023
6c81529
added json capability
aakgna Dec 5, 2023
163aa8e
implemented toJson functionality
aakgna Dec 23, 2023
6f69ce9
returned right value
aakgna Dec 23, 2023
307607a
added changes to toJson
aakgna Jan 3, 2024
cb5dd7b
returned correct value
aakgna Jan 4, 2024
b489343
changes .settings
aakgna Jan 13, 2024
a38c5b7
removed unnecessary changes
aakgna Jan 23, 2024
ab16227
Merge branch 'wala:master' into master
aakgna Jan 23, 2024
a43b836
Merge branch 'wala:master' into master
aakgna Jan 30, 2024
6d15461
added linkedHashmap to AnalysisScope and created test for toJson
aakgna Jan 30, 2024
e57b590
deleted unnecessary lines
aakgna Jan 30, 2024
0f8f978
Merge branch 'wala:master' into master
aakgna Feb 11, 2024
c237c76
implemented changes for toJson and added endlines
aakgna Feb 12, 2024
fbe9c59
completed changes for AnalysisScopeTest and removed 1 import statemen…
aakgna Feb 13, 2024
3cfff82
Tune up test and fix formatting
msridhar Feb 14, 2024
ebd73ae
suppress a warning
msridhar Feb 14, 2024
89359aa
added custom analysisScope test
aakgna Feb 27, 2024
ed5500c
sorted stdlib
aakgna Feb 28, 2024
7036d90
formatting
msridhar Feb 28, 2024
9b7b7e9
updated toJson custom test and added onto toJson method
aakgna Feb 28, 2024
a41401a
test out path for stdlibs
aakgna Mar 1, 2024
c7707eb
Merge branch 'master' into master
aakgna Mar 3, 2024
8b9c04d
modified file path to match all machines
aakgna Mar 3, 2024
15a4a1e
formatting
msridhar Mar 4, 2024
7729aa7
Merge branch 'master' into aakgna/master
msridhar Mar 4, 2024
f777f66
changed assertion in testToJsonCustom
aakgna Mar 4, 2024
efad143
added for loop in testToJsonCustom (stdlibs)
aakgna Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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)
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@
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;
import java.util.LinkedHashMap;
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.
Expand Down Expand Up @@ -345,6 +348,30 @@ public String toString() {
return result.toString();
}

public String toJson() {
aakgna marked this conversation as resolved.
Show resolved Hide resolved
LinkedHashMap<String, Object> res = new LinkedHashMap<>();
LinkedHashMap<String, ArrayList<String>> loaders = new LinkedHashMap<>();
for (ClassLoaderReference loader : loadersByName.values()) {
ArrayList<String> arr = new ArrayList<>();
for (Module m : getModules(loader)) {
arr.add(m.toString());
}
msridhar marked this conversation as resolved.
Show resolved Hide resolved
loaders.put(loader.getName().toString(), arr);
}
res.put("Loaders", loaders);
String[] exclusions = getExclusions().toString().split("\\|");
ArrayList<String> arr2 = new ArrayList<>();
for(int i = 0; i < exclusions.length; i++){
String word = exclusions[i];
word = word.replace("(", "");
word = word.replace(")", "");
arr2.add(word);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, way to go the extra mile to parse the exclusions!

res.put("Exclusions", arr2);
Gson gson = new Gson();
return gson.toJson(res);
}

/**
* @return a String that describes exclusions from the analysis scope.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,4 @@ public boolean hasEdge(MethodReference src, MethodReference dst) {
}
};
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not addressed

Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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\\\\/.*\"]}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking better! But I expect this test will not pass in general, since we have absolute paths in it. So I guess a straightforward string comparison won't work. Here's an alternate approach:

  1. Call scope.toJson() to get the JSON string
  2. Re-parse this String using Gson
  3. Check that specific parts of the resulting Map match what we expect

Can you try that? Let me know if it doesn't make sense

assertEquals(exp, scope.toJson().toString());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this change

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
zipStorePath=wrapper/dists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this change

Loading