|
13 | 13 | import com.intellij.openapi.actionSystem.AnActionEvent; |
14 | 14 | import com.intellij.openapi.actionSystem.PlatformDataKeys; |
15 | 15 | import com.intellij.openapi.project.Project; |
16 | | -import com.intellij.openapi.util.IconLoader; |
17 | 16 | import com.intellij.openapi.util.Key; |
18 | 17 | import com.intellij.openapi.wm.ToolWindow; |
19 | 18 | import com.intellij.openapi.wm.ToolWindowAnchor; |
|
22 | 21 | import com.intellij.ui.content.ContentManager; |
23 | 22 | import com.jetbrains.php.lang.psi.PhpFile; |
24 | 23 | import com.jetbrains.php.lang.psi.elements.PhpClass; |
| 24 | +import org.codehaus.jettison.json.JSONException; |
| 25 | +import org.codehaus.jettison.json.JSONObject; |
25 | 26 | import org.jetbrains.annotations.Nullable; |
26 | 27 |
|
| 28 | +import java.io.BufferedReader; |
| 29 | +import java.io.File; |
| 30 | +import java.io.IOException; |
| 31 | +import java.io.InputStreamReader; |
| 32 | +import java.nio.file.Files; |
| 33 | +import java.nio.file.Paths; |
27 | 34 | import java.util.Arrays; |
28 | 35 |
|
29 | 36 | public class AtoumRunTests extends AnAction { |
@@ -69,35 +76,58 @@ protected String runTest(PhpClass currentTestClass, Project project) { |
69 | 76 |
|
70 | 77 | try { |
71 | 78 | OSProcessHandler processHandler = ScriptRunnerUtil.execute( |
72 | | - "./vendor/bin/atoum", |
73 | | - project.getBasePath(), |
| 79 | + findAtoumBinPath(project), |
| 80 | + project.getBasePath(), |
74 | 81 | null, |
75 | 82 | commandLineArgs |
76 | 83 | ); |
77 | 84 |
|
78 | | - processHandler.addProcessListener(new ProcessAdapter() |
79 | | - { |
| 85 | + processHandler.addProcessListener(new ProcessAdapter() { |
80 | 86 | public void onTextAvailable(ProcessEvent event, Key outputType) { |
81 | | - outputBuilder.append(event.getText()); |
| 87 | + outputBuilder.append(event.getText()); |
82 | 88 | } |
83 | 89 | }); |
84 | 90 |
|
85 | 91 | processHandler.startNotify(); |
86 | | - while (true) |
87 | | - { |
| 92 | + while (true) { |
88 | 93 | boolean finished = processHandler.waitFor(1000L); |
89 | 94 | if (finished) { |
90 | 95 | break; |
91 | 96 | } |
92 | 97 | } |
93 | | - |
94 | 98 | return outputBuilder.toString(); |
95 | 99 | } catch (ExecutionException e1) { |
96 | 100 | e1.printStackTrace(); |
97 | 101 | return "ERROR launching tests" + e1.getMessage(); |
98 | 102 | } |
99 | 103 | } |
100 | 104 |
|
| 105 | + protected String findAtoumBinPath(Project project) |
| 106 | + { |
| 107 | + String defaultBinPath = project.getBasePath() + "/vendor/bin/atoum"; |
| 108 | + |
| 109 | + String binDir = getComposerBinDir(project.getBasePath() + "/composer.json"); |
| 110 | + String binPath = project.getBasePath() + "/" + binDir + "/atoum"; |
| 111 | + if (null != binDir && new File(binPath).exists()) { |
| 112 | + return binPath; |
| 113 | + } |
| 114 | + |
| 115 | + return defaultBinPath; |
| 116 | + } |
| 117 | + |
| 118 | + @Nullable |
| 119 | + protected String getComposerBinDir(String composerPath) { |
| 120 | + try { |
| 121 | + String composerJsonContent = new String(Files.readAllBytes(Paths.get(composerPath))); |
| 122 | + JSONObject obj = new JSONObject(composerJsonContent); |
| 123 | + return obj.getJSONObject("config").get("bin-dir").toString(); |
| 124 | + } catch (JSONException e) { |
| 125 | + return null; |
| 126 | + } catch (IOException e) { |
| 127 | + return null; |
| 128 | + } |
| 129 | + } |
| 130 | + |
101 | 131 |
|
102 | 132 | protected ToolWindow getToolWindow(Project project) { |
103 | 133 | ToolWindow toolWindow; |
|
0 commit comments