Skip to content

Commit

Permalink
Merge pull request #239 from hhpatel14/kantraModel
Browse files Browse the repository at this point in the history
Parse YAML Output to Generate Rulesets List
  • Loading branch information
johnsteele authored Nov 8, 2023
2 parents c6c1180 + 335c786 commit c85e66c
Show file tree
Hide file tree
Showing 7 changed files with 3,093 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ dependencies {
implementation 'commons-io:commons-io:2.6'
implementation 'io.vertx:vertx-core:3.9.4'
implementation 'io.vertx:vertx-web:3.9.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
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 All @@ -47,6 +50,7 @@ publishPlugin {
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url 'https://repository.jboss.org'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package org.jboss.tools.intellij.windup.cli;

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

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

public class KantraCliParamBuilder {

public static List<String> buildParams(KantraConfiguration config, String windupHome) {
List<String> params = Lists.newArrayList();
Map<String, Object> options = config.getOptions();
params.add("analyze");

// input
params.add("--input");
List<String> input = (List<String>)options.get("input");
input.forEach(path -> params.add(path));

// output
params.add("--output");
String output = (String)options.get("output");
params.add(output);

// target
List<String> target = (List<String>)options.get("target");
if (target == null || target.isEmpty()) {
target = Lists.newArrayList();
target.add("eap7");
}
params.add("--target");

for (String aTarget : target) {
params.add(aTarget);
}
// params.add(String.join(",", target));

return params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jboss.tools.intellij.windup.cli;

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 java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

public class RulesetParser {

public static List<KantraConfiguration.Ruleset> parseRuleset(String resultFilePath){

try {
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>>(){});
if (ruleSets != null) {
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);
} catch (Exception e) {
System.err.println("Error parsing YAML: " + e.getMessage());
}
return null;
}
public static void parseRulesetForKantraConfig (KantraConfiguration configuration){
if (configuration.getOptions() != null){
String outputLocation = configuration.getRulesetResultLocation();
configuration.setRulesets(parseRuleset(outputLocation));
if(configuration.getSummary() != null){
configuration.getSummary().setRulesets(parseRuleset(outputLocation));
}

}else{
System.out.println("Error parsing Ruleset at: " + configuration.getRulesetResultLocation());
}

}

}
Loading

0 comments on commit c85e66c

Please sign in to comment.