Skip to content

Commit ecb5a54

Browse files
list-files parallel fix (#1013)
Avoid merging listed files, use a map to store the results of each iteration
1 parent 8cd38ed commit ecb5a54

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

maven-plugins/stager-maven-plugin/src/it/projects/file/pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,26 @@
4646
<file target="docs/4.0.2/index.html"/>
4747
<file target="docs/4.0.2/apidocs/index.html"/>
4848
<file target="docs/4.0.2/images/foo.svg"/>
49+
<file target="docs/3.2.2/index.html"/>
50+
<file target="docs/3.2.2/apidocs/index.html"/>
4951
</files>
5052
<symlinks join="true">
5153
<symlink source="docs/4.0.2" target="docs/v4"/>
54+
<symlink source="docs/3.2.2" target="docs/v3"/>
5255
</symlinks>
5356
<files join="true">
54-
<file target="sitemap.txt">
55-
<list-files dir=".">
57+
<file target="docs/{version}/sitemap.txt">
58+
<iterators>
59+
<variables>
60+
<variable name="version">
61+
<value>v3</value>
62+
<value>v4</value>
63+
</variable>
64+
</variables>
65+
</iterators>
66+
<list-files dir="docs/{version}">
5667
<includes>
57-
<include>**/docs/**/*.html</include>
68+
<include>**/*.html</include>
5869
</includes>
5970
<excludes>
6071
<exclude>**/images/**</exclude>

maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/FileTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
8585
} else {
8686
try (BufferedWriter writer = Files.newBufferedWriter(targetFile)) {
8787
for (TextAction task : tasks()) {
88-
writer.write(task.text());
88+
writer.write(task.text(vars));
8989
}
9090
}
9191
}

maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/ListFilesTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.Set;
24+
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.function.BiFunction;
2526

2627
import io.helidon.build.common.Lists;
@@ -43,7 +44,7 @@ final class ListFilesTask extends StagingTask implements TextAction {
4344
private final List<Substitution> substitutions;
4445
private final List<BiFunction<String, Map<String, String>, String>> chain;
4546
private final String dirName;
46-
private final StringBuilder buf = new StringBuilder();
47+
private final Map<Map<String, String>, String> results = new ConcurrentHashMap<>();
4748

4849
ListFilesTask(ActionIterators iterators,
4950
List<Include> includes,
@@ -60,8 +61,8 @@ final class ListFilesTask extends StagingTask implements TextAction {
6061
}
6162

6263
@Override
63-
public String text() {
64-
return buf.toString();
64+
public String text(Map<String, String> vars) {
65+
return results.getOrDefault(vars, "");
6566
}
6667

6768
List<String> includes() {
@@ -78,15 +79,17 @@ List<Substitution> substitutions() {
7879

7980
@Override
8081
protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars) {
82+
StringBuilder sb = new StringBuilder();
8183
Path resolved = dir.resolve(resolveVar(dirName, vars));
8284
List<Path> files = walk(resolved, FILE_VISIT_OPTIONS, this::filter);
8385
for (Path file : files) {
8486
String entry = normalizePath(dir.relativize(file));
8587
for (var function : chain) {
8688
entry = function.apply(entry, vars);
8789
}
88-
buf.append(entry).append("\n");
90+
sb.append(entry).append("\n");
8991
}
92+
results.put(vars, sb.toString());
9093
}
9194

9295
private boolean filter(Path p, BasicFileAttributes attrs) {

maven-plugins/stager-maven-plugin/src/main/java/io/helidon/build/maven/stager/TextAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.helidon.build.maven.stager;
1717

18+
import java.util.Map;
19+
1820
/**
1921
* A {@link StagingAction} that produces text.
2022
*/
@@ -25,5 +27,5 @@ interface TextAction extends StagingAction {
2527
*
2628
* @return text
2729
*/
28-
String text();
30+
String text(Map<String, String> vars);
2931
}

maven-plugins/stager-maven-plugin/src/test/java/io/helidon/build/maven/stager/ProjectsTestIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,21 @@ void testFile(String basedir) throws IOException {
152152
assertThat(stageDir.resolve("docs/v4/apidocs/index.html"), fileExists());
153153
assertThat(stageDir.resolve("docs/v4/images/foo.svg"), fileExists());
154154

155-
Path file3 = stageDir.resolve("sitemap.txt");
155+
Path file3 = stageDir.resolve("docs/v4/sitemap.txt");
156156
assertThat(file3, fileExists());
157157
assertThat(Files.readAllLines(file3), containsInAnyOrder(
158158
"docs/v4",
159-
"docs/v4/apidocs",
160-
"docs/4.0.2",
161-
"docs/4.0.2/apidocs"
159+
"docs/v4/apidocs"
160+
));
161+
162+
assertThat(stageDir.resolve("docs/v3/index.html"), fileExists());
163+
assertThat(stageDir.resolve("docs/v3/apidocs/index.html"), fileExists());
164+
165+
Path file4 = stageDir.resolve("docs/v3/sitemap.txt");
166+
assertThat(file4, fileExists());
167+
assertThat(Files.readAllLines(file4), containsInAnyOrder(
168+
"docs/v3",
169+
"docs/v3/apidocs"
162170
));
163171
}
164172

0 commit comments

Comments
 (0)