do not remove InjectorFor* if generation fails
This commit is contained in:
@@ -58,6 +58,7 @@ public class DependencyInjectorGenerator {
|
|||||||
String outputFileName = targetSourceRoot + "/" + injectorPackageName.replace(".", "/") + "/" + injectorClassName + ".java";
|
String outputFileName = targetSourceRoot + "/" + injectorPackageName.replace(".", "/") + "/" + injectorClassName + ".java";
|
||||||
|
|
||||||
File file = new File(outputFileName);
|
File file = new File(outputFileName);
|
||||||
|
File tmpfile = new File(outputFileName + ".tmp");
|
||||||
File parentFile = file.getParentFile();
|
File parentFile = file.getParentFile();
|
||||||
if (!parentFile.exists()) {
|
if (!parentFile.exists()) {
|
||||||
if (parentFile.mkdirs()) {
|
if (parentFile.mkdirs()) {
|
||||||
@@ -68,8 +69,8 @@ public class DependencyInjectorGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
FileOutputStream fileOutputStream = new FileOutputStream(tmpfile);
|
||||||
System.out.println("File opened: " + file.getAbsolutePath());
|
System.out.println("File opened: " + tmpfile.getAbsolutePath());
|
||||||
|
|
||||||
PrintStream out = new PrintStream(fileOutputStream);
|
PrintStream out = new PrintStream(fileOutputStream);
|
||||||
try {
|
try {
|
||||||
@@ -102,6 +103,13 @@ public class DependencyInjectorGenerator {
|
|||||||
// out.println();
|
// out.println();
|
||||||
// generateMakeFunction(out);
|
// generateMakeFunction(out);
|
||||||
out.println("}"); // class
|
out.println("}"); // class
|
||||||
|
|
||||||
|
fileOutputStream.close();
|
||||||
|
|
||||||
|
if (!tmpfile.renameTo(file)) {
|
||||||
|
throw new RuntimeException("failed to rename " + tmpfile + " to " + file);
|
||||||
|
}
|
||||||
|
System.out.println("Renamed " + tmpfile + " to " + file);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user