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
079b67c5
Commit
079b67c5
authored
May 11, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
07251a09
7913d9b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
3 deletions
+65
-3
BootJar.java
...g/springframework/boot/gradle/tasks/bundling/BootJar.java
+32
-2
BootJarTests.java
...ingframework/boot/gradle/tasks/bundling/BootJarTests.java
+33
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
View file @
079b67c5
...
@@ -40,6 +40,8 @@ public class BootJar extends Jar implements BootArchive {
...
@@ -40,6 +40,8 @@ public class BootJar extends Jar implements BootArchive {
private
final
BootArchiveSupport
support
=
new
BootArchiveSupport
(
private
final
BootArchiveSupport
support
=
new
BootArchiveSupport
(
"org.springframework.boot.loader.JarLauncher"
,
this
::
resolveZipCompression
);
"org.springframework.boot.loader.JarLauncher"
,
this
::
resolveZipCompression
);
private
final
CopySpec
bootInf
;
private
FileCollection
classpath
;
private
FileCollection
classpath
;
private
String
mainClassName
;
private
String
mainClassName
;
...
@@ -48,8 +50,10 @@ public class BootJar extends Jar implements BootArchive {
...
@@ -48,8 +50,10 @@ public class BootJar extends Jar implements BootArchive {
* Creates a new {@code BootJar} task.
* Creates a new {@code BootJar} task.
*/
*/
public
BootJar
()
{
public
BootJar
()
{
into
(
"BOOT-INF/classes"
,
classpathFiles
(
File:
:
isDirectory
));
this
.
bootInf
=
getProject
().
copySpec
().
into
(
"BOOT-INF"
);
into
(
"BOOT-INF/lib"
,
classpathFiles
(
File:
:
isFile
));
getMainSpec
().
with
(
this
.
bootInf
);
this
.
bootInf
.
into
(
"classes"
,
classpathFiles
(
File:
:
isDirectory
));
this
.
bootInf
.
into
(
"lib"
,
classpathFiles
(
File:
:
isFile
));
}
}
private
Action
<
CopySpec
>
classpathFiles
(
Spec
<
File
>
filter
)
{
private
Action
<
CopySpec
>
classpathFiles
(
Spec
<
File
>
filter
)
{
...
@@ -128,6 +132,32 @@ public class BootJar extends Jar implements BootArchive {
...
@@ -128,6 +132,32 @@ public class BootJar extends Jar implements BootArchive {
this
.
support
.
setExcludeDevtools
(
excludeDevtools
);
this
.
support
.
setExcludeDevtools
(
excludeDevtools
);
}
}
/**
* Returns a {@code CopySpec} that can be used to add content to the {@code BOOT-INF}
* directory of the jar.
* @return a {@code CopySpec} for {@code BOOT-INF}
* @since 2.0.3
*/
public
CopySpec
getBootInf
()
{
CopySpec
child
=
getProject
().
copySpec
();
this
.
bootInf
.
with
(
child
);
return
child
;
}
/**
* Calls the given {@code action} to add content to the {@code BOOT-INF} directory of
* the jar.
* @param action the {@code Action} to call
* @return the {@code CopySpec} for {@code BOOT-INF} that was passed to the
* {@code Action}
* @since 2.0.3
*/
public
CopySpec
bootInf
(
Action
<
CopySpec
>
action
)
{
CopySpec
bootInf
=
getBootInf
();
action
.
execute
(
bootInf
);
return
bootInf
;
}
/**
/**
* Returns the {@link ZipCompression} that should be used when adding the file
* Returns the {@link ZipCompression} that should be used when adding the file
* represented by the given {@code details} to the jar.
* represented by the given {@code details} to the jar.
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java
View file @
079b67c5
/*
/*
* 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");
* 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.
...
@@ -16,6 +16,14 @@
...
@@ -16,6 +16,14 @@
package
org
.
springframework
.
boot
.
gradle
.
tasks
.
bundling
;
package
org
.
springframework
.
boot
.
gradle
.
tasks
.
bundling
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.jar.JarFile
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
/**
* Tests for {@link BootJar}.
* Tests for {@link BootJar}.
*
*
...
@@ -28,4 +36,28 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
...
@@ -28,4 +36,28 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
"BOOT-INF/lib"
,
"BOOT-INF/classes"
);
"BOOT-INF/lib"
,
"BOOT-INF/classes"
);
}
}
@Test
public
void
contentCanBeAddedToBootInfUsingCopySpecFromGetter
()
throws
IOException
{
BootJar
bootJar
=
getTask
();
bootJar
.
setMainClassName
(
"com.example.Application"
);
bootJar
.
getBootInf
().
into
(
"test"
)
.
from
(
new
File
(
"build.gradle"
).
getAbsolutePath
());
bootJar
.
execute
();
try
(
JarFile
jarFile
=
new
JarFile
(
bootJar
.
getArchivePath
()))
{
assertThat
(
jarFile
.
getJarEntry
(
"BOOT-INF/test/build.gradle"
)).
isNotNull
();
}
}
@Test
public
void
contentCanBeAddedToBootInfUsingCopySpecAction
()
throws
IOException
{
BootJar
bootJar
=
getTask
();
bootJar
.
setMainClassName
(
"com.example.Application"
);
bootJar
.
bootInf
((
copySpec
)
->
copySpec
.
into
(
"test"
)
.
from
(
new
File
(
"build.gradle"
).
getAbsolutePath
()));
bootJar
.
execute
();
try
(
JarFile
jarFile
=
new
JarFile
(
bootJar
.
getArchivePath
()))
{
assertThat
(
jarFile
.
getJarEntry
(
"BOOT-INF/test/build.gradle"
)).
isNotNull
();
}
}
}
}
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