Merge branch '2.4.x'
Closes gh-25811
This commit is contained in:
@@ -36,12 +36,16 @@ public class ImagePackager extends Packager {
|
||||
/**
|
||||
* Create a new {@link ImagePackager} instance.
|
||||
* @param source the source file to package
|
||||
* @param backupFile the backup of the source file to package
|
||||
*/
|
||||
public ImagePackager(File source) {
|
||||
super(source, null);
|
||||
public ImagePackager(File source, File backupFile) {
|
||||
super(source);
|
||||
setBackupFile(backupFile);
|
||||
if (isAlreadyPackaged()) {
|
||||
Assert.isTrue(getBackupFile().exists() && getBackupFile().isFile(),
|
||||
"Original source '" + getBackupFile() + "' is required for building an image");
|
||||
Assert.state(!isAlreadyPackaged(getBackupFile()),
|
||||
() -> "Repackaged archive file " + source + " cannot be used to build an image");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +61,6 @@ public class ImagePackager extends Packager {
|
||||
|
||||
private void packageImage(Libraries libraries, AbstractJarWriter writer) throws IOException {
|
||||
File source = isAlreadyPackaged() ? getBackupFile() : getSource();
|
||||
Assert.state(!isAlreadyPackaged(source),
|
||||
() -> "Repackaged archive file " + source + " cannot be used to build an image");
|
||||
try (JarFile sourceJar = new JarFile(source)) {
|
||||
write(sourceJar, libraries, writer);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ public abstract class Packager {
|
||||
|
||||
private final File source;
|
||||
|
||||
private File backupFile;
|
||||
|
||||
private Layout layout;
|
||||
|
||||
private LayoutFactory layoutFactory;
|
||||
@@ -88,9 +90,20 @@ public abstract class Packager {
|
||||
|
||||
/**
|
||||
* Create a new {@link Packager} instance.
|
||||
* @param source the source JAR file to package
|
||||
* @param layoutFactory the layout factory to use or {@code null}
|
||||
* @param source the source archive file to package
|
||||
*/
|
||||
protected Packager(File source) {
|
||||
this(source, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link Packager} instance.
|
||||
* @param source the source archive file to package
|
||||
* @param layoutFactory the layout factory to use or {@code null}
|
||||
* @deprecated since 2.5.0 in favor of {@link #Packager(File)} and
|
||||
* {@link #setLayoutFactory(LayoutFactory)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected Packager(File source, LayoutFactory layoutFactory) {
|
||||
Assert.notNull(source, "Source file must not be null");
|
||||
Assert.isTrue(source.exists() && source.isFile(),
|
||||
@@ -146,6 +159,14 @@ public abstract class Packager {
|
||||
this.layersIndex = new LayersIndex(layers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link File} to use to backup the original source.
|
||||
* @param backupFile the file to use to backup the original source
|
||||
*/
|
||||
protected void setBackupFile(File backupFile) {
|
||||
this.backupFile = backupFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if jarmode jars relevant for the packaging should be automatically included.
|
||||
* @param includeRelevantJarModeJars if relevant jars are included
|
||||
@@ -291,6 +312,9 @@ public abstract class Packager {
|
||||
* @return the file to use to backup the original source
|
||||
*/
|
||||
public final File getBackupFile() {
|
||||
if (this.backupFile != null) {
|
||||
return this.backupFile;
|
||||
}
|
||||
return new File(this.source.getParentFile(), this.source.getName() + ".original");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,29 @@ import org.springframework.util.Assert;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Madhura Bhave
|
||||
* @author Scott Frederick
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class Repackager extends Packager {
|
||||
|
||||
private boolean backupSource = true;
|
||||
|
||||
/**
|
||||
* Create a new {@link Repackager} instance.
|
||||
* @param source the source archive file to package
|
||||
*/
|
||||
public Repackager(File source) {
|
||||
this(source, null);
|
||||
super(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link Repackager} instance.
|
||||
* @param source the source archive file to package
|
||||
* @param layoutFactory the layout factory to use or {@code null}
|
||||
* @deprecated since 2.5.0 in favor of {@link #Repackager(File)} and
|
||||
* {@link #setLayoutFactory(LayoutFactory)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Repackager(File source, LayoutFactory layoutFactory) {
|
||||
super(source, layoutFactory);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -40,7 +40,7 @@ class ImagePackagerTests extends AbstractPackagerTests<ImagePackager> {
|
||||
|
||||
@Override
|
||||
protected ImagePackager createPackager(File source) {
|
||||
return new ImagePackager(source);
|
||||
return new ImagePackager(source, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user