*
* @see java.lang.Thread#run()
*/
public void run() {
try {
final VirtualFileManager manager = VirtualFileManager.getInstance();
VirtualFile virtualFile = manager.refreshAndFindFileByUrl(VfsUtil.pathToUrl(this.outputFile));
int overwriteInd = JOptionPane.NO_OPTION;
if (virtualFile != null && virtualFile.exists()) {
log.debug("file exists so prompt the user for merge request");
overwriteInd =
JOptionPane.showOptionDialog(null,
JUnitGeneratorUtil.getProperty("junit.generator.file.exists"),
"View the difference?",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (JOptionPane.NO_OPTION == overwriteInd) {
//user chose to overwrite the file, so replace the virtual file contents
virtualFile.setBinaryContent(writer.toString().getBytes());
}
} else {
//we need to create the file
final File newFile = new File(this.outputFile);
//create directories if required
if (!newFile.getParentFile().exists()) {
if (newFile.getParentFile().mkdirs()) {
log.debug("created directories");
}
}
//user chose to overwrite
FileWriter w = null;
try {
w = new FileWriter(newFile);
w.write(this.writer.toString());
} catch (IOException e) {
log.warn("Exception while logging the error", e);
} finally {
if (w != null) {
try {
w.close();
} catch (IOException e) {
//ignore
}
}
}
log.info("Created File");
virtualFile = manager.refreshAndFindFileByUrl(VfsUtil.pathToUrl(this.outputFile));
}
final VirtualFile fileToOpen = virtualFile;
if (JOptionPane.NO_OPTION == overwriteInd && virtualFile != null) {
//now open the file