Merge branch '2.3.x'
Closes gh-22349
This commit is contained in:
@@ -35,6 +35,7 @@ import org.springframework.util.StreamUtils;
|
||||
* Adapter class to convert a ZIP file to a {@link TarArchive}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class ZipFileTarArchive implements TarArchive {
|
||||
@@ -54,6 +55,7 @@ public class ZipFileTarArchive implements TarArchive {
|
||||
public ZipFileTarArchive(File zip, Owner owner) {
|
||||
Assert.notNull(zip, "Zip must not be null");
|
||||
Assert.notNull(owner, "Owner must not be null");
|
||||
assertArchiveHasEntries(zip);
|
||||
this.zip = zip;
|
||||
this.owner = owner;
|
||||
}
|
||||
@@ -72,6 +74,16 @@ public class ZipFileTarArchive implements TarArchive {
|
||||
tar.finish();
|
||||
}
|
||||
|
||||
private void assertArchiveHasEntries(File jarFile) {
|
||||
try (ZipFile zipFile = new ZipFile(jarFile)) {
|
||||
Assert.state(zipFile.getEntries().hasMoreElements(), "File '" + jarFile.toString()
|
||||
+ "' is not compatible with buildpacks; ensure jar file is valid and launch script is not enabled");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("File is not readable", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(ZipArchiveEntry zipEntry, InputStream zip, TarArchiveOutputStream tar) throws IOException {
|
||||
TarArchiveEntry tarEntry = convert(zipEntry);
|
||||
tar.putArchiveEntry(tarEntry);
|
||||
|
||||
Reference in New Issue
Block a user