Skip to content

Commit a15f700

Browse files
committed
Fixes for issues 61, 62, and 64. New patch marked version v1.0.2.
Signed-off-by: Rahul Krishna <[email protected]>
1 parent e2bbf7d commit a15f700

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.0.1
1+
version=1.0.2

src/main/java/com/ibm/cldk/CodeAnalyzer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class CodeAnalyzer implements Runnable {
6969
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
7070
private static boolean noBuild = false;
7171

72+
@Option(names = {"--no-copy-dependencies"}, description = "Do copy dependencies to a temporary directory.")
73+
private static boolean noCopyDeps = false;
74+
7275

7376
@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1")
7477
private static int analysisLevel = 1;
@@ -119,10 +122,15 @@ private static void analyze() throws Exception {
119122
else {
120123
// download library dependencies of project for type resolution
121124
String dependencies = null;
122-
if (BuildProject.downloadLibraryDependencies(input)) {
123-
dependencies = String.valueOf(BuildProject.libDownloadPath);
125+
126+
if (!noCopyDeps) {
127+
if (BuildProject.downloadLibraryDependencies(input)) {
128+
dependencies = String.valueOf(BuildProject.libDownloadPath);
129+
} else {
130+
Log.warn("Failed to download library dependencies of project");
131+
}
124132
} else {
125-
Log.warn("Failed to download library dependencies of project");
133+
Log.warn("--no-copy-dependencies is activated, skipping library dependencies download");
126134
}
127135
boolean analysisFileExists = output != null && Files.exists(Paths.get(output + File.separator + outputFileName));
128136

src/main/java/com/ibm/cldk/utils/AnalysisUtils.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ public static Pair<String, Callable> createAndPutNewCallableInSymbolTable(IMetho
8686
* @return int Cyclomatic complexity for method/constructor
8787
*/
8888
public static int getCyclomaticComplexity(IR ir) {
89-
int branchCount = (int)Arrays.stream(ir.getInstructions())
90-
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
91-
.count();
92-
return branchCount + 1;
89+
90+
try {
91+
int branchCount = (int)Arrays.stream(ir.getInstructions())
92+
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
93+
.count();
94+
return branchCount + 1;
95+
} catch (NullPointerException nullPointerException) {
96+
Log.error("Null pointer exception in getCyclomaticComplexity");
97+
throw new RuntimeException("Could not get cyclomatic complexity.");
98+
}
9399
}
94100

95101
public static Pair<String, Callable> getCallableFromSymbolTable(IMethod method) {

src/main/java/com/ibm/cldk/utils/BuildProject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public class BuildProject {
1616

1717
public static Path libDownloadPath;
1818
private static final String LIB_DEPS_DOWNLOAD_DIR = "_library_dependencies";
19-
private static final String MAVEN_CMD = System.getProperty("os.name").toLowerCase().contains("windows") ? "mvn.cmd" : "mvn";
19+
private static final String MAVEN_CMD = System.getProperty("os.name").toLowerCase().contains("windows")
20+
? (new File("mvnw.cmd").exists() ? "mvnw.cmd" : "mvn.cmd")
21+
: (new File("mvnw").exists() ? "mvnw" : "mvn");
2022
private static final String GRADLE_CMD = System.getProperty("os.name").toLowerCase().contains("windows") ? "gradlew.bat" : "gradlew";
2123
public static Path tempInitScript;
2224
static {

src/main/java/com/ibm/cldk/utils/ScopeUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public static AnalysisScope createScope(String projectPath, String applicationDe
7575
.map(path -> path.toAbsolutePath().toString())
7676
.toArray(String[]::new);
7777

78+
// Check if stdlibs is empty and throw an exception if true
79+
if (stdlibs.length == 0) {
80+
Log.error("jmods directory not found or no .jmod files present");
81+
throw new RuntimeException("jmods directory not found or no .jmod files present");
82+
}
83+
7884
for (String stdlib : stdlibs) {
7985
scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib));
8086
}
@@ -106,7 +112,7 @@ public static AnalysisScope createScope(String projectPath, String applicationDe
106112

107113
List<Path> applicationClassFiles = BuildProject.buildProjectAndStreamClassFiles(projectPath, build);
108114
Log.debug("Application class files: " + String.valueOf(applicationClassFiles.size()));
109-
if (applicationClassFiles == null) {
115+
if (applicationClassFiles.isEmpty()) {
110116
Log.error("No application classes found.");
111117
throw new RuntimeException("No application classes found.");
112118
}

0 commit comments

Comments
 (0)