Use posix long names when creating tar archive for image building
Fixes gh-19964
This commit is contained in:
@@ -18,6 +18,10 @@ package org.springframework.boot.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -42,7 +46,7 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
void whenBuildImageIsInvokedWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
|
||||
mavenBuild.project("build-image").goals("package").execute((project) -> {
|
||||
mavenBuild.project("build-image").goals("package").prepare(this::writeLongNameResource).execute((project) -> {
|
||||
File jar = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar");
|
||||
assertThat(jar).isFile();
|
||||
File original = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar.original");
|
||||
@@ -79,6 +83,19 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
private void writeLongNameResource(File project) {
|
||||
StringBuilder name = new StringBuilder();
|
||||
new Random().ints('a', 'z' + 1).limit(128).forEach((i) -> name.append((char) i));
|
||||
try {
|
||||
Path path = project.toPath().resolve(Paths.get("src", "main", "resources", name.toString()));
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.createFile(path);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeImage(ImageReference imageReference) {
|
||||
try {
|
||||
new DockerApi().image().remove(imageReference, false);
|
||||
|
||||
@@ -70,6 +70,8 @@ class MavenBuild {
|
||||
|
||||
private final Properties properties = new Properties();
|
||||
|
||||
private Consumer<File> preparation;
|
||||
|
||||
private File projectDir;
|
||||
|
||||
MavenBuild(File home) {
|
||||
@@ -109,6 +111,11 @@ class MavenBuild {
|
||||
return this;
|
||||
}
|
||||
|
||||
MavenBuild prepare(Consumer<File> callback) {
|
||||
this.preparation = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
void execute(Consumer<File> callback) {
|
||||
Invoker invoker = new DefaultInvoker();
|
||||
invoker.setMavenHome(this.home);
|
||||
@@ -158,6 +165,9 @@ class MavenBuild {
|
||||
request.setBatchMode(true);
|
||||
File target = new File(this.temp, "target");
|
||||
target.mkdirs();
|
||||
if (this.preparation != null) {
|
||||
this.preparation.accept(this.temp);
|
||||
}
|
||||
File buildLogFile = new File(target, "build.log");
|
||||
try (PrintWriter buildLog = new PrintWriter(new FileWriter(buildLogFile))) {
|
||||
request.setOutputHandler(new InvocationOutputHandler() {
|
||||
|
||||
Reference in New Issue
Block a user