Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ReflectionProperties |
|
| 3.5;3,5 |
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 1006198 2010-10-09 17:36:26Z bentmann $ | |
31 | * | |
32 | * @depcrecated | |
33 | */ | |
34 | @Deprecated | |
35 | public class ReflectionProperties | |
36 | extends Properties | |
37 | { | |
38 | ||
39 | private static final long serialVersionUID = 1L; | |
40 | ||
41 | private final MavenProject project; | |
42 | ||
43 | boolean escapedBackslashesInFilePath; | |
44 | ||
45 | public ReflectionProperties( final MavenProject aProject, final boolean escapedBackslashesInFilePath ) | |
46 | { | |
47 | 0 | super(); |
48 | ||
49 | 0 | project = aProject; |
50 | ||
51 | 0 | this.escapedBackslashesInFilePath = escapedBackslashesInFilePath; |
52 | 0 | } |
53 | ||
54 | @Override | |
55 | public Object get( final Object key ) | |
56 | { | |
57 | 0 | Object value = null; |
58 | try | |
59 | { | |
60 | 0 | value = ReflectionValueExtractor.evaluate( "" + key, project ); |
61 | ||
62 | 0 | if ( escapedBackslashesInFilePath && value != null && "java.lang.String".equals( value.getClass() |
63 | .getName() ) ) | |
64 | { | |
65 | 0 | final String val = (String) value; |
66 | ||
67 | // Check if it's a windows path | |
68 | 0 | if ( val.indexOf( ":\\" ) == 1 ) |
69 | { | |
70 | 0 | value = StringUtils.replace( (String) value, "\\", "\\\\" ); |
71 | 0 | value = StringUtils.replace( (String) value, ":", "\\:" ); |
72 | } | |
73 | } | |
74 | } | |
75 | 0 | catch ( final Exception e ) |
76 | { | |
77 | // TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions | |
78 | 0 | } |
79 | 0 | return value; |
80 | } | |
81 | } |