Skip to content

Commit c21d083

Browse files
committed
Write signature files to uber wars for Oracle Java 17 verification
This commit extends 33c5e12 to uber War. Fixes gh-28837 Signed-off-by: Dmitrii Karagodin <[email protected]>
1 parent bc46bb2 commit c21d083

File tree

11 files changed

+149
-27
lines changed

11 files changed

+149
-27
lines changed

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ private String determineSpringBootVersion() {
121121
return (version != null) ? version : "unknown";
122122
}
123123

124-
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile) {
125-
return createCopyAction(jar, resolvedDependencies, supportsSignatureFile, null, null);
124+
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies) {
125+
return createCopyAction(jar, resolvedDependencies, null, null);
126126
}
127127

128-
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile,
128+
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
129129
@Nullable LayerResolver layerResolver, @Nullable String jarmodeToolsLocation) {
130130
File output = jar.getArchiveFile().get().getAsFile();
131131
Manifest manifest = jar.getManifest();
@@ -141,7 +141,7 @@ CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
141141
String encoding = jar.getMetadataCharset();
142142
CopyAction action = new BootZipCopyAction(output, manifest, preserveFileTimestamps, dirPermissions,
143143
filePermissions, includeDefaultLoader, jarmodeToolsLocation, requiresUnpack, exclusions, launchScript,
144-
librarySpec, compressionResolver, encoding, resolvedDependencies, supportsSignatureFile, layerResolver);
144+
librarySpec, compressionResolver, encoding, resolvedDependencies, layerResolver);
145145
return jar.isReproducibleFileOrder() ? new ReproducibleOrderingCopyAction(action) : action;
146146
}
147147

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ protected CopyAction createCopyAction() {
148148
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
149149
}
150150
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
151-
return this.support.createCopyAction(this, this.resolvedDependencies, true, layerResolver,
152-
jarmodeToolsLocation);
151+
return this.support.createCopyAction(this, this.resolvedDependencies, layerResolver, jarmodeToolsLocation);
153152
}
154153

155154
private boolean isIncludeJarmodeTools() {

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ protected CopyAction createCopyAction() {
122122
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
123123
}
124124
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
125-
return this.support.createCopyAction(this, this.resolvedDependencies, false, layerResolver,
126-
jarmodeToolsLocation);
125+
return this.support.createCopyAction(this, this.resolvedDependencies, layerResolver, jarmodeToolsLocation);
127126
}
128127

129128
private boolean isIncludeJarmodeTools() {

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,14 @@ class BootZipCopyAction implements CopyAction {
115115

116116
private final ResolvedDependencies resolvedDependencies;
117117

118-
private final boolean supportsSignatureFile;
119-
120118
private final @Nullable LayerResolver layerResolver;
121119

122120
BootZipCopyAction(File output, Manifest manifest, boolean preserveFileTimestamps, @Nullable Integer dirMode,
123121
@Nullable Integer fileMode, boolean includeDefaultLoader, @Nullable String jarmodeToolsLocation,
124122
Spec<FileTreeElement> requiresUnpack, Spec<FileTreeElement> exclusions,
125123
@Nullable LaunchScriptConfiguration launchScript, Spec<FileCopyDetails> librarySpec,
126124
Function<FileCopyDetails, ZipCompression> compressionResolver, @Nullable String encoding,
127-
ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile,
128-
@Nullable LayerResolver layerResolver) {
125+
ResolvedDependencies resolvedDependencies, @Nullable LayerResolver layerResolver) {
129126
this.output = output;
130127
this.manifest = manifest;
131128
this.preserveFileTimestamps = preserveFileTimestamps;
@@ -140,7 +137,6 @@ class BootZipCopyAction implements CopyAction {
140137
this.compressionResolver = compressionResolver;
141138
this.encoding = encoding;
142139
this.resolvedDependencies = resolvedDependencies;
143-
this.supportsSignatureFile = supportsSignatureFile;
144140
this.layerResolver = layerResolver;
145141
}
146142

@@ -365,7 +361,7 @@ private void writeJarModeLibrary(String location, JarModeLibrary library) throws
365361
}
366362

367363
private void writeSignatureFileIfNecessary() throws IOException {
368-
if (BootZipCopyAction.this.supportsSignatureFile && hasSignedLibrary()) {
364+
if (hasSignedLibrary()) {
369365
writeEntry("META-INF/BOOT.SF", (out) -> {
370366
}, false);
371367
}

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,15 @@ void dirModeAndFileModeAreApplied() throws IOException {
637637
}
638638
}
639639

640+
@TestTemplate
641+
void signed() throws IOException {
642+
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
643+
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
644+
try (JarFile jarFile = new JarFile(jar)) {
645+
assertThat(jarFile.getEntry("META-INF/BOOT.SF")).isNotNull();
646+
}
647+
}
648+
640649
private void copyMainClassApplication() throws IOException {
641650
copyApplication("main");
642651
}

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616

1717
package org.springframework.boot.gradle.tasks.bundling;
1818

19-
import java.io.File;
2019
import java.io.IOException;
2120
import java.util.Arrays;
2221
import java.util.Set;
2322
import java.util.TreeSet;
24-
import java.util.jar.JarFile;
2523

2624
import org.gradle.testkit.runner.BuildResult;
27-
import org.gradle.testkit.runner.TaskOutcome;
2825
import org.junit.jupiter.api.Assumptions;
2926
import org.junit.jupiter.api.TestTemplate;
3027

@@ -46,15 +43,6 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
4643
super("bootJar", "BOOT-INF/lib/", "BOOT-INF/classes/", "BOOT-INF/");
4744
}
4845

49-
@TestTemplate
50-
void signed() throws Exception {
51-
assertThat(this.gradleBuild.build("bootJar").task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
52-
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
53-
try (JarFile jarFile = new JarFile(jar)) {
54-
assertThat(jarFile.getEntry("META-INF/BOOT.SF")).isNotNull();
55-
}
56-
}
57-
5846
@TestTemplate
5947
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
6048
Assumptions.assumeTrue(this.gradleBuild.gradleVersionIsLessThan("9.0-milestone-1"));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id 'war'
19+
id 'java'
20+
id 'org.springframework.boot' version '{version}'
21+
}
22+
23+
bootWar {
24+
mainClass = 'com.example.Application'
25+
}
26+
27+
repositories {
28+
mavenCentral()
29+
maven {
30+
url = 'repository'
31+
}
32+
}
33+
34+
dependencies {
35+
implementation("org.bouncycastle:bcprov-jdk18on:1.78.1")
36+
}

build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/WarIntegrationTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,12 @@ void whenEntryIsExcludedItShouldNotBePresentInTheRepackagedWar(MavenBuild mavenB
240240
});
241241
}
242242

243+
@TestTemplate
244+
void whenSigned(MavenBuild mavenBuild) {
245+
mavenBuild.project("war-signed").execute((project) -> {
246+
File repackaged = new File(project, "target/war-signed-0.0.1.BUILD-SNAPSHOT.war");
247+
assertThat(jar(repackaged)).hasEntryWithName("META-INF/BOOT.SF");
248+
});
249+
}
250+
243251
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springframework.boot.maven.it</groupId>
6+
<artifactId>war-signed</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>@java.version@</maven.compiler.source>
11+
<maven.compiler.target>@java.version@</maven.compiler.target>
12+
</properties>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
<executions>
20+
<execution>
21+
<goals>
22+
<goal>repackage</goal>
23+
</goals>
24+
</execution>
25+
</executions>
26+
</plugin>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-war-plugin</artifactId>
30+
<version>@maven-war-plugin.version@</version>
31+
<configuration>
32+
<archive>
33+
<manifest>
34+
<mainClass>some.random.Main</mainClass>
35+
</manifest>
36+
<manifestEntries>
37+
<Not-Used>Foo</Not-Used>
38+
</manifestEntries>
39+
</archive>
40+
</configuration>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.springframework</groupId>
47+
<artifactId>spring-context</artifactId>
48+
<version>@spring-framework.version@</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>jakarta.servlet</groupId>
52+
<artifactId>jakarta.servlet-api</artifactId>
53+
<version>@jakarta-servlet.version@</version>
54+
<scope>provided</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.bouncycastle</groupId>
58+
<artifactId>bcprov-jdk18on</artifactId>
59+
<version>1.78.1</version>
60+
</dependency>
61+
</dependencies>
62+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.test;
18+
19+
public class SampleApplication {
20+
21+
public static void main(String[] args) {
22+
}
23+
24+
}

0 commit comments

Comments
 (0)