Skip to content

Commit f1fbf63

Browse files
authored
Merge pull request #1 from rahlk/main
Update codeanalyzer to use graalvm
2 parents ae88577 + f09e014 commit f1fbf63

File tree

250 files changed

+3265
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+3265
-2
lines changed

.gitignore

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# User-specific stuff
2+
.idea
3+
.idea/**/workspace.xml
4+
.idea/**/tasks.xml
5+
.idea/**/usage.statistics.xml
6+
.idea/**/dictionaries
7+
.idea/**/shelf
8+
9+
# AWS User-specific
10+
.idea/**/aws.xml
11+
12+
# Generated files
13+
.idea/**/contentModel.xml
14+
15+
# Sensitive or high-churn files
16+
.idea/**/dataSources/
17+
.idea/**/dataSources.ids
18+
.idea/**/dataSources.local.xml
19+
.idea/**/sqlDataSources.xml
20+
.idea/**/dynamic.xml
21+
.idea/**/uiDesigner.xml
22+
.idea/**/dbnavigator.xml
23+
24+
# Gradle
25+
.idea/**/gradle.xml
26+
.idea/**/libraries
27+
28+
# Gradle and Maven with auto-import
29+
# When using Gradle or Maven with auto-import, you should exclude module files,
30+
# since they will be recreated, and may cause churn. Uncomment if using
31+
# auto-import.
32+
# .idea/artifacts
33+
# .idea/compiler.xml
34+
# .idea/jarRepositories.xml
35+
# .idea/modules.xml
36+
# .idea/*.iml
37+
# .idea/modules
38+
# *.iml
39+
# *.ipr
40+
41+
# CMake
42+
cmake-build-*/
43+
44+
# Mongo Explorer plugin
45+
.idea/**/mongoSettings.xml
46+
47+
# File-based project format
48+
*.iws
49+
50+
# IntelliJ
51+
out/
52+
53+
# mpeltonen/sbt-idea plugin
54+
.idea_modules/
55+
56+
# JIRA plugin
57+
atlassian-ide-plugin.xml
58+
59+
# Cursive Clojure plugin
60+
.idea/replstate.xml
61+
62+
# SonarLint plugin
63+
.idea/sonarlint/
64+
65+
# Crashlytics plugin (for Android Studio and IntelliJ)
66+
com_crashlytics_export_strings.xml
67+
crashlytics.properties
68+
crashlytics-build.properties
69+
fabric.properties
70+
71+
# Editor-based Rest Client
72+
.idea/httpRequests
73+
74+
# Android studio 3.1+ serialized cache file
75+
.idea/caches/build_file_checksums.ser
76+
77+
### Intellij Patch ###
78+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
79+
80+
# *.iml
81+
# modules.xml
82+
# .idea/misc.xml
83+
# *.ipr
84+
85+
# Sonarlint plugin
86+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
87+
.idea/**/sonarlint/
88+
89+
# SonarQube Plugin
90+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
91+
.idea/**/sonarIssues.xml
92+
93+
# Markdown Navigator plugin
94+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
95+
.idea/**/markdown-navigator.xml
96+
.idea/**/markdown-navigator-enh.xml
97+
.idea/**/markdown-navigator/
98+
99+
# Cache file creation bug
100+
# See https://youtrack.jetbrains.com/issue/JBR-2257
101+
.idea/$CACHE_FILE$
102+
103+
# CodeStream plugin
104+
# https://plugins.jetbrains.com/plugin/12206-codestream
105+
.idea/codestream.xml
106+
107+
# Azure Toolkit for IntelliJ plugin
108+
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
109+
.idea/**/azureSettings.xml
110+
111+
### Java ###
112+
# Compiled class file
113+
*.class
114+
115+
# Log file
116+
*.log
117+
118+
# BlueJ files
119+
*.ctxt
120+
121+
# Mobile Tools for Java (J2ME)
122+
.mtj.tmp/
123+
124+
# Package Files #
125+
*.jar
126+
*.war
127+
*.nar
128+
*.ear
129+
*.zip
130+
*.tar.gz
131+
*.rar
132+
133+
# Don't ignore the demo binaries
134+
!etc/demo/jar/*.jar
135+
!etc/demo/ear/*.ear
136+
!etc/demo/war/*.war
137+
138+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
139+
hs_err_pid*
140+
replay_pid*
141+
142+
### VisualStudioCode ###
143+
.vscode/*
144+
145+
!src/test/resources/sample_apps/daytrader8/binaries/daytrader8.jar
146+
src/test/resources/sample_apps/daytrader8/output
147+
148+
# Local History for Visual Studio Code
149+
.history/
150+
151+
# Built Visual Studio Code Extensions
152+
*.vsix
153+
154+
### VisualStudioCode Patch ###
155+
# Ignore all local history of files
156+
.history
157+
.ionide
158+
159+
# Support for Project snippet scope
160+
.vscode/*.code-snippets
161+
162+
# Ignore code-workspaces
163+
*.code-workspace
164+
165+
### Gradle ###
166+
.gradle
167+
**/build/
168+
!src/**/build/
169+
170+
# Ignore Gradle GUI config
171+
gradle-app.setting
172+
173+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
174+
!gradle-wrapper.jar
175+
176+
# Avoid ignore Gradle wrappper properties
177+
!gradle-wrapper.properties
178+
179+
# Cache of project
180+
.gradletasknamecache
181+
182+
# Eclipse Gradle plugin generated files
183+
# Eclipse Core
184+
.project
185+
# JDT-specific (Eclipse Java Development Tools)
186+
.classpath
187+
188+
### Gradle Patch ###
189+
# Java heap dump
190+
*.hprof
191+
192+
# End of https://www.toptal.com/developers/gitignore/api/intellij,gradle,java,visualstudiocode
193+
.idea
194+
.DS_Store
195+
.vscode
196+
bin/
197+
etc/
198+
/src/test/resources/sample_apps/daytrader8/output/

LICENSE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright IBM Corporation 2023, 2024
2+
3+
Licensed under the Apache Public License 2.0, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.

README.md

Lines changed: 183 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,183 @@
1-
# codenet-minerva-code-analyzer
2-
Java source code (and/or binary) to JSON based system dependency graph generator.
1+
#
2+
3+
![logo](./docs/assets/logo.png)
4+
5+
Native WALA implementation of source code analysis tool for Enterprise Java Applications.
6+
7+
## 1. Prerequisites
8+
9+
Before you begin, ensure you have met the following requirements:
10+
11+
* You have a Linux/MacOS/WSL machine.
12+
* You have installed the latest version of [SDKMan!](sdkman.io/)
13+
14+
### 1.1. Install SDKMan!
15+
1. Install SDKMan!
16+
Open your terminal and enter the following command:
17+
18+
```bash
19+
curl -s "https://get.sdkman.io" | bash
20+
```
21+
22+
Follow the on-screen instructions to complete the installation.
23+
24+
2. Open a new terminal or source the SDKMan! scripts:
25+
26+
```bash
27+
source "$HOME/.sdkman/bin/sdkman-init.sh"
28+
```
29+
30+
## 2. Building `codeanalyzer`
31+
32+
### 2.1. Install Java 11 or above
33+
34+
1. You can list all available GraalVM versions with:
35+
36+
```bash
37+
sdk list java | grep sem
38+
```
39+
You should see the following:
40+
```
41+
Semeru | | 21.0.2 | sem | | 21.0.2-sem
42+
| | 21.0.1 | sem | | 21.0.1-sem
43+
| | 17.0.10 | sem | | 17.0.10-sem
44+
| | 17.0.9 | sem | | 17.0.9-sem
45+
| | 11.0.22 | sem | installed | 11.0.22-sem
46+
| | 11.0.21 | sem | | 11.0.21-sem
47+
```
48+
49+
2. Install Java 11 or above (we'll go with 17.0.10-sem):
50+
51+
```bash
52+
sdk install java 17.0.10-sem
53+
```
54+
55+
3. Set Java 17 as the current Java version:
56+
57+
```bash
58+
sdk use java 17.0.10-sem
59+
```
60+
61+
### 2.2. Build `codeanalyzer`
62+
63+
Clone the repository (if you haven't already) and navigate into the cloned directory.
64+
65+
Run the Gradle wrapper script to build the project. This will compile the project using GraalVM native image.
66+
67+
```bash
68+
./gradlew fatJar
69+
```
70+
71+
### 2.3. Using `codeanalyzer`
72+
73+
The jar will be built at `build/libs/codeanalyzer-1.0.jar`. It may be used as follows:
74+
75+
```help
76+
Usage: java -jar /path/to/codeanalyzer-1.0.jar [-hqV] [-d=<appDeps>] [-e=<extraLibs>] -i=<input>
77+
-o=<outDir>
78+
Convert java binary (*.jar, *.ear, *.war) to a neo4j graph.
79+
-d, --app-deps=<appDeps> Path to the application dependencies.
80+
-e, --extra-libs=<extraLibs>
81+
Path to the extra libraries.
82+
-h, --help Show this help message and exit.
83+
-i, --input=<input> Path to the input jar(s).
84+
-o, --output=<outDir> Destination directory to save the output graphs.
85+
-q, --quiet Don't print logs to console.
86+
-V, --version Print version information and exit.
87+
```
88+
89+
90+
## 3. Installing `codeanalyzer` as a native binary (once built, no JVM will be required for running `codeanalyzer`)
91+
92+
To install `codeanalyzer`, follow these steps:
93+
94+
### 3.1. Install GraalVM using SDKMan
95+
96+
1. You can list all available GraalVM versions with:
97+
98+
```bash
99+
sdk list java | grep graal
100+
```
101+
102+
2. Install GraalVM 17 or above (we'll go with 21.0.2-graalce):
103+
104+
```bash
105+
sdk install java 21.0.2-graalce
106+
```
107+
108+
3. Set GraalVM 21 as the current Java version:
109+
110+
```bash
111+
sdk use java 21.0.2-graalce
112+
```
113+
114+
### 3.2. Build the Project
115+
116+
Clone the repository (if you haven't already) and navigate into the cloned directory.
117+
118+
Run the Gradle wrapper script to build the project. This will compile the project using GraalVM native image.
119+
120+
```bash
121+
./gradlew nativeCompile -PbinDir=$HOME/.local/bin
122+
```
123+
124+
**Note: `-PbinDir` is optional. If not provided, this command places the binaries in `build/bin`.**
125+
126+
### 3.3. Using `codeanalyzer`
127+
128+
Assuming the path you provided in `-PbinDir` (in my case `$HOME/.local/bin`) is in your `$PATH`, after installation, you can use `codeanalyzer` by following the below format:
129+
130+
```help
131+
Usage: codeanalyzer [-hqV] [-d=<appDeps>] [-e=<extraLibs>] -i=<input>
132+
-o=<outDir>
133+
Convert java binary (*.jar, *.ear, *.war) to a neo4j graph.
134+
-d, --app-deps=<appDeps> Path to the application dependencies.
135+
-e, --extra-libs=<extraLibs>
136+
Path to the extra libraries.
137+
-h, --help Show this help message and exit.
138+
-i, --input=<input> Path to the input jar(s).
139+
-o, --output=<outDir> Destination directory to save the output graphs.
140+
-q, --quiet Don't print logs to console.
141+
-V, --version Print version information and exit.
142+
```
143+
144+
There is a sample application in `src/test/resources/sample_apps/daytrader8/binaries/`. You can use this to test the tool.
145+
146+
```sh
147+
codeanalyzer -i src/test/resources/sample_apps/daytrader8/binaries/
148+
```
149+
150+
This will produce print the SDG on the console. Explore other flags to save the output to a JSON.
151+
152+
## FAQ
153+
154+
1. After making a few code changes, my native binary gives random exceptions. But, my code works perfectly with `java -jar`.
155+
156+
The `reflect-config.json` is most likely out of date. Plese follow the below instructions:
157+
158+
a. Build the fatjar using `./gradlew fatJar`
159+
160+
b. Run the following
161+
162+
```sh
163+
java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image-config -jar build/libs/codeanalyzer-1.0.jar -i src/test/resources/sample.applications/daytrader8/source -a 2 -v
164+
```
165+
166+
c. Then build using the instructions in [§3.3](./README.md#33-build-the-project).
167+
168+
The problem should be resolved.
169+
170+
## LICENSE
171+
172+
```LICENSE
173+
Copyright IBM Corporation 2023, 2024
174+
175+
Licensed under the Apache Public License 2.0, Version 2.0 (the "License");
176+
you may not use this file except in compliance with the License.
177+
178+
Unless required by applicable law or agreed to in writing, software
179+
distributed under the License is distributed on an "AS IS" BASIS,
180+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181+
See the License for the specific language governing permissions and
182+
limitations under the License.
183+
```

0 commit comments

Comments
 (0)