Skip to content

Commit b8eab5d

Browse files
committed
refactor: move WebJar-related resources to ResourceUrl.
Addressed to #927 No functional changes.
1 parent 18086f4 commit b8eab5d

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
<!-- Set JVM options for maven-surefire-plugin -->
463463
<argLine>-Xss256k</argLine>
464464

465-
<!-- Don't forget to update version in the Url class -->
465+
<!-- Don't forget to update version in the ResourceUrl class -->
466466
<bootstrap.version>3.4.1</bootstrap.version>
467467

468468
<cglib.version>2.2.2</cglib.version>
@@ -520,7 +520,7 @@
520520
<!-- Redefine default value from spring-boot-dependencies (https://github.com/spring-projects/spring-boot/blob/v1.5.21.RELEASE/spring-boot-dependencies/pom.xml) -->
521521
<jetty.version>9.2.18.v20160721</jetty.version>
522522

523-
<!-- Don't forget to update version in the Url class -->
523+
<!-- Don't forget to update version in the ResourceUrl class -->
524524
<jquery.version>1.9.1</jquery.version>
525525

526526
<jsoup.version>1.12.1</jsoup.version>
@@ -554,7 +554,7 @@
554554
<robotframework-selenium.version>2.53.1.1</robotframework-selenium.version>
555555
<robotframework.version>3.0.4</robotframework.version>
556556

557-
<!-- Don't forget to update version in the Url class and in the src/main/webapp/WEB-INF/views/series/add.html -->
557+
<!-- Don't forget to update version in the ResourceUrl class and in the src/main/webapp/WEB-INF/views/series/add.html -->
558558
<selectizejs.version>0.12.5</selectizejs.version>
559559

560560
<!-- Redefine default value from spring-boot-dependencies (https://github.com/spring-projects/spring-boot/blob/v1.5.21.RELEASE/spring-boot-dependencies/pom.xml) -->

src/main/java/ru/mystamps/web/Url.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,6 @@ public final class Url {
4545
// see also src/main/resources/application-test.properties
4646
public static final String H2_CONSOLE_PAGE = "/console";
4747

48-
// CheckStyle: ignore LineLength for next 3 lines
49-
private static final String BOOTSTRAP_CSS = "/public/bootstrap/3.4.1/css/bootstrap.min.css";
50-
private static final String BOOTSTRAP_JS = "/public/bootstrap/3.4.1/js/bootstrap.min.js";
51-
private static final String JQUERY_JS = "/public/jquery/1.9.1/jquery.min.js";
52-
53-
// CheckStyle: ignore LineLength for next 3 lines
54-
// FIXME: use minimal version of CSS file when it will be available (https://github.com/webjars/selectize.js/issues/3)
55-
private static final String SELECTIZE_CSS = "/public/selectize/0.12.5/css/selectize.bootstrap3.css";
56-
private static final String SELECTIZE_JS = "/public/selectize/0.12.5/js/standalone/selectize.min.js";
57-
58-
// see also pom.xml and ru.mystamps.web.config.MvcConfig#addResourceHandlers()
59-
// CheckStyle: ignore LineLength for next 5 lines
60-
private static final String BOOTSTRAP_CSS_CDN = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css";
61-
private static final String BOOTSTRAP_JS_CDN = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js";
62-
private static final String JQUERY_JS_CDN = "https://yandex.st/jquery/1.9.1/jquery.min.js";
63-
private static final String SELECTIZE_CSS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.5/css/selectize.bootstrap3.min.css";
64-
private static final String SELECTIZE_JS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.5/js/standalone/selectize.min.js";
65-
6648
private Url() {
6749
}
6850

@@ -83,27 +65,16 @@ public static Map<String, String> asMap(boolean production) {
8365
SeriesSalesImportUrl.exposeUrlsToView(map);
8466
SiteUrl.exposeUrlsToView(map);
8567

68+
ResourceUrl.exposeWebjarResourcesToView(map, production);
69+
8670
map.put("PUBLIC_URL", production ? SiteUrl.PUBLIC_URL : SiteUrl.SITE);
8771

8872
if (serveContentFromSingleHost) {
8973
ImageUrl.exposeResourcesToView(map, null);
9074
ResourceUrl.exposeResourcesToView(map, null);
91-
92-
map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS);
93-
map.put("BOOTSTRAP_JS", BOOTSTRAP_JS);
94-
map.put("JQUERY_JS", JQUERY_JS);
95-
map.put("SELECTIZE_CSS", SELECTIZE_CSS);
96-
map.put("SELECTIZE_JS", SELECTIZE_JS);
9775
} else {
9876
ImageUrl.exposeResourcesToView(map, ResourceUrl.STATIC_RESOURCES_URL);
9977
ResourceUrl.exposeResourcesToView(map, ResourceUrl.STATIC_RESOURCES_URL);
100-
101-
// Use CDN for the external resources like libraries
102-
map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS_CDN);
103-
map.put("BOOTSTRAP_JS", BOOTSTRAP_JS_CDN);
104-
map.put("JQUERY_JS", JQUERY_JS_CDN);
105-
map.put("SELECTIZE_CSS", SELECTIZE_CSS_CDN);
106-
map.put("SELECTIZE_JS", SELECTIZE_JS_CDN);
10778
}
10879

10980
return map;

src/main/java/ru/mystamps/web/config/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
126126
.resourceChain(true)
127127
.addResolver(resourceResolver);
128128

129-
// For WebJars:
129+
// For WebJars. See also ResourceUrl class
130130
registry.addResourceHandler("/public/bootstrap/**")
131131
.addResourceLocations("classpath:/META-INF/resources/webjars/bootstrap/");
132132
registry.addResourceHandler("/public/jquery/**")

src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public final class ResourceUrl {
4444
private static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js";
4545
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css";
4646
private static final String FAVICON_ICO = "/favicon.ico";
47+
48+
// see also pom.xml and MvcConfig.addResourceHandlers()
49+
private static final String BOOTSTRAP_CSS = "/bootstrap/3.4.1/css/bootstrap.min.css";
50+
private static final String BOOTSTRAP_JS = "/bootstrap/3.4.1/js/bootstrap.min.js";
51+
private static final String JQUERY_JS = "/jquery/1.9.1/jquery.min.js";
52+
private static final String SELECTIZE_JS = "/0.12.5/js/standalone/selectize.min.js";
53+
54+
// CheckStyle: ignore LineLength for next 3 lines
55+
// FIXME: use minimal version of CSS file when it will be available (https://github.com/webjars/selectize.js/issues/3)
56+
private static final String SELECTIZE_CSS = "/public/selectize/0.12.5/css/selectize.bootstrap3.css";
57+
private static final String SELECTIZE_CSS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.5/css/selectize.bootstrap3.min.css";
4758

4859
private ResourceUrl() {
4960
}
@@ -63,6 +74,25 @@ public static void exposeResourcesToView(Map<String, String> resources, String h
6374
put(resources, host, "SERIES_INFO_JS", SERIES_INFO_JS);
6475
}
6576

77+
// see also MvcConfig.addResourceHandlers()
78+
public static void exposeWebjarResourcesToView(Map<String, String> resources, boolean useCdn) {
79+
if (useCdn) {
80+
put(resources, "https://maxcdn.bootstrapcdn.com", "BOOTSTRAP_CSS", BOOTSTRAP_CSS);
81+
put(resources, "https://maxcdn.bootstrapcdn.com", "BOOTSTRAP_JS", BOOTSTRAP_JS);
82+
put(resources, "https://yandex.st", "JQUERY_JS", JQUERY_JS);
83+
// CheckStyle: ignore LineLength for next 1 line
84+
put(resources, "https://cdnjs.cloudflare.com/ajax/libs/selectize.js", "SELECTIZE_JS", SELECTIZE_JS);
85+
put(resources, null, "SELECTIZE_CSS", SELECTIZE_CSS_CDN);
86+
return;
87+
}
88+
89+
put(resources, "/public", "BOOTSTRAP_CSS", BOOTSTRAP_CSS);
90+
put(resources, "/public", "BOOTSTRAP_JS", BOOTSTRAP_JS);
91+
put(resources, "/public", "JQUERY_JS", JQUERY_JS);
92+
put(resources, "/public/selectize", "SELECTIZE_JS", SELECTIZE_JS);
93+
put(resources, null, "SELECTIZE_CSS", SELECTIZE_CSS);
94+
}
95+
6696
private static void put(Map<String, String> map, String valuePrefix, String key, String value) {
6797
if (valuePrefix == null) {
6898
map.put(key, value);

0 commit comments

Comments
 (0)