You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/05/17 10:03:38 UTC
[camel-quarkus] 04/06: Check for duplicates in merged properties
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 3cc5e0eea2df2f3561b0cb39143e905ddec1c559
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Fri May 14 17:35:51 2021 +0200
Check for duplicates in merged properties
---
tooling/scripts/group-tests.groovy | 55 ++++++++++++++++++++++++++++++++------
1 file changed, 47 insertions(+), 8 deletions(-)
diff --git a/tooling/scripts/group-tests.groovy b/tooling/scripts/group-tests.groovy
index 5e01b2d..98e34ee 100644
--- a/tooling/scripts/group-tests.groovy
+++ b/tooling/scripts/group-tests.groovy
@@ -35,25 +35,26 @@ final Path sourceDir = Paths.get(properties['group-tests.source.dir'])
final String[] concatRelPaths = properties['group-tests.concat.rel.paths'].split('[\\s,]+')
final Path destinationModuleDir = Paths.get(properties['group-tests.dest.module.dir'])
-final Map<String, StringBuilder> mergedFiles = new HashMap<>()
-concatRelPaths.each {relPath -> mergedFiles.put(relPath, new StringBuilder())}
+final Map<String, ResourceConcatenator> mergedFiles = new HashMap<>()
+concatRelPaths.each {relPath -> mergedFiles.put(relPath, new ResourceConcatenator()) }
Files.list(sourceDir)
- .filter {p -> Files.exists(p.resolve('pom.xml'))}
+ .filter { p -> Files.exists(p.resolve('pom.xml')) }
.sorted()
- .forEach {p ->
- mergedFiles.each { relPath, sb -> (Files.exists(p.resolve(relPath))) ? (sb.append(p.resolve(relPath).getText('UTF-8') + '\n')) : sb }
+ .forEach { p ->
+ mergedFiles.each { relPath, cat ->
+ cat.append(p.resolve(relPath))
+ }
copyResources(p.resolve('src/main/java'), destinationModuleDir.resolve('target/src/main/java'))
copyResources(p.resolve('src/test/java'), destinationModuleDir.resolve('target/src/test/java'))
copyResources(p.resolve('src/main/resources'), destinationModuleDir.resolve('target/classes'))
copyResources(p.resolve('src/test/resources'), destinationModuleDir.resolve('target/test-classes'))
}
-mergedFiles.each { relPath, sb ->
+mergedFiles.each { relPath, cat ->
String destRelPath = relPath.replace('src/main/resources/', 'target/classes/').replace('src/test/resources/', 'target/test-classes/')
Path destPath = destinationModuleDir.resolve(destRelPath)
- Files.createDirectories(destPath.getParent())
- Files.write(destPath, sb.toString().getBytes('UTF-8'))
+ cat.store(destPath)
}
static void copyResources(Path source, Path dest) {
@@ -63,3 +64,41 @@ static void copyResources(Path source, Path dest) {
}
}
}
+
+class ResourceConcatenator {
+ private final StringBuilder sb = new StringBuilder()
+ private final Properties props = new Properties()
+ private final List<Path> visitedPaths = new ArrayList<>()
+
+ public ResourceConcatenator append(Path path) {
+ if (Files.exists(path)) {
+ if (path.getFileName().toString().endsWith(".properties")) {
+ Properties newProps = new Properties()
+ path.withInputStream { is ->
+ newProps.load(is)
+ }
+ newProps.each { key, val ->
+ if (props.containsKey(key) && !props.get(key).equals(val)) {
+ throw new IllegalStateException("Conflicting property value "+ key +" = "+ val +": found in "+ path + " conflicting with some of " + visitedPaths);
+ }
+ }
+ props.putAll(newProps)
+ } else {
+ sb.append(path.getText('UTF-8') + '\n')
+ }
+ visitedPaths.add(path)
+ }
+ return this
+ }
+
+ public void store(Path path) {
+ Files.createDirectories(path.getParent())
+ if (path.getFileName().toString().endsWith(".properties")) {
+ path.withOutputStream { out ->
+ props.store(out, "")
+ }
+ } else {
+ Files.write(path, sb.toString().getBytes('UTF-8'))
+ }
+ }
+}