1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.s3.publisher.maven.plugin.config;
18
19 import java.io.*;
20 import java.util.*;
21
22 public class IncludedFilesListBuilder extends AbstractFilesListBuilder {
23
24 private final List<Include> includes;
25 private final ConstrainedFilesListBuilder constrainedFilesListBuilder;
26
27 public IncludedFilesListBuilder(final File inputDirectory,
28 final List<Include> includes,
29 final List<String> excludes, final List<Metadata> metadatas) {
30 super(inputDirectory, excludes, metadatas);
31 this.includes = includes;
32 constrainedFilesListBuilder = new ConstrainedFilesListBuilder(
33 inputDirectory, excludes, metadatas);
34 }
35
36 public List<ManagedFile> build() throws IOException {
37 for (final Include include : includes) {
38 collectIncludedFiles(include);
39 replaceConstrainedFiles(include);
40 }
41 return new ArrayList<>(fileMap.values());
42 }
43
44 private void collectIncludedFiles(final Include include)
45 throws IOException {
46 final List<String> includedFileNames =
47 getMatchingFilesNames(include.getBind().getPattern());
48 for (final String fileName : includedFileNames) {
49 final ManagedFile managedFile =
50 new ManagedFile(fileName, getMetadata(include.getBind()));
51 fileMap.put(fileName, managedFile);
52 }
53 }
54
55 private void replaceConstrainedFiles(final Include include)
56 throws IOException {
57 final List<ManagedFile> constrainedFiles =
58 constrainedFilesListBuilder.build(include);
59 for (final ManagedFile managedFile : constrainedFiles) {
60 fileMap.put(managedFile.getFilename(), managedFile);
61 }
62 }
63 }