View Javadoc
1   package org.apache.maven.plugin.assembly.format;
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   * @author Andreas Hoheneder (ahoh_at_inode.at)
30   * @version $Id: ReflectionProperties.java 1639422 2014-11-13 18:08:07Z krosenvold $
31   * @deprecated
32   */
33  @Deprecated
34  public class ReflectionProperties
35      extends Properties
36  {
37  
38      private static final long serialVersionUID = 1L;
39  
40      private final MavenProject project;
41  
42      final boolean escapedBackslashesInFilePath;
43  
44      public ReflectionProperties( final MavenProject aProject, final boolean escapedBackslashesInFilePath )
45      {
46          super();
47  
48          project = aProject;
49  
50          this.escapedBackslashesInFilePath = escapedBackslashesInFilePath;
51      }
52  
53      @Override
54      public Object get( final Object key )
55      {
56          Object value = null;
57          try
58          {
59              value = ReflectionValueExtractor.evaluate( "" + key, project );
60  
61              if ( escapedBackslashesInFilePath && value != null && "java.lang.String".equals(
62                  value.getClass().getName() ) )
63              {
64                  final String val = (String) value;
65  
66                  // Check if it's a windows path
67                  if ( val.indexOf( ":\\" ) == 1 )
68                  {
69                      value = StringUtils.replace( (String) value, "\\", "\\\\" );
70                      value = StringUtils.replace( (String) value, ":", "\\:" );
71                  }
72              }
73          }
74          catch ( final Exception e )
75          {
76              // TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions
77          }
78          return value;
79      }
80  }