Coverage Report - org.apache.maven.model.converter.PluginComparator
 
Classes in this File Line Coverage Branch Coverage Complexity
PluginComparator
97%
31/32
97%
33/34
13,5
 
 1  
 package org.apache.maven.model.converter;
 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.model.Plugin;
 23  
 
 24  
 import java.util.Comparator;
 25  
 
 26  
 /**
 27  
  * A comparator for <code>Plugin</code>s. It compares the plugins' groupIds and
 28  
  * artifactIds.
 29  
  *
 30  
  * @author Dennis Lundberg
 31  
  * @version $Id: PluginComparator.java 661727 2008-05-30 14:21:49Z bentmann $
 32  
  */
 33  4
 public class PluginComparator
 34  
     implements Comparator
 35  
 {
 36  
     public int compare( Object o1, Object o2 )
 37  
     {
 38  
         // Check for null objects
 39  21
         if ( o1 == null && o2 == null )
 40  
         {
 41  1
             return 0;
 42  
         }
 43  20
         if ( o1 == null )
 44  
         {
 45  1
             return -1;
 46  
         }
 47  19
         if ( o2 == null )
 48  
         {
 49  1
             return 1;
 50  
         }
 51  
 
 52  
         // Check classes
 53  18
         if ( !( o1 instanceof Plugin ) && !( o2 instanceof Plugin ) )
 54  
         {
 55  1
             return 0;
 56  
         }
 57  17
         if ( !( o1 instanceof Plugin ) )
 58  
         {
 59  1
             return -1;
 60  
         }
 61  16
         if ( !( o2 instanceof Plugin ) )
 62  
         {
 63  1
             return 1;
 64  
         }
 65  15
         Plugin plugin1 = (Plugin) o1;
 66  15
         Plugin plugin2 = (Plugin) o2;
 67  
 
 68  
         // Check for null values
 69  15
         if ( plugin1.getGroupId() == null && plugin2.getGroupId() == null )
 70  
         {
 71  2
             return compareArtifactId( plugin1, plugin2 );
 72  
         }
 73  13
         if ( plugin1.getGroupId() == null )
 74  
         {
 75  3
             return -1;
 76  
         }
 77  10
         if ( plugin2.getGroupId() == null )
 78  
         {
 79  3
             return 1;
 80  
         }
 81  
 
 82  
         // Compare values
 83  
         int answer;
 84  7
         answer = plugin1.getGroupId().compareTo( plugin2.getGroupId() );
 85  7
         if ( answer == 0 )
 86  
         {
 87  5
             answer = compareArtifactId( plugin1, plugin2 );
 88  
         }
 89  
 
 90  7
         return answer;
 91  
     }
 92  
 
 93  
     private int compareArtifactId( Plugin plugin1, Plugin plugin2 )
 94  
     {
 95  7
         if ( plugin1.getArtifactId() == null && plugin2.getArtifactId() == null )
 96  
         {
 97  0
             return 0;
 98  
         }
 99  7
         if ( plugin1.getArtifactId() == null )
 100  
         {
 101  1
             return -1;
 102  
         }
 103  6
         if ( plugin2.getArtifactId() == null )
 104  
         {
 105  1
             return 1;
 106  
         }
 107  5
         return plugin1.getArtifactId().compareTo( plugin2.getArtifactId() );
 108  
     }
 109  
 }