fix for output file by short name inside working dir (IDEA-153832)
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Mon, 2 May 2016 17:01:36 +0000 (19:01 +0200)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 3 May 2016 08:47:40 +0000 (10:47 +0200)
java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java
platform/lang-impl/src/com/intellij/diagnostic/logging/OutputFileUtil.java

index f07cb5301613691e6cef6c9556126cd28aa96feb..dd5d7148e811fb56989ff8f15db16fd47c1d4d1b 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.execution;
 
 import com.intellij.ExtensionPoints;
 import com.intellij.debugger.impl.GenericDebuggerRunnerSettings;
+import com.intellij.diagnostic.logging.OutputFileUtil;
 import com.intellij.execution.configurations.*;
 import com.intellij.execution.process.OSProcessHandler;
 import com.intellij.execution.process.ProcessAdapter;
@@ -124,7 +125,8 @@ public abstract class JavaTestFrameworkRunnableState<T extends ModuleBasedConfig
       @Override
       public void startNotified(ProcessEvent event) {
         if (getConfiguration().isSaveOutputToFile()) {
-          root.setOutputFilePath(getConfiguration().getOutputFilePath());
+          final File file = OutputFileUtil.getOutputFile(getConfiguration());
+          root.setOutputFilePath(file != null ? file.getAbsolutePath() : null);
         }
       }
 
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