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  
  */
 32  400106
 public class SimpleRecursionInterceptor
 33  
     implements RecursionInterceptor
 34  
 {
 35  
 
 36  400106
     private Stack expressions = new Stack();
 37  
 
 38  
     /**
 39  
      * {@inheritDoc}
 40  
      */
 41  
     public void expressionResolutionFinished( String expression )
 42  
     {
 43  400171
         expressions.pop();
 44  400171
     }
 45  
 
 46  
     /**
 47  
      * {@inheritDoc}
 48  
      */
 49  
     public void expressionResolutionStarted( String expression )
 50  
     {
 51  400171
         expressions.push( expression );
 52  400171
     }
 53  
 
 54  
     /**
 55  
      * Check whether the current expression is already present in the in-process
 56  
      * stack.
 57  
      */
 58  
     public boolean hasRecursiveExpression( String expression )
 59  
     {
 60  400162
         return expressions.contains( expression );
 61  
     }
 62  
 
 63  
     /**
 64  
      * When an expression is determined to be a recursive reference, this method
 65  
      * returns the sublist of tracked expressions that participate in this cycle.
 66  
      * Otherwise, if the expression isn't present in the in-process stack, return
 67  
      * {@link Collections#EMPTY_LIST}.
 68  
      */
 69  
     public List getExpressionCycle( String expression )
 70  
     {
 71  5
         int idx = expressions.indexOf( expression );
 72  5
         if ( idx < 0 )
 73  
         {
 74  0
             return Collections.EMPTY_LIST;
 75  
         }
 76  
         else
 77  
         {
 78  5
             return expressions.subList( idx, expressions.size() );
 79  
         }
 80  
     }
 81  
 
 82  
     public void clear(){
 83  0
         expressions.clear();
 84  0
     }
 85  
 }