View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.resources.filters;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.apache.commons.io.FileUtils;
28  import org.apache.maven.execution.MavenSession;
29  import org.apache.maven.project.MavenProject;
30  import org.apache.maven.shared.filtering.MavenFilteringException;
31  import org.apache.maven.shared.filtering.MavenResourcesExecution;
32  import org.apache.maven.shared.filtering.MavenResourcesFiltering;
33  
34  /**
35   * @author <a href="mailto:olamy@apache.org">olamy</a>
36   * @since 2.5
37   * @version $Id: ItFilter.java 1000643 2010-09-23 21:50:36Z olamy $
38   * @plexus.component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" 
39   *                   role-hint="itFilter"
40   */
41  public class ItFilter
42      implements MavenResourcesFiltering
43  {
44  
45      /** 
46       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(java.util.List, java.io.File, org.apache.maven.project.MavenProject, java.lang.String, java.util.List, java.util.List, org.apache.maven.execution.MavenSession)
47       */
48      public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
49                                   List fileFilters, List nonFilteredFileExtensions, MavenSession mavenSession )
50          throws MavenFilteringException
51      {
52          //no op
53      }
54  
55      /** 
56       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(java.util.List, java.io.File, java.lang.String, java.util.List, java.io.File, java.util.List)
57       */
58      public void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers,
59                                   File resourcesBaseDirectory, List nonFilteredFileExtensions )
60          throws MavenFilteringException
61      {
62          // no op
63      }
64  
65      /** 
66       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#getDefaultNonFilteredFileExtensions()
67       */
68      public List getDefaultNonFilteredFileExtensions()
69      {
70          //  no op
71          return Collections.EMPTY_LIST;
72      }
73  
74      /** 
75       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filteredFileExtension(java.lang.String, java.util.List)
76       */
77      public boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions )
78      {
79          return false;
80      }
81  
82      /** 
83       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(org.apache.maven.shared.filtering.MavenResourcesExecution)
84       */
85      public void filterResources( MavenResourcesExecution mavenResourcesExecution )
86          throws MavenFilteringException
87      {
88          System.out.println("ItFilter filterResources");
89          try
90          {
91              File f = new File( mavenResourcesExecution.getOutputDirectory(), "foo.txt" );
92              List lines = new ArrayList();
93              
94              lines.add( "foo" );
95              lines.add( "version="+mavenResourcesExecution.getMavenProject().getVersion() );
96              lines.add( "toto=" + mavenResourcesExecution.getMavenSession().getExecutionProperties().getProperty( "toto" ) );
97              FileUtils.writeLines( f, lines );
98          }
99          catch ( IOException e )
100         {
101             throw new MavenFilteringException( e.getMessage(), e );
102         }
103 
104     }
105 
106 }