View Javadoc
1   package org.apache.maven.model.interpolation;
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 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   * Wraps another value source and intercepts interpolated expressions, checking for problems.
32   * 
33   * @author Benjamin Bentmann
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      public 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      public Object getValue( String expression )
57      {
58          Object value = valueSource.getValue( expression );
59  
60          if ( value != null && expression.startsWith( bannedPrefix ) )
61          {
62              String msg = "The expression ${" + expression + "} is deprecated.";
63              if ( newPrefix != null && newPrefix.length() > 0 )
64              {
65                  msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
66              }
67              problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 ).setMessage( msg ) );
68          }
69  
70          return value;
71      }
72  
73      @SuppressWarnings( "unchecked" )
74      public List getFeedback()
75      {
76          return valueSource.getFeedback();
77      }
78  
79      public void clearFeedback()
80      {
81          valueSource.clearFeedback();
82      }
83  
84  }