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