23
23
24
24
package org .kohsuke .stapler .jelly ;
25
25
26
- import com .google .common .cache .CacheBuilder ;
27
- import com .google .common .cache .CacheLoader ;
28
- import com .google .common .cache .LoadingCache ;
29
26
import org .apache .commons .jelly .JellyContext ;
30
27
import org .apache .commons .jelly .JellyException ;
31
28
import org .apache .commons .jelly .TagLibrary ;
35
32
36
33
import java .lang .ref .WeakReference ;
37
34
import java .net .URL ;
35
+ import java .util .concurrent .ConcurrentHashMap ;
36
+ import java .util .concurrent .ConcurrentMap ;
38
37
39
38
/**
40
39
* {@link MetaClassLoader} tear-off for Jelly support.
@@ -47,7 +46,7 @@ public class JellyClassLoaderTearOff {
47
46
/**
48
47
* See {@link JellyClassTearOff#scripts} for why we use {@link WeakReference} here.
49
48
*/
50
- private volatile WeakReference <LoadingCache <String ,TagLibrary >> taglibs ;
49
+ private volatile WeakReference <ConcurrentMap <String ,TagLibrary >> taglibs ;
51
50
52
51
static ExpressionFactory EXPRESSION_FACTORY = new JexlExpressionFactory ();
53
52
@@ -56,16 +55,18 @@ public JellyClassLoaderTearOff(MetaClassLoader owner) {
56
55
}
57
56
58
57
public TagLibrary getTagLibrary (String nsUri ) {
59
- LoadingCache <String ,TagLibrary > m =null ;
58
+ ConcurrentMap <String ,TagLibrary > m =null ;
60
59
if (taglibs !=null )
61
60
m = taglibs .get ();
62
61
if (m ==null ) {
63
- m = CacheBuilder .newBuilder ().build (new CacheLoader <String ,TagLibrary >() {
64
- public TagLibrary load (String nsUri ) {
62
+ m = new ConcurrentHashMap <>();
63
+ taglibs = new WeakReference <>(m );
64
+ }
65
+ TagLibrary tl = m .computeIfAbsent (nsUri , key -> {
65
66
if (owner .parent !=null ) {
66
67
// parent first
67
- TagLibrary tl = owner .parent .loadTearOff (JellyClassLoaderTearOff .class ).getTagLibrary (nsUri );
68
- if (tl !=null ) return tl ;
68
+ TagLibrary taglib = owner .parent .loadTearOff (JellyClassLoaderTearOff .class ).getTagLibrary (nsUri );
69
+ if (taglib !=null ) return taglib ;
69
70
}
70
71
71
72
String taglibBasePath = trimHeadSlash (nsUri );
@@ -90,12 +91,7 @@ public TagLibrary load(String nsUri) {
90
91
return new StaplerTagLibrary ();
91
92
92
93
return NO_SUCH_TAGLIBRARY ; // "not found" is also cached.
93
- }
94
- });
95
- taglibs = new WeakReference <LoadingCache <String ,TagLibrary >>(m );
96
- }
97
-
98
- TagLibrary tl = m .getUnchecked (nsUri );
94
+ });
99
95
if (tl ==NO_SUCH_TAGLIBRARY ) return null ;
100
96
return tl ;
101
97
}
0 commit comments