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
98644df6
Commit
98644df6
authored
Apr 28, 2020
by
Paddy Drury
Committed by
Andy Wilkinson
Apr 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop limiting layer customization to external modules
See gh-21207
parent
fe347df5
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
209 additions
and
38 deletions
+209
-38
LayerResolver.java
...ngframework/boot/gradle/tasks/bundling/LayerResolver.java
+18
-14
BootJarIntegrationTests.java
...k/boot/gradle/tasks/bundling/BootJarIntegrationTests.java
+69
-0
BootJarTests.java
...ingframework/boot/gradle/tasks/bundling/BootJarTests.java
+62
-24
BootJarIntegrationTests-projectDependenciesCanBeIncludedInCustomLayer.gradle
...ests-projectDependenciesCanBeIncludedInCustomLayer.gradle
+60
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerResolver.java
View file @
98644df6
...
...
@@ -24,11 +24,13 @@ import java.util.LinkedHashMap;
import
java.util.Map
;
import
java.util.Set
;
import
org.gradle.api.artifacts.ArtifactCollection
;
import
org.gradle.api.artifacts.Configuration
;
import
org.gradle.api.artifacts.ModuleVersionIdentifier
;
import
org.gradle.api.artifacts.ResolvedArtifact
;
import
org.gradle.api.artifacts.ResolvedConfiguration
;
import
org.gradle.api.artifacts.component.ComponentIdentifier
;
import
org.gradle.api.artifacts.component.ModuleComponentIdentifier
;
import
org.gradle.api.artifacts.
result.ResolvedArtifactResult
;
import
org.gradle.api.artifacts.
component.ProjectComponentIdentifier
;
import
org.gradle.api.file.FileCopyDetails
;
import
org.gradle.api.specs.Spec
;
...
...
@@ -43,6 +45,7 @@ import org.springframework.boot.loader.tools.LibraryCoordinates;
* @author Madhura Bhave
* @author Scott Frederick
* @author Phillip Webb
* @author Paddy Drury
* @see BootZipCopyAction
*/
class
LayerResolver
{
...
...
@@ -110,7 +113,7 @@ class LayerResolver {
if
(
configuration
.
isCanBeResolved
()
&&
!
DEPRECATED_FOR_RESOLUTION_CONFIGURATIONS
.
contains
(
configuration
.
getName
()))
{
this
.
configurationDependencies
.
put
(
configuration
,
new
ResolvedConfigurationDependencies
(
configuration
.
get
Incoming
().
getArtifacts
()));
new
ResolvedConfigurationDependencies
(
configuration
.
get
ResolvedConfiguration
()));
}
}
...
...
@@ -133,14 +136,15 @@ class LayerResolver {
private
final
Map
<
File
,
LibraryCoordinates
>
artifactCoordinates
=
new
LinkedHashMap
<>();
ResolvedConfigurationDependencies
(
ArtifactCollection
resolvedDependencies
)
{
if
(
resolved
Dependencies
!=
null
)
{
for
(
ResolvedArtifact
Result
resolvedArtifact
:
resolvedDependencies
.
get
Artifacts
())
{
ResolvedConfigurationDependencies
(
ResolvedConfiguration
resolvedConfiguration
)
{
if
(
resolved
Configuration
!=
null
)
{
for
(
ResolvedArtifact
resolvedArtifact
:
resolvedConfiguration
.
getResolved
Artifacts
())
{
ComponentIdentifier
identifier
=
resolvedArtifact
.
getId
().
getComponentIdentifier
();
if
(
identifier
instanceof
ModuleComponentIdentifier
)
{
if
(
identifier
instanceof
ModuleComponentIdentifier
||
identifier
instanceof
ProjectComponentIdentifier
)
{
this
.
artifactCoordinates
.
put
(
resolvedArtifact
.
getFile
(),
new
Module
Component
IdentifierLibraryCoordinates
(
(
ModuleComponentIdentifier
)
identifier
));
new
Module
Version
IdentifierLibraryCoordinates
(
resolvedArtifact
.
getModuleVersion
().
getId
()
));
}
}
}
...
...
@@ -153,13 +157,13 @@ class LayerResolver {
}
/**
* Adapts a {@link Module
Component
Identifier} to {@link LibraryCoordinates}.
* Adapts a {@link Module
Version
Identifier} to {@link LibraryCoordinates}.
*/
private
static
class
Module
Component
IdentifierLibraryCoordinates
implements
LibraryCoordinates
{
private
static
class
Module
Version
IdentifierLibraryCoordinates
implements
LibraryCoordinates
{
private
final
Module
Component
Identifier
identifier
;
private
final
Module
Version
Identifier
identifier
;
Module
ComponentIdentifierLibraryCoordinates
(
ModuleComponent
Identifier
identifier
)
{
Module
VersionIdentifierLibraryCoordinates
(
ModuleVersion
Identifier
identifier
)
{
this
.
identifier
=
identifier
;
}
...
...
@@ -170,7 +174,7 @@ class LayerResolver {
@Override
public
String
getArtifactId
()
{
return
this
.
identifier
.
get
Modul
e
();
return
this
.
identifier
.
get
Nam
e
();
}
@Override
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java
View file @
98644df6
...
...
@@ -53,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
* @author Madhura Bhave
* @author Paddy Drury
*/
class
BootJarIntegrationTests
extends
AbstractBootArchiveIntegrationTests
{
...
...
@@ -176,6 +177,64 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
assertExtractedLayers
(
layerNames
,
indexedLayers
);
}
@TestTemplate
void
projectDependenciesCanBeIncludedInCustomLayer
()
throws
IOException
{
writeSettingsGradle
();
writeMainClass
();
writeResource
();
BuildResult
build
=
this
.
gradleBuild
.
build
(
"bootJar"
);
assertThat
(
build
.
task
(
":bootJar"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
Map
<
String
,
List
<
String
>>
indexedLayers
;
String
layerToolsJar
=
"BOOT-INF/lib/"
+
JarModeLibrary
.
LAYER_TOOLS
.
getName
();
try
(
JarFile
jarFile
=
new
JarFile
(
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"build/libs"
).
listFiles
()[
0
]))
{
assertThat
(
jarFile
.
getEntry
(
layerToolsJar
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/foo-1.2.3.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/bar-1.2.3.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/commons-lang3-3.9.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/spring-core-5.2.5.RELEASE.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/spring-jcl-5.2.5.RELEASE.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/lib/commons-io-2.7-SNAPSHOT.jar"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/classes/example/Main.class"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/classes/static/file.txt"
)).
isNotNull
();
assertThat
(
jarFile
.
getEntry
(
"BOOT-INF/layers.idx"
)).
isNotNull
();
indexedLayers
=
readLayerIndex
(
jarFile
);
}
List
<
String
>
layerNames
=
Arrays
.
asList
(
"dependencies"
,
"commons-dependencies"
,
"snapshot-dependencies"
,
"subproject-dependencies"
,
"static"
,
"app"
);
assertThat
(
indexedLayers
.
keySet
()).
containsExactlyElementsOf
(
layerNames
);
Set
<
String
>
expectedSubprojectDependencies
=
new
TreeSet
<>();
expectedSubprojectDependencies
.
add
(
"BOOT-INF/lib/foo-1.2.3.jar"
);
expectedSubprojectDependencies
.
add
(
"BOOT-INF/lib/bar-1.2.3.jar"
);
Set
<
String
>
expectedDependencies
=
new
TreeSet
<>();
expectedDependencies
.
add
(
"BOOT-INF/lib/spring-core-5.2.5.RELEASE.jar"
);
expectedDependencies
.
add
(
"BOOT-INF/lib/spring-jcl-5.2.5.RELEASE.jar"
);
List
<
String
>
expectedSnapshotDependencies
=
new
ArrayList
<>();
expectedSnapshotDependencies
.
add
(
"BOOT-INF/lib/commons-io-2.7-SNAPSHOT.jar"
);
(
layerToolsJar
.
contains
(
"SNAPSHOT"
)
?
expectedSnapshotDependencies
:
expectedDependencies
).
add
(
layerToolsJar
);
assertThat
(
indexedLayers
.
get
(
"subproject-dependencies"
))
.
containsExactlyElementsOf
(
expectedSubprojectDependencies
);
assertThat
(
indexedLayers
.
get
(
"dependencies"
)).
containsExactlyElementsOf
(
expectedDependencies
);
assertThat
(
indexedLayers
.
get
(
"commons-dependencies"
)).
containsExactly
(
"BOOT-INF/lib/commons-lang3-3.9.jar"
);
assertThat
(
indexedLayers
.
get
(
"snapshot-dependencies"
)).
containsExactlyElementsOf
(
expectedSnapshotDependencies
);
assertThat
(
indexedLayers
.
get
(
"static"
)).
containsExactly
(
"BOOT-INF/classes/static/"
);
List
<
String
>
appLayer
=
new
ArrayList
<>(
indexedLayers
.
get
(
"app"
));
Set
<
String
>
nonLoaderEntries
=
new
TreeSet
<>();
nonLoaderEntries
.
add
(
"BOOT-INF/classes/example/"
);
nonLoaderEntries
.
add
(
"BOOT-INF/classpath.idx"
);
nonLoaderEntries
.
add
(
"BOOT-INF/layers.idx"
);
nonLoaderEntries
.
add
(
"META-INF/"
);
assertThat
(
appLayer
).
containsSubsequence
(
nonLoaderEntries
);
appLayer
.
removeAll
(
nonLoaderEntries
);
assertThat
(
appLayer
).
containsExactly
(
"org/"
);
BuildResult
listLayers
=
this
.
gradleBuild
.
build
(
"listLayers"
);
assertThat
(
listLayers
.
task
(
":listLayers"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
String
listLayersOutput
=
listLayers
.
getOutput
();
assertThat
(
new
BufferedReader
(
new
StringReader
(
listLayersOutput
)).
lines
()).
containsSequence
(
layerNames
);
BuildResult
extractLayers
=
this
.
gradleBuild
.
build
(
"extractLayers"
);
assertThat
(
extractLayers
.
task
(
":extractLayers"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
assertExtractedLayers
(
layerNames
,
indexedLayers
);
}
private
void
assertExtractedLayers
(
List
<
String
>
layerNames
,
Map
<
String
,
List
<
String
>>
indexedLayers
)
throws
IOException
{
Map
<
String
,
List
<
String
>>
extractedLayers
=
readExtractedLayers
(
this
.
gradleBuild
.
getProjectDir
(),
layerNames
);
...
...
@@ -201,6 +260,16 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
return
false
;
}
private
void
writeSettingsGradle
()
{
File
settings
=
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"settings.gradle"
);
try
(
PrintWriter
writer
=
new
PrintWriter
(
new
FileWriter
(
settings
)))
{
writer
.
println
(
"include 'foo', 'bar'"
);
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
private
void
writeMainClass
()
{
File
examplePackage
=
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"src/main/java/example"
);
examplePackage
.
mkdirs
();
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java
View file @
98644df6
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-projectDependenciesCanBeIncludedInCustomLayer.gradle
0 → 100644
View file @
98644df6
plugins
{
id
'java'
id
'org.springframework.boot'
version
'{version}'
}
subprojects
{
apply
plugin:
'java'
group
=
'org.example.projects'
version
=
'1.2.3'
}
bootJar
{
mainClassName
=
'com.example.Application'
layered
{
application
{
intoLayer
(
"static"
)
{
include
"META-INF/resources/**"
,
"resources/**"
,
"static/**"
,
"public/**"
}
intoLayer
(
"app"
)
}
dependencies
{
intoLayer
(
"subproject-dependencies"
)
{
include
"org.example.projects:*"
}
intoLayer
(
"snapshot-dependencies"
)
{
include
"*:*:*SNAPSHOT"
}
intoLayer
(
"commons-dependencies"
)
{
include
"org.apache.commons:*"
}
intoLayer
(
"dependencies"
)
}
layerOrder
=
[
"dependencies"
,
"commons-dependencies"
,
"snapshot-dependencies"
,
"subproject-dependencies"
,
"static"
,
"app"
]
}
}
repositories
{
mavenCentral
()
maven
{
url
"https://repository.apache.org/content/repositories/snapshots"
}
}
dependencies
{
implementation
(
project
(
':foo'
))
implementation
(
project
(
':bar'
))
implementation
(
"commons-io:commons-io:2.7-SNAPSHOT"
)
implementation
(
"org.apache.commons:commons-lang3:3.9"
)
implementation
(
"org.springframework:spring-core:5.2.5.RELEASE"
)
}
task
listLayers
(
type:
JavaExec
)
{
classpath
=
bootJar
.
outputs
.
files
systemProperties
=
[
"jarmode"
:
"layertools"
]
args
"list"
}
task
extractLayers
(
type:
JavaExec
)
{
classpath
=
bootJar
.
outputs
.
files
systemProperties
=
[
"jarmode"
:
"layertools"
]
args
"extract"
}
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