fix for output file by short name inside working dir (IDEA-153832)
[idea/community.git] / platform / lang-impl / src / com / intellij / diagnostic / logging / OutputFileUtil.java
index 647ba6697f7ddf4398128ef3ea09bd6ba2f5934f..5c4f3ad9a3e3a494ffb929eac55f7fc629dfcad1 100644 (file)
@@ -53,14 +53,29 @@ public class OutputFileUtil {
   private OutputFileUtil() {
   }
 
+  public static File getOutputFile(@NotNull final RunConfigurationBase configuration) {
+    String outputFilePath = configuration.getOutputFilePath();
+    if (outputFilePath != null) {
+      final String filePath = FileUtil.toSystemDependentName(outputFilePath);
+      File file = new File(filePath);
+      if (configuration instanceof CommonProgramRunConfigurationParameters && !FileUtil.isAbsolute(filePath)) {
+        String directory = ((CommonProgramRunConfigurationParameters)configuration).getWorkingDirectory();
+        if (directory != null) {
+          file = new File(new File(directory), filePath);
+        }
+      }
+      return file;
+    }
+    return null;
+  }
+
   public static void attachDumpListener(@NotNull final RunConfigurationBase configuration, @NotNull final ProcessHandler startedProcess, @Nullable final ExecutionConsole console) {
     if (!configuration.isSaveOutputToFile()) {
       return;
     }
 
-    String outputFilePath = configuration.getOutputFilePath();
-    if (outputFilePath != null) {
-      final String filePath = FileUtil.toSystemDependentName(outputFilePath);
+    final File file = getOutputFile(configuration);
+    if (file != null) {
       startedProcess.addProcessListener(new ProcessAdapter() {
         private PrintStream myOutput;
         @Override
@@ -73,18 +88,11 @@ public class OutputFileUtil {
         @Override
         public void startNotified(ProcessEvent event) {
           try {
-            File file = new File(filePath);
-            if (configuration instanceof CommonProgramRunConfigurationParameters && !FileUtil.isAbsolute(filePath)) {
-              String directory = ((CommonProgramRunConfigurationParameters)configuration).getWorkingDirectory();
-              if (directory != null) {
-                file = new File(new File(directory), filePath);
-              }
-            }
             myOutput = new PrintStream(new FileOutputStream(file));
           }
           catch (FileNotFoundException ignored) {
           }
-          startedProcess.notifyTextAvailable(CONSOLE_OUTPUT_FILE_MESSAGE + filePath + "\n", ProcessOutputTypes.SYSTEM);
+          startedProcess.notifyTextAvailable(CONSOLE_OUTPUT_FILE_MESSAGE + FileUtil.toSystemDependentName(file.getAbsolutePath()) + "\n", ProcessOutputTypes.SYSTEM);
         }
 
         @Override