View Javadoc
1   package org.apache.maven.project;
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 java.io.File;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  /**
27   * Holds all POM files that are known to the reactor. This allows the project builder to resolve imported POMs from the
28   * reactor when building another project's effective model.
29   * 
30   * @author Benjamin Bentmann
31   */
32  class ReactorModelPool
33  {
34  
35      private final Map<CacheKey, File> pomFiles = new HashMap<CacheKey, File>();
36  
37      public File get( String groupId, String artifactId, String version )
38      {
39          return pomFiles.get( new CacheKey( groupId, artifactId, version ) );
40      }
41  
42      public void put( String groupId, String artifactId, String version, File pomFile )
43      {
44          pomFiles.put( new CacheKey( groupId, artifactId, version ), pomFile );
45      }
46  
47      private static final class CacheKey
48      {
49  
50          private final String groupId;
51  
52          private final String artifactId;
53  
54          private final String version;
55  
56          private final int hashCode;
57  
58          public CacheKey( String groupId, String artifactId, String version )
59          {
60              this.groupId = ( groupId != null ) ? groupId : "";
61              this.artifactId = ( artifactId != null ) ? artifactId : "";
62              this.version = ( version != null ) ? version : "";
63  
64              int hash = 17;
65              hash = hash * 31 + this.groupId.hashCode();
66              hash = hash * 31 + this.artifactId.hashCode();
67              hash = hash * 31 + this.version.hashCode();
68              hashCode = hash;
69          }
70  
71          @Override
72          public boolean equals( Object obj )
73          {
74              if ( this == obj )
75              {
76                  return true;
77              }
78  
79              if ( !( obj instanceof CacheKey ) )
80              {
81                  return false;
82              }
83  
84              CacheKey that = (CacheKey) obj;
85  
86              return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
87                  && version.equals( that.version );
88          }
89  
90          @Override
91          public int hashCode()
92          {
93              return hashCode;
94          }
95  
96          @Override
97          public String toString()
98          {
99              StringBuilder buffer = new StringBuilder( 96 );
100             buffer.append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( version );
101             return buffer.toString();
102         }
103 
104     }
105 
106 }