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.codehaus.plexus.interpolation.ValueSource;
27  
28  
29  
30  
31  
32  
33  class ProblemDetectingValueSource
34      implements ValueSource
35  {
36  
37      private final ValueSource valueSource;
38  
39      private final String bannedPrefix;
40  
41      private final String newPrefix;
42  
43      private final ModelProblemCollector problems;
44  
45      public ProblemDetectingValueSource( ValueSource valueSource, String bannedPrefix, String newPrefix,
46                                          ModelProblemCollector problems )
47      {
48          this.valueSource = valueSource;
49          this.bannedPrefix = bannedPrefix;
50          this.newPrefix = newPrefix;
51          this.problems = problems;
52      }
53  
54      public Object getValue( String expression )
55      {
56          Object value = valueSource.getValue( expression );
57  
58          if ( value != null && expression.startsWith( bannedPrefix ) )
59          {
60              String msg = "The expression ${" + expression + "} is deprecated.";
61              if ( newPrefix != null && newPrefix.length() > 0 )
62              {
63                  msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
64              }
65              problems.add( Severity.WARNING, msg, null, null );
66          }
67  
68          return value;
69      }
70  
71      @SuppressWarnings( "unchecked" )
72      public List getFeedback()
73      {
74          return valueSource.getFeedback();
75      }
76  
77      public void clearFeedback()
78      {
79          valueSource.clearFeedback();
80      }
81  
82  }