Browse Source

Merge pull request #42411 from choi-hyeseong

* pr/42411:
  Polish 'Remove duplicated `file.getName()` call'
  Remove duplicated `file.getName()` call

Closes gh-42411
pull/42420/head
Phillip Webb 1 year ago
parent
commit
65a72c0969
  1. 22
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -108,19 +108,13 @@ public class WebServerPortFileWriter implements ApplicationListener<WebServerIni @@ -108,19 +108,13 @@ public class WebServerPortFileWriter implements ApplicationListener<WebServerIni
if (!StringUtils.hasLength(namespace)) {
return this.file;
}
String name = this.file.getName();
String extension = StringUtils.getFilenameExtension(this.file.getName());
name = name.substring(0, name.length() - extension.length() - 1);
if (isUpperCase(name)) {
name = name + "-" + namespace.toUpperCase(Locale.ENGLISH);
}
else {
name = name + "-" + namespace.toLowerCase(Locale.ENGLISH);
}
if (StringUtils.hasLength(extension)) {
name = name + "." + extension;
}
return new File(this.file.getParentFile(), name);
String filename = this.file.getName();
String extension = StringUtils.getFilenameExtension(filename);
String filenameWithoutExtension = filename.substring(0, filename.length() - extension.length() - 1);
String suffix = (!isUpperCase(filename)) ? namespace.toLowerCase(Locale.ENGLISH)
: namespace.toUpperCase(Locale.ENGLISH);
return new File(this.file.getParentFile(),
filenameWithoutExtension + "-" + suffix + ((!StringUtils.hasLength(extension)) ? "" : "." + extension));
}
private String getServerNamespace(ApplicationContext applicationContext) {

Loading…
Cancel
Save