Skip to content

Commit

Permalink
Issue 214: Support of config bundles with extra configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush kumar sadangi authored and piyush kumar sadangi committed Dec 9, 2024
1 parent 435cd31 commit e1c5904
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RegexpHeader/Example2/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</module>

<module name="RegexpHeader">
<property name="headerFile" value="config/java.header"/>
<property name="headerFile" value="java.header"/>
<property name="multiLines" value="10, 13"/>
</module>

Expand Down
1 change: 1 addition & 0 deletions RegexpHeader/Example2/extra-config-files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java.header
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public final class CheckstyleExampleExtractor {
/** The root directory of the project. */
private static final Path PROJECT_ROOT = Paths.get("").toAbsolutePath().getParent();

/** The constant for RegexHeader module. */
private static final String REGEXP_HEADER_MODULE = "regexpheader/Example2";

/** The constant for extra config file for RegexHeader. */
private static final String JAVA_HEADER_FILE = "java.header";

/** The filename for project properties. */
private static final String PROJ_PROP_FILENAME = "list-of-projects.properties";

Expand Down Expand Up @@ -428,8 +434,17 @@ private static void processFile(
try {
final String templateFilePath = getTemplateFilePathForExamples(exampleFile);
if (templateFilePath != null) {
final String generatedContent =
String generatedContent =
ConfigSerializer.serializeConfigToString(exampleFile, templateFilePath);

// Special case handling for RegexpHeader/Example2 having external config
if (exampleFile.contains(REGEXP_HEADER_MODULE)) {
generatedContent = generatedContent.replace(
"config/java.header",
JAVA_HEADER_FILE
);
}

writeConfigFile(outputPath, generatedContent);
copyPropertiesFile(outputPath);
generateReadme(outputPath);
Expand Down Expand Up @@ -570,8 +585,19 @@ private static void generateAllInOneContent(
final String templateFilePath = getTemplateFilePathForExamples(allExampleFiles.get(0));
final Path outputFilePath = allInOneSubfolderPath.resolve("config.xml");

final String generatedContent = ConfigSerializer.serializeAllInOneConfigToString(
String generatedContent = ConfigSerializer.serializeAllInOneConfigToString(
allExampleFiles.toArray(new String[0]), templateFilePath);

// Special case handling for RegexpHeader/Example2 in all-in-one config
if (allInOneSubfolderPath != null
&& allInOneSubfolderPath.getParent() != null
&& allInOneSubfolderPath.getParent().toString().contains(REGEXP_HEADER_MODULE)) {
generatedContent = generatedContent.replace(
"config/java.header",
JAVA_HEADER_FILE
);
}

Files.writeString(outputFilePath, generatedContent);
}

Expand Down

0 comments on commit e1c5904

Please sign in to comment.