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 10, 2024
1 parent 435cd31 commit 26cbd35
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 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 @@ -32,6 +32,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand All @@ -57,6 +58,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 +435,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 @@ -565,13 +581,28 @@ private static List<String> getAllExampleFiles(final List<Path> exampleDirs)
*/
private static void generateAllInOneContent(
final List<String> allExampleFiles,
final Path allInOneSubfolderPath)
throws Exception {
final Path allInOneSubfolderPath
) throws Exception {

// Fail fast if null is not allowed
Objects.requireNonNull(allInOneSubfolderPath, "allInOneSubfolderPath must not be null");

final String templateFilePath = getTemplateFilePathForExamples(allExampleFiles.get(0));
final Path outputFilePath = allInOneSubfolderPath.resolve("config.xml");

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

final Path parent = allInOneSubfolderPath.getParent();
if (parent != null) {
final String parentPath = parent.toString();
if (parentPath.contains(REGEXP_HEADER_MODULE)) {
generatedContent = generatedContent.replace("config/java.header", JAVA_HEADER_FILE);
}
}

Files.writeString(outputFilePath, generatedContent);
}

Expand Down

0 comments on commit 26cbd35

Please sign in to comment.