Skip to content

Commit 60f6158

Browse files
committed
Polish 'Remove duplicated file.getName() call'
See gh-42411
1 parent bd223e8 commit 60f6158

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

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

Lines changed: 8 additions & 13 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,18 +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(name);
113-
114-
StringBuilder builder = new StringBuilder(name);
115-
116-
String suffix = "-" + (isUpperCase(name) ? namespace.toUpperCase(Locale.ENGLISH) : namespace.toLowerCase(Locale.ENGLISH));
117-
if (StringUtils.hasLength(extension))
118-
builder.insert(name.lastIndexOf(extension) - 1, suffix);
119-
else
120-
builder.append(suffix);
121-
122-
return new File(this.file.getParentFile(), builder.toString());
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));
123118
}
124119

125120
private String getServerNamespace(ApplicationContext applicationContext) {

0 commit comments

Comments
 (0)