Coverage Report - org.codehaus.mojo.flatten.model.resolution.ReactorModelPool
 
Classes in this File Line Coverage Branch Coverage Complexity
ReactorModelPool
36%
4/11
50%
1/2
2,167
ReactorModelPool$Coordinates
0%
0/13
0%
0/10
2,167
 
 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  
 package org.codehaus.mojo.flatten.model.resolution;
 20  
 
 21  
 import com.google.common.base.Objects;
 22  
 import org.apache.maven.project.MavenProject;
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.HashMap;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 
 29  
 /**
 30  
  * Holds a list of models and allows to retrieve them by their coordinates.
 31  
  *
 32  
  * @author Christoph Böhme
 33  
  */
 34  1
 class ReactorModelPool
 35  
 {
 36  
 
 37  1
     private Map<Coordinates, File> models = new HashMap<Coordinates, File>();
 38  
 
 39  
     public File find( String groupId, String artifactId, String version )
 40  
     {
 41  0
         return models.get( new Coordinates( groupId, artifactId, version ) );
 42  
     }
 43  
 
 44  
     public void addProjects( List<MavenProject> projects )
 45  
     {
 46  1
         for ( MavenProject project : projects )
 47  
         {
 48  0
             addProject( project );
 49  0
         }
 50  1
     }
 51  
 
 52  
     public void addProject( MavenProject project )
 53  
     {
 54  0
         Coordinates coordinates = new Coordinates( project.getGroupId(), project.getArtifactId(),
 55  0
                 project.getVersion() );
 56  0
         models.put( coordinates, project.getFile() );
 57  0
     }
 58  
 
 59  
     private static final class Coordinates
 60  
     {
 61  
         final String groupId;
 62  
         final String artifactId;
 63  
         final String version;
 64  
 
 65  0
         Coordinates( String groupId, String artifactId, String version ) {
 66  0
             this.groupId = groupId;
 67  0
             this.artifactId = artifactId;
 68  0
             this.version = version;
 69  0
         }
 70  
 
 71  
         @Override
 72  
         public boolean equals(Object obj) {
 73  0
             if (obj == this) {
 74  0
                 return true;
 75  
             }
 76  0
             if (obj instanceof Coordinates) {
 77  0
                 Coordinates other = (Coordinates) obj;
 78  0
                 return artifactId.equals(other.artifactId) && groupId.equals(other.groupId)
 79  0
                         && version.equals(other.version);
 80  
             }
 81  0
             return false;
 82  
         }
 83  
 
 84  
         @Override
 85  
         public int hashCode() {
 86  0
             return Objects.hashCode(artifactId, groupId, version);
 87  
         }
 88  
 
 89  
     }
 90  
 
 91  
 }