Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ private String determineSpringBootVersion() {
return (version != null) ? version : "unknown";
}

CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile) {
return createCopyAction(jar, resolvedDependencies, supportsSignatureFile, null, null);
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies) {
return createCopyAction(jar, resolvedDependencies, null, null);
}

CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile,
CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
@Nullable LayerResolver layerResolver, @Nullable String jarmodeToolsLocation) {
File output = jar.getArchiveFile().get().getAsFile();
Manifest manifest = jar.getManifest();
Expand All @@ -135,7 +135,7 @@ CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
String encoding = jar.getMetadataCharset();
CopyAction action = new BootZipCopyAction(output, manifest, preserveFileTimestamps, dirPermissions,
filePermissions, includeDefaultLoader, jarmodeToolsLocation, requiresUnpack, exclusions, launchScript,
librarySpec, compressionResolver, encoding, resolvedDependencies, supportsSignatureFile, layerResolver);
librarySpec, compressionResolver, encoding, resolvedDependencies, layerResolver);
return action;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ protected CopyAction createCopyAction() {
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
}
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
return this.support.createCopyAction(this, this.resolvedDependencies, true, layerResolver,
jarmodeToolsLocation);
return this.support.createCopyAction(this, this.resolvedDependencies, layerResolver, jarmodeToolsLocation);
}

private boolean isIncludeJarmodeTools() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ protected CopyAction createCopyAction() {
layerResolver = new LayerResolver(this.resolvedDependencies, this.layered, this::isLibrary);
}
String jarmodeToolsLocation = isIncludeJarmodeTools() ? LIB_DIRECTORY : null;
return this.support.createCopyAction(this, this.resolvedDependencies, false, layerResolver,
jarmodeToolsLocation);
return this.support.createCopyAction(this, this.resolvedDependencies, layerResolver, jarmodeToolsLocation);
}

private boolean isIncludeJarmodeTools() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,14 @@ class BootZipCopyAction implements CopyAction {

private final ResolvedDependencies resolvedDependencies;

private final boolean supportsSignatureFile;

private final @Nullable LayerResolver layerResolver;

BootZipCopyAction(File output, Manifest manifest, boolean preserveFileTimestamps, @Nullable Integer dirMode,
@Nullable Integer fileMode, boolean includeDefaultLoader, @Nullable String jarmodeToolsLocation,
Spec<FileTreeElement> requiresUnpack, Spec<FileTreeElement> exclusions,
@Nullable LaunchScriptConfiguration launchScript, Spec<FileCopyDetails> librarySpec,
Function<FileCopyDetails, ZipCompression> compressionResolver, @Nullable String encoding,
ResolvedDependencies resolvedDependencies, boolean supportsSignatureFile,
@Nullable LayerResolver layerResolver) {
ResolvedDependencies resolvedDependencies, @Nullable LayerResolver layerResolver) {
this.output = output;
this.manifest = manifest;
this.preserveFileTimestamps = preserveFileTimestamps;
Expand All @@ -137,7 +134,6 @@ class BootZipCopyAction implements CopyAction {
this.compressionResolver = compressionResolver;
this.encoding = encoding;
this.resolvedDependencies = resolvedDependencies;
this.supportsSignatureFile = supportsSignatureFile;
this.layerResolver = layerResolver;
}

Expand Down Expand Up @@ -362,7 +358,7 @@ private void writeJarModeLibrary(String location, JarModeLibrary library) throws
}

private void writeSignatureFileIfNecessary() throws IOException {
if (BootZipCopyAction.this.supportsSignatureFile && hasSignedLibrary()) {
if (hasSignedLibrary()) {
writeEntry("META-INF/BOOT.SF", (out) -> {
}, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ void dirModeAndFileModeAreApplied() throws IOException {
}
}

@TestTemplate
void signed() throws IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
try (JarFile jarFile = new JarFile(jar)) {
assertThat(jarFile.getEntry("META-INF/BOOT.SF")).isNotNull();
}
}

private void copyMainClassApplication() throws IOException {
copyApplication("main");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

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

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarFile;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.TestTemplate;

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

@TestTemplate
void signed() throws Exception {
assertThat(this.gradleBuild.build("bootJar").task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
try (JarFile jarFile = new JarFile(jar)) {
assertThat(jarFile.getEntry("META-INF/BOOT.SF")).isNotNull();
}
}

@TestTemplate
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
Assumptions.assumeTrue(this.gradleBuild.gradleVersionIsLessThan("9.0-milestone-1"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012-present 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.
*/

plugins {
id 'war'
id 'java'
id 'org.springframework.boot' version '{version}'
}

bootWar {
mainClass = 'com.example.Application'
}

repositories {
mavenCentral()
maven {
url = 'repository'
}
}

dependencies {
implementation("org.bouncycastle:bcprov-jdk18on:1.78.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,12 @@ void whenEntryIsExcludedItShouldNotBePresentInTheRepackagedWar(MavenBuild mavenB
});
}

@TestTemplate
void whenSigned(MavenBuild mavenBuild) {
mavenBuild.project("war-signed").execute((project) -> {
File repackaged = new File(project, "target/war-signed-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(repackaged)).hasEntryWithName("META-INF/BOOT.SF");
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>war-signed</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>@java.version@</maven.compiler.source>
<maven.compiler.target>@java.version@</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>@maven-war-plugin.version@</version>
<configuration>
<archive>
<manifest>
<mainClass>some.random.Main</mainClass>
</manifest>
<manifestEntries>
<Not-Used>Foo</Not-Used>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>@spring-framework.version@</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>@jakarta-servlet.version@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.78.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2012-present 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.test;

public class SampleApplication {

public static void main(String[] args) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public Repackager(File source) {
@Override
protected void writeSignatureFileIfNecessary(Map<String, Library> writtenLibraries, AbstractJarWriter writer)
throws IOException {
if (getSource().getName().toLowerCase(Locale.ROOT).endsWith(".jar") && hasSignedLibrary(writtenLibraries)) {
String sourceName = getSource().getName().toLowerCase(Locale.ROOT);
if ((sourceName.endsWith(".jar") || sourceName.endsWith(".war")) && hasSignedLibrary(writtenLibraries)) {
writer.writeEntry("META-INF/BOOT.SF", (entryWriter) -> {
});
}
Expand Down