Skip to content

Commit 40533cb

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 <4319788@gmail.com>
1 parent 42cc777 commit 40533cb

File tree

11 files changed

+152
-28
lines changed

11 files changed

+152
-28
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ private String determineSpringBootVersion() {
124124
}
125125

126126
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
127-
LoaderImplementation loaderImplementation, boolean supportsSignatureFile) {
128-
return createCopyAction(jar, resolvedDependencies, loaderImplementation, supportsSignatureFile, null, null);
127+
LoaderImplementation loaderImplementation) {
128+
return createCopyAction(jar, resolvedDependencies, loaderImplementation, null, null);
129129
}
130130

131131
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
132-
LoaderImplementation loaderImplementation, boolean supportsSignatureFile,
133-
@Nullable LayerResolver layerResolver, @Nullable String jarmodeToolsLocation) {
132+
LoaderImplementation loaderImplementation, @Nullable LayerResolver layerResolver,
133+
@Nullable String jarmodeToolsLocation) {
134134
File output = jar.getArchiveFile().get().getAsFile();
135135
Manifest manifest = jar.getManifest();
136136
boolean preserveFileTimestamps = jar.isPreserveFileTimestamps();
@@ -145,8 +145,7 @@ CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
145145
String encoding = jar.getMetadataCharset();
146146
CopyAction action = new BootZipCopyAction(output, manifest, preserveFileTimestamps, dirPermissions,
147147
filePermissions, includeDefaultLoader, jarmodeToolsLocation, requiresUnpack, exclusions, launchScript,
148-
librarySpec, compressionResolver, encoding, resolvedDependencies, supportsSignatureFile, layerResolver,
149-
loaderImplementation);
148+
librarySpec, compressionResolver, encoding, resolvedDependencies, layerResolver, loaderImplementation);
150149
return jar.isReproducibleFileOrder() ? new ReproducibleOrderingCopyAction(action) : action;
151150
}
152151

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected CopyAction createCopyAction() {
151151
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
152152
}
153153
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
154-
return this.support.createCopyAction(this, this.resolvedDependencies, loaderImplementation, true, layerResolver,
154+
return this.support.createCopyAction(this, this.resolvedDependencies, loaderImplementation, layerResolver,
155155
jarmodeToolsLocation);
156156
}
157157

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ protected CopyAction createCopyAction() {
125125
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
126126
}
127127
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
128-
return this.support.createCopyAction(this, this.resolvedDependencies, loaderImplementation, false,
129-
layerResolver, jarmodeToolsLocation);
128+
return this.support.createCopyAction(this, this.resolvedDependencies, loaderImplementation, layerResolver,
129+
jarmodeToolsLocation);
130130
}
131131

132132
private boolean isIncludeJarmodeTools() {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ class BootZipCopyAction implements CopyAction {
116116

117117
private final ResolvedDependencies resolvedDependencies;
118118

119-
private final boolean supportsSignatureFile;
120-
121119
private final @Nullable LayerResolver layerResolver;
122120

123121
private final LoaderImplementation loaderImplementation;
@@ -127,8 +125,8 @@ class BootZipCopyAction implements CopyAction {
127125
Spec<FileTreeElement> requiresUnpack, Spec<FileTreeElement> exclusions,
128126
@Nullable LaunchScriptConfiguration launchScript, Spec<FileCopyDetails> librarySpec,
129127
Function<FileCopyDetails, ZipCompression> compressionResolver, @Nullable String encoding,
130-
ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile,
131-
@Nullable LayerResolver layerResolver, LoaderImplementation loaderImplementation) {
128+
ResolvedDependencies resolvedDependencies, @Nullable LayerResolver layerResolver,
129+
LoaderImplementation loaderImplementation) {
132130
this.output = output;
133131
this.manifest = manifest;
134132
this.preserveFileTimestamps = preserveFileTimestamps;
@@ -143,7 +141,6 @@ class BootZipCopyAction implements CopyAction {
143141
this.compressionResolver = compressionResolver;
144142
this.encoding = encoding;
145143
this.resolvedDependencies = resolvedDependencies;
146-
this.supportsSignatureFile = supportsSignatureFile;
147144
this.layerResolver = layerResolver;
148145
this.loaderImplementation = loaderImplementation;
149146
}
@@ -370,7 +367,7 @@ private void writeJarModeLibrary(String location, JarModeLibrary library) throws
370367
}
371368

372369
private void writeSignatureFileIfNecessary() throws IOException {
373-
if (BootZipCopyAction.this.supportsSignatureFile && hasSignedLibrary()) {
370+
if (hasSignedLibrary()) {
374371
writeEntry("META-INF/BOOT.SF", (out) -> {
375372
}, false);
376373
}

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
@@ -647,6 +647,15 @@ void dirModeAndFileModeAreApplied() throws IOException {
647647
}
648648
}
649649

650+
@TestTemplate
651+
void signed() throws IOException {
652+
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
653+
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
654+
try (JarFile jarFile = new JarFile(jar)) {
655+
assertThat(jarFile.getEntry("META-INF/BOOT.SF")).isNotNull();
656+
}
657+
}
658+
650659
private void copyMainClassApplication() throws IOException {
651660
copyApplication("main");
652661
}

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)