Skip to content

Commit 3ed77ae

Browse files
committed
Polish
1 parent f7397b9 commit 3ed77ae

File tree

33 files changed

+108
-246
lines changed

33 files changed

+108
-246
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcDatabaseDialect.java

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.data.jdbc;
1818

19-
import java.util.function.Supplier;
20-
2119
import org.springframework.data.jdbc.core.dialect.JdbcDb2Dialect;
2220
import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect;
2321
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
@@ -26,6 +24,7 @@
2624
import org.springframework.data.relational.core.dialect.H2Dialect;
2725
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
2826
import org.springframework.data.relational.core.dialect.MariaDbDialect;
27+
import org.springframework.data.relational.core.dialect.MySqlDialect;
2928
import org.springframework.data.relational.core.dialect.OracleDialect;
3029

3130
/**
@@ -34,87 +33,56 @@
3433
* @author Jens Schauder
3534
* @since 3.3.0
3635
*/
37-
public enum JdbcDatabaseDialect implements Supplier<Dialect> {
36+
public enum JdbcDatabaseDialect {
3837

3938
/**
4039
* Provides an instance of {@link JdbcDb2Dialect}.
4140
*/
42-
DB2 {
43-
@Override
44-
public Dialect get() {
45-
return JdbcDb2Dialect.INSTANCE;
46-
}
47-
},
41+
DB2(JdbcDb2Dialect.INSTANCE),
4842

4943
/**
5044
* Provides an instance of {@link H2Dialect}.
5145
*/
52-
H2 {
53-
@Override
54-
public Dialect get() {
55-
return H2Dialect.INSTANCE;
56-
}
57-
},
46+
H2(H2Dialect.INSTANCE),
5847

5948
/**
6049
* Provides an instance of {@link HsqlDbDialect}.
6150
*/
62-
HSQL {
63-
@Override
64-
public Dialect get() {
65-
return HsqlDbDialect.INSTANCE;
66-
}
67-
},
51+
HSQL(HsqlDbDialect.INSTANCE),
6852

6953
/**
7054
* Provides an instance of {@link MariaDbDialect}.
7155
*/
72-
MARIA {
73-
@Override
74-
public Dialect get() {
75-
return MariaDbDialect.INSTANCE;
76-
}
77-
},
56+
MARIA(MySqlDialect.INSTANCE),
7857

7958
/**
8059
* Provides an instance of {@link JdbcMySqlDialect}.
8160
*/
82-
MYSQL {
83-
@Override
84-
public Dialect get() {
85-
return JdbcMySqlDialect.INSTANCE;
86-
}
87-
},
61+
MYSQL(MySqlDialect.INSTANCE),
8862

8963
/**
9064
* Provides an instance of {@link OracleDialect}.
9165
*/
92-
ORACLE {
93-
@Override
94-
public Dialect get() {
95-
return OracleDialect.INSTANCE;
96-
97-
}
98-
},
66+
ORACLE(OracleDialect.INSTANCE),
9967

10068
/**
10169
* Provides an instance of {@link JdbcPostgresDialect}.
10270
*/
103-
POSTGRESQL {
104-
@Override
105-
public Dialect get() {
106-
return JdbcPostgresDialect.INSTANCE;
107-
}
108-
},
71+
POSTGRESQL(JdbcPostgresDialect.INSTANCE),
10972

11073
/**
11174
* Provides an instance of {@link JdbcSqlServerDialect}.
11275
*/
113-
SQL_SERVER {
114-
@Override
115-
public Dialect get() {
116-
return JdbcSqlServerDialect.INSTANCE;
117-
}
76+
SQL_SERVER(JdbcSqlServerDialect.INSTANCE);
77+
78+
private final Dialect dialect;
79+
80+
JdbcDatabaseDialect(Dialect dialect) {
81+
this.dialect = dialect;
82+
}
83+
84+
final Dialect getDialect() {
85+
return this.dialect;
11886
}
11987

12088
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations op
148148
@ConditionalOnMissingBean
149149
public Dialect jdbcDialect(NamedParameterJdbcOperations operations) {
150150
JdbcDatabaseDialect dialect = this.properties.getDialect();
151-
if (dialect != null) {
152-
return dialect.get();
153-
}
154-
return super.jdbcDialect(operations);
151+
return (dialect != null) ? dialect.getDialect() : super.jdbcDialect(operations);
155152
}
156153

157154
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/BundleContentProperty.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ private Path toPath() {
6868

6969
private Resource getResource() {
7070
Assert.state(!isPemContent(), "Value contains PEM content");
71-
ApplicationResourceLoader resourceLoader = new ApplicationResourceLoader();
72-
return resourceLoader.getResource(this.value);
71+
return new ApplicationResourceLoader().getResource(this.value);
7372
}
7473

7574
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ void SseSubscriptionShouldWork() {
109109
.contentTypeCompatibleWith(MediaType.TEXT_EVENT_STREAM)
110110
.expectBody(String.class)
111111
.returnResult();
112-
113112
assertThat(result.getResponseBody()).contains("event:next",
114113
"data:{\"data\":{\"booksOnSale\":{\"id\":\"book-1\",\"name\":\"GraphQL for beginners\",\"pageCount\":100,\"author\":\"John GraphQL\"}}}",
115114
"event:next",

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ protected CopyAction createCopyAction() {
156156

157157
@SuppressWarnings("removal")
158158
private boolean isIncludeJarmodeTools() {
159-
if (!this.getIncludeTools().get()) {
160-
return false;
161-
}
162-
return this.layered.getIncludeLayerTools().get();
159+
return Boolean.TRUE.equals(this.getIncludeTools().get())
160+
&& Boolean.TRUE.equals(this.layered.getIncludeLayerTools().get());
163161
}
164162

165163
@Override

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ protected CopyAction createCopyAction() {
130130

131131
@SuppressWarnings("removal")
132132
private boolean isIncludeJarmodeTools() {
133-
if (!this.getIncludeTools().get()) {
134-
return false;
135-
}
136-
return this.layered.getIncludeLayerTools().get();
133+
return Boolean.TRUE.equals(this.getIncludeTools().get())
134+
&& Boolean.TRUE.equals(this.layered.getIncludeLayerTools().get());
137135
}
138136

139137
@Override

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/Command.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,13 @@ private String claimArg(Deque<String> args) {
316316
}
317317
if (this.optionalValue) {
318318
String nextArg = args.peek();
319-
if (nextArg == null || nextArg.startsWith("--")) {
320-
return null;
321-
}
319+
return (nextArg != null && !nextArg.startsWith("--")) ? args.removeFirst() : null;
320+
}
321+
try {
322322
return args.removeFirst();
323323
}
324-
else {
325-
try {
326-
return args.removeFirst();
327-
}
328-
catch (NoSuchElementException ex) {
329-
throw new MissingValueException(this.name);
330-
}
324+
catch (NoSuchElementException ex) {
325+
throw new MissingValueException(this.name);
331326
}
332327
}
333328

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/ExtractCommand.java

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ private void extractArchive(FileResolver fileResolver, EntryNameTransformer entr
236236
}
237237

238238
private Layers getLayers() {
239-
if (this.layers != null) {
240-
return this.layers;
241-
}
242-
return Layers.get(this.context);
239+
return (this.layers != null) ? this.layers : Layers.get(this.context);
243240
}
244241

245242
private void createApplication(JarStructure jarStructure, FileResolver fileResolver, Map<Option, String> options)
@@ -250,7 +247,7 @@ private void createApplication(JarStructure jarStructure, FileResolver fileResol
250247
}
251248
String librariesDirectory = getLibrariesDirectory(options);
252249
Manifest manifest = jarStructure.createLauncherManifest((library) -> librariesDirectory + library);
253-
mkDirs(file.getParentFile());
250+
mkdirs(file.getParentFile());
254251
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(file), manifest)) {
255252
withJarEntries(this.context.getArchiveFile(), ((stream, jarEntry) -> {
256253
Entry entry = jarStructure.resolve(jarEntry);
@@ -272,14 +269,11 @@ private String getApplicationFilename(Map<Option, String> options) {
272269
}
273270

274271
private static boolean isType(Entry entry, Type type) {
275-
if (entry == null) {
276-
return false;
277-
}
278-
return entry.type() == type;
272+
return (entry != null) && entry.type() == type;
279273
}
280274

281275
private static void extractEntry(InputStream stream, JarEntry entry, File file) throws IOException {
282-
mkDirs(file.getParentFile());
276+
mkdirs(file.getParentFile());
283277
try (OutputStream out = new FileOutputStream(file)) {
284278
StreamUtils.copy(stream, out);
285279
}
@@ -293,27 +287,18 @@ private static void extractEntry(InputStream stream, JarEntry entry, File file)
293287
}
294288

295289
private static FileTime getCreationTime(JarEntry entry) {
296-
if (entry.getCreationTime() != null) {
297-
return entry.getCreationTime();
298-
}
299-
return entry.getLastModifiedTime();
290+
return (entry.getCreationTime() != null) ? entry.getCreationTime() : entry.getLastModifiedTime();
300291
}
301292

302293
private static FileTime getLastAccessTime(JarEntry entry) {
303-
if (entry.getLastAccessTime() != null) {
304-
return entry.getLastAccessTime();
305-
}
306-
return getLastModifiedTime(entry);
294+
return (entry.getLastAccessTime() != null) ? entry.getLastAccessTime() : getLastModifiedTime(entry);
307295
}
308296

309297
private static FileTime getLastModifiedTime(JarEntry entry) {
310-
if (entry.getLastModifiedTime() != null) {
311-
return entry.getLastModifiedTime();
312-
}
313-
return entry.getCreationTime();
298+
return (entry.getLastModifiedTime() != null) ? entry.getLastModifiedTime() : entry.getCreationTime();
314299
}
315300

316-
private static void mkDirs(File file) throws IOException {
301+
private static void mkdirs(File file) throws IOException {
317302
if (!file.exists() && !file.mkdirs()) {
318303
throw new IOException("Unable to create directory " + file);
319304
}
@@ -461,7 +446,7 @@ private static final class LayersFileResolver implements FileResolver {
461446
public void createDirectories() throws IOException {
462447
for (String layer : this.layers) {
463448
if (shouldExtractLayer(layer)) {
464-
mkDirs(getLayerDirectory(layer));
449+
mkdirs(getLayerDirectory(layer));
465450
}
466451
}
467452
}
@@ -492,10 +477,7 @@ private File getLayerDirectory(String layer) {
492477
}
493478

494479
private boolean shouldExtractLayer(String layer) {
495-
if (this.layersToExtract.isEmpty()) {
496-
return true;
497-
}
498-
return this.layersToExtract.contains(layer);
480+
return this.layersToExtract.isEmpty() || this.layersToExtract.contains(layer);
499481
}
500482

501483
}

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedJarStructure.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ class IndexedJarStructure implements JarStructure {
6565

6666
private static String getLocation(Manifest manifest, String attribute) {
6767
String location = getMandatoryAttribute(manifest, attribute);
68-
if (!location.endsWith("/")) {
69-
location = location + "/";
70-
}
71-
return location;
68+
return (!location.endsWith("/")) ? location + "/" : location;
7269
}
7370

7471
private static List<String> readIndexFile(String indexFile) {
@@ -78,12 +75,8 @@ private static List<String> readIndexFile(String indexFile) {
7875
.toArray(String[]::new);
7976
List<String> classpathEntries = new ArrayList<>();
8077
for (String line : lines) {
81-
if (line.startsWith("- ")) {
82-
classpathEntries.add(line.substring(3, line.length() - 1));
83-
}
84-
else {
85-
throw new IllegalStateException("Classpath index file is malformed");
86-
}
78+
Assert.state(line.startsWith("- "), "Classpath index file is malformed");
79+
classpathEntries.add(line.substring(3, line.length() - 1));
8780
}
8881
Assert.state(!classpathEntries.isEmpty(), "Empty classpath index file loaded");
8982
return classpathEntries;
@@ -99,10 +92,10 @@ public Entry resolve(String name) {
9992
if (this.classpathEntries.contains(name)) {
10093
return new Entry(name, toStructureDependency(name), Type.LIBRARY);
10194
}
102-
else if (name.startsWith(this.classesLocation)) {
95+
if (name.startsWith(this.classesLocation)) {
10396
return new Entry(name, name.substring(this.classesLocation.length()), Type.APPLICATION_CLASS_OR_RESOURCE);
10497
}
105-
else if (name.startsWith("org/springframework/boot/loader")) {
98+
if (name.startsWith("org/springframework/boot/loader")) {
10699
return new Entry(name, name, Type.LOADER);
107100
}
108101
return null;

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/JarStructure.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ default Entry resolve(ZipEntry entry) {
6868
* @param type of the entry
6969
*/
7070
record Entry(String originalLocation, String location, Type type) {
71+
7172
enum Type {
7273

7374
LIBRARY, APPLICATION_CLASS_OR_RESOURCE, LOADER
7475

7576
}
77+
7678
}
7779

7880
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
import static org.assertj.core.api.Assertions.assertThat;
4545

4646
/**
47+
* Base class for jar mode tests.
48+
*
4749
* @author Moritz Halbritter
4850
*/
49-
abstract class AbstractTests {
51+
abstract class AbstractJarModeTests {
5052

5153
@TempDir
5254
File tempDir;

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/test/java/org/springframework/boot/jarmode/tools/ExtractCommandTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* @author Moritz Halbritter
4242
*/
43-
class ExtractCommandTests extends AbstractTests {
43+
class ExtractCommandTests extends AbstractJarModeTests {
4444

4545
private static final Instant CREATION_TIME = Instant.parse("2020-01-01T00:00:00Z");
4646

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/test/java/org/springframework/boot/jarmode/tools/ListLayersCommandTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Moritz Halbritter
3131
*/
32-
class ListLayersCommandTests extends AbstractTests {
32+
class ListLayersCommandTests extends AbstractJarModeTests {
3333

3434
@Test
3535
void shouldListLayers() throws IOException {

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/test/java/org/springframework/boot/jarmode/tools/ToolsJarModeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Moritz Halbritter
3030
*/
31-
class ToolsJarModeTests extends AbstractTests {
31+
class ToolsJarModeTests extends AbstractJarModeTests {
3232

3333
private ToolsJarMode mode;
3434

0 commit comments

Comments
 (0)