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
9dc858cd
Commit
9dc858cd
authored
Jan 21, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing properties to RepackageTask and improve test coverage
Closes gh-4978
parent
36133d93
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
311 additions
and
9 deletions
+311
-9
FullyExecutableJarTests.java
.../springframework/boot/gradle/FullyExecutableJarTests.java
+182
-0
build.gradle
...adle-tests/src/test/resources/executable-jar/build.gradle
+53
-0
extension.script
...-tests/src/test/resources/executable-jar/extension.script
+1
-0
task.script
...radle-tests/src/test/resources/executable-jar/task.script
+1
-0
ProjectLibraries.java
...ringframework/boot/gradle/repackage/ProjectLibraries.java
+8
-3
RepackageTask.java
.../springframework/boot/gradle/repackage/RepackageTask.java
+66
-6
No files found.
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/FullyExecutableJarTests.java
0 → 100644
View file @
9dc858cd
/*
* Copyright 2012-2015 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
.
gradle
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
org.gradle.tooling.ProjectConnection
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Integration tests for creating a fully executable jar with Gradle.
*
* @author Andy Wilkinson
*/
public
class
FullyExecutableJarTests
{
private
static
final
String
BOOT_VERSION
=
Versions
.
getBootVersion
();
private
static
ProjectConnection
project
;
@BeforeClass
public
static
void
createProject
()
throws
IOException
{
project
=
new
ProjectCreator
().
createProject
(
"executable-jar"
);
}
@Test
public
void
jarIsNotExecutableByDefault
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
).
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
false
));
}
@Test
public
void
madeExecutableViaExtension
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
).
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionExecutable=true"
).
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
}
@Test
public
void
madeExecutableViaTask
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PtaskExecutable=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
}
@Test
public
void
taskTakesPrecedenceForMakingJarExecutable
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionExecutable=false"
,
"-PtaskExecutable=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
}
@Test
public
void
scriptPropertiesFromTask
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PtaskProperties=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
assertThat
(
containsLine
(
"# Provides:.*__task__"
,
executableJar
),
is
(
true
));
}
@Test
public
void
scriptPropertiesFromExtension
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
).
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionProperties=true"
).
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
assertThat
(
containsLine
(
"# Provides:.*__extension__"
,
executableJar
),
is
(
true
));
}
@Test
public
void
taskTakesPrecedenceForScriptProperties
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionProperties=true"
,
"-PtaskProperties=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
isFullyExecutable
(
executableJar
),
is
(
true
));
assertThat
(
containsLine
(
"# Provides:.*__task__"
,
executableJar
),
is
(
true
));
}
@Test
public
void
customScriptFromTask
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PtaskScript=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
containsLine
(
"Custom task script"
,
executableJar
),
is
(
true
));
}
@Test
public
void
customScriptFromExtension
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionScript=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
containsLine
(
"Custom extension script"
,
executableJar
),
is
(
true
));
}
@Test
public
void
taskTakesPrecedenceForCustomScript
()
throws
IOException
{
project
.
newBuild
().
forTasks
(
"clean"
,
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PextensionScript=true"
,
"-PtaskScript=true"
)
.
run
();
File
buildLibs
=
new
File
(
"target/executable-jar/build/libs"
);
File
executableJar
=
new
File
(
buildLibs
,
"executable-jar.jar"
);
assertThat
(
containsLine
(
"Custom task script"
,
executableJar
),
is
(
true
));
}
private
boolean
isFullyExecutable
(
File
file
)
throws
IOException
{
return
containsLine
(
"#!/bin/bash"
,
file
);
}
private
boolean
containsLine
(
String
toMatch
,
File
file
)
throws
IOException
{
Pattern
pattern
=
Pattern
.
compile
(
toMatch
);
for
(
String
line
:
readLines
(
file
))
{
if
(
pattern
.
matcher
(
line
).
matches
())
{
return
true
;
}
}
return
false
;
}
private
List
<
String
>
readLines
(
File
file
)
throws
IOException
{
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
file
));
String
line
;
List
<
String
>
lines
=
new
ArrayList
<
String
>();
try
{
while
((
line
=
reader
.
readLine
())
!=
null
&&
lines
.
size
()
<
50
)
{
lines
.
add
(
line
);
}
}
finally
{
reader
.
close
();
}
return
lines
;
}
}
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/executable-jar/build.gradle
0 → 100644
View file @
9dc858cd
buildscript
{
repositories
{
mavenLocal
()
}
dependencies
{
classpath
"org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
}
}
repositories
{
mavenLocal
()
mavenCentral
()
}
apply
plugin:
'spring-boot'
apply
plugin:
'java'
dependencies
{
compile
'org.springframework.boot:spring-boot-starter-freemarker'
compile
'org.springframework.boot:spring-boot-starter-web'
compile
'org.springframework.boot:spring-boot-devtools'
compile
files
(
"foo.jar"
)
}
springBoot
{
mainClass
=
'foo.bar.Baz'
}
if
(
project
.
properties
[
'taskExecutable'
])
{
bootRepackage
.
executable
=
Boolean
.
valueOf
(
project
.
taskExecutable
)
}
if
(
project
.
properties
[
'extensionExecutable'
])
{
springBoot
.
executable
=
Boolean
.
valueOf
(
project
.
extensionExecutable
)
}
if
(
project
.
properties
[
'taskProperties'
])
{
bootRepackage
.
executable
=
true
bootRepackage
.
embeddedLaunchScriptProperties
=
[
'initInfoProvides'
:
'__task__'
]
}
if
(
project
.
properties
[
'extensionProperties'
])
{
bootRepackage
.
executable
=
true
springBoot
.
embeddedLaunchScriptProperties
=
[
'initInfoProvides'
:
'__extension__'
]
}
if
(
project
.
properties
[
'taskScript'
])
{
bootRepackage
.
embeddedLaunchScript
=
file
(
'task.script'
)
}
if
(
project
.
properties
[
'extensionScript'
])
{
springBoot
.
embeddedLaunchScript
=
file
(
'extension.script'
)
}
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/executable-jar/extension.script
0 → 100644
View file @
9dc858cd
Custom extension script
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/executable-jar/task.script
0 → 100644
View file @
9dc858cd
Custom task script
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/repackage/ProjectLibraries.java
View file @
9dc858cd
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
@@ -48,6 +48,8 @@ class ProjectLibraries implements Libraries {
...
@@ -48,6 +48,8 @@ class ProjectLibraries implements Libraries {
private
final
SpringBootPluginExtension
extension
;
private
final
SpringBootPluginExtension
extension
;
private
final
boolean
excludeDevtools
;
private
String
providedConfigurationName
=
"providedRuntime"
;
private
String
providedConfigurationName
=
"providedRuntime"
;
private
String
customConfigurationName
=
null
;
private
String
customConfigurationName
=
null
;
...
@@ -56,10 +58,13 @@ class ProjectLibraries implements Libraries {
...
@@ -56,10 +58,13 @@ class ProjectLibraries implements Libraries {
* Create a new {@link ProjectLibraries} instance of the specified {@link Project}.
* Create a new {@link ProjectLibraries} instance of the specified {@link Project}.
* @param project the gradle project
* @param project the gradle project
* @param extension the extension
* @param extension the extension
* @param excludeDevTools whether Spring Boot Devtools should be excluded
*/
*/
ProjectLibraries
(
Project
project
,
SpringBootPluginExtension
extension
)
{
ProjectLibraries
(
Project
project
,
SpringBootPluginExtension
extension
,
boolean
excludeDevTools
)
{
this
.
project
=
project
;
this
.
project
=
project
;
this
.
extension
=
extension
;
this
.
extension
=
extension
;
this
.
excludeDevtools
=
excludeDevTools
;
}
}
/**
/**
...
@@ -165,7 +170,7 @@ class ProjectLibraries implements Libraries {
...
@@ -165,7 +170,7 @@ class ProjectLibraries implements Libraries {
}
}
private
boolean
isExcluded
(
GradleLibrary
library
)
{
private
boolean
isExcluded
(
GradleLibrary
library
)
{
if
(
this
.
ex
tension
.
isExcludeDevtools
()
&&
isDevToolsJar
(
library
))
{
if
(
this
.
ex
cludeDevtools
&&
isDevToolsJar
(
library
))
{
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/repackage/RepackageTask.java
View file @
9dc858cd
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
@@ -19,6 +19,7 @@ package org.springframework.boot.gradle.repackage;
...
@@ -19,6 +19,7 @@ package org.springframework.boot.gradle.repackage;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -57,6 +58,14 @@ public class RepackageTask extends DefaultTask {
...
@@ -57,6 +58,14 @@ public class RepackageTask extends DefaultTask {
private
File
outputFile
;
private
File
outputFile
;
private
Boolean
excludeDevtools
;
private
Boolean
executable
;
private
File
embeddedLaunchScript
;
private
Map
<
String
,
String
>
embeddedLaunchScriptProperties
;
public
void
setCustomConfiguration
(
String
customConfiguration
)
{
public
void
setCustomConfiguration
(
String
customConfiguration
)
{
this
.
customConfiguration
=
customConfiguration
;
this
.
customConfiguration
=
customConfiguration
;
}
}
...
@@ -89,6 +98,39 @@ public class RepackageTask extends DefaultTask {
...
@@ -89,6 +98,39 @@ public class RepackageTask extends DefaultTask {
this
.
outputFile
=
file
;
this
.
outputFile
=
file
;
}
}
public
Boolean
getExcludeDevtools
()
{
return
this
.
excludeDevtools
;
}
public
void
setExcludeDevtools
(
Boolean
excludeDevtools
)
{
this
.
excludeDevtools
=
excludeDevtools
;
}
public
Boolean
getExecutable
()
{
return
this
.
executable
;
}
public
void
setExecutable
(
Boolean
executable
)
{
this
.
executable
=
executable
;
}
public
File
getEmbeddedLaunchScript
()
{
return
this
.
embeddedLaunchScript
;
}
public
void
setEmbeddedLaunchScript
(
File
embeddedLaunchScript
)
{
this
.
embeddedLaunchScript
=
embeddedLaunchScript
;
}
public
Map
<
String
,
String
>
getEmbeddedLaunchScriptProperties
()
{
return
this
.
embeddedLaunchScriptProperties
;
}
public
void
setEmbeddedLaunchScriptProperties
(
Map
<
String
,
String
>
embeddedLaunchScriptProperties
)
{
this
.
embeddedLaunchScriptProperties
=
embeddedLaunchScriptProperties
;
}
@TaskAction
@TaskAction
public
void
repackage
()
{
public
void
repackage
()
{
Project
project
=
getProject
();
Project
project
=
getProject
();
...
@@ -102,7 +144,9 @@ public class RepackageTask extends DefaultTask {
...
@@ -102,7 +144,9 @@ public class RepackageTask extends DefaultTask {
Project
project
=
getProject
();
Project
project
=
getProject
();
SpringBootPluginExtension
extension
=
project
.
getExtensions
()
SpringBootPluginExtension
extension
=
project
.
getExtensions
()
.
getByType
(
SpringBootPluginExtension
.
class
);
.
getByType
(
SpringBootPluginExtension
.
class
);
ProjectLibraries
libraries
=
new
ProjectLibraries
(
project
,
extension
);
ProjectLibraries
libraries
=
new
ProjectLibraries
(
project
,
extension
,
(
this
.
excludeDevtools
!=
null
&&
this
.
excludeDevtools
)
||
extension
.
isExcludeDevtools
());
if
(
extension
.
getProvidedConfiguration
()
!=
null
)
{
if
(
extension
.
getProvidedConfiguration
()
!=
null
)
{
libraries
.
setProvidedConfigurationName
(
extension
.
getProvidedConfiguration
());
libraries
.
setProvidedConfigurationName
(
extension
.
getProvidedConfiguration
());
}
}
...
@@ -223,14 +267,30 @@ public class RepackageTask extends DefaultTask {
...
@@ -223,14 +267,30 @@ public class RepackageTask extends DefaultTask {
}
}
private
LaunchScript
getLaunchScript
()
throws
IOException
{
private
LaunchScript
getLaunchScript
()
throws
IOException
{
if
(
this
.
extension
.
isExecutable
()
if
(
isExecutable
()
||
getEmbeddedLaunchScript
()
!=
null
)
{
||
this
.
extension
.
getEmbeddedLaunchScript
()
!=
null
)
{
return
new
DefaultLaunchScript
(
getEmbeddedLaunchScript
(),
return
new
DefaultLaunchScript
(
this
.
extension
.
getEmbeddedLaunchScript
(),
getEmbeddedLaunchScriptProperties
());
this
.
extension
.
getEmbeddedLaunchScriptProperties
());
}
}
return
null
;
return
null
;
}
}
private
boolean
isExecutable
()
{
return
RepackageTask
.
this
.
executable
!=
null
?
RepackageTask
.
this
.
executable
:
this
.
extension
.
isExecutable
();
}
private
File
getEmbeddedLaunchScript
()
{
return
RepackageTask
.
this
.
embeddedLaunchScript
!=
null
?
RepackageTask
.
this
.
embeddedLaunchScript
:
this
.
extension
.
getEmbeddedLaunchScript
();
}
private
Map
<
String
,
String
>
getEmbeddedLaunchScriptProperties
()
{
return
RepackageTask
.
this
.
embeddedLaunchScriptProperties
!=
null
?
RepackageTask
.
this
.
embeddedLaunchScriptProperties
:
this
.
extension
.
getEmbeddedLaunchScriptProperties
();
}
}
}
/**
/**
...
...
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