Skip to content

fix: bootstrapper gitignore exclusion fix #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading