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