Coverage Report - org.apache.maven.artifact.resolver.DebugResolutionListener
 
Classes in this File Line Coverage Branch Coverage Complexity
DebugResolutionListener
0 %
0/47
0 %
0/16
1,429
 
 1  
 package org.apache.maven.artifact.resolver;
 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 org.apache.maven.artifact.Artifact;
 23  
 import org.apache.maven.artifact.versioning.VersionRange;
 24  
 import org.codehaus.plexus.logging.Logger;
 25  
 
 26  
 import java.util.Set;
 27  
 import java.util.HashSet;
 28  
 
 29  
 /**
 30  
  * Send resolution events to the debug log.
 31  
  *
 32  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 33  
  * @version $Id: DebugResolutionListener.java 640549 2008-03-24 20:05:11Z bentmann $
 34  
  */
 35  
 public class DebugResolutionListener
 36  
     implements ResolutionListener, ResolutionListenerForDepMgmt
 37  
 {
 38  
     private Logger logger;
 39  
 
 40  0
     private String indent = "";
 41  
 
 42  0
     private static Set ignoredArtifacts = new HashSet();
 43  
     
 44  
     public DebugResolutionListener( Logger logger )
 45  0
     {
 46  0
         this.logger = logger;
 47  0
     }
 48  
 
 49  
     public void testArtifact( Artifact node )
 50  
     {
 51  0
     }
 52  
 
 53  
     public void startProcessChildren( Artifact artifact )
 54  
     {
 55  0
         indent += "  ";
 56  0
     }
 57  
 
 58  
     public void endProcessChildren( Artifact artifact )
 59  
     {
 60  0
         indent = indent.substring( 2 );
 61  0
     }
 62  
 
 63  
     public void includeArtifact( Artifact artifact )
 64  
     {
 65  0
         logger.debug( indent + artifact + " (selected for " + artifact.getScope() + ")" );
 66  0
     }
 67  
 
 68  
     public void omitForNearer( Artifact omitted, Artifact kept )
 69  
     {
 70  0
         String omittedVersion = omitted.getVersion();
 71  0
         String keptVersion = kept.getVersion();
 72  
 
 73  0
         if ( omittedVersion != null ? !omittedVersion.equals( keptVersion ) : keptVersion != null )
 74  
         {
 75  0
             logger.debug( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
 76  
         }
 77  0
     }
 78  
 
 79  
     public void omitForCycle( Artifact omitted )
 80  
     {
 81  0
         logger.debug( indent + omitted + " (removed - causes a cycle in the graph)" );
 82  0
     }
 83  
 
 84  
     public void updateScopeCurrentPom( Artifact artifact, String ignoredScope )
 85  
     {
 86  0
         logger.debug( indent + artifact + " (not setting scope to: " + ignoredScope + "; local scope " + artifact.getScope() +
 87  
             " wins)" );
 88  
 
 89  
         // TODO: better way than static? this might hide messages in a reactor
 90  0
         if ( !ignoredArtifacts.contains( artifact ) )
 91  
         {
 92  0
             logger.warn( "\n\tArtifact " + artifact + " retains local scope '" + artifact.getScope() +
 93  
                 "' overriding broader scope '" + ignoredScope + "'\n" +
 94  
                 "\tgiven by a dependency. If this is not intended, modify or remove the local scope.\n" );
 95  0
             ignoredArtifacts.add( artifact );
 96  
         }
 97  0
     }
 98  
 
 99  
     public void updateScope( Artifact artifact, String scope )
 100  
     {
 101  0
         logger.debug( indent + artifact + " (setting scope to: " + scope + ")" );
 102  0
     }
 103  
 
 104  
     public void selectVersionFromRange( Artifact artifact )
 105  
     {
 106  0
         logger.debug( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: " +
 107  
             artifact.getVersionRange() + ")" );
 108  0
     }
 109  
 
 110  
     public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
 111  
     {
 112  0
         logger.debug( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: " +
 113  
             replacement.getVersionRange() + " to: " + newRange + " )" );
 114  0
     }
 115  
 
 116  
     /**
 117  
      * The logic used here used to be a copy of the logic used in the DefaultArtifactCollector, and this method was
 118  
      * called right before the actual version/scope changes were done. However, a different set of conditionals (and
 119  
      * more information) is needed to be able to determine when and if the version and/or scope changes. See the two
 120  
      * added methods, manageArtifactVersion and manageArtifactScope.
 121  
      */
 122  
     public void manageArtifact( Artifact artifact, Artifact replacement )
 123  
     {
 124  0
         String msg = indent + artifact;
 125  0
         msg += " (";
 126  0
         if ( replacement.getVersion() != null )
 127  
         {
 128  0
             msg += "applying version: " + replacement.getVersion() + ";";
 129  
         }
 130  0
         if ( replacement.getScope() != null )
 131  
         {
 132  0
             msg += "applying scope: " + replacement.getScope();
 133  
         }
 134  0
         msg += ")";
 135  0
         logger.debug( msg );
 136  0
     }
 137  
 
 138  
     public void manageArtifactVersion( Artifact artifact, Artifact replacement )
 139  
     {
 140  
         // only show msg if a change is actually taking place
 141  0
         if ( !replacement.getVersion().equals( artifact.getVersion() ) )
 142  
         {
 143  0
             String msg = indent + artifact + " (applying version: " + replacement.getVersion() + ")";
 144  0
             logger.debug( msg );
 145  
         }
 146  0
     }
 147  
 
 148  
     public void manageArtifactScope( Artifact artifact, Artifact replacement )
 149  
     {
 150  
         // only show msg if a change is actually taking place
 151  0
         if ( !replacement.getScope().equals( artifact.getScope() ) )
 152  
         {
 153  0
             String msg = indent + artifact + " (applying scope: " + replacement.getScope() + ")";
 154  0
             logger.debug( msg );
 155  
         }
 156  0
     }
 157  
 
 158  
 }