-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from hhpatel14/kantraModel
Parse YAML Output to Generate Rulesets List
- Loading branch information
Showing
7 changed files
with
3,093 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/jboss/tools/intellij/windup/cli/KantraCliParamBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/jboss/tools/intellij/windup/cli/RulesetParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.