Skip to content
Prev Previous commit
Next Next commit
merge File content function added
  • Loading branch information
VamshikShetty committed Feb 14, 2019
commit e44d3db46da0ca15d0d44b7f013a39e68cfb9e86
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ public File writeToFile(String filename, String contents) throws IOException {
return output;
}

public String mergeFileContent(String fileName, String content) throws IOException {

File f1 = new File(fileName);

if(!f1.exists()){
return content;
}

FileReader fileReader = new FileReader(f1);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line,existingContent = "";

while((line = bufferedReader.readLine()) != null) {
if(existingContent=="")
existingContent = line;
else
existingContent += System.lineSeparator() + line;
}

if(!existingContent.isEmpty()) {
content = existingContent + System.lineSeparator() + content;
}
return content;
}

public String readTemplate(String name) {
try {
Reader reader = getTemplateReader(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,11 @@ public Reader getTemplate(String name) {
.defaultValue("")
.compile(template);

writeToFile(outputFilename, tmpl.execute(bundle));
String contents = tmpl.execute(bundle);
if(support.merge)
contents = mergeFileContent(outputFilename, contents);
writeToFile(outputFilename, contents);

File written = new File(outputFilename);
files.add(written);
if (config.isEnablePostProcessFile()) {
Expand Down