From 72a7a856c6237aef5835abe036d016ec5a0fcee7 Mon Sep 17 00:00:00 2001 From: jycr Date: Mon, 10 Jul 2023 16:33:39 +0200 Subject: [PATCH] Removes metadata for rules not available in corresponding language --- ecocode-rules-specifications/pom.xml | 65 ++++++------------- .../src/main/script/prepare-resources.groovy | 33 ++++++++++ 2 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 ecocode-rules-specifications/src/main/script/prepare-resources.groovy diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml index 6dee12f0d..d1857eb63 100644 --- a/ecocode-rules-specifications/pom.xml +++ b/ecocode-rules-specifications/pom.xml @@ -65,6 +65,11 @@ - syntax highlighting (see code blocks on ASCIIDOC rules) - inclusions (see: php/EC74.asciidoc) - table data generation from CSV (see: php/EC34.asciidoc) + + NB: Current version has a bug which display following false positive warning : + [WARNING] Duplicated destination found: overwriting file ... + + This issue is fixed in 3.x release of asciidoctor-maven-plugin --> org.asciidoctor asciidoctor-maven-plugin @@ -78,12 +83,13 @@ ${project.basedir}/src/main/rules - ${project.build.directory}/rules + ${project.build.directory}/rules-html coderay style true + true false true @@ -97,57 +103,24 @@ - org.apache.maven.plugins - maven-antrun-plugin - 3.1.0 + org.codehaus.gmaven + groovy-maven-plugin + 2.1.1 - process-resources + generate-resources - run + execute - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + ${project.basedir}/src/main/script/prepare-resources.groovy + + ${project.build.directory}/rules-html + ${project.build.outputDirectory}/io/ecocode/rules + diff --git a/ecocode-rules-specifications/src/main/script/prepare-resources.groovy b/ecocode-rules-specifications/src/main/script/prepare-resources.groovy new file mode 100644 index 000000000..15eb9bee7 --- /dev/null +++ b/ecocode-rules-specifications/src/main/script/prepare-resources.groovy @@ -0,0 +1,33 @@ +#!/usr/bin/env groovy +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.StandardCopyOption + +Path projectBasedir = Path.of(project.basedir.absolutePath) + +Path sourceDir = Path.of(Objects.requireNonNull(properties.sourceDir, "property must be set: sourceDir")) +Path targetDir = Path.of(Objects.requireNonNull(properties.targetDir, "property must be set: targetDir")) + +def copyFile(Path basedirPath, Path source, Path target) { + log.debug("Copy: {} -> {}", basedirPath.relativize(source), basedirPath.relativize(target)) + Files.createDirectories(target.parent) + Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING) +} + +sourceDir.traverse(type: groovy.io.FileType.FILES, nameFilter: ~/.*\.html$/) { Path htmlPath -> + def language = htmlPath.parent.fileName.toString() + def languageDir = targetDir.resolve(language) + + def ruleDir = htmlPath.parent.parent + def ruleKey = ruleDir.fileName.toString() + + def metadataFileSourcePath = ruleDir.resolve(ruleKey + ".json") + + def htmlTargetPath = languageDir.resolve(htmlPath.fileName) + def metadataFileTargetPath = languageDir.resolve(metadataFileSourcePath.fileName) + + if(Files.exists(metadataFileSourcePath)) { + copyFile(projectBasedir, htmlPath, htmlTargetPath) + copyFile(projectBasedir, metadataFileSourcePath, metadataFileTargetPath) + } +}