1818 */
1919
2020/*
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.
2222 * Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
2323 * Portions Copyright (c) 2022, Krystof Tulinger <k.tulinger@seznam.cz>.
2424 */
3434import java .util .TreeSet ;
3535
3636import org .jetbrains .annotations .NotNull ;
37+ import org .jetbrains .annotations .VisibleForTesting ;
3738import org .webjars .WebJarAssetLocator ;
3839
3940/**
4344 */
4445public class Scripts implements Iterable <Scripts .Script > {
4546
46- private static final String DEBUG_SUFFIX = "-debug" ;
47+ @ VisibleForTesting
48+ static final String DEBUG_SUFFIX = "-debug" ;
4749 private static final String WEBJAR_PATH_PREFIX = "META-INF/resources/" ;
4850
49- enum Type {
51+ /**
52+ * Holds type of the script.
53+ */
54+ public enum Type {
5055 MINIFIED , DEBUG
5156 }
5257
@@ -64,12 +69,18 @@ public abstract static class Script {
6469 */
6570 protected String scriptData ;
6671 protected int priority ;
72+ private final String scriptName ;
6773
68- protected Script (String scriptData , int priority ) {
74+ protected Script (String scriptName , String scriptData , int priority ) {
75+ this .scriptName = scriptName ;
6976 this .scriptData = scriptData ;
7077 this .priority = priority ;
7178 }
7279
80+ public String getScriptName () {
81+ return scriptName ;
82+ }
83+
7384 public abstract String toHtml ();
7485
7586 public String getScriptData () {
@@ -87,7 +98,11 @@ public int getPriority() {
8798 public static class FileScript extends Script {
8899
89100 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 );
91106 }
92107
93108 @ Override
@@ -98,7 +113,6 @@ public String toHtml() {
98113 this .getPriority () +
99114 "\" ></script>\n " ;
100115 }
101-
102116 }
103117
104118 protected static final Map <String , Script > SCRIPTS = new TreeMap <>();
@@ -209,6 +223,11 @@ public boolean isEmpty() {
209223 return outputScripts .iterator ();
210224 }
211225
226+ @ VisibleForTesting
227+ List <String > getScriptNames () {
228+ return outputScripts .stream ().map (Script ::getScriptName ).toList ();
229+ }
230+
212231 /**
213232 * Add a script which is identified by the name.
214233 *
@@ -231,7 +250,7 @@ public boolean addScript(String contextPath, String scriptName, Type type) {
231250 }
232251
233252 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 (),
235254 SCRIPTS .get (scriptName ).getPriority ()));
236255 }
237256
0 commit comments