Skip to content

Commit

Permalink
Kantra
Browse files Browse the repository at this point in the history
  • Loading branch information
hhpatel14 committed Nov 17, 2023
1 parent c85e66c commit 4580a96
Show file tree
Hide file tree
Showing 49 changed files with 544 additions and 1,334 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.4'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.4'
implementation 'org.yaml:snakeyaml:1.28'


compile files(new File(buildDir, 'resources/resources')) {
builtBy 'copyResources'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ideaVersion=2020.2
projectVersion=1.2.0
ideaVersion=2020.3
projectVersion=1.3.0
jetBrainsToken=invalid
jetBrainsChannel=stable
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package org.jboss.tools.intellij.windup.cli;

import com.google.common.collect.Lists;
import org.jboss.tools.intellij.windup.model.KantraConfiguration;
import org.jboss.tools.intellij.windup.model.WindupConfiguration;

import java.util.List;
import java.util.Map;

public class KantraCliParamBuilder {

public static List<String> buildParams(KantraConfiguration config, String windupHome) {
public static List<String> buildParams(WindupConfiguration config, String windupHome) {
List<String> params = Lists.newArrayList();
Map<String, Object> options = config.getOptions();
params.add("analyze");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public static class ProgressMessage {
String task = "";
int totalWork = 0;
String value = "";

public ProgressMessage(String op, String task, int totalWork, String value) {
this.op = op;
this.task = task;
this.totalWork = totalWork;
this.value = value;
}
}

private IProgressListener progressListener;
Expand All @@ -35,6 +42,7 @@ public static class ProgressMessage {
private boolean done = false;

public ProgressMonitor(IProgressListener progressListener) {
System.out.println("(((((( This is the progressMonitor ))))))");
this.progressListener = progressListener;
}

Expand Down Expand Up @@ -163,7 +171,7 @@ public static JsonObject parseProgressMessage(String text) {
}

public static ProgressMessage parse(JsonObject json) throws JsonSyntaxException {
ProgressMonitor.ProgressMessage msg = new ProgressMonitor.ProgressMessage();
ProgressMonitor.ProgressMessage msg = new ProgressMonitor.ProgressMessage("","",0,"");
msg.op = json.get("op").getAsString();
if (json.has("value")) {
msg.value = json.get("value").getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,58 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.jboss.tools.intellij.windup.model.KantraConfiguration;

import org.jboss.tools.intellij.windup.model.WindupConfiguration.*;
import org.jboss.tools.intellij.windup.model.WindupConfiguration;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RulesetParser {

public static List<KantraConfiguration.Ruleset> parseRuleset(String resultFilePath){
public static List<Ruleset> parseRuleset(String resultFilePath) {
Thread currentThread = Thread.currentThread();
ClassLoader originalClassLoader = currentThread.getContextClassLoader();
ClassLoader jacksonClassLoader = RulesetParser.class.getClassLoader();

try {
currentThread.setContextClassLoader(jacksonClassLoader);

ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
File yamlFile = new File(resultFilePath);
objectMapper.findAndRegisterModules();
List<KantraConfiguration.Ruleset> ruleSets = objectMapper.readValue(yamlFile, new TypeReference<List<KantraConfiguration.Ruleset>>(){});
List<WindupConfiguration.Ruleset> ruleSets = objectMapper.readValue(
yamlFile, new TypeReference<List<WindupConfiguration.Ruleset>>(){}
);
if (ruleSets != null) {
ruleSets.removeIf(ruleset -> (ruleset.getViolations() == null || ruleset.getViolations().isEmpty() ) );
System.out.println("**************** In Parser --> Size of the ruleSet ***************" + ruleSets.size());
ruleSets.removeIf(ruleset -> (ruleset.getViolations() == null || ruleset.getViolations().isEmpty()));
return ruleSets;
} else {
System.out.println("YAML file is empty or invalid.");
}
} catch (FileNotFoundException e) {
System.err.println("File not found: " + resultFilePath);
System.err.println("File not found : this is the problem ----> " + resultFilePath);
} catch (Exception e) {
System.err.println("Error parsing YAML: " + e.getMessage());
} finally {
currentThread.setContextClassLoader(originalClassLoader);
}
return null;
}
public static void parseRulesetForKantraConfig (KantraConfiguration configuration){

public static void parseRulesetForKantraConfig (WindupConfiguration configuration){
if (configuration.getOptions() != null){
String outputLocation = configuration.getRulesetResultLocation();
configuration.setRulesets(parseRuleset(outputLocation));

if(configuration.getSummary() != null){
configuration.getSummary().setRulesets(parseRuleset(outputLocation));
parseIncidents(configuration.getRulesets(), configuration);
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ size of the Incident $$$$$$$$$$$$$$$");
System.out.println(configuration.getSummary().getIssues().size());
}else {
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ configuration.getSummary() != null $$$$$$$$$$$$$$");
}

}else{
Expand All @@ -45,4 +63,41 @@ public static void parseRulesetForKantraConfig (KantraConfiguration configuratio

}

public static void parseIncidents (List<WindupConfiguration.Ruleset> rulesets, WindupConfiguration configuration) {
if (rulesets != null){
for (WindupConfiguration.Ruleset ruleset: rulesets){
Map<String, Violation> violations = ruleset.getViolations();
if (violations != null ){
for(WindupConfiguration.Violation violation : violations.values()){
List<WindupConfiguration.Incident> incidents = violation.getIncidents();
for (WindupConfiguration.Incident incident : incidents ) {
incident.id = WindupConfiguration.generateUniqueId();
incident.title = violation.getDescription().split("\n", 2)[0];
ArrayList<String> inputs = (ArrayList<String>) configuration.getOptions().get("input");
String input = inputs.get(0);
String filePath = incident.getUri();;
String absolutePath = filePath.substring(filePath.indexOf("/source") + "/source".length());
System.out.println("input: " + input);
System.out.println("File path of the incidents: " + incident.file);
System.out.println("Absolute path: "+input + absolutePath);
incident.file = input + absolutePath;
incident.setUri(input + absolutePath);
incident.effort = String.valueOf(violation.getEffort());
incident.links = violation.getLinks();
incident.category = violation.getCategory();
if (configuration.getSummary().completeIssues.contains(incident.id)) {
incident.complete = true;
}
incident.configuration = configuration;
configuration.getSummary().incidents.add(incident);
}
}
}
}

}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public RunAnalysisCommandHandler(Project project,
this.project = project;
this.console = console;
commandLine = new GeneralCommandLine();
commandLine.setExePath(executable);
commandLine.setExePath("kantra");
commandLine.addParameters(params);
System.out.println("This is RunAnalysis Command handler............. constructor");
System.out.println(onComplete.toString());
this.progressMonitor = new ProgressMonitor(this.createProgressListener(onComplete));
}

Expand Down Expand Up @@ -81,6 +83,7 @@ public void run(final ProgressIndicator indicator) {
progressIndicator.setFraction(0.01);
handler.waitFor();
logTime();
System.out.println("This is the end of the runAnlysis");
}
catch (Exception e) {
e.printStackTrace();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.CharsetToolkit;
import org.jboss.tools.intellij.windup.explorer.actions.RunConfigurationAction;
Expand All @@ -25,6 +26,8 @@ public class WindupCliProcessHandler extends OSProcessHandler {
private WindupConsole console;
private boolean isCancelled = false;

int i = 0;

public WindupCliProcessHandler(
Process process,
GeneralCommandLine commandLine,
Expand All @@ -40,6 +43,11 @@ public WindupCliProcessHandler(

@Override
public final void notifyTextAvailable(@NotNull String text, @NotNull final Key outputType) {

if(i <= 10){
System.out.println ("This is output from Kantra -----------------------> " + text);
}
i++;
if (progressIndicator.isCanceled()) {
destroyProcess();
RunConfigurationAction.running = false;
Expand All @@ -61,6 +69,28 @@ else if (text.contains("Reading tags definitions")) {
else if (text.contains("Finished provider load")) {
progressIndicator.setText("Loading transformation paths...");
}
else if (text.contains("rules parsed")) {
progressIndicator.setText("Parsing rules...");
progressIndicator.setFraction(0.10);
}
else if (text.contains("rule response received")) {
progressIndicator.setText("Running Analysis...");
progressIndicator.setFraction(0.25);
}
else if (text.contains("running dependency analysis")) {
progressIndicator.setText("Running Dependency Analysis...");
progressIndicator.setFraction(0.75);
}
else if (text.contains("generating static report")) {
progressIndicator.setText("Generating static report...");
progressIndicator.setFraction(0.95);
}
else if (text.contains("Static report created.")) {
System.out.println(text + "---------------------------------------: detected ");
ProgressMonitor.ProgressMessage msg = new ProgressMonitor.ProgressMessage("complete", "", 20, "");
progressMonitor.handleMessage(msg);
progressIndicator.setFraction(1);
}
else if (text.contains(PROGRESS)) {
JsonObject json = ProgressMonitor.parseProgressMessage(text);
if (json != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import com.google.common.collect.Maps;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.exec.*;
import org.jboss.tools.intellij.windup.model.WindupConfiguration;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.jboss.tools.intellij.windup.cli.ProgressMonitor.PROGRESS;

public class WindupCliRunner {

private static final String JAVA_HOME = "JAVA_HOME";
Expand All @@ -30,14 +27,14 @@ public static void run(WindupConfiguration configuration,
ProgressMonitor progressMonitor,
CliListener listener) {
String javaHome = "";
String windupCli = (String)configuration.getOptions().get("cli");
List<String> params = WindupCliParamBuilder.buildParams(configuration, windupCli);
String windupCli = "kantra";
List<String> params = KantraCliParamBuilder.buildParams(configuration, windupCli);
WindupCliRunner.executeAnalysis(windupCli, javaHome, params, progressMonitor, listener);
}

private static void executeAnalysis(String cli, String javaHome, List<String> params, ProgressMonitor progressMonitor, CliListener listener) {
System.out.println("execute CLI");
CommandLine cmdLine = CommandLine.parse(cli);
CommandLine cmdLine = CommandLine.parse("kantra");
Map<String, String> env = Maps.newHashMap();
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
env.put(entry.getKey(), entry.getValue());
Expand Down
Loading

0 comments on commit 4580a96

Please sign in to comment.