File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
java/org/checkstyle/autofix
resources/META-INF/rewrite Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ public class CheckstyleAutoFix extends Recipe {
4242 example = "config/checkstyle.xml" )
4343 private String configurationPath ;
4444
45+ @ Option (displayName = "Checkstyle properties file path" ,
46+ description = "Path to the file containing the Checkstyle Properties." ,
47+ example = "config/checkstyle.properties" ,
48+ required = false )
49+ private String propertiesPath ;
50+
4551 @ Override
4652 public String getDisplayName () {
4753 return "Checkstyle autoFix" ;
@@ -60,6 +66,10 @@ public String getConfigurationPath() {
6066 return configurationPath ;
6167 }
6268
69+ public String getPropertiesPath () {
70+ return propertiesPath ;
71+ }
72+
6373 @ Override
6474 public List <Recipe > getRecipeList () {
6575 final List <CheckstyleViolation > violations = CheckstyleReportParser
@@ -69,6 +79,6 @@ public List<Recipe> getRecipeList() {
6979 }
7080
7181 private CheckConfiguration loadCheckstyleConfiguration () {
72- return ConfigurationLoader .loadConfiguration (getConfigurationPath ());
82+ return ConfigurationLoader .loadConfiguration (getConfigurationPath (), getPropertiesPath () );
7383 }
7484}
Original file line number Diff line number Diff line change 1717
1818package org .checkstyle .autofix .parser ;
1919
20+ import java .io .FileInputStream ;
21+ import java .io .IOException ;
2022import java .util .HashMap ;
2123import java .util .List ;
2224import java .util .Map ;
@@ -57,13 +59,26 @@ private static CheckConfiguration mapConfiguration(Configuration config) {
5759 return new CheckConfiguration (config .getName (), properties , List .of (simpleChildren ));
5860 }
5961
60- public static CheckConfiguration loadConfiguration (String checkstyleConfigurationPath ) {
62+ public static CheckConfiguration loadConfiguration (String checkstyleConfigurationPath ,
63+ String propFile ) {
64+ Properties props = new Properties ();
65+ if (propFile == null ) {
66+ props = System .getProperties ();
67+ }
68+ else {
69+ try (FileInputStream input = new FileInputStream (propFile )) {
70+ props .load (input );
71+ }
72+ catch (IOException exception ) {
73+ throw new IllegalStateException ("Failed to read: " + propFile , exception );
74+ }
75+ }
6176
6277 final Configuration checkstyleConfig ;
6378 try {
6479 checkstyleConfig = com .puppycrawl .tools .checkstyle .ConfigurationLoader
6580 .loadConfiguration (checkstyleConfigurationPath ,
66- new PropertiesExpander (new Properties () ));
81+ new PropertiesExpander (props ));
6782 }
6883 catch (CheckstyleException exception ) {
6984 throw new IllegalStateException ("Failed to load configuration:"
Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ recipeList:
1616 - org.checkstyle.autofix.CheckstyleAutoFix :
1717 violationReportPath : " target/checkstyle/checkstyle-report.xml"
1818 configurationPath : " https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle-checks.xml"
19+ propertiesPath : " config/checkstyle.properties"
You can’t perform that action at this time.
0 commit comments