Skip to content

Commit b070c39

Browse files
committed
Merge branch '2.4.x'
Closes gh-24598
2 parents a27aecc + 5fa5b62 commit b070c39

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/JarTypeFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import java.util.Arrays;
2121
import java.util.Collections;
2222
import java.util.HashSet;
23+
import java.util.Optional;
2324
import java.util.Set;
2425
import java.util.jar.JarFile;
26+
import java.util.jar.Manifest;
2527

2628
import org.apache.maven.artifact.Artifact;
2729

@@ -43,8 +45,9 @@ class JarTypeFilter extends DependencyFilter {
4345
@Override
4446
protected boolean filter(Artifact artifact) {
4547
try (JarFile jarFile = new JarFile(artifact.getFile())) {
46-
String jarType = jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Jar-Type");
47-
return jarType != null && EXCLUDED_JAR_TYPES.contains(jarType);
48+
return Optional.ofNullable(jarFile.getManifest()).map(Manifest::getMainAttributes)
49+
.map((attributes) -> attributes.getValue("Spring-Boot-Jar-Type")).map(EXCLUDED_JAR_TYPES::contains)
50+
.orElse(Boolean.FALSE);
4851
}
4952
catch (IOException ex) {
5053
return false;

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/JarTypeFilterTests.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,39 @@ void whenArtifactHasAnnotationProcessorJarTypeThenItIsExcluded() {
6060
assertThat(new JarTypeFilter().filter(createArtifact("annotation-processor"))).isTrue();
6161
}
6262

63-
private Artifact createArtifact(String jarType) {
63+
@Test
64+
void whenArtifactHasNoManifestFileThenItIsIncluded() {
65+
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();
66+
}
67+
68+
private Artifact createArtifact(String springBootJarType) {
6469
Path jarPath = this.temp.resolve("test.jar");
6570
Manifest manifest = new Manifest();
6671
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
67-
if (jarType != null) {
68-
manifest.getMainAttributes().putValue("Spring-Boot-Jar-Type", jarType);
72+
if (springBootJarType != null) {
73+
manifest.getMainAttributes().putValue("Spring-Boot-Jar-Type", springBootJarType);
6974
}
7075
try {
7176
new JarOutputStream(new FileOutputStream(jarPath.toFile()), manifest).close();
7277
}
7378
catch (IOException ex) {
7479
throw new RuntimeException(ex);
7580
}
81+
return mockArtifact(jarPath);
82+
}
83+
84+
private Artifact createArtifactWithNoManifest() {
85+
Path jarPath = this.temp.resolve("test.jar");
86+
try {
87+
new JarOutputStream(new FileOutputStream(jarPath.toFile())).close();
88+
}
89+
catch (IOException ex) {
90+
throw new RuntimeException(ex);
91+
}
92+
return mockArtifact(jarPath);
93+
}
94+
95+
private Artifact mockArtifact(Path jarPath) {
7696
Artifact artifact = mock(Artifact.class);
7797
given(artifact.getFile()).willReturn(jarPath.toFile());
7898
return artifact;

0 commit comments

Comments
 (0)