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
b545330d
Commit
b545330d
authored
Jan 02, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix reusable archive creation with Gradle 4.1 and later
Closes gh-11468
parent
a6c301ed
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
10 deletions
+59
-10
BootZipCopyAction.java
...amework/boot/gradle/tasks/bundling/BootZipCopyAction.java
+15
-10
AbstractBootArchiveIntegrationTests.java
...e/tasks/bundling/AbstractBootArchiveIntegrationTests.java
+16
-0
BootJarIntegrationTests-reproducibleArchive.gradle
...ndling/BootJarIntegrationTests-reproducibleArchive.gradle
+14
-0
BootWarIntegrationTests-reproducibleArchive.gradle
...ndling/BootWarIntegrationTests-reproducibleArchive.gradle
+14
-0
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 @
b545330d
...
@@ -20,6 +20,8 @@ import java.io.File;
...
@@ -20,6 +20,8 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.function.Function
;
import
java.util.function.Function
;
...
@@ -39,7 +41,6 @@ import org.gradle.api.internal.file.copy.FileCopyDetailsInternal;
...
@@ -39,7 +41,6 @@ import org.gradle.api.internal.file.copy.FileCopyDetailsInternal;
import
org.gradle.api.specs.Spec
;
import
org.gradle.api.specs.Spec
;
import
org.gradle.api.specs.Specs
;
import
org.gradle.api.specs.Specs
;
import
org.gradle.api.tasks.WorkResult
;
import
org.gradle.api.tasks.WorkResult
;
import
org.gradle.util.GUtil
;
import
org.springframework.boot.loader.tools.DefaultLaunchScript
;
import
org.springframework.boot.loader.tools.DefaultLaunchScript
;
import
org.springframework.boot.loader.tools.FileUtils
;
import
org.springframework.boot.loader.tools.FileUtils
;
...
@@ -52,6 +53,9 @@ import org.springframework.boot.loader.tools.FileUtils;
...
@@ -52,6 +53,9 @@ import org.springframework.boot.loader.tools.FileUtils;
*/
*/
class
BootZipCopyAction
implements
CopyAction
{
class
BootZipCopyAction
implements
CopyAction
{
private
static
final
long
CONSTANT_TIME_FOR_ZIP_ENTRIES
=
new
GregorianCalendar
(
1980
,
Calendar
.
FEBRUARY
,
1
,
0
,
0
,
0
).
getTimeInMillis
();
private
final
File
output
;
private
final
File
output
;
private
final
boolean
preserveFileTimestamps
;
private
final
boolean
preserveFileTimestamps
;
...
@@ -158,20 +162,14 @@ class BootZipCopyAction implements CopyAction {
...
@@ -158,20 +162,14 @@ class BootZipCopyAction implements CopyAction {
private
void
writeDirectory
(
ZipArchiveEntry
entry
,
ZipArchiveOutputStream
out
)
private
void
writeDirectory
(
ZipArchiveEntry
entry
,
ZipArchiveOutputStream
out
)
throws
IOException
{
throws
IOException
{
if
(!
this
.
preserveFileTimestamps
)
{
prepareEntry
(
entry
,
UnixStat
.
DIR_FLAG
|
UnixStat
.
DEFAULT_DIR_PERM
);
entry
.
setTime
(
GUtil
.
CONSTANT_TIME_FOR_ZIP_ENTRIES
);
}
entry
.
setUnixMode
(
UnixStat
.
DIR_FLAG
|
UnixStat
.
DEFAULT_DIR_PERM
);
out
.
putArchiveEntry
(
entry
);
out
.
putArchiveEntry
(
entry
);
out
.
closeArchiveEntry
();
out
.
closeArchiveEntry
();
}
}
private
void
writeClass
(
ZipArchiveEntry
entry
,
ZipInputStream
in
,
private
void
writeClass
(
ZipArchiveEntry
entry
,
ZipInputStream
in
,
ZipArchiveOutputStream
out
)
throws
IOException
{
ZipArchiveOutputStream
out
)
throws
IOException
{
if
(!
this
.
preserveFileTimestamps
)
{
prepareEntry
(
entry
,
UnixStat
.
FILE_FLAG
|
UnixStat
.
DEFAULT_FILE_PERM
);
entry
.
setTime
(
GUtil
.
CONSTANT_TIME_FOR_ZIP_ENTRIES
);
}
entry
.
setUnixMode
(
UnixStat
.
FILE_FLAG
|
UnixStat
.
DEFAULT_FILE_PERM
);
out
.
putArchiveEntry
(
entry
);
out
.
putArchiveEntry
(
entry
);
byte
[]
buffer
=
new
byte
[
4096
];
byte
[]
buffer
=
new
byte
[
4096
];
int
read
;
int
read
;
...
@@ -181,6 +179,13 @@ class BootZipCopyAction implements CopyAction {
...
@@ -181,6 +179,13 @@ class BootZipCopyAction implements CopyAction {
out
.
closeArchiveEntry
();
out
.
closeArchiveEntry
();
}
}
private
void
prepareEntry
(
ZipArchiveEntry
entry
,
int
unixMode
)
{
if
(!
this
.
preserveFileTimestamps
)
{
entry
.
setTime
(
CONSTANT_TIME_FOR_ZIP_ENTRIES
);
}
entry
.
setUnixMode
(
unixMode
);
}
private
void
writeLaunchScriptIfNecessary
(
FileOutputStream
fileStream
)
{
private
void
writeLaunchScriptIfNecessary
(
FileOutputStream
fileStream
)
{
try
{
try
{
if
(
this
.
launchScript
!=
null
)
{
if
(
this
.
launchScript
!=
null
)
{
...
@@ -280,7 +285,7 @@ class BootZipCopyAction implements CopyAction {
...
@@ -280,7 +285,7 @@ class BootZipCopyAction implements CopyAction {
private
long
getTime
(
FileCopyDetails
details
)
{
private
long
getTime
(
FileCopyDetails
details
)
{
return
this
.
preserveFileTimestamps
?
details
.
getLastModified
()
return
this
.
preserveFileTimestamps
?
details
.
getLastModified
()
:
GUtil
.
CONSTANT_TIME_FOR_ZIP_ENTRIES
;
:
CONSTANT_TIME_FOR_ZIP_ENTRIES
;
}
}
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java
View file @
b545330d
...
@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
...
@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
import
org.springframework.boot.gradle.junit.GradleCompatibilitySuite
;
import
org.springframework.boot.gradle.junit.GradleCompatibilitySuite
;
import
org.springframework.boot.gradle.testkit.GradleBuild
;
import
org.springframework.boot.gradle.testkit.GradleBuild
;
import
org.springframework.boot.loader.tools.FileUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -56,6 +57,21 @@ public abstract class AbstractBootArchiveIntegrationTests {
...
@@ -56,6 +57,21 @@ public abstract class AbstractBootArchiveIntegrationTests {
.
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
.
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
}
}
@Test
public
void
reproducibleArchive
()
throws
InvalidRunnerConfigurationException
,
UnexpectedBuildFailure
,
IOException
,
InterruptedException
{
assertThat
(
this
.
gradleBuild
.
build
(
this
.
taskName
).
task
(
":"
+
this
.
taskName
)
.
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
File
jar
=
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"build/libs"
)
.
listFiles
()[
0
];
String
firstHash
=
FileUtils
.
sha1Hash
(
jar
);
Thread
.
sleep
(
1500
);
assertThat
(
this
.
gradleBuild
.
build
(
"clean"
,
this
.
taskName
)
.
task
(
":"
+
this
.
taskName
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
String
secondHash
=
FileUtils
.
sha1Hash
(
jar
);
assertThat
(
firstHash
).
isEqualTo
(
secondHash
);
}
@Test
@Test
public
void
upToDateWhenBuiltTwice
()
throws
InvalidRunnerConfigurationException
,
public
void
upToDateWhenBuiltTwice
()
throws
InvalidRunnerConfigurationException
,
UnexpectedBuildFailure
,
IOException
{
UnexpectedBuildFailure
,
IOException
{
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-reproducibleArchive.gradle
0 → 100644
View file @
b545330d
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'java'
apply
plugin:
'org.springframework.boot'
bootJar
{
mainClassName
=
'com.example.Application'
preserveFileTimestamps
=
false
reproducibleFileOrder
=
true
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-reproducibleArchive.gradle
0 → 100644
View file @
b545330d
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'war'
apply
plugin:
'org.springframework.boot'
bootWar
{
mainClassName
=
'com.example.Application'
preserveFileTimestamps
=
false
reproducibleFileOrder
=
true
}
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