-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes metadata for rules not available in corresponding language
- Loading branch information
Showing
2 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ecocode-rules-specifications/src/main/script/prepare-resources.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |