forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloadUctCommand.java
143 lines (127 loc) · 4.68 KB
/
DownloadUctCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2uct.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.PtyCommandLine;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessHandlerFactory;
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.RegisterToolWindowTask;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.magento.idea.magento2plugin.MagentoIcons;
import org.jetbrains.annotations.NotNull;
public final class DownloadUctCommand {
private static final String TAB_TITLE = "Create UCT project";
private final Project project;
/**
* Download UCT command constructor.
*
* @param project Project
*/
public DownloadUctCommand(final @NotNull Project project) {
this.project = project;
}
/**
* Start UCT downloading process.
*/
public void execute() throws ExecutionException {
final ConsoleView consoleView = createConsole();
final OSProcessHandler processHandler = createProcessHandler();
consoleView.attachToProcess(processHandler);
processHandler.startNotify();
}
/**
* Create process handler.
*
* @return OSProcessHandler
*/
private OSProcessHandler createProcessHandler() throws ExecutionException {
final GeneralCommandLine commandLine = createGeneralCommandLine(true);
commandLine.setWorkDirectory(project.getBasePath());
commandLine.setExePath("composer");
commandLine.addParameters(
"create-project",
"magento/upgrade-compatibility-tool",
"uct",
"--repository",
"https://repo.magento.com",
"--ansi"
);
final OSProcessHandler processHandler = ProcessHandlerFactory
.getInstance()
.createColoredProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
/**
* Create general command line.
*
* @param withPty boolean
*
* @return GeneralCommandLine
*/
private GeneralCommandLine createGeneralCommandLine(final boolean withPty) {
GeneralCommandLine commandLine;
if (withPty) {
if (SystemInfo.isWindows) {
commandLine = new GeneralCommandLine();
commandLine.getEnvironment().putIfAbsent("TERM", "xterm");
} else {
commandLine = new PtyCommandLine().withInitialColumns(2500);
}
} else {
commandLine = new GeneralCommandLine();
}
return commandLine;
}
/**
* Create console view.
*
* @return ConsoleView
*/
private ConsoleView createConsole() {
ToolWindow toolWindow = ToolWindowManager
.getInstance(project)
.getToolWindow(ToolWindowId.RUN);
if (toolWindow == null) {
toolWindow = ToolWindowManager.getInstance(project).registerToolWindow(
new RegisterToolWindowTask(
ToolWindowId.RUN,
ToolWindowAnchor.BOTTOM,
null,
false,
true,
true,
true,
null,
AllIcons.Actions.Execute,
null
)
);
}
final ConsoleView consoleView = TextConsoleBuilderFactory.getInstance()
.createBuilder(project)
.getConsole();
final Content content = toolWindow
.getContentManager()
.getFactory()
.createContent(consoleView.getComponent(), TAB_TITLE, true);
content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
content.setIcon(MagentoIcons.PLUGIN_ICON_SMALL);
toolWindow.getContentManager().addContent(content);
toolWindow.show();
return consoleView;
}
}