From 32374e3d623ca0169fd4084baa14842c5d101b3e Mon Sep 17 00:00:00 2001 From: piyush kumar sadangi Date: Thu, 16 Jan 2025 11:11:16 +0530 Subject: [PATCH] Issue #219: Support of config bundles with extra configuration files --- Header/all-examples-in-one/java.header | 18 ++++++++ .../extractor/CheckstyleExampleExtractor.java | 42 ++++++++++++------- 2 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 Header/all-examples-in-one/java.header diff --git a/Header/all-examples-in-one/java.header b/Header/all-examples-in-one/java.header new file mode 100644 index 00000000..646d8127 --- /dev/null +++ b/Header/all-examples-in-one/java.header @@ -0,0 +1,18 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// checkstyle: Checks Java source code and other text files for adherence to a set of rules. +// Copyright (C) 2001-2025 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +/////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java b/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java index e0e6a2ba..b97827f5 100644 --- a/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java +++ b/extractor/src/main/java/com/example/extractor/CheckstyleExampleExtractor.java @@ -88,7 +88,7 @@ public final class CheckstyleExampleExtractor { private static final String EXAMPLE4_DIR = "Example4"; /** The name of the Header directory. */ - private static final String HEADER_DIR = "Header"; + private static final String HEADER_MODULE = "Header"; /** Number of expected arguments when processing a single input file. */ private static final int SINGLE_INPUT_FILE_ARG_COUNT = 5; @@ -160,7 +160,7 @@ public static void main(final String[] args) throws Exception { YamlParserAndProjectHandler.processProjectsForExamples(PROJECT_ROOT.toString()); for (final Map.Entry> entry : moduleExamples.entrySet()) { - generateAllInOneConfig(entry.getKey(), entry.getValue()); + generateAllInOneConfig(entry.getKey(), entry.getValue(), checkstyleRepoPath); generateReadmes(entry.getKey(), entry.getValue()); } } @@ -366,7 +366,7 @@ private static boolean containsExampleFile(final Path path) { * * @param inputDir Input directory path * @param checkstyleRepoPath The path to the Checkstyle repository. - * @return Module name if processing was successful, null otherwise + * @return Module name if processing was successful, null otherwise. * @throws Exception If an I/O error occurs */ public static String processDirectory(final String inputDir, @@ -464,7 +464,7 @@ private static void processFile( * (next to config.xml) if it exists. * * @param outputPath The folder where config.xml is placed. - * @param checkstyleRepoPath The path to Checkstyle repository + * @param checkstyleRepoPath The path to Checkstyle repository. * @throws IOException if an I/O error occurs. */ private static void copyJavaHeaderIfNeeded(final Path outputPath, @@ -489,9 +489,9 @@ private static void copyJavaHeaderIfNeeded(final Path outputPath, /** * Checks if the output path requires a java.header file and copies it if needed. * - * @param outputPath The path where config.xml is placed - * @param checkstyleRepoPath The path to Checkstyle repository - * @throws IOException if an I/O error occurs + * @param outputPath The path where config.xml is placed. + * @param checkstyleRepoPath The path to Checkstyle repository. + * @throws IOException if an I/O error occurs. */ private static void handleHeaderFileIfNeeded(final Path outputPath, final String checkstyleRepoPath) @@ -506,7 +506,7 @@ private static void handleHeaderFileIfNeeded(final Path outputPath, .map(Path::toString) .orElse(""); - if (HEADER_DIR.equals(parentName) + if (HEADER_MODULE.equals(parentName) && (EXAMPLE2_DIR.equals(folderName) || EXAMPLE4_DIR.equals(folderName))) { copyJavaHeaderIfNeeded(outputPath, checkstyleRepoPath); @@ -573,12 +573,14 @@ private static void generateReadme(final Path outputPath) throws Exception { * Generate all-in-one configuration for a module. * * @param moduleName Module name - * @param exampleDirs List of example directories - * @throws Exception If an I/O error occurs during generation + * @param exampleDirs List of example directories. + * @param checkstyleRepoPath The path to the Checkstyle repository. + * @throws Exception If an I/O error occurs during generation. */ public static void generateAllInOneConfig( final String moduleName, - final List exampleDirs) + final List exampleDirs, + final String checkstyleRepoPath) throws Exception { final List allExampleFiles = getAllExampleFiles(exampleDirs); final boolean shouldProceed = !allExampleFiles.isEmpty(); @@ -594,7 +596,7 @@ public static void generateAllInOneConfig( Files.createDirectories(allInOneSubfolderPath); generateAllInOneContent(allExampleFiles, allInOneSubfolderPath); - handleAllExamplesInOne(moduleName, allInOneSubfolderPath); + handleAllExamplesInOne(moduleName, allInOneSubfolderPath, checkstyleRepoPath); generateAllInOneReadme(allInOneSubfolderPath, moduleName); } } @@ -642,12 +644,14 @@ private static void generateAllInOneContent( /** * Handles the creation and copying of project files for the "all-examples-in-one" case. * - * @param moduleName The name of the module. + * @param moduleName The name of the module. + * @param checkstyleRepoPath The path to the Checkstyle repository. * @param allInOneSubfolderPath The path to the "all-examples-in-one" subfolder. */ private static void handleAllExamplesInOne( final String moduleName, - final Path allInOneSubfolderPath) { + final Path allInOneSubfolderPath, + final String checkstyleRepoPath) { try { final Map yamlData = YamlParserAndProjectHandler.parseYamlFile(); final Map moduleConfig = (Map) yamlData.get(moduleName); @@ -681,11 +685,21 @@ private static void handleAllExamplesInOne( allProjectLines, moduleName ); + + // Add java.header for Header module's all-in-one examples + if (HEADER_MODULE.equals(moduleName)) { + copyJavaHeaderIfNeeded(allInOneSubfolderPath, checkstyleRepoPath); + } } else { // Copy default properties and YAML files copyDefaultPropertiesFile(allInOneSubfolderPath); copyDefaultYamlFile(allInOneSubfolderPath); + + // Add java.header for Header module's all-in-one examples + if (HEADER_MODULE.equals(moduleName)) { + copyJavaHeaderIfNeeded(allInOneSubfolderPath, checkstyleRepoPath); + } } } catch (IOException ex) {