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.plugins.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.shared.filtering.MavenFilteringException;
29  import org.apache.maven.shared.filtering.MavenResourcesExecution;
30  import org.apache.maven.shared.filtering.MavenResourcesFiltering;
31  import org.codehaus.plexus.component.annotations.Component;
32  
33  /**
34   * @author Olivier Lamy
35   * @since 2.5
36   * @version $Id$
37   */
38  @Component(role = org.apache.maven.shared.filtering.MavenResourcesFiltering.class, hint = "itFilter")
39  public class ItFilter
40      implements MavenResourcesFiltering
41  {
42  
43  
44      /** 
45       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#getDefaultNonFilteredFileExtensions()
46       */
47      public List<String> getDefaultNonFilteredFileExtensions()
48      {
49          //  no op
50          return Collections.<String>emptyList();
51      }
52  
53      /** 
54       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filteredFileExtension(String, List)
55       */
56      public boolean filteredFileExtension( String fileName, List<String> userNonFilteredFileExtensions )
57      {
58          return false;
59      }
60  
61      /** 
62       * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(org.apache.maven.shared.filtering.MavenResourcesExecution)
63       */
64      public void filterResources( MavenResourcesExecution mavenResourcesExecution )
65          throws MavenFilteringException
66      {
67          System.out.println("ItFilter filterResources");
68          try
69          {
70              File f = new File( mavenResourcesExecution.getOutputDirectory(), "foo.txt" );
71              List<String> lines = new ArrayList<String>();
72              
73              lines.add( "foo" );
74              lines.add( "version="+mavenResourcesExecution.getMavenProject().getVersion() );
75              lines.add( "toto=" + mavenResourcesExecution.getMavenSession().getSystemProperties().getProperty( "toto" ) );
76              FileUtils.writeLines( f, lines );
77          }
78          catch ( IOException e )
79          {
80              throw new MavenFilteringException( e.getMessage(), e );
81          }
82  
83      }
84  
85  }