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
b070c39a
Commit
b070c39a
authored
Dec 23, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-24598
parents
a27aecc0
5fa5b624
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
JarTypeFilter.java
...in/java/org/springframework/boot/maven/JarTypeFilter.java
+5
-2
JarTypeFilterTests.java
...va/org/springframework/boot/maven/JarTypeFilterTests.java
+23
-3
No files found.
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/JarTypeFilter.java
View file @
b070c39a
...
@@ -20,8 +20,10 @@ import java.io.IOException;
...
@@ -20,8 +20,10 @@ import java.io.IOException;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
java.util.jar.Manifest
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.artifact.Artifact
;
...
@@ -43,8 +45,9 @@ class JarTypeFilter extends DependencyFilter {
...
@@ -43,8 +45,9 @@ class JarTypeFilter extends DependencyFilter {
@Override
@Override
protected
boolean
filter
(
Artifact
artifact
)
{
protected
boolean
filter
(
Artifact
artifact
)
{
try
(
JarFile
jarFile
=
new
JarFile
(
artifact
.
getFile
()))
{
try
(
JarFile
jarFile
=
new
JarFile
(
artifact
.
getFile
()))
{
String
jarType
=
jarFile
.
getManifest
().
getMainAttributes
().
getValue
(
"Spring-Boot-Jar-Type"
);
return
Optional
.
ofNullable
(
jarFile
.
getManifest
()).
map
(
Manifest:
:
getMainAttributes
)
return
jarType
!=
null
&&
EXCLUDED_JAR_TYPES
.
contains
(
jarType
);
.
map
((
attributes
)
->
attributes
.
getValue
(
"Spring-Boot-Jar-Type"
)).
map
(
EXCLUDED_JAR_TYPES:
:
contains
)
.
orElse
(
Boolean
.
FALSE
);
}
}
catch
(
IOException
ex
)
{
catch
(
IOException
ex
)
{
return
false
;
return
false
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/JarTypeFilterTests.java
View file @
b070c39a
...
@@ -60,12 +60,17 @@ class JarTypeFilterTests {
...
@@ -60,12 +60,17 @@ class JarTypeFilterTests {
assertThat
(
new
JarTypeFilter
().
filter
(
createArtifact
(
"annotation-processor"
))).
isTrue
();
assertThat
(
new
JarTypeFilter
().
filter
(
createArtifact
(
"annotation-processor"
))).
isTrue
();
}
}
private
Artifact
createArtifact
(
String
jarType
)
{
@Test
void
whenArtifactHasNoManifestFileThenItIsIncluded
()
{
assertThat
(
new
JarTypeFilter
().
filter
(
createArtifactWithNoManifest
())).
isFalse
();
}
private
Artifact
createArtifact
(
String
springBootJarType
)
{
Path
jarPath
=
this
.
temp
.
resolve
(
"test.jar"
);
Path
jarPath
=
this
.
temp
.
resolve
(
"test.jar"
);
Manifest
manifest
=
new
Manifest
();
Manifest
manifest
=
new
Manifest
();
manifest
.
getMainAttributes
().
putValue
(
"Manifest-Version"
,
"1.0"
);
manifest
.
getMainAttributes
().
putValue
(
"Manifest-Version"
,
"1.0"
);
if
(
j
arType
!=
null
)
{
if
(
springBootJ
arType
!=
null
)
{
manifest
.
getMainAttributes
().
putValue
(
"Spring-Boot-Jar-Type"
,
j
arType
);
manifest
.
getMainAttributes
().
putValue
(
"Spring-Boot-Jar-Type"
,
springBootJ
arType
);
}
}
try
{
try
{
new
JarOutputStream
(
new
FileOutputStream
(
jarPath
.
toFile
()),
manifest
).
close
();
new
JarOutputStream
(
new
FileOutputStream
(
jarPath
.
toFile
()),
manifest
).
close
();
...
@@ -73,6 +78,21 @@ class JarTypeFilterTests {
...
@@ -73,6 +78,21 @@ class JarTypeFilterTests {
catch
(
IOException
ex
)
{
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
}
}
return
mockArtifact
(
jarPath
);
}
private
Artifact
createArtifactWithNoManifest
()
{
Path
jarPath
=
this
.
temp
.
resolve
(
"test.jar"
);
try
{
new
JarOutputStream
(
new
FileOutputStream
(
jarPath
.
toFile
())).
close
();
}
catch
(
IOException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
return
mockArtifact
(
jarPath
);
}
private
Artifact
mockArtifact
(
Path
jarPath
)
{
Artifact
artifact
=
mock
(
Artifact
.
class
);
Artifact
artifact
=
mock
(
Artifact
.
class
);
given
(
artifact
.
getFile
()).
willReturn
(
jarPath
.
toFile
());
given
(
artifact
.
getFile
()).
willReturn
(
jarPath
.
toFile
());
return
artifact
;
return
artifact
;
...
...
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