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
aa09058d
Commit
aa09058d
authored
Feb 19, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove implicit layers support from the layer tools
Closes gh-20187
parent
d8c309a3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
181 deletions
+130
-181
ImplicitLayers.java
...ringframework/boot/jarmode/layertools/ImplicitLayers.java
+0
-83
Layers.java
...a/org/springframework/boot/jarmode/layertools/Layers.java
+4
-1
HelpCommandTests.java
...ngframework/boot/jarmode/layertools/HelpCommandTests.java
+28
-2
ImplicitLayersTests.java
...ramework/boot/jarmode/layertools/ImplicitLayersTests.java
+0
-83
LayerToolsJarModeTests.java
...ework/boot/jarmode/layertools/LayerToolsJarModeTests.java
+28
-2
ListCommandTests.java
...ngframework/boot/jarmode/layertools/ListCommandTests.java
+65
-6
list-output.txt
...g/springframework/boot/jarmode/layertools/list-output.txt
+5
-4
No files found.
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/ImplicitLayers.java
deleted
100644 → 0
View file @
d8c309a3
/*
* Copyright 2012-2020 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
.
jarmode
.
layertools
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
/**
* {@link Layers} implementation that uses implicit rules to slice the application.
*
* @author Phillip Webb
*/
class
ImplicitLayers
implements
Layers
{
private
static
final
String
DEPENDENCIES_LAYER
=
"dependencies"
;
private
static
final
String
SNAPSHOT_DEPENDENCIES_LAYER
=
"snapshot-dependencies"
;
private
static
final
String
RESOURCES_LAYER
=
"resources"
;
private
static
final
String
APPLICATION_LAYER
=
"application"
;
private
static
final
List
<
String
>
LAYERS
;
static
{
List
<
String
>
layers
=
new
ArrayList
<>();
layers
.
add
(
DEPENDENCIES_LAYER
);
layers
.
add
(
SNAPSHOT_DEPENDENCIES_LAYER
);
layers
.
add
(
RESOURCES_LAYER
);
layers
.
add
(
APPLICATION_LAYER
);
LAYERS
=
Collections
.
unmodifiableList
(
layers
);
}
private
static
final
String
[]
CLASS_LOCATIONS
=
{
""
,
"BOOT-INF/classes/"
};
private
static
final
String
[]
RESOURCE_LOCATIONS
=
{
"META-INF/resources/"
,
"resources/"
,
"static/"
,
"public/"
};
@Override
public
Iterator
<
String
>
iterator
()
{
return
LAYERS
.
iterator
();
}
@Override
public
String
getLayer
(
ZipEntry
entry
)
{
return
getLayer
(
entry
.
getName
());
}
String
getLayer
(
String
name
)
{
if
(
name
.
endsWith
(
"SNAPSHOT.jar"
))
{
return
SNAPSHOT_DEPENDENCIES_LAYER
;
}
if
(
name
.
endsWith
(
".jar"
))
{
return
DEPENDENCIES_LAYER
;
}
if
(!
name
.
endsWith
(
".class"
))
{
for
(
String
classLocation
:
CLASS_LOCATIONS
)
{
for
(
String
resourceLocation
:
RESOURCE_LOCATIONS
)
{
if
(
name
.
startsWith
(
classLocation
+
resourceLocation
))
{
return
RESOURCES_LAYER
;
}
}
}
}
return
APPLICATION_LAYER
;
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/main/java/org/springframework/boot/jarmode/layertools/Layers.java
View file @
aa09058d
...
...
@@ -49,7 +49,10 @@ interface Layers extends Iterable<String> {
*/
static
Layers
get
(
Context
context
)
{
IndexedLayers
indexedLayers
=
IndexedLayers
.
get
(
context
);
return
(
indexedLayers
!=
null
)
?
indexedLayers
:
new
ImplicitLayers
();
if
(
indexedLayers
==
null
)
{
throw
new
IllegalStateException
(
"Failed to load layers.idx which is required by layertools"
);
}
return
indexedLayers
;
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/HelpCommandTests.java
View file @
aa09058d
...
...
@@ -17,11 +17,19 @@
package
org
.
springframework
.
boot
.
jarmode
.
layertools
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.jar.JarEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
...
@@ -38,10 +46,13 @@ class HelpCommandTests {
private
TestPrintStream
out
;
@TempDir
File
temp
;
@BeforeEach
void
setup
()
{
void
setup
()
throws
Exception
{
Context
context
=
mock
(
Context
.
class
);
given
(
context
.
getJarFile
()).
willReturn
(
new
File
(
"test.jar"
));
given
(
context
.
getJarFile
()).
willReturn
(
createJar
File
(
"test.jar"
));
this
.
command
=
new
HelpCommand
(
context
,
LayerToolsJarMode
.
Runner
.
getCommands
(
context
));
this
.
out
=
new
TestPrintStream
(
this
);
}
...
...
@@ -60,4 +71,19 @@ class HelpCommandTests {
}
private
File
createJarFile
(
String
name
)
throws
IOException
{
File
file
=
new
File
(
this
.
temp
,
name
);
try
(
ZipOutputStream
jarOutputStream
=
new
ZipOutputStream
(
new
FileOutputStream
(
file
)))
{
JarEntry
indexEntry
=
new
JarEntry
(
"BOOT-INF/layers.idx"
);
jarOutputStream
.
putNextEntry
(
indexEntry
);
Writer
writer
=
new
OutputStreamWriter
(
jarOutputStream
,
StandardCharsets
.
UTF_8
);
writer
.
write
(
"a\n"
);
writer
.
write
(
"b\n"
);
writer
.
write
(
"c\n"
);
writer
.
write
(
"d\n"
);
writer
.
flush
();
}
return
file
;
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ImplicitLayersTests.java
deleted
100644 → 0
View file @
d8c309a3
/*
* Copyright 2012-2020 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
.
jarmode
.
layertools
;
import
java.util.zip.ZipEntry
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ImplicitLayers}.
*
* @author Phillip Webb
*/
class
ImplicitLayersTests
{
private
Layers
layers
=
new
ImplicitLayers
();
@Test
void
iteratorReturnsLayers
()
{
assertThat
(
this
.
layers
).
containsExactly
(
"dependencies"
,
"snapshot-dependencies"
,
"resources"
,
"application"
);
}
@Test
void
getLayerWhenSnapshotJarReturnsSnapshotDependencies
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/lib/mylib-SNAPSHOT.jar"
)))
.
isEqualTo
(
"snapshot-dependencies"
);
}
@Test
void
getLayerWhenNonSnapshotJarReturnsDependencies
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/lib/mylib.jar"
))).
isEqualTo
(
"dependencies"
);
}
@Test
void
getLayerWhenLoaderClassReturnsApplication
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"org/springframework/boot/loader/Example.class"
)))
.
isEqualTo
(
"application"
);
}
@Test
void
getLayerWhenStaticResourceReturnsResources
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/META-INF/resources/image.gif"
)))
.
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/resources/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/static/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/public/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"META-INF/resources/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"resources/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"static/image.gif"
))).
isEqualTo
(
"resources"
);
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"public/image.gif"
))).
isEqualTo
(
"resources"
);
}
@Test
void
getLayerWhenRegularClassReturnsApplication
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/com.example/App.class"
))).
isEqualTo
(
"application"
);
}
@Test
void
getLayerWhenClassResourceReturnsApplication
()
{
assertThat
(
this
.
layers
.
getLayer
(
zipEntry
(
"BOOT-INF/classes/application.properties"
))).
isEqualTo
(
"application"
);
}
private
ZipEntry
zipEntry
(
String
name
)
{
return
new
ZipEntry
(
name
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/LayerToolsJarModeTests.java
View file @
aa09058d
...
...
@@ -17,11 +17,19 @@
package
org
.
springframework
.
boot
.
jarmode
.
layertools
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintStream
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.jar.JarEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
...
@@ -40,10 +48,13 @@ class LayerToolsJarModeTests {
private
PrintStream
systemOut
;
@TempDir
File
temp
;
@BeforeEach
void
setup
()
{
void
setup
()
throws
Exception
{
Context
context
=
mock
(
Context
.
class
);
given
(
context
.
getJarFile
()).
willReturn
(
new
File
(
"test.jar"
));
given
(
context
.
getJarFile
()).
willReturn
(
createJar
File
(
"test.jar"
));
this
.
out
=
new
TestPrintStream
(
this
);
this
.
systemOut
=
System
.
out
;
System
.
setOut
(
this
.
out
);
...
...
@@ -68,4 +79,19 @@ class LayerToolsJarModeTests {
assertThat
(
this
.
out
).
hasSameContentAsResource
(
"list-output.txt"
);
}
private
File
createJarFile
(
String
name
)
throws
IOException
{
File
file
=
new
File
(
this
.
temp
,
name
);
try
(
ZipOutputStream
jarOutputStream
=
new
ZipOutputStream
(
new
FileOutputStream
(
file
)))
{
JarEntry
indexEntry
=
new
JarEntry
(
"BOOT-INF/layers.idx"
);
jarOutputStream
.
putNextEntry
(
indexEntry
);
Writer
writer
=
new
OutputStreamWriter
(
jarOutputStream
,
StandardCharsets
.
UTF_8
);
writer
.
write
(
"a\n"
);
writer
.
write
(
"b\n"
);
writer
.
write
(
"c\n"
);
writer
.
write
(
"d\n"
);
writer
.
flush
();
}
return
file
;
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ListCommandTests.java
View file @
aa09058d
...
...
@@ -16,11 +16,24 @@
package
org
.
springframework
.
boot
.
jarmode
.
layertools
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
java.io.Writer
;
import
java.nio.charset.StandardCharsets
;
import
java.util.jar.JarEntry
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
* Tests for {@link ListCommand}.
...
...
@@ -29,20 +42,66 @@ import static org.mockito.Mockito.mock;
*/
class
ListCommandTests
{
private
ListCommand
command
;
@TempDir
File
temp
;
private
TestPrintStream
out
;
@Mock
private
Context
context
;
private
File
jarFile
;
@BeforeEach
void
setup
()
{
this
.
command
=
new
ListCommand
(
mock
(
Context
.
class
));
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
jarFile
=
createJarFile
(
"test.jar"
);
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
this
.
command
=
new
ListCommand
(
this
.
context
);
this
.
out
=
new
TestPrintStream
(
this
);
}
private
ListCommand
command
;
private
TestPrintStream
out
;
@Test
void
listLayersShouldListLayers
()
{
this
.
command
.
printLayers
(
new
ImplicitLayers
(),
this
.
out
);
Layers
layers
=
IndexedLayers
.
get
(
this
.
context
);
this
.
command
.
printLayers
(
layers
,
this
.
out
);
assertThat
(
this
.
out
).
hasSameContentAsResource
(
"list-output.txt"
);
}
private
File
createJarFile
(
String
name
)
throws
IOException
{
File
file
=
new
File
(
this
.
temp
,
name
);
try
(
ZipOutputStream
jarOutputStream
=
new
ZipOutputStream
(
new
FileOutputStream
(
file
)))
{
writeLayersIndex
(
jarOutputStream
);
String
entryPrefix
=
"BOOT-INF/layers/"
;
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"a/"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"a/a.jar"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"b/"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"b/b.jar"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"c/"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"c/c.jar"
));
jarOutputStream
.
closeEntry
();
jarOutputStream
.
putNextEntry
(
new
ZipEntry
(
entryPrefix
+
"d/"
));
jarOutputStream
.
closeEntry
();
}
return
file
;
}
private
void
writeLayersIndex
(
ZipOutputStream
out
)
throws
IOException
{
JarEntry
indexEntry
=
new
JarEntry
(
"BOOT-INF/layers.idx"
);
out
.
putNextEntry
(
indexEntry
);
Writer
writer
=
new
OutputStreamWriter
(
out
,
StandardCharsets
.
UTF_8
);
writer
.
write
(
"a\n"
);
writer
.
write
(
"b\n"
);
writer
.
write
(
"c\n"
);
writer
.
write
(
"d\n"
);
writer
.
flush
();
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/resources/org/springframework/boot/jarmode/layertools/list-output.txt
View file @
aa09058d
dependencies
snapshot-dependencies
resources
application
springbootapplication
a
b
c
d
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