Skip to content

Commit f93a609

Browse files
committed
refactor(ResourceUrl): move static resources-related values to the corresponding class.
Addressed to #927 No functional changes.
1 parent 4a1c672 commit f93a609

File tree

11 files changed

+92
-47
lines changed

11 files changed

+92
-47
lines changed

Dangerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,9 @@ end
698698
js_file = %r{^src/main/javascript/.*\.js$}
699699
css_file = %r{^src/main/webapp/.*\.css$}
700700
modified_resources = git.modified_files.any? { |file| file =~ js_file || file =~ css_file }
701-
updated_url = git.modified_files.include? 'src/main/java/ru/mystamps/web/Url.java'
701+
updated_url = git.modified_files.include? 'src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java'
702702
if modified_resources && !updated_url
703-
warn("danger check: looks like you forgot to update `Url.RESOURCES_VERSION` after modifying JS/CSS file(s)")
703+
warn("danger check: looks like you forgot to update `ResourceUrl.RESOURCES_VERSION` after modifying JS/CSS file(s)")
704704
end
705705

706706
all_checks_passed = violation_report[:errors].empty? && violation_report[:warnings].empty? && violation_report[:messages].empty?

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

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ru.mystamps.web.feature.series.SeriesUrl;
2828
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
2929
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportUrl;
30+
import ru.mystamps.web.feature.site.ResourceUrl;
3031
import ru.mystamps.web.feature.site.SiteUrl;
3132

3233
import java.util.HashMap;
@@ -44,26 +45,10 @@ public final class Url {
4445
// see also src/main/resources/application-test.properties
4546
public static final String H2_CONSOLE_PAGE = "/console";
4647

47-
// MUST be updated when any of our resources were modified
48-
public static final String RESOURCES_VERSION = "v0.3.13";
49-
50-
private static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
51-
52-
// CheckStyle: ignore LineLength for next 7 lines
53-
private static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css";
54-
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
55-
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
56-
private static final String PARTICIPANT_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/participant/add.min.js"; // NOPMD: AvoidDuplicateLiterals
57-
private static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js"; // NOPMD: AvoidDuplicateLiterals
58-
private static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js"; // NOPMD: AvoidDuplicateLiterals
59-
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js"; // NOPMD: AvoidDuplicateLiterals
60-
private static final String FAVICON_ICO = "/favicon.ico";
61-
62-
// CheckStyle: ignore LineLength for next 4 lines
48+
// CheckStyle: ignore LineLength for next 3 lines
6349
private static final String BOOTSTRAP_CSS = "/public/bootstrap/3.4.1/css/bootstrap.min.css";
6450
private static final String BOOTSTRAP_JS = "/public/bootstrap/3.4.1/js/bootstrap.min.js";
6551
private static final String JQUERY_JS = "/public/jquery/1.9.1/jquery.min.js";
66-
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css";
6752

6853
// CheckStyle: ignore LineLength for next 3 lines
6954
// FIXME: use minimal version of CSS file when it will be available (https://github.com/webjars/selectize.js/issues/3)
@@ -92,41 +77,26 @@ public static Map<String, String> asMap(boolean production) {
9277
CollectionUrl.exposeUrlsToView(map);
9378
ParticipantUrl.exposeUrlsToView(map);
9479
ReportUrl.exposeUrlsToView(map);
80+
ResourceUrl.exposeUrlsToView(map);
9581
SeriesUrl.exposeUrlsToView(map);
9682
SeriesImportUrl.exposeUrlsToView(map);
9783
SeriesSalesImportUrl.exposeUrlsToView(map);
9884
SiteUrl.exposeUrlsToView(map);
9985

100-
map.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE);
10186
map.put("PUBLIC_URL", production ? SiteUrl.PUBLIC_URL : SiteUrl.SITE);
10287

10388
if (serveContentFromSingleHost) {
10489
ImageUrl.exposeResourcesToView(map, null);
90+
ResourceUrl.exposeResourcesToView(map, null);
10591

10692
map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS);
10793
map.put("BOOTSTRAP_JS", BOOTSTRAP_JS);
108-
map.put("CATALOG_UTILS_JS", CATALOG_UTILS_JS);
109-
map.put("COLLECTION_INFO_JS", COLLECTION_INFO_JS);
110-
map.put("DATE_UTILS_JS", DATE_UTILS_JS);
111-
map.put("FAVICON_ICO", FAVICON_ICO);
11294
map.put("JQUERY_JS", JQUERY_JS);
113-
map.put("MAIN_CSS", MAIN_CSS);
114-
map.put("PARTICIPANT_ADD_JS", PARTICIPANT_ADD_JS);
11595
map.put("SELECTIZE_CSS", SELECTIZE_CSS);
11696
map.put("SELECTIZE_JS", SELECTIZE_JS);
117-
map.put("SERIES_ADD_JS", SERIES_ADD_JS);
118-
map.put("SERIES_INFO_JS", SERIES_INFO_JS);
11997
} else {
120-
ImageUrl.exposeResourcesToView(map, STATIC_RESOURCES_URL);
121-
122-
map.put("CATALOG_UTILS_JS", STATIC_RESOURCES_URL + CATALOG_UTILS_JS);
123-
map.put("COLLECTION_INFO_JS", STATIC_RESOURCES_URL + COLLECTION_INFO_JS);
124-
map.put("DATE_UTILS_JS", STATIC_RESOURCES_URL + DATE_UTILS_JS);
125-
map.put("FAVICON_ICO", STATIC_RESOURCES_URL + FAVICON_ICO);
126-
map.put("MAIN_CSS", STATIC_RESOURCES_URL + MAIN_CSS);
127-
map.put("PARTICIPANT_ADD_JS", STATIC_RESOURCES_URL + PARTICIPANT_ADD_JS);
128-
map.put("SERIES_ADD_JS", STATIC_RESOURCES_URL + SERIES_ADD_JS);
129-
map.put("SERIES_INFO_JS", STATIC_RESOURCES_URL + SERIES_INFO_JS);
98+
ImageUrl.exposeResourcesToView(map, ResourceUrl.STATIC_RESOURCES_URL);
99+
ResourceUrl.exposeResourcesToView(map, ResourceUrl.STATIC_RESOURCES_URL);
130100

131101
// Use CDN for the external resources like libraries
132102
map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS_CDN);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
4040
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
4141
import org.springframework.web.servlet.resource.VersionResourceResolver;
42-
import ru.mystamps.web.Url;
4342
import ru.mystamps.web.feature.account.AccountConfig;
4443
import ru.mystamps.web.feature.account.AccountUrl;
4544
import ru.mystamps.web.feature.category.CategoryConfig;
@@ -59,6 +58,7 @@
5958
import ru.mystamps.web.feature.series.importing.SeriesImportUrl;
6059
import ru.mystamps.web.feature.series.importing.event.EventsConfig;
6160
import ru.mystamps.web.feature.series.importing.sale.SeriesSalesImportConfig;
61+
import ru.mystamps.web.feature.site.ResourceUrl;
6262
import ru.mystamps.web.feature.site.SiteConfig;
6363
import ru.mystamps.web.feature.site.SiteUrl;
6464
import ru.mystamps.web.support.spring.mvc.RestExceptionHandler;
@@ -111,7 +111,7 @@ public void addViewControllers(ViewControllerRegistry registry) {
111111
@Override
112112
public void addResourceHandlers(ResourceHandlerRegistry registry) {
113113
VersionResourceResolver resourceResolver = new VersionResourceResolver()
114-
.addFixedVersionStrategy(Url.RESOURCES_VERSION, "/**");
114+
.addFixedVersionStrategy(ResourceUrl.RESOURCES_VERSION, "/**");
115115

116116
@SuppressWarnings("checkstyle:magicnumber")
117117
CacheControl cacheControl = CacheControl.maxAge(7, TimeUnit.DAYS);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (C) 2009-2019 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.feature.site;
19+
20+
import java.util.Map;
21+
22+
/**
23+
* Static resources URLs.
24+
*
25+
* Should be used everywhere instead of hard-coded paths.
26+
*
27+
* @author Slava Semushin
28+
*/
29+
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
30+
public final class ResourceUrl {
31+
32+
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
33+
34+
// MUST be updated when any of our resources were modified
35+
public static final String RESOURCES_VERSION = "v0.3.13";
36+
37+
// CheckStyle: ignore LineLength for next 8 lines
38+
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";
39+
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
40+
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js";
41+
private static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css";
42+
private static final String PARTICIPANT_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/participant/add.min.js";
43+
private static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js";
44+
private static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js";
45+
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css";
46+
private static final String FAVICON_ICO = "/favicon.ico";
47+
48+
private ResourceUrl() {
49+
}
50+
51+
public static void exposeUrlsToView(Map<String, String> urls) {
52+
urls.put("BOOTSTRAP_LANGUAGE", BOOTSTRAP_LANGUAGE);
53+
}
54+
55+
public static void exposeResourcesToView(Map<String, String> resources, String host) {
56+
put(resources, host, "CATALOG_UTILS_JS", CATALOG_UTILS_JS);
57+
put(resources, host, "COLLECTION_INFO_JS", COLLECTION_INFO_JS);
58+
put(resources, host, "DATE_UTILS_JS", DATE_UTILS_JS);
59+
put(resources, host, "FAVICON_ICO", FAVICON_ICO);
60+
put(resources, host, "MAIN_CSS", MAIN_CSS);
61+
put(resources, host, "PARTICIPANT_ADD_JS", PARTICIPANT_ADD_JS);
62+
put(resources, host, "SERIES_ADD_JS", SERIES_ADD_JS);
63+
put(resources, host, "SERIES_INFO_JS", SERIES_INFO_JS);
64+
}
65+
66+
private static void put(Map<String, String> map, String valuePrefix, String key, String value) {
67+
if (valuePrefix == null) {
68+
map.put(key, value);
69+
return;
70+
}
71+
72+
map.put(key, valuePrefix + value);
73+
}
74+
75+
}

src/main/javascript/CatalogUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
var CatalogUtils = {

src/main/javascript/DateUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
var DateUtils = {

src/main/javascript/collection/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
function initPage(statByCategories, statByCountries) {

src/main/javascript/participant/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
function initPage() {

src/main/javascript/series/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
function initPage(suggestCategoryUrl, suggestCountryUrl) {

src/main/javascript/series/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// IMPORTANT:
3-
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
//
55

66
function initPage(ajax, importSeriesSaleUrl, csrfHeaderName, csrfTokenValue) {

src/main/webapp/WEB-INF/static/styles/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* IMPORTANT:
3-
* You have to update Url.RESOURCES_VERSION each time whenever you're modified this file!
3+
* You have to update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
44
*/
55

66
/* Only for debug: highlight borders of rows and columns */

0 commit comments

Comments
 (0)