Skip to content

Commit 8203f15

Browse files
UCT run configuration development (download UCT if it is not found)
1 parent 524d4c7 commit 8203f15

File tree

8 files changed

+283
-18
lines changed

8 files changed

+283
-18
lines changed

src/com/magento/idea/magento2plugin/MagentoIcons.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
@SuppressWarnings({"PMD.ClassNamingConventions"})
1212
public class MagentoIcons {
13+
1314
public static final Icon WEB_API = IconLoader.getIcon("/icons/webapi.png", MagentoIcons.class);
1415
public static final Icon MODULE = IconLoader.getIcon("/icons/module.png", MagentoIcons.class);
16+
public static final Icon PLUGIN_ICON = IconLoader.getIcon(
17+
"/META-INF/pluginIcon.svg",
18+
MagentoIcons.class
19+
);
1520
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2uct.execution;
7+
8+
import com.intellij.execution.ExecutionException;
9+
import com.intellij.execution.configurations.GeneralCommandLine;
10+
import com.intellij.execution.filters.TextConsoleBuilderFactory;
11+
import com.intellij.execution.process.OSProcessHandler;
12+
import com.intellij.execution.process.ProcessHandlerFactory;
13+
import com.intellij.execution.process.ProcessTerminatedListener;
14+
import com.intellij.execution.ui.ConsoleView;
15+
import com.intellij.openapi.project.Project;
16+
import com.intellij.openapi.wm.RegisterToolWindowTask;
17+
import com.intellij.openapi.wm.ToolWindow;
18+
import com.intellij.openapi.wm.ToolWindowAnchor;
19+
import com.intellij.openapi.wm.ToolWindowId;
20+
import com.intellij.openapi.wm.ToolWindowManager;
21+
import com.intellij.ui.content.Content;
22+
import org.jetbrains.annotations.NotNull;
23+
24+
public final class DownloadUctCommand {
25+
26+
private static final String TAB_TITLE = "Create UCT project";
27+
private final Project project;
28+
29+
/**
30+
* Download UCT command constructor.
31+
*
32+
* @param project Project
33+
*/
34+
public DownloadUctCommand(final @NotNull Project project) {
35+
this.project = project;
36+
}
37+
38+
/**
39+
* Start UCT downloading process.
40+
*/
41+
public void execute() {
42+
final ConsoleView consoleView = createConsole();
43+
try {
44+
final OSProcessHandler processHandler = createProcessHandler();
45+
consoleView.attachToProcess(processHandler);
46+
processHandler.startNotify();
47+
} catch (ExecutionException exception) {
48+
//NOPMD
49+
}
50+
}
51+
52+
/**
53+
* Create process handler.
54+
*
55+
* @return OSProcessHandler
56+
*/
57+
private OSProcessHandler createProcessHandler() throws ExecutionException {
58+
final GeneralCommandLine commandLine = new GeneralCommandLine();
59+
commandLine.setWorkDirectory(project.getBasePath());
60+
commandLine.setExePath("composer");
61+
commandLine.addParameters(
62+
"create-project",
63+
"magento/upgrade-compatibility-tool",
64+
"uct",
65+
"--repository",
66+
"https://repo.magento.com",
67+
"--ansi"
68+
);
69+
70+
final OSProcessHandler processHandler = ProcessHandlerFactory
71+
.getInstance()
72+
.createColoredProcessHandler(commandLine);
73+
74+
ProcessTerminatedListener.attach(processHandler);
75+
76+
return processHandler;
77+
}
78+
79+
/**
80+
* Create console view.
81+
*
82+
* @return ConsoleView
83+
*/
84+
private ConsoleView createConsole() {
85+
ToolWindow toolWindow = ToolWindowManager
86+
.getInstance(project)
87+
.getToolWindow(ToolWindowId.RUN);
88+
89+
if (toolWindow == null) {
90+
toolWindow = ToolWindowManager.getInstance(project).registerToolWindow(
91+
new RegisterToolWindowTask(
92+
ToolWindowId.RUN,
93+
ToolWindowAnchor.BOTTOM,
94+
null,
95+
false,
96+
true,
97+
true,
98+
true,
99+
null,
100+
null,
101+
null
102+
)
103+
);
104+
}
105+
final ConsoleView consoleView = TextConsoleBuilderFactory.getInstance()
106+
.createBuilder(project)
107+
.getConsole();
108+
final Content content = toolWindow
109+
.getContentManager()
110+
.getFactory()
111+
.createContent(consoleView.getComponent(), TAB_TITLE, true);
112+
toolWindow.getContentManager().addContent(content);
113+
toolWindow.show();
114+
115+
return consoleView;
116+
}
117+
}

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.intellij.execution.ExecutionException;
99
import com.intellij.execution.Executor;
10+
import com.intellij.execution.RunManager;
1011
import com.intellij.execution.configurations.CommandLineState;
1112
import com.intellij.execution.configurations.ConfigurationFactory;
1213
import com.intellij.execution.configurations.GeneralCommandLine;
@@ -29,6 +30,7 @@
2930
import com.magento.idea.magento2uct.execution.filters.UctPhpFileFilter;
3031
import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter;
3132
import com.magento.idea.magento2uct.settings.UctSettingsService;
33+
import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil;
3234
import com.magento.idea.magento2uct.versioning.IssueSeverityLevel;
3335
import org.jetbrains.annotations.NotNull;
3436
import org.jetbrains.annotations.Nullable;
@@ -145,6 +147,24 @@ public boolean hasIgnoreCurrentVersionIssues() {
145147
return getOptions().hasIgnoreCurrentVersionIssues();
146148
}
147149

150+
/**
151+
* Set is settings is newly created.
152+
*
153+
* @param isNewlyCreated boolean
154+
*/
155+
public void setIsNewlyCreated(final boolean isNewlyCreated) {
156+
getOptions().setIsNewlyCreated(isNewlyCreated);
157+
}
158+
159+
/**
160+
* Check if run configuration settings is newly created setting.
161+
*
162+
* @return boolean
163+
*/
164+
public boolean isNewlyCreated() {
165+
return getOptions().isNewlyCreated();
166+
}
167+
148168
@Override
149169
public @NotNull SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
150170
return new UctSettingsEditor(getProject());
@@ -157,7 +177,10 @@ public void checkConfiguration() throws RuntimeConfigurationException {
157177

158178
@Override
159179
public @Nullable @NlsActions.ActionText String suggestedName() {
160-
return UctRunConfigurationType.SHORT_TITLE;
180+
return this.getName().isEmpty() ? RunManager.getInstance(getProject()).suggestUniqueName(
181+
UctRunConfigurationType.SHORT_TITLE,
182+
this.getType()
183+
) : this.getName();
161184
}
162185

163186
@Override
@@ -181,14 +204,20 @@ public void checkConfiguration() throws RuntimeConfigurationException {
181204
);
182205
}
183206

207+
final boolean isValidPath = UctExecutableValidatorUtil.validate(getScriptName());
208+
184209
if (getScriptName().isEmpty()) {
185210
throw new ExecutionException("The UCT executable path is not specified");
186211
} else {
187-
if (settingsService != null) {
212+
if (settingsService != null && isValidPath) {
188213
settingsService.setUctExecutablePath(getScriptName());
189214
}
190215
}
191216

217+
if (!isValidPath) {
218+
throw new ExecutionException("The UCT executable path is not valid");
219+
}
220+
192221
if (getComingVersion().isEmpty()) {
193222
throw new ExecutionException("The coming/target version is not specified");
194223
}

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions
2020
.provideDelegate(this, "minIssueLevel");
2121
private final StoredProperty<Boolean> hasIgnoreCurrentVersionIssues = property(false)
2222
.provideDelegate(this, "hasIgnoreCurrentVersionIssues");
23+
private final StoredProperty<Boolean> isNewlyCreated = property(true)
24+
.provideDelegate(this, "isNewlyCreated");
2325

2426
/**
2527
* Set script name setting.
@@ -110,4 +112,22 @@ public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersi
110112
public boolean hasIgnoreCurrentVersionIssues() {
111113
return hasIgnoreCurrentVersionIssues.getValue(this);
112114
}
115+
116+
/**
117+
* Set is settings is newly created.
118+
*
119+
* @param isNewlyCreated boolean
120+
*/
121+
public void setIsNewlyCreated(final boolean isNewlyCreated) {
122+
this.isNewlyCreated.setValue(this, isNewlyCreated);
123+
}
124+
125+
/**
126+
* Check if run configuration settings is newly created setting.
127+
*
128+
* @return boolean
129+
*/
130+
public boolean isNewlyCreated() {
131+
return isNewlyCreated.getValue(this);
132+
}
113133
}

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public String getConfigurationTypeDescription() {
3030

3131
@Override
3232
public Icon getIcon() {
33-
return MagentoIcons.ADOBE;
33+
return MagentoIcons.PLUGIN_ICON;
3434
}
3535

3636
@Override

src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="15" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="983" height="418"/>
6+
<xy x="20" y="20" width="983" height="442"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -135,6 +135,7 @@
135135
</constraints>
136136
<properties>
137137
<font size="12"/>
138+
<icon value="general/information.png"/>
138139
<text value="If your CLI output is cut, you should increase your buffer size:"/>
139140
</properties>
140141
</component>
@@ -157,13 +158,13 @@
157158
<text value="errors and warnings in your Upgrade Compatibility Tool report."/>
158159
</properties>
159160
</component>
160-
<grid id="b7201" binding="warningPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
161-
<margin top="10" left="0" bottom="0" right="0"/>
161+
<grid id="b7201" binding="warningPanel" layout-manager="GridLayoutManager" row-count="1" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
162+
<margin top="10" left="10" bottom="10" right="10"/>
162163
<constraints>
163-
<grid row="13" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
164+
<grid row="13" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
164165
</constraints>
165166
<properties/>
166-
<border type="none"/>
167+
<border type="etched"/>
167168
<children>
168169
<component id="df92" class="javax.swing.JLabel" binding="uctLookupFailedWarning">
169170
<constraints>
@@ -174,14 +175,33 @@
174175
<enabled value="true"/>
175176
<font size="12" style="1"/>
176177
<icon value="general/warning.png"/>
177-
<text value="Could not find UCT in the project"/>
178+
<text value="Could not find UCT in the project:"/>
178179
</properties>
179180
</component>
180181
<hspacer id="d7c91">
181182
<constraints>
182-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
183+
<grid row="0" column="3" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
183184
</constraints>
184185
</hspacer>
186+
<component id="34ffd" class="org.jdesktop.swingx.JXHyperlink" binding="installTypeOne">
187+
<constraints>
188+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
189+
</constraints>
190+
<properties>
191+
<actionCommand value=""/>
192+
<clickedColor color="-11176758"/>
193+
<contentAreaFilled value="true"/>
194+
<hideActionText value="false"/>
195+
<horizontalTextPosition value="11"/>
196+
<icon value="actions/install.png"/>
197+
<iconTextGap value="5"/>
198+
<inheritsPopupMenu value="false"/>
199+
<label value="Download"/>
200+
<margin top="0" left="2" bottom="0" right="2"/>
201+
<overrulesActionOnClick value="false"/>
202+
<text value="Download"/>
203+
</properties>
204+
</component>
185205
</children>
186206
</grid>
187207
</children>

0 commit comments

Comments
 (0)