Skip to content

Commit 65a72c0

Browse files
committed
Merge pull request #42411 from choi-hyeseong
* pr/42411: Polish 'Remove duplicated `file.getName()` call' Remove duplicated `file.getName()` call Closes gh-42411
2 parents 21b0bde + 60f6158 commit 65a72c0

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -108,19 +108,13 @@ protected File getPortFile(ApplicationContext applicationContext) {
108108
if (!StringUtils.hasLength(namespace)) {
109109
return this.file;
110110
}
111-
String name = this.file.getName();
112-
String extension = StringUtils.getFilenameExtension(this.file.getName());
113-
name = name.substring(0, name.length() - extension.length() - 1);
114-
if (isUpperCase(name)) {
115-
name = name + "-" + namespace.toUpperCase(Locale.ENGLISH);
116-
}
117-
else {
118-
name = name + "-" + namespace.toLowerCase(Locale.ENGLISH);
119-
}
120-
if (StringUtils.hasLength(extension)) {
121-
name = name + "." + extension;
122-
}
123-
return new File(this.file.getParentFile(), name);
111+
String filename = this.file.getName();
112+
String extension = StringUtils.getFilenameExtension(filename);
113+
String filenameWithoutExtension = filename.substring(0, filename.length() - extension.length() - 1);
114+
String suffix = (!isUpperCase(filename)) ? namespace.toLowerCase(Locale.ENGLISH)
115+
: namespace.toUpperCase(Locale.ENGLISH);
116+
return new File(this.file.getParentFile(),
117+
filenameWithoutExtension + "-" + suffix + ((!StringUtils.hasLength(extension)) ? "" : "." + extension));
124118
}
125119

126120
private String getServerNamespace(ApplicationContext applicationContext) {

0 commit comments

Comments
 (0)