Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #219: Support of config bundles with extra configuration files #226

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Header/all-examples-in-one/java.header
Original file line number Diff line number Diff line change
@@ -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
///////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,7 +160,7 @@ public static void main(final String[] args) throws Exception {
YamlParserAndProjectHandler.processProjectsForExamples(PROJECT_ROOT.toString());

for (final Map.Entry<String, List<Path>> entry : moduleExamples.entrySet()) {
generateAllInOneConfig(entry.getKey(), entry.getValue());
generateAllInOneConfig(entry.getKey(), entry.getValue(), checkstyleRepoPath);
generateReadmes(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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<Path> exampleDirs)
final List<Path> exampleDirs,
final String checkstyleRepoPath)
throws Exception {
final List<String> allExampleFiles = getAllExampleFiles(exampleDirs);
final boolean shouldProceed = !allExampleFiles.isEmpty();
Expand All @@ -594,7 +596,7 @@ public static void generateAllInOneConfig(
Files.createDirectories(allInOneSubfolderPath);

generateAllInOneContent(allExampleFiles, allInOneSubfolderPath);
handleAllExamplesInOne(moduleName, allInOneSubfolderPath);
handleAllExamplesInOne(moduleName, allInOneSubfolderPath, checkstyleRepoPath);
generateAllInOneReadme(allInOneSubfolderPath, moduleName);
}
}
Expand Down Expand Up @@ -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<String, Object> yamlData = YamlParserAndProjectHandler.parseYamlFile();
final Map<String, Object> moduleConfig = (Map<String, Object>) yamlData.get(moduleName);
Expand Down Expand Up @@ -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) {
Expand Down
Loading