View Javadoc
1   /*
2    * Copyright 2023 Adrian Herscu
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 ConstrainedFilesListBuilder extends AbstractFilesListBuilder {
23  
24      public ConstrainedFilesListBuilder(final File inputDirectory,
25          final List<String> excludes, final List<Metadata> metadatas) {
26          super(inputDirectory, excludes, metadatas);
27      }
28  
29      public List<ManagedFile> build(final Include include) throws IOException {
30          List<ManagedFile> managedFiles;
31          if (include.getContraints() == null) {
32              managedFiles = Collections.emptyList();
33          } else {
34              for (final Bind constraint : include.getContraints()) {
35                  final List<String> constrainedFileNames =
36                      getMatchingFilesNames(constraint.getPattern());
37                  for (final String fileName : constrainedFileNames) {
38                      final ManagedFile managedFile =
39                          new ManagedFile(fileName, getMetadata(constraint));
40                      fileMap.put(fileName, managedFile);
41                  }
42              }
43              managedFiles = new ArrayList<>(fileMap.values());
44          }
45          return managedFiles;
46      }
47  }