Coverage Report - org.codehaus.plexus.interpolation.SimpleRecursionInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleRecursionInterceptor
76 %
10/13
50 %
1/2
1,4
 
 1  
 package org.codehaus.plexus.interpolation;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2008 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.Collections;
 20  
 import java.util.List;
 21  
 import java.util.Stack;
 22  
 
 23  
 /**
 24  
  * Simplest implementation of a {@link RecursionInterceptor}, which checks whether
 25  
  * the existing interpolation effort is already attempting to resolve an exact
 26  
  * expression, but has not finished. This will not catch synonym expressions, as
 27  
  * are found in Maven (${project.build.directory}, ${pom.build.directory}, and
 28  
  * ${build.directory} are synonyms).
 29  
  *
 30  
  * @author jdcasey
 31  
  * @version $Id$
 32  
  */
 33  400105
 public class SimpleRecursionInterceptor
 34  
     implements RecursionInterceptor
 35  
 {
 36  
 
 37  400105
     private Stack expressions = new Stack();
 38  
 
 39  
     /**
 40  
      * {@inheritDoc}
 41  
      */
 42  
     public void expressionResolutionFinished( String expression )
 43  
     {
 44  400158
         expressions.pop();
 45  400158
     }
 46  
 
 47  
     /**
 48  
      * {@inheritDoc}
 49  
      */
 50  
     public void expressionResolutionStarted( String expression )
 51  
     {
 52  400158
         expressions.push( expression );
 53  400158
     }
 54  
 
 55  
     /**
 56  
      * Check whether the current expression is already present in the in-process
 57  
      * stack.
 58  
      */
 59  
     public boolean hasRecursiveExpression( String expression )
 60  
     {
 61  400149
         return expressions.contains( expression );
 62  
     }
 63  
 
 64  
     /**
 65  
      * When an expression is determined to be a recursive reference, this method
 66  
      * returns the sublist of tracked expressions that participate in this cycle.
 67  
      * Otherwise, if the expression isn't present in the in-process stack, return
 68  
      * {@link Collections#EMPTY_LIST}.
 69  
      */
 70  
     public List getExpressionCycle( String expression )
 71  
     {
 72  5
         int idx = expressions.indexOf( expression );
 73  5
         if ( idx < 0 )
 74  
         {
 75  0
             return Collections.EMPTY_LIST;
 76  
         }
 77  
         else
 78  
         {
 79  5
             return expressions.subList( idx, expressions.size() );
 80  
         }
 81  
     }
 82  
 
 83  
     public void clear(){
 84  0
         expressions.clear();
 85  0
     }
 86  
 }