View Javadoc
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.apache.maven.repository.internal;
20  
21  import org.apache.maven.model.building.ModelCache;
22  import org.eclipse.aether.RepositoryCache;
23  import org.eclipse.aether.RepositorySystemSession;
24  
25  /**
26   * A model builder cache backed by the repository system cache.
27   *
28   * @deprecated since 4.0.0, use {@code maven-api-impl} jar instead
29   */
30  @Deprecated(since = "4.0.0")
31  class DefaultModelCache implements ModelCache {
32  
33      private final RepositorySystemSession session;
34  
35      private final RepositoryCache cache;
36  
37      public static ModelCache newInstance(RepositorySystemSession session) {
38          if (session.getCache() == null) {
39              return null;
40          } else {
41              return new DefaultModelCache(session);
42          }
43      }
44  
45      private DefaultModelCache(RepositorySystemSession session) {
46          this.session = session;
47          this.cache = session.getCache();
48      }
49  
50      @Override
51      public Object get(String groupId, String artifactId, String version, String tag) {
52          return cache.get(session, new Key(groupId, artifactId, version, tag));
53      }
54  
55      @Override
56      public void put(String groupId, String artifactId, String version, String tag, Object data) {
57          cache.put(session, new Key(groupId, artifactId, version, tag), data);
58      }
59  
60      static class Key {
61  
62          private final String groupId;
63  
64          private final String artifactId;
65  
66          private final String version;
67  
68          private final String tag;
69  
70          private final int hash;
71  
72          Key(String groupId, String artifactId, String version, String tag) {
73              this.groupId = groupId;
74              this.artifactId = artifactId;
75              this.version = version;
76              this.tag = tag;
77  
78              int h = 17;
79              h = h * 31 + this.groupId.hashCode();
80              h = h * 31 + this.artifactId.hashCode();
81              h = h * 31 + this.version.hashCode();
82              h = h * 31 + this.tag.hashCode();
83              hash = h;
84          }
85  
86          @Override
87          public boolean equals(Object obj) {
88              if (this == obj) {
89                  return true;
90              }
91              if (null == obj || !getClass().equals(obj.getClass())) {
92                  return false;
93              }
94  
95              Key that = (Key) obj;
96              return artifactId.equals(that.artifactId)
97                      && groupId.equals(that.groupId)
98                      && version.equals(that.version)
99                      && tag.equals(that.tag);
100         }
101 
102         @Override
103         public int hashCode() {
104             return hash;
105         }
106     }
107 }