Coverage Report - org.apache.maven.toolchain.RequirementMatcherFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
RequirementMatcherFactory
50 %
2/4
N/A
1,571
RequirementMatcherFactory$1
N/A
N/A
1,571
RequirementMatcherFactory$ExactMatcher
100 %
5/5
N/A
1,571
RequirementMatcherFactory$VersionMatcher
73 %
8/11
100 %
4/4
1,571
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  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,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 
 20  
 package org.apache.maven.toolchain;
 21  
 
 22  
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 23  
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 24  
 import org.apache.maven.artifact.versioning.VersionRange;
 25  
 
 26  
 /**
 27  
  *
 28  
  * @author mkleint
 29  
  */
 30  
 public final class RequirementMatcherFactory
 31  
 {
 32  
 
 33  
     private RequirementMatcherFactory( )
 34  0
     {
 35  0
     }
 36  
 
 37  
     public static RequirementMatcher createExactMatcher( String provideValue )
 38  
     {
 39  1
         return new ExactMatcher( provideValue );
 40  
     }
 41  
 
 42  
     public static RequirementMatcher createVersionMatcher( String provideValue )
 43  
     {
 44  1
         return new VersionMatcher( provideValue );
 45  
     }
 46  
 
 47  1
     private static final class ExactMatcher
 48  
         implements RequirementMatcher
 49  
     {
 50  
 
 51  
         private String provides;
 52  
 
 53  
         private ExactMatcher( String provides )
 54  1
         {
 55  1
             this.provides = provides;
 56  1
         }
 57  
 
 58  
         public boolean matches( String requirement )
 59  
         {
 60  4
             return provides.equalsIgnoreCase( requirement );
 61  
         }
 62  
     }
 63  
 
 64  1
     private static final class VersionMatcher
 65  
         implements RequirementMatcher
 66  
     {
 67  
 
 68  
         DefaultArtifactVersion version;
 69  
 
 70  
         private VersionMatcher( String version )
 71  1
         {
 72  1
             this.version = new DefaultArtifactVersion(version);
 73  1
         }
 74  
 
 75  
         public boolean matches( String requirement )
 76  
         {
 77  
             try 
 78  
             {
 79  7
                 VersionRange range = VersionRange.createFromVersionSpec(requirement);
 80  7
                 if (range.hasRestrictions()) {
 81  5
                     return range.containsVersion(version);
 82  
                 } else {
 83  2
                     return range.getRecommendedVersion().compareTo(version) == 0;
 84  
                 }
 85  
             } 
 86  0
             catch (InvalidVersionSpecificationException ex) 
 87  
             {
 88  
                 //TODO error reporting
 89  0
                 ex.printStackTrace();
 90  0
                 return false;
 91  
             }
 92  
         }
 93  
     }
 94  
 }