View Javadoc

1   package org.apache.maven.shared.filtering;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *    http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.execution.MavenSession;
23  import org.apache.maven.project.MavenProject;
24  
25  import java.util.ArrayList;
26  import java.util.LinkedHashSet;
27  import java.util.List;
28  import java.util.Properties;
29  import java.util.Set;
30  
31  /**
32   * @since 1.0-beta-3
33   */
34  public class AbstractMavenFilteringRequest
35  {
36  
37      private MavenProject mavenProject;
38  
39      private List<String> filters;
40  
41      private boolean escapeWindowsPaths = true;
42  
43      private String encoding;
44  
45      private MavenSession mavenSession;
46  
47      /** 
48       * List of Strings considered as expressions which contains values in the project/pom:
49       * pom project
50       * Default value will be pom and project.
51       *
52       * @since 1.0-beta-2
53       */
54      private List<String> projectStartExpressions = new ArrayList<String>();
55      
56      /**
57       * String which will escape interpolation mechanism:
58       * foo \${foo.bar} -> foo ${foo.bar}
59       *
60       * @since 1.0-beta-2
61       */
62      private String escapeString;
63      
64      /**
65       * @since 1.0-beta-3
66       */
67      private Properties additionalProperties;
68      
69      /**
70       * @since 1.0-beta-3
71       */
72      private boolean injectProjectBuildFilters = false;
73      
74      /**
75       * Set of expression delimiter specifications to use during filtering. Delimiter specifications are
76       * given in the form 'BEGIN*END' or, for symmetrical delimiters, simply 'TOKEN'. The default
77       * values are '${*}' and '@'.
78       * 
79       * @since 1.0-beta-3
80       */
81      private LinkedHashSet<String> delimiters = new LinkedHashSet<String>();
82      
83      /**
84       * Do not stop trying to filter tokens when reaching EOL.
85       *
86       * @since 1.0
87       */
88      private boolean supportMultiLineFiltering;
89      
90      protected AbstractMavenFilteringRequest()
91      {
92          initDefaults();
93      }
94  
95      protected AbstractMavenFilteringRequest( MavenProject mavenProject, List<String> filters,
96                                               String encoding, MavenSession mavenSession )
97      {
98          initDefaults();
99          this.mavenProject = mavenProject;
100         this.filters = filters;
101         this.encoding = encoding;
102         this.mavenSession = mavenSession;
103     }
104 
105     private void initDefaults()
106     {
107         projectStartExpressions.add( "pom" );
108         projectStartExpressions.add( "project" );
109         
110         delimiters.add( "${*}" );
111         delimiters.add( "@" );
112     }
113 
114     public MavenProject getMavenProject()
115     {
116         return mavenProject;
117     }
118 
119     public void setMavenProject( MavenProject mavenProject )
120     {
121         this.mavenProject = mavenProject;
122     }
123 
124     public List<String> getFilters()
125     {
126         return filters;
127     }
128 
129     public void setFilters( List<String> filters )
130     {
131         this.filters = filters;
132     }
133 
134     public List<String> getFileFilters()
135     {
136         return getFilters();
137     }
138 
139     public void setFileFilters( List<String> filters )
140     {
141         setFilters( filters );
142     }
143 
144     /**
145      * @since 1.0-beta-3
146      */
147     public boolean isEscapeWindowsPaths()
148     {
149         return escapeWindowsPaths;
150     }
151 
152     /**
153      * @since 1.0-beta-3
154      */
155     public void setEscapeWindowsPaths( boolean escapedBackslashesInFilePath )
156     {
157         this.escapeWindowsPaths = escapedBackslashesInFilePath;
158     }
159     
160     public boolean isEscapedBackslashesInFilePath()
161     {
162         return isEscapeWindowsPaths();
163     }
164     
165     public void setEscapedBackslashesInFilePath( boolean escape )
166     {
167         setEscapeWindowsPaths( escape );
168     }
169 
170     public String getEncoding()
171     {
172         return encoding;
173     }
174 
175     public void setEncoding( String encoding )
176     {
177         this.encoding = encoding;
178     }
179 
180     public MavenSession getMavenSession()
181     {
182         return mavenSession;
183     }
184 
185     public void setMavenSession( MavenSession mavenSession )
186     {
187         this.mavenSession = mavenSession;
188     }
189 
190     /**
191      * @since 1.0-beta-3
192      */
193     public Properties getAdditionalProperties()
194     {
195         return additionalProperties;
196     }
197 
198     /**
199      * @since 1.0-beta-3
200      */
201     public void setAdditionalProperties( Properties additionalProperties )
202     {
203         this.additionalProperties = additionalProperties;
204     }
205 
206     /**
207      * @since 1.0-beta-3
208      */
209     public boolean isInjectProjectBuildFilters()
210     {
211         return injectProjectBuildFilters;
212     }
213 
214     /**
215      * @since 1.0-beta-3
216      */
217     public void setInjectProjectBuildFilters( boolean injectProjectBuildFilters )
218     {
219         this.injectProjectBuildFilters = injectProjectBuildFilters;
220     }
221 
222     /**
223      * @since 1.0-beta-2
224      */
225     public String getEscapeString()
226     {
227         return escapeString;
228     }
229 
230     /**
231      * @param escapeString
232      * @since 1.0-beta-2
233      */
234     public void setEscapeString( String escapeString )
235     {
236         this.escapeString = escapeString;
237     }
238     
239     /**
240      * @since 1.0-beta-2
241      */
242     public List getProjectStartExpressions()
243     {
244         return projectStartExpressions;
245     }
246 
247     /**
248      * @param projectStartExpressions
249      * @since 1.0-beta-2
250      */
251     public void setProjectStartExpressions( List projectStartExpressions )
252     {
253         this.projectStartExpressions = projectStartExpressions;
254     }
255 
256     /**
257      * See {@link AbstractMavenFilteringRequest#delimiters} for more information and default values.
258      *
259      * @return Not allowed to be <code>null</code> or empty.
260      * @since 1.0-beta-3
261      */
262     public LinkedHashSet<String> getDelimiters()
263     {
264         return delimiters;
265     }
266 
267     /**
268      * Set the delimiter specifications to use during filtering. Specifications should be of the form:
269      * 'BEGIN*END' for asymmetrical delimiters, or 'TOKEN' for symmetrical delimiters. See
270      * {@link AbstractMavenFilteringRequest#delimiters} for more information and default values.
271      * 
272      * @param delimiters If <code>null</code>, reset delimiters to '${*}' only. Otherwise, use the provided value.
273      * @since 1.0-beta-3
274      */
275     public void setDelimiters( LinkedHashSet<String> delimiters )
276     {
277         if ( delimiters == null || delimiters.isEmpty() )
278         {
279             this.delimiters.clear();
280             this.delimiters.add( "${*}" );
281         }
282         else
283         {
284             this.delimiters = delimiters;
285         }
286     }
287 
288     public boolean isSupportMultiLineFiltering()
289     {
290         return supportMultiLineFiltering;
291     }
292 
293     public void setSupportMultiLineFiltering( boolean supportMultiLineFiltering )
294     {
295         this.supportMultiLineFiltering = supportMultiLineFiltering;
296     }
297 
298 }