Skip to content

Commit 783a7ca

Browse files
committed
Merge branch '5.1.x'
2 parents 4f57d71 + 9f03d15 commit 783a7ca

File tree

10 files changed

+84
-58
lines changed

10 files changed

+84
-58
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ configure(allprojects) { project ->
143143
}
144144

145145
checkstyle {
146-
toolVersion = "8.16"
146+
toolVersion = "8.17"
147147
configDir = rootProject.file("src/checkstyle")
148148
}
149149

@@ -157,7 +157,7 @@ configure(allprojects) { project ->
157157
testCompile("junit:junit:4.12") {
158158
exclude group: "org.hamcrest", module: "hamcrest-core"
159159
}
160-
testCompile("org.mockito:mockito-core:2.23.4") {
160+
testCompile("org.mockito:mockito-core:2.24.0") {
161161
exclude group: "org.hamcrest", module: "hamcrest-core"
162162
}
163163
testCompile("io.mockk:mockk:1.9")

spring-core/src/main/java/org/springframework/util/SocketUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,7 +73,6 @@ public class SocketUtils {
7373
* &lt;bean id="bean2" ... p:port="#{socketUtils.findAvailableTcpPort(30000)}" /&gt;</code></pre>
7474
*/
7575
public SocketUtils() {
76-
/* no-op */
7776
}
7877

7978

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,7 +76,6 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
7676
* @since 4.0.3
7777
*/
7878
public ResourceDatabasePopulator() {
79-
/* no-op */
8079
}
8180

8281
/**
@@ -87,7 +86,6 @@ public ResourceDatabasePopulator() {
8786
* @since 4.0.3
8887
*/
8988
public ResourceDatabasePopulator(Resource... scripts) {
90-
this();
9189
setScripts(scripts);
9290
}
9391

@@ -97,19 +95,19 @@ public ResourceDatabasePopulator(Resource... scripts) {
9795
* logged but not cause a failure
9896
* @param ignoreFailedDrops flag to indicate that a failed SQL {@code DROP}
9997
* statement can be ignored
100-
* @param sqlScriptEncoding the encoding for the supplied SQL scripts; may
101-
* be {@code null} or <em>empty</em> to indicate platform encoding
98+
* @param sqlScriptEncoding the encoding for the supplied SQL scripts
99+
* (may be {@code null} or <em>empty</em> to indicate platform encoding)
102100
* @param scripts the scripts to execute to initialize or clean up the database
103101
* (never {@code null})
104102
* @since 4.0.3
105103
*/
106104
public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops,
107105
@Nullable String sqlScriptEncoding, Resource... scripts) {
108106

109-
this(scripts);
110107
this.continueOnError = continueOnError;
111108
this.ignoreFailedDrops = ignoreFailedDrops;
112109
setSqlScriptEncoding(sqlScriptEncoding);
110+
setScripts(scripts);
113111
}
114112

115113

@@ -148,10 +146,10 @@ private void assertContentsOfScriptArray(Resource... scripts) {
148146
}
149147

150148
/**
151-
* Specify the encoding for the configured SQL scripts, if different from the
152-
* platform encoding.
153-
* @param sqlScriptEncoding the encoding used in scripts; may be {@code null}
154-
* or empty to indicate platform encoding
149+
* Specify the encoding for the configured SQL scripts,
150+
* if different from the platform encoding.
151+
* @param sqlScriptEncoding the encoding used in scripts
152+
* (may be {@code null} or empty to indicate platform encoding)
155153
* @see #addScript(Resource)
156154
*/
157155
public void setSqlScriptEncoding(@Nullable String sqlScriptEncoding) {

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,7 +107,7 @@ public abstract class ScriptUtils {
107107
* in a block comment will be omitted from the output. In addition, multiple
108108
* adjacent whitespace characters will be collapsed into a single space.
109109
* @param script the SQL script
110-
* @param separator character separating each statement &mdash; typically a ';'
110+
* @param separator character separating each statement (typically a ';')
111111
* @param statements the list that will contain the individual statements
112112
* @throws ScriptException if an error occurred while splitting the SQL script
113113
* @see #splitSqlScript(String, String, List)
@@ -130,7 +130,8 @@ public static void splitSqlScript(String script, char separator, List<String> st
130130
* in a block comment will be omitted from the output. In addition, multiple
131131
* adjacent whitespace characters will be collapsed into a single space.
132132
* @param script the SQL script
133-
* @param separator text separating each statement &mdash; typically a ';' or newline character
133+
* @param separator text separating each statement
134+
* (typically a ';' or newline character)
134135
* @param statements the list that will contain the individual statements
135136
* @throws ScriptException if an error occurred while splitting the SQL script
136137
* @see #splitSqlScript(String, char, List)
@@ -153,11 +154,11 @@ public static void splitSqlScript(String script, String separator, List<String>
153154
* omitted from the output. In addition, multiple adjacent whitespace characters
154155
* will be collapsed into a single space.
155156
* @param resource the resource from which the script was read
156-
* @param script the SQL script; never {@code null} or empty
157-
* @param separator text separating each statement &mdash; typically a ';' or
158-
* newline character; never {@code null}
159-
* @param commentPrefix the prefix that identifies SQL line comments &mdash;
160-
* typically "--"; never {@code null} or empty
157+
* @param script the SQL script
158+
* @param separator text separating each statement
159+
* (typically a ';' or newline character)
160+
* @param commentPrefix the prefix that identifies SQL line comments
161+
* (typically "--")
161162
* @param blockCommentStartDelimiter the <em>start</em> block comment delimiter;
162163
* never {@code null} or empty
163164
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter;
@@ -259,7 +260,7 @@ else if (c == ' ' || c == '\n' || c == '\t') {
259260
* @throws IOException in case of I/O errors
260261
*/
261262
static String readScript(EncodedResource resource) throws IOException {
262-
return readScript(resource, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR);
263+
return readScript(resource, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
263264
}
264265

265266
/**
@@ -270,18 +271,19 @@ static String readScript(EncodedResource resource) throws IOException {
270271
* a statement &mdash; will be included in the results.
271272
* @param resource the {@code EncodedResource} containing the script
272273
* to be processed
273-
* @param commentPrefix the prefix that identifies comments in the SQL script &mdash;
274-
* typically "--"
275-
* @param separator the statement separator in the SQL script &mdash; typically ";"
274+
* @param commentPrefix the prefix that identifies comments in the SQL script
275+
* (typically "--")
276+
* @param separator the statement separator in the SQL script (typically ";")
277+
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
276278
* @return a {@code String} containing the script lines
277279
* @throws IOException in case of I/O errors
278280
*/
279281
private static String readScript(EncodedResource resource, @Nullable String commentPrefix,
280-
@Nullable String separator) throws IOException {
282+
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
281283

282284
LineNumberReader lnr = new LineNumberReader(resource.getReader());
283285
try {
284-
return readScript(lnr, commentPrefix, separator);
286+
return readScript(lnr, commentPrefix, separator, blockCommentEndDelimiter);
285287
}
286288
finally {
287289
lnr.close();
@@ -297,19 +299,21 @@ private static String readScript(EncodedResource resource, @Nullable String comm
297299
* a statement &mdash; will be included in the results.
298300
* @param lineNumberReader the {@code LineNumberReader} containing the script
299301
* to be processed
300-
* @param commentPrefix the prefix that identifies comments in the SQL script &mdash;
301-
* typically "--"
302-
* @param separator the statement separator in the SQL script &mdash; typically ";"
302+
* @param lineCommentPrefix the prefix that identifies comments in the SQL script
303+
* (typically "--")
304+
* @param separator the statement separator in the SQL script (typically ";")
305+
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
303306
* @return a {@code String} containing the script lines
304307
* @throws IOException in case of I/O errors
305308
*/
306-
public static String readScript(LineNumberReader lineNumberReader, @Nullable String commentPrefix,
307-
@Nullable String separator) throws IOException {
309+
public static String readScript(LineNumberReader lineNumberReader, @Nullable String lineCommentPrefix,
310+
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
308311

309312
String currentStatement = lineNumberReader.readLine();
310313
StringBuilder scriptBuilder = new StringBuilder();
311314
while (currentStatement != null) {
312-
if (commentPrefix != null && !currentStatement.startsWith(commentPrefix)) {
315+
if ((blockCommentEndDelimiter != null && currentStatement.contains(blockCommentEndDelimiter)) ||
316+
(lineCommentPrefix != null && !currentStatement.startsWith(lineCommentPrefix))) {
313317
if (scriptBuilder.length() > 0) {
314318
scriptBuilder.append('\n');
315319
}
@@ -431,16 +435,14 @@ public static void executeSqlScript(Connection connection, EncodedResource resou
431435
* @param ignoreFailedDrops whether or not to continue in the event of specifically
432436
* an error on a {@code DROP} statement
433437
* @param commentPrefix the prefix that identifies single-line comments in the
434-
* SQL script &mdash; typically "--"
438+
* SQL script (typically "--")
435439
* @param separator the script statement separator; defaults to
436440
* {@value #DEFAULT_STATEMENT_SEPARATOR} if not specified and falls back to
437441
* {@value #FALLBACK_STATEMENT_SEPARATOR} as a last resort; may be set to
438442
* {@value #EOF_STATEMENT_SEPARATOR} to signal that the script contains a
439443
* single statement without a separator
440-
* @param blockCommentStartDelimiter the <em>start</em> block comment delimiter; never
441-
* {@code null} or empty
442-
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter; never
443-
* {@code null} or empty
444+
* @param blockCommentStartDelimiter the <em>start</em> block comment delimiter
445+
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
444446
* @throws ScriptException if an error occurred while executing the SQL script
445447
* @see #DEFAULT_STATEMENT_SEPARATOR
446448
* @see #FALLBACK_STATEMENT_SEPARATOR
@@ -460,7 +462,7 @@ public static void executeSqlScript(Connection connection, EncodedResource resou
460462

461463
String script;
462464
try {
463-
script = readScript(resource, commentPrefix, separator);
465+
script = readScript(resource, commentPrefix, separator, blockCommentEndDelimiter);
464466
}
465467
catch (IOException ex) {
466468
throw new CannotReadScriptException(resource, ex);

spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ public void readAndSplitScriptContainingMultiLineComments() throws Exception {
162162
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
163163
}
164164

165+
@Test
166+
public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
167+
String script = readScript("test-data-with-multi-line-nested-comments.sql");
168+
List<String> statements = new ArrayList<>();
169+
splitSqlScript(script, ';', statements);
170+
171+
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
172+
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
173+
174+
assertEquals("wrong number of statements", 2, statements.size());
175+
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
176+
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
177+
}
178+
165179
@Test
166180
public void containsDelimiters() {
167181
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* This is a multi line comment
2+
* The next comment line has no text
3+
4+
* The next comment line starts with a space.
5+
* x, y, z...
6+
*/
7+
8+
INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller');
9+
-- This is also a comment.
10+
/*-------------------------------------------
11+
-- A fancy multi-line comments that puts
12+
-- single line comments inside of a multi-line
13+
-- comment block.
14+
Moreover, the block commend end delimiter
15+
appears on a line that can potentially also
16+
be a single-line comment if we weren't
17+
already inside a multi-line comment run.
18+
-------------------------------------------*/
19+
INSERT INTO
20+
users(first_name, last_name) -- This is a single line comment containing the block-end-comment sequence here */ but it's still a single-line comment
21+
VALUES( 'Sam' -- first_name
22+
, 'Brannen' -- last_name
23+
);--

spring-test/src/main/java/org/springframework/test/context/TestExecutionListener.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,6 @@ public interface TestExecutionListener {
7878
* @since 3.0
7979
*/
8080
default void beforeTestClass(TestContext testContext) throws Exception {
81-
/* no-op */
8281
}
8382

8483
/**
@@ -92,7 +91,6 @@ default void beforeTestClass(TestContext testContext) throws Exception {
9291
* @throws Exception allows any exception to propagate
9392
*/
9493
default void prepareTestInstance(TestContext testContext) throws Exception {
95-
/* no-op */
9694
}
9795

9896
/**
@@ -116,7 +114,6 @@ default void prepareTestInstance(TestContext testContext) throws Exception {
116114
* @see #afterTestExecution
117115
*/
118116
default void beforeTestMethod(TestContext testContext) throws Exception {
119-
/* no-op */
120117
}
121118

122119
/**
@@ -137,7 +134,6 @@ default void beforeTestMethod(TestContext testContext) throws Exception {
137134
* @see #afterTestExecution
138135
*/
139136
default void beforeTestExecution(TestContext testContext) throws Exception {
140-
/* no-op */
141137
}
142138

143139
/**
@@ -158,7 +154,6 @@ default void beforeTestExecution(TestContext testContext) throws Exception {
158154
* @see #beforeTestExecution
159155
*/
160156
default void afterTestExecution(TestContext testContext) throws Exception {
161-
/* no-op */
162157
}
163158

164159
/**
@@ -182,7 +177,6 @@ default void afterTestExecution(TestContext testContext) throws Exception {
182177
* @see #afterTestExecution
183178
*/
184179
default void afterTestMethod(TestContext testContext) throws Exception {
185-
/* no-op */
186180
}
187181

188182
/**
@@ -197,7 +191,6 @@ default void afterTestMethod(TestContext testContext) throws Exception {
197191
* @since 3.0
198192
*/
199193
default void afterTestClass(TestContext testContext) throws Exception {
200-
/* no-op */
201194
}
202195

203196
}

spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -141,7 +141,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
141141
* @since 4.0.4
142142
*/
143143
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
144-
/* no-op */
144+
// no-op
145145
}
146146

147147
/**

spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,7 +142,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
142142
* @since 4.0.4
143143
*/
144144
protected void validateMergedContextConfiguration(WebMergedContextConfiguration mergedConfig) {
145-
/* no-op */
145+
// no-op
146146
}
147147

148148
/**

0 commit comments

Comments
 (0)