Skip to content

Commit

Permalink
Removes metadata for rules not available in corresponding language
Browse files Browse the repository at this point in the history
  • Loading branch information
jycr committed Jul 11, 2023
1 parent b01ab2f commit 72a7a85
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
65 changes: 19 additions & 46 deletions ecocode-rules-specifications/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
Expand All @@ -78,12 +83,13 @@
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/rules</sourceDirectory>
<outputDirectory>${project.build.directory}/rules</outputDirectory>
<outputDirectory>${project.build.directory}/rules-html</outputDirectory>
<attributes>
<source-highlighter>coderay</source-highlighter>
<coderay-css>style</coderay-css>
</attributes>
<preserveDirectories>true</preserveDirectories>
<embedAssets>true</embedAssets>
<headerFooter>false</headerFooter>
<relativeBaseDir>true</relativeBaseDir>
<logHandler>
Expand All @@ -97,57 +103,24 @@
</plugin>
<plugin>
<!--
Target resources tree need to be "flat".
Each metadata JSON file must be in the same tree as the HTML description file for the corresponding language.
The only way currently found to generate the correct file tree is to use antrun-plugin with `flattenmapper`
Prepare resources tree needed by language.
Each metadata JSON file must be in the same folder as the HTML description file for the corresponding language.
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
<goal>execute</goal>
</goals>
<configuration>
<target>
<copy todir="${project.build.outputDirectory}/io/ecocode/rules/java">
<fileset dir="${project.build.directory}/rules">
<include name="*/java/EC*.html"/>
<include name="*/EC*.json"/>
</fileset>
<flattenmapper/>
</copy>
<copy todir="${project.build.outputDirectory}/io/ecocode/rules/php">
<fileset dir="${project.build.directory}/rules">
<include name="*/php/EC*.html"/>
<include name="*/EC*.json"/>
</fileset>
<flattenmapper/>
</copy>
<copy todir="${project.build.outputDirectory}/io/ecocode/rules/python">
<fileset dir="${project.build.directory}/rules">
<include name="*/python/EC*.html"/>
<include name="*/EC*.json"/>
</fileset>
<flattenmapper/>
</copy>
<copy todir="${project.build.outputDirectory}/io/ecocode/rules/js">
<fileset dir="${project.build.directory}/rules">
<include name="*/js/EC*.html"/>
<include name="*/EC*.json"/>
</fileset>
<flattenmapper/>
</copy>
<copy todir="${project.build.outputDirectory}/io/ecocode/rules/ts">
<fileset dir="${project.build.directory}/rules">
<include name="*/ts/EC*.html"/>
<include name="*/EC*.json"/>
</fileset>
<flattenmapper/>
</copy>
</target>
<source>${project.basedir}/src/main/script/prepare-resources.groovy</source>
<properties>
<sourceDir>${project.build.directory}/rules-html</sourceDir>
<targetDir>${project.build.outputDirectory}/io/ecocode/rules</targetDir>
</properties>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 72a7a85

Please sign in to comment.