Skip to content

Commit

Permalink
devonfw#759: Added method that deletes file
Browse files Browse the repository at this point in the history
Added A method that deletes a 'replacement-patterns.properties' -file, if it exists
  • Loading branch information
leonrohne27 committed Nov 25, 2024
1 parent af2842e commit 78c2fad
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ public void replaceIdeVariables() {
Files.walk(workspaceDir)
.filter(Files::isRegularFile) // Filter for regular files
.forEach(file -> {
// Process each found file
processFileForVariableReplacement(file, legacyToNewMapping);
if (file.getFileName().toString().equals("replacement-patterns.properties")) {
handleReplacementPatternsFile(file); // This deletes the file if not empty
}
if (Files.exists(file)) {
// Process each found file
processFileForVariableReplacement(file, legacyToNewMapping);
}
});
} catch (IOException e) {
this.context.error("Error while processing files in workspace: " + workspaceDir, e);
Expand Down Expand Up @@ -222,4 +227,26 @@ private void processFileForVariableReplacement(Path file, Map<String, String> le
this.context.error("Error processing file: {}, exception: {}", file, e);
}
}

private void handleReplacementPatternsFile(Path file) {
// If the file matches 'replacement-patterns.properties'
if (Files.exists(file) && Files.isRegularFile(file)) {
try {
// Read the file content
String content = Files.readString(file);

if (!content.trim().isEmpty()) {
// Log a warning if the file is not empty
this.context.warning("The file 'replacement-patterns.properties' is not empty: " + file);
}

// Delete the file after processing
Files.delete(file);
this.context.success("Deleted 'replacement-patterns.properties' from: " + file);
} catch (IOException e) {
// Handle any exceptions during reading or deleting the file
this.context.error("Error processing 'replacement-patterns.properties' file: " + file, e);
}
}
}
}

0 comments on commit 78c2fad

Please sign in to comment.