View Javadoc
1   /*
2    * Copyright 2014 The Codehaus Foundation.
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  package org.codehaus.plexus.archiver.util;
17  
18  import javax.annotation.Nonnull;
19  
20  import org.codehaus.plexus.archiver.BaseFileSet;
21  import org.codehaus.plexus.components.io.filemappers.FileMapper;
22  import org.codehaus.plexus.components.io.fileselectors.FileSelector;
23  import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
24  
25  /**
26   * Default implementation of {@link BaseFileSet}.
27   *
28   * @since 1.0-alpha-9
29   */
30  public abstract class AbstractFileSet<T extends AbstractFileSet> implements BaseFileSet {
31  
32      private String prefix;
33  
34      private String[] includes;
35  
36      private String[] excludes;
37  
38      private FileSelector[] fileSelectors;
39  
40      private boolean caseSensitive = true;
41  
42      private boolean usingDefaultExcludes = true;
43  
44      private boolean includingEmptyDirectories = true;
45  
46      private InputStreamTransformer streamTransformer = null;
47  
48      private FileMapper[] fileMappers;
49  
50      /**
51       * Sets a string of patterns, which excluded files
52       * should match.
53       */
54      public void setExcludes(String[] excludes) {
55          this.excludes = excludes;
56      }
57  
58      @Override
59      public String[] getExcludes() {
60          return excludes;
61      }
62  
63      /**
64       * Sets a set of file selectors, which should be used
65       * to select the included files.
66       */
67      public void setFileSelectors(FileSelector[] fileSelectors) {
68          this.fileSelectors = fileSelectors;
69      }
70  
71      @Override
72      public FileSelector[] getFileSelectors() {
73          return fileSelectors;
74      }
75  
76      /**
77       * Sets a string of patterns, which included files
78       * should match.
79       */
80      public void setIncludes(String[] includes) {
81          this.includes = includes;
82      }
83  
84      @Override
85      public String[] getIncludes() {
86          return includes;
87      }
88  
89      /**
90       * Sets the prefix, which the file sets contents shall
91       * have.
92       */
93      public void setPrefix(String prefix) {
94          this.prefix = prefix;
95      }
96  
97      @Override
98      public String getPrefix() {
99          return prefix;
100     }
101 
102     /**
103      * Sets, whether the include/exclude patterns are
104      * case sensitive. Defaults to true.
105      */
106     public void setCaseSensitive(boolean caseSensitive) {
107         this.caseSensitive = caseSensitive;
108     }
109 
110     @Override
111     public boolean isCaseSensitive() {
112         return caseSensitive;
113     }
114 
115     /**
116      * Sets, whether the default excludes are being
117      * applied. Defaults to true.
118      */
119     public void setUsingDefaultExcludes(boolean usingDefaultExcludes) {
120         this.usingDefaultExcludes = usingDefaultExcludes;
121     }
122 
123     @Override
124     public boolean isUsingDefaultExcludes() {
125         return usingDefaultExcludes;
126     }
127 
128     /**
129      * Sets, whether empty directories are being included. Defaults
130      * to true.
131      */
132     public void setIncludingEmptyDirectories(boolean includingEmptyDirectories) {
133         this.includingEmptyDirectories = includingEmptyDirectories;
134     }
135 
136     @Override
137     public boolean isIncludingEmptyDirectories() {
138         return includingEmptyDirectories;
139     }
140 
141     public T prefixed(String prefix) {
142         setPrefix(prefix);
143         return (T) this;
144     }
145 
146     public T include(String[] includes) {
147         setIncludes(includes);
148         return (T) this;
149     }
150 
151     public T exclude(String[] excludes) {
152         setExcludes(excludes);
153         return (T) this;
154     }
155 
156     public T includeExclude(String[] includes, String[] excludes) {
157         return (T) include(includes).exclude(excludes);
158     }
159 
160     public T includeEmptyDirs(boolean includeEmptyDirectories) {
161         setIncludingEmptyDirectories(includeEmptyDirectories);
162         return (T) this;
163     }
164 
165     @SuppressWarnings("unchecked")
166     public T usingDefaultExcludes(boolean usingDefaultExcludes) {
167         setUsingDefaultExcludes(usingDefaultExcludes);
168         return (T) this;
169     }
170 
171     public void setStreamTransformer(@Nonnull InputStreamTransformer streamTransformer) {
172         this.streamTransformer = streamTransformer;
173     }
174 
175     @Override
176     public InputStreamTransformer getStreamTransformer() {
177         return streamTransformer;
178     }
179 
180     /**
181      * Sets a set of file mappers, which should be used
182      * to change the filename of the included files.
183      */
184     public void setFileMappers(FileMapper[] fileMappers) {
185         this.fileMappers = fileMappers;
186     }
187 
188     @Override
189     public FileMapper[] getFileMappers() {
190         return fileMappers;
191     }
192 }