From 18fbd83cdf2fa72e7fca00df47f37d0a9ede9121 Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Tue, 12 Nov 2024 23:16:10 +0530 Subject: [PATCH] Issue 214: Support of config bundles with extra configuration files --- RegexpHeader/Example2/config.xml | 2 +- RegexpHeader/Example2/extra-config-files.txt | 1 + .../extractor/CheckstyleExampleExtractor.java | 29 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 RegexpHeader/Example2/extra-config-files.txt diff --git a/RegexpHeader/Example2/config.xml b/RegexpHeader/Example2/config.xml index a43216ec1..4786176d8 100644 --- a/RegexpHeader/Example2/config.xml +++ b/RegexpHeader/Example2/config.xml @@ -17,7 +17,7 @@ - + diff --git a/RegexpHeader/Example2/extra-config-files.txt b/RegexpHeader/Example2/extra-config-files.txt new file mode 100644 index 000000000..93925e67c --- /dev/null +++ b/RegexpHeader/Example2/extra-config-files.txt @@ -0,0 +1 @@ +java.header \ No newline at end of file diff --git a/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java b/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java index de14e8acd..f6c21a3d8 100644 --- a/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java +++ b/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java @@ -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"; @@ -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); @@ -570,8 +585,18 @@ 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.getParent() != null + && allInOneSubfolderPath.getParent().toString().contains(REGEXP_HEADER_MODULE)) { + generatedContent = generatedContent.replace( + "config/java.header", + JAVA_HEADER_FILE + ); + } + Files.writeString(outputFilePath, generatedContent); }