41
41
* shading process.
42
42
*/
43
43
public class ServicesResourceTransformer
44
- extends AbstractCompatibilityTransformer
44
+ extends AbstractCompatibilityTransformer
45
45
{
46
-
47
46
private static final String SERVICES_PATH = "META-INF/services" ;
48
47
49
48
private final Map <String , ArrayList <String >> serviceEntries = new HashMap <>();
50
49
51
- private List <Relocator > relocators ;
52
-
53
50
private long time = Long .MIN_VALUE ;
54
51
55
52
public boolean canTransformResource ( String resource )
@@ -58,14 +55,20 @@ public boolean canTransformResource( String resource )
58
55
}
59
56
60
57
public void processResource ( String resource , InputStream is , final List <Relocator > relocators , long time )
61
- throws IOException
58
+ throws IOException
62
59
{
63
- ArrayList < String > out = serviceEntries . get ( resource );
64
- if ( out == null )
60
+ resource = resource . substring ( SERVICES_PATH . length () + 1 );
61
+ for ( Relocator relocator : relocators )
65
62
{
66
- out = new ArrayList <>();
67
- serviceEntries .put ( resource , out );
63
+ if ( relocator .canRelocateClass ( resource ) )
64
+ {
65
+ resource = relocator .relocateClass ( resource );
66
+ break ;
67
+ }
68
68
}
69
+ resource = SERVICES_PATH + '/' + resource ;
70
+
71
+ ArrayList <String > out = serviceEntries .computeIfAbsent ( resource , k -> new ArrayList <>() );
69
72
70
73
Scanner scanner = new Scanner ( is , StandardCharsets .UTF_8 .name () );
71
74
while ( scanner .hasNextLine () )
@@ -81,14 +84,9 @@ public void processResource( String resource, InputStream is, final List<Relocat
81
84
out .add ( relContent );
82
85
}
83
86
84
- if ( this .relocators == null )
85
- {
86
- this .relocators = relocators ;
87
- }
88
-
89
87
if ( time > this .time )
90
88
{
91
- this .time = time ;
89
+ this .time = time ;
92
90
}
93
91
}
94
92
@@ -98,28 +96,13 @@ public boolean hasTransformedResource()
98
96
}
99
97
100
98
public void modifyOutputStream ( JarOutputStream jos )
101
- throws IOException
99
+ throws IOException
102
100
{
103
101
for ( Map .Entry <String , ArrayList <String >> entry : serviceEntries .entrySet () )
104
102
{
105
103
String key = entry .getKey ();
106
104
ArrayList <String > data = entry .getValue ();
107
105
108
- if ( relocators != null )
109
- {
110
- key = key .substring ( SERVICES_PATH .length () + 1 );
111
- for ( Relocator relocator : relocators )
112
- {
113
- if ( relocator .canRelocateClass ( key ) )
114
- {
115
- key = relocator .relocateClass ( key );
116
- break ;
117
- }
118
- }
119
-
120
- key = SERVICES_PATH + '/' + key ;
121
- }
122
-
123
106
JarEntry jarEntry = new JarEntry ( key );
124
107
jarEntry .setTime ( time );
125
108
jos .putNextEntry ( jarEntry );
0 commit comments