Skip to content

Commit

Permalink
Remove dangling file
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Krishna <[email protected]>
  • Loading branch information
rahlk committed Feb 3, 2025
1 parent 9792b65 commit 2fa0cae
Show file tree
Hide file tree
Showing 197 changed files with 6,103 additions and 353 deletions.
24 changes: 23 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ repositories {
mavenLocal()
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

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

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
// TestContainers
testImplementation 'org.testcontainers:testcontainers:1.19.3'
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'

// JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.1' // for @ParameterizedTest
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'

// SLF4J - for TestContainers logging
testImplementation 'org.slf4j:slf4j-api:2.0.9'
testImplementation 'org.slf4j:slf4j-simple:2.0.9'

}

test {
useJUnitPlatform()
// Optional: Enable TestContainers reuse to speed up tests
systemProperty 'testcontainers.reuse.enable', 'true'
}

task fatJar(type: Jar) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.1.0
version=2.0.0
73 changes: 42 additions & 31 deletions src/main/java/com/ibm/cldk/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,9 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

*/
package com.ibm.cldk;

import com.github.javaparser.Problem;
import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import com.ibm.cldk.entities.JavaCompilationUnit;
import com.ibm.cldk.utils.BuildProject;
import com.ibm.cldk.utils.Log;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import org.apache.commons.lang3.tuple.Pair;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
Expand All @@ -38,13 +24,32 @@
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Pair;

import com.github.javaparser.Problem;
import com.google.common.reflect.TypeToken;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ibm.cldk.entities.JavaCompilationUnit;
import com.ibm.cldk.utils.BuildProject;
import com.ibm.cldk.utils.Log;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

class VersionProvider implements CommandLine.IVersionProvider {

public String[] getVersion() throws Exception {
String version = getClass().getPackage().getImplementationVersion();
return new String[]{ version != null ? version : "unknown" };
return new String[]{version != null ? version : "unknown"};
}
}

/**
* The type Code analyzer.
*/
Expand All @@ -69,6 +74,8 @@ public class CodeAnalyzer implements Runnable {
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
private static boolean noBuild = false;

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

@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1")
private static int analysisLevel = 1;
Expand All @@ -83,6 +90,7 @@ public class CodeAnalyzer implements Runnable {
.setPrettyPrinting()
.disableHtmlEscaping()
.create();

/**
* The entry point of application.
*
Expand All @@ -108,22 +116,26 @@ private static void analyze() throws Exception {

JsonObject combinedJsonObject = new JsonObject();
Map<String, JavaCompilationUnit> symbolTable;
projectRootPom = projectRootPom == null ? input : projectRootPom;
// First of all if, sourceAnalysis is provided, we will analyze the source code instead of the project.
if (sourceAnalysis != null) {
// Construct symbol table for source code
Log.debug("Single file analysis.");
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult = SymbolTable.extractSingle(sourceAnalysis);
symbolTable = symbolTableExtractionResult.getLeft();
}

else {
} else {
// download library dependencies of project for type resolution
String dependencies = null;
if (BuildProject.downloadLibraryDependencies(input)) {
dependencies = String.valueOf(BuildProject.libDownloadPath);
} else {
try {
if (BuildProject.downloadLibraryDependencies(input, projectRootPom)) {
dependencies = String.valueOf(BuildProject.libDownloadPath);
} else {
Log.warn("Failed to download library dependencies of project");
}
} catch (IllegalStateException illegalStateException) {
Log.warn("Failed to download library dependencies of project");
}

boolean analysisFileExists = output != null && Files.exists(Paths.get(output + File.separator + outputFileName));

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

// if target files specified for analysis level 2, downgrade to analysis level 1
if (analysisLevel > 1) {
Log.warn("Incremental analysis is supported at analysis level 1 only; " +
"performing analysis level 1 for target files");
Log.warn("Incremental analysis is supported at analysis level 1 only; "
+ "performing analysis level 1 for target files");
analysisLevel = 1;
}

Expand All @@ -158,12 +170,10 @@ private static void analyze() throws Exception {
}
symbolTable = existingSymbolTable;
}
}

else {
} else {
// construct symbol table for project, write parse problems to file in output directory if specified
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult =
SymbolTable.extractAll(Paths.get(input));
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult
= SymbolTable.extractAll(Paths.get(input));

symbolTable = symbolTableExtractionResult.getLeft();
}
Expand Down Expand Up @@ -221,7 +231,8 @@ private static void emit(String consolidatedJSONString) throws IOException {
}

private static Map<String, JavaCompilationUnit> readSymbolTableFromFile(File analysisJsonFile) {
Type symbolTableType = new TypeToken<Map<String, JavaCompilationUnit>>() {}.getType();
Type symbolTableType = new TypeToken<Map<String, JavaCompilationUnit>>() {
}.getType();
try (FileReader reader = new FileReader(analysisJsonFile)) {
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
return gson.fromJson(jsonObject.get("symbol_table"), symbolTableType);
Expand All @@ -230,4 +241,4 @@ private static Map<String, JavaCompilationUnit> readSymbolTableFromFile(File ana
}
return null;
}
}
}
Loading

0 comments on commit 2fa0cae

Please sign in to comment.