Detect path of exploded war correctly on Windows
Previously, AbstractEmbeddedServletContainerFactory detected an exploded war by looking for `/WEB-INF/` in the path of its code source's location. This failed on Windows due to the use of `\` rather than `/` separators. This commit updates AbstractEmbeddedServletContainerFactory to uses the OS's separator rather than hardcoding `/`. Closes gh-8100
This commit is contained in:
parent
265a712294
commit
bfee21730c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2015 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -83,16 +83,22 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getExplodedWarFileDocumentRoot() {
|
private File getExplodedWarFileDocumentRoot() {
|
||||||
File file = getCodeSourceArchive();
|
return getExplodedWarFileDocumentRoot(getCodeSourceArchive());
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
this.logger.debug("Code archive: " + file);
|
|
||||||
}
|
}
|
||||||
if (file != null && file.exists()
|
|
||||||
&& file.getAbsolutePath().contains("/WEB-INF/")) {
|
File getExplodedWarFileDocumentRoot(File codeSourceFile) {
|
||||||
String path = file.getAbsolutePath();
|
if (this.logger.isDebugEnabled()) {
|
||||||
path = path.substring(0, path.indexOf("/WEB-INF/"));
|
this.logger.debug("Code archive: " + codeSourceFile);
|
||||||
|
}
|
||||||
|
if (codeSourceFile != null && codeSourceFile.exists()) {
|
||||||
|
String path = codeSourceFile.getAbsolutePath();
|
||||||
|
int webInfPathIndex = path
|
||||||
|
.indexOf(File.separatorChar + "WEB-INF" + File.separatorChar);
|
||||||
|
if (webInfPathIndex >= 0) {
|
||||||
|
path = path.substring(0, webInfPathIndex);
|
||||||
return new File(path);
|
return new File(path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -915,6 +915,24 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||||
assertThat(getCharset(Locale.ITALIAN)).isNull();
|
assertThat(getCharset(Locale.ITALIAN)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void explodedWarFileDocumentRootWhenRunningFromExplodedWar() throws Exception {
|
||||||
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||||
|
File webInfClasses = this.temporaryFolder.newFolder("test.war", "WEB-INF", "lib",
|
||||||
|
"spring-boot.jar");
|
||||||
|
File documentRoot = factory.getExplodedWarFileDocumentRoot(webInfClasses);
|
||||||
|
assertThat(documentRoot)
|
||||||
|
.isEqualTo(webInfClasses.getParentFile().getParentFile().getParentFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void explodedWarFileDocumentRootWhenRunningFromPackagedWar() throws Exception {
|
||||||
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||||
|
File codeSourceFile = this.temporaryFolder.newFile("test.war");
|
||||||
|
File documentRoot = factory.getExplodedWarFileDocumentRoot(codeSourceFile);
|
||||||
|
assertThat(documentRoot).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void addConnector(int port,
|
protected abstract void addConnector(int port,
|
||||||
AbstractEmbeddedServletContainerFactory factory);
|
AbstractEmbeddedServletContainerFactory factory);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue