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
2c2b9622
Commit
2c2b9622
authored
Jun 17, 2019
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-17232
parents
f4d9e1c6
d82ccf14
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
214 additions
and
131 deletions
+214
-131
BootZipCopyAction.java
...amework/boot/gradle/tasks/bundling/BootZipCopyAction.java
+90
-130
LoaderZipEntries.java
...ramework/boot/gradle/tasks/bundling/LoaderZipEntries.java
+116
-0
AbstractBootArchiveTests.java
.../boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
+8
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java
View file @
2c2b9622
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LoaderZipEntries.java
0 → 100644
View file @
2c2b9622
/*
* 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
*
* https://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
.
gradle
.
tasks
.
bundling
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
org.apache.commons.compress.archivers.zip.UnixStat
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveEntry
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
;
import
org.gradle.api.file.FileTreeElement
;
import
org.gradle.api.specs.Spec
;
/**
* Internal utility used to copy entries from the {@code spring-boot-loader.jar}.
*
* @author Andy Wilkinson
* @author Phillip Webb
*/
class
LoaderZipEntries
{
private
Long
entryTime
;
LoaderZipEntries
(
Long
entryTime
)
{
this
.
entryTime
=
entryTime
;
}
public
Spec
<
FileTreeElement
>
writeTo
(
ZipArchiveOutputStream
zipOutputStream
)
throws
IOException
{
WrittenDirectoriesSpec
writtenDirectoriesSpec
=
new
WrittenDirectoriesSpec
();
try
(
ZipInputStream
loaderJar
=
new
ZipInputStream
(
getClass
().
getResourceAsStream
(
"/META-INF/loader/spring-boot-loader.jar"
)))
{
java
.
util
.
zip
.
ZipEntry
entry
=
loaderJar
.
getNextEntry
();
while
(
entry
!=
null
)
{
if
(
entry
.
isDirectory
()
&&
!
entry
.
getName
().
equals
(
"META-INF/"
))
{
writeDirectory
(
new
ZipArchiveEntry
(
entry
),
zipOutputStream
);
writtenDirectoriesSpec
.
add
(
entry
);
}
else
if
(
entry
.
getName
().
endsWith
(
".class"
))
{
writeClass
(
new
ZipArchiveEntry
(
entry
),
loaderJar
,
zipOutputStream
);
}
entry
=
loaderJar
.
getNextEntry
();
}
}
return
writtenDirectoriesSpec
;
}
private
void
writeDirectory
(
ZipArchiveEntry
entry
,
ZipArchiveOutputStream
out
)
throws
IOException
{
prepareEntry
(
entry
,
UnixStat
.
DIR_FLAG
|
UnixStat
.
DEFAULT_DIR_PERM
);
out
.
putArchiveEntry
(
entry
);
out
.
closeArchiveEntry
();
}
private
void
writeClass
(
ZipArchiveEntry
entry
,
ZipInputStream
in
,
ZipArchiveOutputStream
out
)
throws
IOException
{
prepareEntry
(
entry
,
UnixStat
.
FILE_FLAG
|
UnixStat
.
DEFAULT_FILE_PERM
);
out
.
putArchiveEntry
(
entry
);
copy
(
in
,
out
);
out
.
closeArchiveEntry
();
}
private
void
prepareEntry
(
ZipArchiveEntry
entry
,
int
unixMode
)
{
if
(
this
.
entryTime
!=
null
)
{
entry
.
setTime
(
this
.
entryTime
);
}
entry
.
setUnixMode
(
unixMode
);
}
private
void
copy
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
=
-
1
;
while
((
bytesRead
=
in
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
bytesRead
);
}
}
/**
* Spec to track directories that have been written.
*/
private
static
class
WrittenDirectoriesSpec
implements
Spec
<
FileTreeElement
>
{
private
final
Set
<
String
>
entries
=
new
HashSet
<>();
@Override
public
boolean
isSatisfiedBy
(
FileTreeElement
element
)
{
String
path
=
element
.
getRelativePath
().
getPathString
();
if
(
element
.
isDirectory
()
&&
!
path
.
endsWith
((
"/"
)))
{
path
+=
"/"
;
}
return
this
.
entries
.
contains
(
path
);
}
public
void
add
(
ZipEntry
entry
)
{
this
.
entries
.
add
(
entry
.
getName
());
}
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
View file @
2c2b9622
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
gradle
.
tasks
.
bundling
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
...
...
@@ -34,6 +35,7 @@ import java.util.jar.JarFile;
import
java.util.jar.JarOutputStream
;
import
java.util.jar.Manifest
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveEntry
;
import
org.apache.commons.compress.archivers.zip.ZipFile
;
...
...
@@ -188,13 +190,18 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
void
loaderIsWrittenToTheRootOfTheJar
()
throws
IOException
{
void
loaderIsWrittenToTheRootOfTheJar
AfterManifest
()
throws
IOException
{
this
.
task
.
setMainClassName
(
"com.example.Main"
);
executeTask
();
try
(
JarFile
jarFile
=
new
JarFile
(
this
.
task
.
getArchivePath
()))
{
assertThat
(
jarFile
.
getEntry
(
"org/springframework/boot/loader/LaunchedURLClassLoader.class"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"org/springframework/boot/loader/"
)).
isNotNull
();
}
// gh-16698
try
(
ZipInputStream
zipInputStream
=
new
ZipInputStream
(
new
FileInputStream
(
this
.
task
.
getArchivePath
())))
{
assertThat
(
zipInputStream
.
getNextEntry
().
getName
()).
isEqualTo
(
"META-INF/"
);
assertThat
(
zipInputStream
.
getNextEntry
().
getName
()).
isEqualTo
(
"META-INF/MANIFEST.MF"
);
}
}
@Test
...
...
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