View Javadoc

1   package org.apache.maven.plugin.assembly.format;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.maven.project.MavenProject;
20  import org.codehaus.plexus.util.StringUtils;
21  import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
22  
23  import java.util.Properties;
24  
25  /**
26   * @author Andreas Hoheneder (ahoh_at_inode.at)
27   * @version $Id: ReflectionProperties.java 999612 2010-09-21 20:34:50Z jdcasey $
28   * 
29   * @depcrecated
30   */
31  @Deprecated
32  public class ReflectionProperties
33      extends Properties
34  {
35  
36      private static final long serialVersionUID = 1L;
37  
38      private final MavenProject project;
39  
40      boolean escapedBackslashesInFilePath;
41  
42      public ReflectionProperties( final MavenProject aProject, final boolean escapedBackslashesInFilePath )
43      {
44          super();
45  
46          project = aProject;
47  
48          this.escapedBackslashesInFilePath = escapedBackslashesInFilePath;
49      }
50  
51      @Override
52      public Object get( final Object key )
53      {
54          Object value = null;
55          try
56          {
57              value = ReflectionValueExtractor.evaluate( "" + key, project );
58  
59              if ( escapedBackslashesInFilePath && value != null && "java.lang.String".equals( value.getClass()
60                                                                                                    .getName() ) )
61              {
62                  final String val = (String) value;
63  
64                  // Check if it's a windows path
65                  if ( val.indexOf( ":\\" ) == 1 )
66                  {
67                      value = StringUtils.replace( (String) value, "\\", "\\\\" );
68                      value = StringUtils.replace( (String) value, ":", "\\:" );
69                  }
70              }
71          }
72          catch ( final Exception e )
73          {
74              // TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
75          }
76          return value;
77      }
78  }