1 package org.apache.maven.model.interpolation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.model.building.ModelProblemCollector;
25 import org.apache.maven.model.building.ModelProblem.Severity;
26 import org.apache.maven.model.building.ModelProblem.Version;
27 import org.apache.maven.model.building.ModelProblemCollectorRequest;
28 import org.codehaus.plexus.interpolation.ValueSource;
29
30
31
32
33
34
35 class ProblemDetectingValueSource
36 implements ValueSource
37 {
38
39 private final ValueSource valueSource;
40
41 private final String bannedPrefix;
42
43 private final String newPrefix;
44
45 private final ModelProblemCollector problems;
46
47 ProblemDetectingValueSource( ValueSource valueSource, String bannedPrefix, String newPrefix,
48 ModelProblemCollector problems )
49 {
50 this.valueSource = valueSource;
51 this.bannedPrefix = bannedPrefix;
52 this.newPrefix = newPrefix;
53 this.problems = problems;
54 }
55
56 @Override
57 public Object getValue( String expression )
58 {
59 Object value = valueSource.getValue( expression );
60
61 if ( value != null && expression.startsWith( bannedPrefix ) )
62 {
63 String msg = "The expression ${" + expression + "} is deprecated.";
64 if ( newPrefix != null && newPrefix.length() > 0 )
65 {
66 msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
67 }
68 problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 ).setMessage( msg ) );
69 }
70
71 return value;
72 }
73
74 @Override
75 @SuppressWarnings( "unchecked" )
76 public List getFeedback()
77 {
78 return valueSource.getFeedback();
79 }
80
81 @Override
82 public void clearFeedback()
83 {
84 valueSource.clearFeedback();
85 }
86
87 }