Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
35b7a169
Commit
35b7a169
authored
Feb 28, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
52b40ee4
3cc0055d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
143 additions
and
16 deletions
+143
-16
JettyServletWebServerFactory.java
...boot/web/embedded/jetty/JettyServletWebServerFactory.java
+1
-1
TomcatServletWebServerFactory.java
...ot/web/embedded/tomcat/TomcatServletWebServerFactory.java
+1
-1
UndertowServletWebServerFactory.java
...eb/embedded/undertow/UndertowServletWebServerFactory.java
+1
-1
AbstractServletWebServerFactory.java
...t/web/servlet/server/AbstractServletWebServerFactory.java
+12
-0
StaticResourceJars.java
...framework/boot/web/servlet/server/StaticResourceJars.java
+28
-11
StaticResourceJarsTests.java
...work/boot/web/servlet/server/StaticResourceJarsTests.java
+98
-0
IdeApplicationLauncher.java
...amework/boot/context/embedded/IdeApplicationLauncher.java
+2
-2
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java
View file @
35b7a169
...
...
@@ -287,7 +287,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
private
Resource
createResource
(
URL
url
)
throws
IOException
{
if
(
"file"
.
equals
(
url
.
getProtocol
()))
{
File
file
=
new
File
(
url
.
getFile
(
));
File
file
=
new
File
(
getDecodedFile
(
url
));
if
(
file
.
isFile
())
{
return
Resource
.
newResource
(
"jar:"
+
url
+
"!/META-INF/resources"
);
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java
View file @
35b7a169
...
...
@@ -682,7 +682,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private
void
addResourceJars
(
List
<
URL
>
resourceJarUrls
)
{
for
(
URL
url
:
resourceJarUrls
)
{
String
file
=
url
.
getFile
(
);
String
file
=
getDecodedFile
(
url
);
if
(
file
.
endsWith
(
".jar"
)
||
file
.
endsWith
(
".jar!/"
))
{
String
jar
=
url
.
toString
();
if
(!
jar
.
startsWith
(
"jar:"
))
{
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java
View file @
35b7a169
...
...
@@ -367,7 +367,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
:
new
LoaderHidingResourceManager
(
rootResourceManager
));
for
(
URL
url
:
metaInfResourceUrls
)
{
if
(
"file"
.
equals
(
url
.
getProtocol
()))
{
File
file
=
new
File
(
url
.
getFile
(
));
File
file
=
new
File
(
getDecodedFile
(
url
));
if
(
file
.
isFile
())
{
try
{
resourceJarUrls
.
add
(
new
URL
(
"jar:"
+
url
+
"!/"
));
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java
View file @
35b7a169
...
...
@@ -17,7 +17,9 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
import
java.io.File
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -280,6 +282,16 @@ public abstract class AbstractServletWebServerFactory
return
this
.
staticResourceJars
.
getUrls
();
}
protected
final
String
getDecodedFile
(
URL
url
)
{
try
{
return
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
ex
)
{
throw
new
IllegalStateException
(
"Failed to decode '"
+
url
.
getFile
()
+
"' using UTF-8"
);
}
}
protected
final
File
getValidSessionStoreDir
()
{
return
getValidSessionStoreDir
(
true
);
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java
View file @
35b7a169
...
...
@@ -18,15 +18,18 @@ package org.springframework.boot.web.servlet.server;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.management.ManagementFactory
;
import
java.net.JarURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.net.URLConnection
;
import
java.net.URLDecoder
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.jar.JarFile
;
import
java.util.stream.Stream
;
/**
* Logic to extract URLs of static resource jars (those containing
...
...
@@ -37,21 +40,25 @@ import java.util.jar.JarFile;
*/
class
StaticResourceJars
{
public
final
List
<
URL
>
getUrls
()
{
List
<
URL
>
getUrls
()
{
ClassLoader
classLoader
=
getClass
().
getClassLoader
();
List
<
URL
>
urls
=
new
ArrayList
<>();
if
(
classLoader
instanceof
URLClassLoader
)
{
for
(
URL
url
:
((
URLClassLoader
)
classLoader
).
getURLs
())
{
addUrl
(
urls
,
url
);
}
return
getUrlsFrom
(((
URLClassLoader
)
classLoader
).
getURLs
());
}
else
{
for
(
String
entry
:
ManagementFactory
.
getRuntimeMXBean
().
getClassPath
()
.
split
(
File
.
pathSeparator
))
{
addUrl
(
urls
,
toUrl
(
entry
));
}
return
getUrlsFrom
(
Stream
.
of
(
ManagementFactory
.
getRuntimeMXBean
().
getClassPath
()
.
split
(
File
.
pathSeparator
))
.
map
(
this
::
toUrl
).
toArray
(
URL
[]::
new
));
}
}
List
<
URL
>
getUrlsFrom
(
URL
...
urls
)
{
List
<
URL
>
resourceJarUrls
=
new
ArrayList
<>();
for
(
URL
url
:
urls
)
{
addUrl
(
resourceJarUrls
,
url
);
}
return
u
rls
;
return
resourceJarU
rls
;
}
private
URL
toUrl
(
String
classPathEntry
)
{
...
...
@@ -67,7 +74,7 @@ class StaticResourceJars {
private
void
addUrl
(
List
<
URL
>
urls
,
URL
url
)
{
try
{
if
(
"file"
.
equals
(
url
.
getProtocol
()))
{
addUrlFile
(
urls
,
url
,
new
File
(
url
.
getFile
(
)));
addUrlFile
(
urls
,
url
,
new
File
(
getDecodedFile
(
url
)));
}
else
{
addUrlConnection
(
urls
,
url
,
url
.
openConnection
());
...
...
@@ -78,6 +85,16 @@ class StaticResourceJars {
}
}
private
String
getDecodedFile
(
URL
url
)
{
try
{
return
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
ex
)
{
throw
new
IllegalStateException
(
"Failed to decode '"
+
url
.
getFile
()
+
"' using UTF-8"
);
}
}
private
void
addUrlFile
(
List
<
URL
>
urls
,
URL
url
,
File
file
)
{
if
((
file
.
isDirectory
()
&&
new
File
(
file
,
"META-INF/resources"
).
isDirectory
())
||
isResourcesJar
(
file
))
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java
0 → 100644
View file @
35b7a169
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.List
;
import
java.util.function.Consumer
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link StaticResourceJars}.
*
* @author Rupert Madden-Abbott
* @author Andy Wilkinson
*/
public
class
StaticResourceJarsTests
{
@Rule
public
final
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
@Test
public
void
includeJarWithStaticResources
()
throws
Exception
{
File
jarFile
=
createResourcesJar
(
"test-resources.jar"
);
List
<
URL
>
staticResourceJarUrls
=
new
StaticResourceJars
()
.
getUrlsFrom
(
jarFile
.
toURI
().
toURL
());
assertThat
(
staticResourceJarUrls
).
hasSize
(
1
);
}
@Test
public
void
includeJarWithStaticResourcesWithUrlEncodedSpaces
()
throws
Exception
{
File
jarFile
=
createResourcesJar
(
"test resources.jar"
);
List
<
URL
>
staticResourceJarUrls
=
new
StaticResourceJars
()
.
getUrlsFrom
(
jarFile
.
toURI
().
toURL
());
assertThat
(
staticResourceJarUrls
).
hasSize
(
1
);
}
@Test
public
void
excludeJarWithoutStaticResources
()
throws
Exception
{
File
jarFile
=
createJar
(
"dependency.jar"
);
List
<
URL
>
staticResourceJarUrls
=
new
StaticResourceJars
()
.
getUrlsFrom
(
jarFile
.
toURI
().
toURL
());
assertThat
(
staticResourceJarUrls
).
hasSize
(
0
);
}
private
File
createResourcesJar
(
String
name
)
throws
IOException
{
return
createJar
(
name
,
(
output
)
->
{
JarEntry
jarEntry
=
new
JarEntry
(
"META-INF/resources"
);
try
{
output
.
putNextEntry
(
jarEntry
);
output
.
closeEntry
();
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
});
}
private
File
createJar
(
String
name
)
throws
IOException
{
return
createJar
(
name
,
null
);
}
private
File
createJar
(
String
name
,
Consumer
<
JarOutputStream
>
customizer
)
throws
IOException
{
File
jarFile
=
this
.
temporaryFolder
.
newFile
(
name
);
JarOutputStream
jarOutputStream
=
new
JarOutputStream
(
new
FileOutputStream
(
jarFile
));
if
(
customizer
!=
null
)
{
customizer
.
accept
(
jarOutputStream
);
}
jarOutputStream
.
close
();
return
jarFile
;
}
}
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java
View file @
35b7a169
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
*/
class
IdeApplicationLauncher
extends
AbstractApplicationLauncher
{
private
final
File
exploded
=
new
File
(
"target/ide"
);
private
final
File
exploded
=
new
File
(
"target/ide
application
"
);
IdeApplicationLauncher
(
ApplicationBuilder
applicationBuilder
)
{
super
(
applicationBuilder
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment