Add Maven and Gradle option for the loader implementation to use
Add properties to the Maven and Gradle plugins so that users can switch between the two loader modules. See gh-37669
This commit is contained in:
@@ -51,8 +51,6 @@ import org.apache.commons.compress.archivers.zip.UnixStat;
|
||||
*/
|
||||
public abstract class AbstractJarWriter implements LoaderClassesWriter {
|
||||
|
||||
private static final String NESTED_LOADER_JAR = "META-INF/loader/spring-boot-loader-classic.jar";
|
||||
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
|
||||
private static final int UNIX_FILE_MODE = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
|
||||
@@ -199,13 +197,15 @@ public abstract class AbstractJarWriter implements LoaderClassesWriter {
|
||||
return library.getLastModified();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the required spring-boot-loader classes to the JAR.
|
||||
* @throws IOException if the classes cannot be written
|
||||
*/
|
||||
@Override
|
||||
public void writeLoaderClasses() throws IOException {
|
||||
writeLoaderClasses(NESTED_LOADER_JAR);
|
||||
writeLoaderClasses(LoaderImplementation.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLoaderClasses(LoaderImplementation loaderImplementation) throws IOException {
|
||||
writeLoaderClasses((loaderImplementation != null) ? loaderImplementation.getJarResourceName()
|
||||
: LoaderImplementation.DEFAULT.getJarResourceName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Common {@link Layout}s.
|
||||
* Common {@link Layout layouts}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -34,6 +34,14 @@ public interface LoaderClassesWriter {
|
||||
*/
|
||||
void writeLoaderClasses() throws IOException;
|
||||
|
||||
/**
|
||||
* Write the default required spring-boot-loader classes to the JAR.
|
||||
* @param loaderImplementation the specific implementation to write
|
||||
* @throws IOException if the classes cannot be written
|
||||
* @since 3.2.0
|
||||
*/
|
||||
void writeLoaderClasses(LoaderImplementation loaderImplementation) throws IOException;
|
||||
|
||||
/**
|
||||
* Write custom required spring-boot-loader classes to the JAR.
|
||||
* @param loaderJarResourceName the name of the resource containing the loader classes
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2012-2023 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.springframework.boot.loader.tools;
|
||||
|
||||
/**
|
||||
* Supported loader implementations.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public enum LoaderImplementation {
|
||||
|
||||
/**
|
||||
* The default recommended loader implementation.
|
||||
*/
|
||||
DEFAULT("META-INF/loader/spring-boot-loader.jar"),
|
||||
|
||||
/**
|
||||
* The classic loader implementation as used with Spring Boot 3.1 and earlier.
|
||||
*/
|
||||
CLASSIC("META-INF/loader/spring-boot-loader-classic.jar");
|
||||
|
||||
private final String jarResourceName;
|
||||
|
||||
LoaderImplementation(String jarResourceName) {
|
||||
this.jarResourceName = jarResourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the nested resource that can be loaded from the tools jar.
|
||||
* @return the jar resource name
|
||||
*/
|
||||
public String getJarResourceName() {
|
||||
return this.jarResourceName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -88,6 +88,8 @@ public abstract class Packager {
|
||||
|
||||
private Layout layout;
|
||||
|
||||
private LoaderImplementation loaderImplementation;
|
||||
|
||||
private LayoutFactory layoutFactory;
|
||||
|
||||
private Layers layers;
|
||||
@@ -135,6 +137,14 @@ public abstract class Packager {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loader implementation to use.
|
||||
* @param loaderImplementation the loaderImplementation to set
|
||||
*/
|
||||
public void setLoaderImplementation(LoaderImplementation loaderImplementation) {
|
||||
this.loaderImplementation = loaderImplementation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the layout factory for the jar. The factory can be used when no specific
|
||||
* layout is specified.
|
||||
@@ -215,7 +225,7 @@ public abstract class Packager {
|
||||
customLoaderLayout.writeLoadedClasses(writer);
|
||||
}
|
||||
else if (layout.isExecutable()) {
|
||||
writer.writeLoaderClasses();
|
||||
writer.writeLoaderClasses(this.loaderImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user