Browse Source

Polish 'Remove duplicated `file.getName()` call'

See gh-42411
pull/42420/head
Phillip Webb 1 year ago
parent
commit
60f615849d
  1. 21
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerPortFileWriter.java

21
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,18 +108,13 @@ public class WebServerPortFileWriter implements ApplicationListener<WebServerIni @@ -108,18 +108,13 @@ public class WebServerPortFileWriter implements ApplicationListener<WebServerIni
if (!StringUtils.hasLength(namespace)) {
return this.file;
}
String name = this.file.getName();
String extension = StringUtils.getFilenameExtension(name);
StringBuilder builder = new StringBuilder(name);
String suffix = "-" + (isUpperCase(name) ? namespace.toUpperCase(Locale.ENGLISH) : namespace.toLowerCase(Locale.ENGLISH));
if (StringUtils.hasLength(extension))
builder.insert(name.lastIndexOf(extension) - 1, suffix);
else
builder.append(suffix);
return new File(this.file.getParentFile(), builder.toString());
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