Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/org/checkstyle/autofix/CheckstyleAutoFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class CheckstyleAutoFix extends Recipe {
example = "config/checkstyle.xml")
private String configurationPath;

@Option(displayName = "Checkstyle properties file path",
description = "Path to the file containing the Checkstyle Properties.",
example = "config/checkstyle.properties",
required = false)
private String propertiesPath;

@Override
public String getDisplayName() {
return "Checkstyle autoFix";
Expand All @@ -60,6 +66,10 @@ public String getConfigurationPath() {
return configurationPath;
}

public String getPropertiesPath() {
return propertiesPath;
}

@Override
public List<Recipe> getRecipeList() {
final List<CheckstyleViolation> violations = CheckstyleReportParser
Expand All @@ -69,6 +79,6 @@ public List<Recipe> getRecipeList() {
}

private CheckConfiguration loadCheckstyleConfiguration() {
return ConfigurationLoader.loadConfiguration(getConfigurationPath());
return ConfigurationLoader.loadConfiguration(getConfigurationPath(), getPropertiesPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.checkstyle.autofix.parser;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -57,13 +59,26 @@ private static CheckConfiguration mapConfiguration(Configuration config) {
return new CheckConfiguration(config.getName(), properties, List.of(simpleChildren));
}

public static CheckConfiguration loadConfiguration(String checkstyleConfigurationPath) {
public static CheckConfiguration loadConfiguration(String checkstyleConfigurationPath,
String propFile) {
Properties props = new Properties();
if (propFile == null) {
props = System.getProperties();
}
else {
try (FileInputStream input = new FileInputStream(propFile)) {
props.load(input);
}
catch (IOException exception) {
throw new IllegalStateException("Failed to read: " + propFile, exception);
}
}

final Configuration checkstyleConfig;
try {
checkstyleConfig = com.puppycrawl.tools.checkstyle.ConfigurationLoader
.loadConfiguration(checkstyleConfigurationPath,
new PropertiesExpander(new Properties()));
new PropertiesExpander(props));
}
catch (CheckstyleException exception) {
throw new IllegalStateException("Failed to load configuration:"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/rewrite/recipes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ recipeList:
- org.checkstyle.autofix.CheckstyleAutoFix:
violationReportPath: "target/checkstyle/checkstyle-report.xml"
configurationPath: "https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle-checks.xml"
propertiesPath: "config/checkstyle.properties"
Loading