Skip to content

Commit 2fa0cae

Browse files
committed
Remove dangling file
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 9792b65 commit 2fa0cae

File tree

197 files changed

+6103
-353
lines changed

Some content is hidden

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

197 files changed

+6103
-353
lines changed

build.gradle

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ repositories {
2929
mavenLocal()
3030
}
3131

32+
java {
33+
sourceCompatibility = JavaVersion.VERSION_11
34+
targetCompatibility = JavaVersion.VERSION_11
35+
}
3236

3337
if (project.hasProperty('mainClass')) {
3438
mainClassName = project.getProperty('mainClass')
@@ -119,7 +123,25 @@ dependencies {
119123
implementation('org.jgrapht:jgrapht-ext:1.5.2')
120124
implementation('com.github.javaparser:javaparser-symbol-solver-core:3.25.9')
121125

122-
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
126+
// TestContainers
127+
testImplementation 'org.testcontainers:testcontainers:1.19.3'
128+
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'
129+
130+
// JUnit 5
131+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
132+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.1' // for @ParameterizedTest
133+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
134+
135+
// SLF4J - for TestContainers logging
136+
testImplementation 'org.slf4j:slf4j-api:2.0.9'
137+
testImplementation 'org.slf4j:slf4j-simple:2.0.9'
138+
139+
}
140+
141+
test {
142+
useJUnitPlatform()
143+
// Optional: Enable TestContainers reuse to speed up tests
144+
systemProperty 'testcontainers.reuse.enable', 'true'
123145
}
124146

125147
task fatJar(type: Jar) {

gradle.properties

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

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

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@
99
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
12-
*/
13-
12+
*/
1413
package com.ibm.cldk;
1514

16-
import com.github.javaparser.Problem;
17-
import com.google.common.reflect.TypeToken;
18-
import com.google.gson.*;
19-
import com.ibm.cldk.entities.JavaCompilationUnit;
20-
import com.ibm.cldk.utils.BuildProject;
21-
import com.ibm.cldk.utils.Log;
22-
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
23-
import com.ibm.wala.ipa.cha.ClassHierarchyException;
24-
import org.apache.commons.lang3.tuple.Pair;
25-
import picocli.CommandLine;
26-
import picocli.CommandLine.Command;
27-
import picocli.CommandLine.Option;
28-
2915
import java.io.File;
3016
import java.io.FileReader;
3117
import java.io.FileWriter;
@@ -38,13 +24,32 @@
3824
import java.util.Map;
3925
import java.util.stream.Collectors;
4026

27+
import org.apache.commons.lang3.tuple.Pair;
28+
29+
import com.github.javaparser.Problem;
30+
import com.google.common.reflect.TypeToken;
31+
import com.google.gson.FieldNamingPolicy;
32+
import com.google.gson.Gson;
33+
import com.google.gson.GsonBuilder;
34+
import com.google.gson.JsonElement;
35+
import com.google.gson.JsonObject;
36+
import com.google.gson.JsonParser;
37+
import com.ibm.cldk.entities.JavaCompilationUnit;
38+
import com.ibm.cldk.utils.BuildProject;
39+
import com.ibm.cldk.utils.Log;
40+
41+
import picocli.CommandLine;
42+
import picocli.CommandLine.Command;
43+
import picocli.CommandLine.Option;
4144

4245
class VersionProvider implements CommandLine.IVersionProvider {
46+
4347
public String[] getVersion() throws Exception {
4448
String version = getClass().getPackage().getImplementationVersion();
45-
return new String[]{ version != null ? version : "unknown" };
49+
return new String[]{version != null ? version : "unknown"};
4650
}
4751
}
52+
4853
/**
4954
* The type Code analyzer.
5055
*/
@@ -69,6 +74,8 @@ public class CodeAnalyzer implements Runnable {
6974
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
7075
private static boolean noBuild = false;
7176

77+
@Option(names = {"-f", "--project-root-path"}, description = "Path to the root pom.xml/build.gradle file of the project.")
78+
public static String projectRootPom;
7279

7380
@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1")
7481
private static int analysisLevel = 1;
@@ -83,6 +90,7 @@ public class CodeAnalyzer implements Runnable {
8390
.setPrettyPrinting()
8491
.disableHtmlEscaping()
8592
.create();
93+
8694
/**
8795
* The entry point of application.
8896
*
@@ -108,22 +116,26 @@ private static void analyze() throws Exception {
108116

109117
JsonObject combinedJsonObject = new JsonObject();
110118
Map<String, JavaCompilationUnit> symbolTable;
119+
projectRootPom = projectRootPom == null ? input : projectRootPom;
111120
// First of all if, sourceAnalysis is provided, we will analyze the source code instead of the project.
112121
if (sourceAnalysis != null) {
113122
// Construct symbol table for source code
114123
Log.debug("Single file analysis.");
115124
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult = SymbolTable.extractSingle(sourceAnalysis);
116125
symbolTable = symbolTableExtractionResult.getLeft();
117-
}
118-
119-
else {
126+
} else {
120127
// download library dependencies of project for type resolution
121128
String dependencies = null;
122-
if (BuildProject.downloadLibraryDependencies(input)) {
123-
dependencies = String.valueOf(BuildProject.libDownloadPath);
124-
} else {
129+
try {
130+
if (BuildProject.downloadLibraryDependencies(input, projectRootPom)) {
131+
dependencies = String.valueOf(BuildProject.libDownloadPath);
132+
} else {
133+
Log.warn("Failed to download library dependencies of project");
134+
}
135+
} catch (IllegalStateException illegalStateException) {
125136
Log.warn("Failed to download library dependencies of project");
126137
}
138+
127139
boolean analysisFileExists = output != null && Files.exists(Paths.get(output + File.separator + outputFileName));
128140

129141
// if target files are specified, compute symbol table information for the given files
@@ -132,8 +144,8 @@ private static void analyze() throws Exception {
132144

133145
// if target files specified for analysis level 2, downgrade to analysis level 1
134146
if (analysisLevel > 1) {
135-
Log.warn("Incremental analysis is supported at analysis level 1 only; " +
136-
"performing analysis level 1 for target files");
147+
Log.warn("Incremental analysis is supported at analysis level 1 only; "
148+
+ "performing analysis level 1 for target files");
137149
analysisLevel = 1;
138150
}
139151

@@ -158,12 +170,10 @@ private static void analyze() throws Exception {
158170
}
159171
symbolTable = existingSymbolTable;
160172
}
161-
}
162-
163-
else {
173+
} else {
164174
// construct symbol table for project, write parse problems to file in output directory if specified
165-
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult =
166-
SymbolTable.extractAll(Paths.get(input));
175+
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult
176+
= SymbolTable.extractAll(Paths.get(input));
167177

168178
symbolTable = symbolTableExtractionResult.getLeft();
169179
}
@@ -221,7 +231,8 @@ private static void emit(String consolidatedJSONString) throws IOException {
221231
}
222232

223233
private static Map<String, JavaCompilationUnit> readSymbolTableFromFile(File analysisJsonFile) {
224-
Type symbolTableType = new TypeToken<Map<String, JavaCompilationUnit>>() {}.getType();
234+
Type symbolTableType = new TypeToken<Map<String, JavaCompilationUnit>>() {
235+
}.getType();
225236
try (FileReader reader = new FileReader(analysisJsonFile)) {
226237
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
227238
return gson.fromJson(jsonObject.get("symbol_table"), symbolTableType);
@@ -230,4 +241,4 @@ private static Map<String, JavaCompilationUnit> readSymbolTableFromFile(File ana
230241
}
231242
return null;
232243
}
233-
}
244+
}

0 commit comments

Comments
 (0)