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