Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jun 4, 2024
1 parent ce98728 commit 68cc5f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;

import io.spring.initializr.generator.buildsystem.BuildSystem;
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
Expand Down Expand Up @@ -153,15 +154,15 @@ private TarArchiveOutputStream createTarArchiveOutputStream(OutputStream output)
}

private <T extends ArchiveEntry> Path createArchive(ProjectGenerationResult result, String fileExtension,
Function<OutputStream, ? extends ArchiveOutputStream> archiveOutputStream,
Function<OutputStream, ? extends ArchiveOutputStream<T>> archiveOutputStream,
BiFunction<File, String, T> archiveEntry, BiConsumer<T, Integer> setMode) throws IOException {
Path archive = this.projectGenerationInvoker.createDistributionFile(result.getRootDirectory(),
"." + fileExtension);
String wrapperScript = getWrapperScript(result.getProjectDescription());
try (ArchiveOutputStream output = archiveOutputStream.apply(Files.newOutputStream(archive))) {
Files.walk(result.getRootDirectory())
.filter((path) -> !result.getRootDirectory().equals(path))
.forEach((path) -> {
try (ArchiveOutputStream<T> output = archiveOutputStream.apply(Files.newOutputStream(archive))) {
Stream<Path> files = Files.walk(result.getRootDirectory());
try (files) {
files.filter((path) -> !result.getRootDirectory().equals(path)).forEach((path) -> {
try {
String entryName = getEntryName(result.getRootDirectory(), path);
T entry = archiveEntry.apply(path.toFile(), entryName);
Expand All @@ -176,6 +177,7 @@ private <T extends ArchiveEntry> Path createArchive(ProjectGenerationResult resu
throw new IllegalStateException(ex);
}
});
}
}
return archive;
}
Expand All @@ -198,12 +200,7 @@ private int getUnixMode(String wrapperScript, String entryName, Path path) {
private String generateFileName(String artifactId, String extension) {
String candidate = (StringUtils.hasText(artifactId) ? artifactId
: this.metadataProvider.get().getArtifactId().getContent());
try {
return URLEncoder.encode(candidate, "UTF-8") + "." + extension;
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException("Cannot encode URL", ex);
}
return URLEncoder.encode(candidate, StandardCharsets.UTF_8) + "." + extension;
}

private static String getWrapperScript(ProjectDescription description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
Expand Down Expand Up @@ -332,13 +332,12 @@ protected JSONObject readJsonFrom(String path) {
try {
ClassPathResource resource = new ClassPathResource(path);
try (InputStream in = resource.getInputStream()) {
String json = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
String json = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
String placeholder = "";
if (this instanceof AbstractInitializrControllerIntegrationTests) {
placeholder = ((AbstractInitializrControllerIntegrationTests) this).host;
}
if (this instanceof AbstractFullStackInitializrIntegrationTests) {
AbstractFullStackInitializrIntegrationTests test = (AbstractFullStackInitializrIntegrationTests) this;
if (this instanceof AbstractFullStackInitializrIntegrationTests test) {
placeholder = test.host + ":" + test.port;
}
// Let's parse the port as it is random
Expand Down Expand Up @@ -389,9 +388,9 @@ private enum BitMaskFilePermission {

OTHERS_EXECUTE(0001);

private int mask;
private final int mask;

private PosixFilePermission filePermission;
private final PosixFilePermission filePermission;

BitMaskFilePermission(int mask) {
this.mask = mask;
Expand Down

0 comments on commit 68cc5f6

Please sign in to comment.