1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.codehaus.plexus.classworlds.realm.ClassRealm;
28 import org.codehaus.plexus.component.annotations.Component;
29 import org.sonatype.aether.graph.DependencyFilter;
30
31
32
33
34 @Component( role = ProjectRealmCache.class )
35 public class DefaultProjectRealmCache
36 implements ProjectRealmCache
37 {
38
39 private static class CacheKey
40 {
41
42 private final List<? extends ClassRealm> extensionRealms;
43
44 private final int hashCode;
45
46 public CacheKey( List<? extends ClassRealm> extensionRealms )
47 {
48 this.extensionRealms = ( extensionRealms != null ) ? extensionRealms : Collections.<ClassRealm> emptyList();
49
50 this.hashCode = this.extensionRealms.hashCode();
51 }
52
53 @Override
54 public int hashCode()
55 {
56 return hashCode;
57 }
58
59 @Override
60 public boolean equals( Object o )
61 {
62 if ( o == this )
63 {
64 return true;
65 }
66
67 if ( !( o instanceof CacheKey ) )
68 {
69 return false;
70 }
71
72 CacheKey other = (CacheKey) o;
73
74 return extensionRealms.equals( other.extensionRealms );
75 }
76
77 }
78
79 private final Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
80
81 public CacheRecord get( List<? extends ClassRealm> extensionRealms )
82 {
83 return cache.get( new CacheKey( extensionRealms ) );
84 }
85
86 public CacheRecord put( List<? extends ClassRealm> extensionRealms, ClassRealm projectRealm,
87 DependencyFilter extensionArtifactFilter )
88 {
89 if ( projectRealm == null )
90 {
91 throw new NullPointerException();
92 }
93
94 CacheKey key = new CacheKey( extensionRealms );
95
96 if ( cache.containsKey( key ) )
97 {
98 throw new IllegalStateException( "Duplicate project realm for extensions " + extensionRealms );
99 }
100
101 CacheRecord record = new CacheRecord( projectRealm, extensionArtifactFilter );
102
103 cache.put( key, record );
104
105 return record;
106 }
107
108 public void flush()
109 {
110 cache.clear();
111 }
112
113 public void register( MavenProject project, CacheRecord record )
114 {
115
116 }
117
118 }