Skip to content

Commit

Permalink
fix: bootstrapper gitignore exclusion fix (#2409)
Browse files Browse the repository at this point in the history

Signed-off-by: Attila Mészáros <csviri@gmail.com>
  • Loading branch information
csviri authored May 27, 2024
1 parent 7d6f9c9 commit 9cf2baa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class Bootstrapper {

private MustacheFactory mustacheFactory = new DefaultMustacheFactory();

private static final List<String> TOP_LEVEL_STATIC_FILES =
List.of(".gitignore", "README.md");
// .gitignore gets excluded from resource, using here a prefixed version
private static final Map<String, String> TOP_LEVEL_STATIC_FILES =
Map.of("_.gitignore", ".gitignore", "README.md", "README.md");
private static final List<String> JAVA_FILES =
List.of("CustomResource.java", "Reconciler.java",
"Spec.java", "Status.java");
Expand Down Expand Up @@ -106,22 +107,23 @@ private void addTemplatedFile(File projectDir, String fileName, String groupId,
}

private void addStaticFiles(File projectDir) {
TOP_LEVEL_STATIC_FILES.forEach(f -> addStaticFile(projectDir, f));
TOP_LEVEL_STATIC_FILES.forEach((key, value) -> addStaticFile(projectDir, key, value));
}

private void addStaticFile(File targetDir, String fileName) {
addStaticFile(targetDir, fileName, null);
private void addStaticFile(File targetDir, String fileName, String targetFileName) {
addStaticFile(targetDir, fileName, targetFileName, null);
}

private void addStaticFile(File targetDir, String fileName, String subDir) {
private void addStaticFile(File targetDir, String fileName, String targetFilename,
String subDir) {
String sourcePath = subDir == null ? "/static/" : "/static/" + subDir;
String path = sourcePath + fileName;
try (var is = Bootstrapper.class.getResourceAsStream(path)) {
targetDir = subDir == null ? targetDir : new File(targetDir, subDir);
if (subDir != null) {
FileUtils.forceMkdir(targetDir);
}
FileUtils.copyInputStreamToFile(is, new File(targetDir, fileName));
FileUtils.copyInputStreamToFile(is, new File(targetDir, targetFilename));
} catch (IOException e) {
throw new RuntimeException("File path: " + path, e);
}
Expand Down

0 comments on commit 9cf2baa

Please sign in to comment.