Skip to content

Commit e14c7da

Browse files
committed
Merge branch '1.5.x'
2 parents 661fd84 + 11d13d1 commit e14c7da

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2017 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.
@@ -83,15 +83,21 @@ else if (this.logger.isDebugEnabled()) {
8383
}
8484

8585
private File getExplodedWarFileDocumentRoot() {
86-
File file = getCodeSourceArchive();
86+
return getExplodedWarFileDocumentRoot(getCodeSourceArchive());
87+
}
88+
89+
File getExplodedWarFileDocumentRoot(File codeSourceFile) {
8790
if (this.logger.isDebugEnabled()) {
88-
this.logger.debug("Code archive: " + file);
91+
this.logger.debug("Code archive: " + codeSourceFile);
8992
}
90-
if (file != null && file.exists()
91-
&& file.getAbsolutePath().contains("/WEB-INF/")) {
92-
String path = file.getAbsolutePath();
93-
path = path.substring(0, path.indexOf("/WEB-INF/"));
94-
return new File(path);
93+
if (codeSourceFile != null && codeSourceFile.exists()) {
94+
String path = codeSourceFile.getAbsolutePath();
95+
int webInfPathIndex = path
96+
.indexOf(File.separatorChar + "WEB-INF" + File.separatorChar);
97+
if (webInfPathIndex >= 0) {
98+
path = path.substring(0, webInfPathIndex);
99+
return new File(path);
100+
}
95101
}
96102
return null;
97103
}

spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 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.
@@ -942,6 +942,24 @@ public void jspServletIsNotInDevelopmentModeByDefault() throws Exception {
942942
assertThat(options.getDevelopment()).isEqualTo(false);
943943
}
944944

945+
@Test
946+
public void explodedWarFileDocumentRootWhenRunningFromExplodedWar() throws Exception {
947+
AbstractEmbeddedServletContainerFactory factory = getFactory();
948+
File webInfClasses = this.temporaryFolder.newFolder("test.war", "WEB-INF", "lib",
949+
"spring-boot.jar");
950+
File documentRoot = factory.getExplodedWarFileDocumentRoot(webInfClasses);
951+
assertThat(documentRoot)
952+
.isEqualTo(webInfClasses.getParentFile().getParentFile().getParentFile());
953+
}
954+
955+
@Test
956+
public void explodedWarFileDocumentRootWhenRunningFromPackagedWar() throws Exception {
957+
AbstractEmbeddedServletContainerFactory factory = getFactory();
958+
File codeSourceFile = this.temporaryFolder.newFile("test.war");
959+
File documentRoot = factory.getExplodedWarFileDocumentRoot(codeSourceFile);
960+
assertThat(documentRoot).isNull();
961+
}
962+
945963
protected abstract void addConnector(int port,
946964
AbstractEmbeddedServletContainerFactory factory);
947965

0 commit comments

Comments
 (0)