ClientLibraryImpl.java
9.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.granite.ui.clientlibs.impl;
import com.adobe.granite.ui.clientlibs.ClientLibrary;
import com.adobe.granite.ui.clientlibs.LibraryType;
import com.adobe.granite.ui.clientlibs.impl.FileBundle;
import com.adobe.granite.ui.clientlibs.impl.ProcessorConfig;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ClientLibraryImpl
implements ClientLibrary {
private static final String MINIFIED_SELECTOR = ".min";
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private final String path;
private final Builder cfg;
private final Map<LibraryType, FileBundle> bundles = new HashMap<LibraryType, FileBundle>();
private final Map<String, ClientLibraryImpl> depLibs = new LinkedHashMap<String, ClientLibraryImpl>();
private final Map<String, ClientLibraryImpl> embLibs = new LinkedHashMap<String, ClientLibraryImpl>();
private final Set<String> embedders = new HashSet<String>();
private Set<String> sourcePaths;
private ClientLibraryImpl(Builder cfg) {
this.cfg = cfg;
this.path = cfg.path;
}
private static String[] trimAndClean(String[] strings) {
int i;
if (strings == null) {
return new String[0];
}
int j = 0;
for (i = 0; i < strings.length; ++i) {
String s;
String string = s = strings[i] == null ? "" : strings[i].trim();
if (s.length() <= 0) continue;
strings[j++] = s;
}
if (j != i) {
String[] copy = new String[j];
System.arraycopy(strings, 0, copy, 0, j);
return copy;
}
return strings;
}
public Map<String, ClientLibraryImpl> getDependencies(boolean transitive) {
LinkedHashMap<String, ClientLibraryImpl> deps = new LinkedHashMap<String, ClientLibraryImpl>();
this.resolve(deps, transitive);
if (transitive) {
for (ClientLibraryImpl emb : this.embLibs.values()) {
emb.resolve(deps, true);
}
}
for (ClientLibraryImpl emb : this.embLibs.values()) {
deps.remove(emb.getPath());
}
return deps;
}
public Map<String, ClientLibraryImpl> getEmbedded(LibraryType type) {
if (this.embLibs.isEmpty()) {
return this.embLibs;
}
LinkedHashMap<String, ClientLibraryImpl> libs = new LinkedHashMap<String, ClientLibraryImpl>();
for (ClientLibraryImpl emb : this.embLibs.values()) {
if (!emb.hasType(type) || this.cfg.themeName == null != (emb.cfg.themeName == null) || !Arrays.equals(this.cfg.channels, emb.cfg.channels)) continue;
libs.put(emb.getPath(), emb);
}
return libs;
}
@Override
public String getPath() {
return this.path;
}
@Override
public String getThemeName() {
return this.cfg.themeName;
}
@Override
public String getThemeLibId() {
return this.cfg.libId;
}
@Override
public String getIncludePath(LibraryType type) {
return this.getIncludePath(type, false);
}
@Override
public String getIncludePath(LibraryType type, boolean minified) {
if (this.cfg.isLegacy || type == null) {
return this.path;
}
if (this.bundles.containsKey((Object)type)) {
StringBuilder ret = new StringBuilder(this.path);
ret.append(this.cfg.cacheKey);
if (minified) {
ret.append(".min");
}
ret.append(type.extension);
return ret.toString();
}
return null;
}
@Override
public String[] getCategories() {
return this.cfg.categories;
}
@Override
public String[] getEmbeddedCategories() {
return this.cfg.embeds;
}
@Override
public String[] getDependentCategories() {
return this.cfg.dependencies;
}
@Override
public String[] getChannels() {
return this.cfg.channels;
}
@Override
public Set<LibraryType> getTypes() {
return Collections.unmodifiableSet(this.bundles.keySet());
}
@Override
public boolean allowProxy() {
return this.cfg.allowProxy;
}
protected List<ProcessorConfig> getProcessorConfig(LibraryType type) {
return type == LibraryType.CSS ? this.cfg.cssProcessors : this.cfg.jsProcessors;
}
protected void addDependency(ClientLibraryImpl lib) {
this.depLibs.put(lib.getPath(), lib);
}
protected void addEmbedded(ClientLibraryImpl lib) {
this.embLibs.put(lib.getPath(), lib);
lib.embedders.add(this.path);
}
protected FileBundle getBundle(LibraryType type) {
return this.bundles.get((Object)type);
}
protected void addBundle(LibraryType type, FileBundle bundle) {
this.bundles.put(type, bundle);
}
protected void clear() {
this.depLibs.clear();
this.embLibs.clear();
this.embedders.clear();
}
protected Set<String> getEmbedders() {
return this.embedders;
}
protected ClientLibraryImpl createCopy() {
ClientLibraryImpl lib = new ClientLibraryImpl(this.cfg);
lib.bundles.putAll(this.bundles);
lib.depLibs.putAll(this.depLibs);
lib.embLibs.putAll(this.embLibs);
lib.embedders.addAll(this.embedders);
return lib;
}
protected void relink(Map<String, ClientLibraryImpl> libs) {
HashSet<String> paths = new HashSet<String>(this.depLibs.keySet());
for (String path2 : paths) {
this.depLibs.put(path2, libs.get(path2));
}
paths.clear();
paths.addAll(this.embLibs.keySet());
for (String path2 : paths) {
this.embLibs.put(path2, libs.get(path2));
}
}
private void resolve(Map<String, ClientLibraryImpl> collect, boolean transitive) {
for (ClientLibraryImpl dep : this.depLibs.values()) {
if (collect.containsKey(dep.getPath())) continue;
if (transitive) {
dep.resolve(collect, true);
}
collect.put(dep.getPath(), dep);
}
}
private boolean hasType(LibraryType type) {
return this.bundles.isEmpty() || type == null || this.bundles.containsKey((Object)type);
}
public Set<String> getSourcePaths() {
if (this.sourcePaths == null) {
this.sourcePaths = new HashSet<String>();
for (FileBundle bundle : this.bundles.values()) {
bundle.addSourcePaths(this.sourcePaths);
}
}
return this.sourcePaths;
}
public void invalidateSourcePaths() {
this.sourcePaths = null;
}
static /* synthetic */ String[] access$000() {
return EMPTY_STRING_ARRAY;
}
public static class Builder {
private final String path;
private String[] categories = ClientLibraryImpl.access$000();
private String[] dependencies = ClientLibraryImpl.access$000();
private String[] embeds = ClientLibraryImpl.access$000();
private String[] channels = ClientLibraryImpl.access$000();
private boolean isLegacy;
private String themeName;
private String libId;
private boolean allowProxy;
private String cacheKey = "";
private List<ProcessorConfig> cssProcessors = Collections.emptyList();
private List<ProcessorConfig> jsProcessors = Collections.emptyList();
public Builder(String path) {
this.path = path;
}
public Builder withCategories(String[] categories) {
this.categories = ClientLibraryImpl.trimAndClean(categories);
return this;
}
public Builder withDependencies(String[] dependencies) {
this.dependencies = ClientLibraryImpl.trimAndClean(dependencies);
return this;
}
public Builder withEmbeds(String[] embeds) {
this.embeds = ClientLibraryImpl.trimAndClean(embeds);
return this;
}
public Builder withChannels(String[] channels) {
this.channels = ClientLibraryImpl.trimAndClean(channels);
return this;
}
public Builder withIsLegacy(boolean isLegacy) {
this.isLegacy = isLegacy;
return this;
}
public Builder withThemeName(String themeName) {
this.themeName = themeName;
return this;
}
public Builder withLibId(String libId) {
this.libId = libId;
return this;
}
public Builder withAllowProxy(boolean allowProxy) {
this.allowProxy = allowProxy;
return this;
}
public Builder withCacheKey(String cacheKey) {
this.cacheKey = cacheKey == null ? "" : "." + cacheKey;
return this;
}
public Builder withCssProcessors(List<ProcessorConfig> config) {
this.cssProcessors = config == null ? Collections.emptyList() : config;
return this;
}
public Builder withJsProcessors(List<ProcessorConfig> config) {
this.jsProcessors = config == null ? Collections.emptyList() : config;
return this;
}
public ClientLibraryImpl build() {
return new ClientLibraryImpl(this);
}
}
}