View Javadoc

1   package org.apache.maven.plugin.resources;
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.project.MavenProject;
23  import org.codehaus.plexus.util.StringUtils;
24  import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
25  
26  import java.util.Properties;
27  
28  /**
29   * @deprecated use classes in the component maven-filtering
30   * TODO remove the class ?
31   * @author Andreas Hoheneder (ahoh_at_inode.at)
32   * @version $Id: ReflectionProperties.java 728546 2008-12-21 22:56:51Z bentmann $
33   */
34  public class ReflectionProperties
35      extends Properties
36  {
37  
38      private MavenProject project;
39  
40      private boolean escapedBackslashesInFilePath;
41  
42      public ReflectionProperties( MavenProject aProject, boolean escapedBackslashesInFilePath )
43      {
44          super();
45  
46          project = aProject;
47  
48          this.escapedBackslashesInFilePath = escapedBackslashesInFilePath;
49      }
50  
51      public Object get( Object key )
52      {
53          Object value = null;
54          try
55          {
56              value = ReflectionValueExtractor.evaluate( "" + key, project );
57  
58              if ( escapedBackslashesInFilePath && ( value instanceof String ) )
59              {
60                  String val = (String) value;
61  
62                  // Check if it's a windows path
63                  if ( val.indexOf( ":\\" ) == 1 )
64                  {
65                      value = StringUtils.replace( (String) value, "\\", "\\\\" );
66                      value = StringUtils.replace( (String) value, ":", "\\:" );
67                  }
68              }
69          }
70          catch ( Exception e )
71          {
72              // TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
73          }
74          return value;
75      }
76  }