18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2017, 2023 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2017, 2025 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected] >.
23
23
* Portions Copyright (c) 2022, Krystof Tulinger <[email protected] >.
24
24
*/
34
34
import java .util .TreeSet ;
35
35
36
36
import org .jetbrains .annotations .NotNull ;
37
+ import org .jetbrains .annotations .VisibleForTesting ;
37
38
import org .webjars .WebJarAssetLocator ;
38
39
39
40
/**
43
44
*/
44
45
public class Scripts implements Iterable <Scripts .Script > {
45
46
46
- private static final String DEBUG_SUFFIX = "-debug" ;
47
+ @ VisibleForTesting
48
+ static final String DEBUG_SUFFIX = "-debug" ;
47
49
private static final String WEBJAR_PATH_PREFIX = "META-INF/resources/" ;
48
50
49
- enum Type {
51
+ /**
52
+ * Holds type of the script.
53
+ */
54
+ public enum Type {
50
55
MINIFIED , DEBUG
51
56
}
52
57
@@ -64,12 +69,18 @@ public abstract static class Script {
64
69
*/
65
70
protected String scriptData ;
66
71
protected int priority ;
72
+ private final String scriptName ;
67
73
68
- protected Script (String scriptData , int priority ) {
74
+ protected Script (String scriptName , String scriptData , int priority ) {
75
+ this .scriptName = scriptName ;
69
76
this .scriptData = scriptData ;
70
77
this .priority = priority ;
71
78
}
72
79
80
+ public String getScriptName () {
81
+ return scriptName ;
82
+ }
83
+
73
84
public abstract String toHtml ();
74
85
75
86
public String getScriptData () {
@@ -87,7 +98,11 @@ public int getPriority() {
87
98
public static class FileScript extends Script {
88
99
89
100
public FileScript (String script , int priority ) {
90
- super (script , priority );
101
+ super (null , script , priority );
102
+ }
103
+
104
+ public FileScript (String scriptName , String script , int priority ) {
105
+ super (scriptName , script , priority );
91
106
}
92
107
93
108
@ Override
@@ -98,7 +113,6 @@ public String toHtml() {
98
113
this .getPriority () +
99
114
"\" ></script>\n " ;
100
115
}
101
-
102
116
}
103
117
104
118
protected static final Map <String , Script > SCRIPTS = new TreeMap <>();
@@ -209,6 +223,11 @@ public boolean isEmpty() {
209
223
return outputScripts .iterator ();
210
224
}
211
225
226
+ @ VisibleForTesting
227
+ List <String > getScriptNames () {
228
+ return outputScripts .stream ().map (Script ::getScriptName ).toList ();
229
+ }
230
+
212
231
/**
213
232
* Add a script which is identified by the name.
214
233
*
@@ -231,7 +250,7 @@ public boolean addScript(String contextPath, String scriptName, Type type) {
231
250
}
232
251
233
252
private void addScript (String contextPath , String scriptName ) {
234
- this .addScript (new FileScript (contextPath + SCRIPTS .get (scriptName ).getScriptData (),
253
+ this .addScript (new FileScript (scriptName , contextPath + SCRIPTS .get (scriptName ).getScriptData (),
235
254
SCRIPTS .get (scriptName ).getPriority ()));
236
255
}
237
256
0 commit comments