Skip to content

Commit 653c544

Browse files
committed
Changed AngularCLI Global preferences and CLI setting in Angular Project-Wizard
See #107 and #94 - The global preference page now only validates the "global cli". - The Angular Project-Wizard has now the option to use global preferences instead of global CLI.
1 parent d8c9a22 commit 653c544

4 files changed

Lines changed: 91 additions & 69 deletions

File tree

ts.eclipse.ide.angular.cli/src/ts/eclipse/ide/angular/internal/cli/AngularCLIMessages.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public class AngularCLIMessages extends NLS {
5858
public static String NewAngularProjectWizard_unsupportedProjectNames;
5959

6060
public static String WizardNewNgProjectCreationPage_angular_cli_group_label;
61-
public static String WizardNewNgProjectCreationPage_useGlobalAngularCLI;
61+
public static String WizardNewNgProjectCreationPage_useGlobalPreferencesCLI;
6262
public static String WizardNewNgProjectCreationPage_useInstallAngularCLI;
63-
public static String WizardNewNgProjectCreationPage_searchingForGlobalAngularCLI;
64-
public static String WizardNewNgProjectCreationPage_noGlobalAngularCLI;
63+
public static String WizardNewNgProjectCreationPage_searchingForGlobalPreferencesCLI;
64+
public static String WizardNewNgProjectCreationPage_noGlobalPreferencesCLI;
6565

6666
public static String NewAngularProjectParamsWizardPage_title;
6767
public static String NewAngularProjectParamsWizardPage_prefix;

ts.eclipse.ide.angular.cli/src/ts/eclipse/ide/angular/internal/cli/AngularCLIMessages.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ NewAngularProjectWizard_invalidProjectName=Project name "{0}" is not valid. New
4646
NewAngularProjectWizard_unsupportedProjectNames=Project name "{0}" is not a supported name.
4747

4848
WizardNewNgProjectCreationPage_angular_cli_group_label=Angular CLI
49-
WizardNewNgProjectCreationPage_useGlobalAngularCLI=Use global
49+
WizardNewNgProjectCreationPage_useGlobalPreferencesCLI=Use global preferences
5050
WizardNewNgProjectCreationPage_useInstallAngularCLI=Install
51-
WizardNewNgProjectCreationPage_searchingForGlobalAngularCLI=Searching for global Angular CLI...
52-
WizardNewNgProjectCreationPage_noGlobalAngularCLI=No global Angular CLI installation found.
51+
WizardNewNgProjectCreationPage_searchingForGlobalPreferencesCLI=Searching for global Angular CLI in global preferences...
52+
WizardNewNgProjectCreationPage_noGlobalPreferencesCLI=No Angular CLI installation found in global preferences.
5353

5454
NewAngularProjectParamsWizardPage_title=Optional Params
5555
NewAngularProjectParamsWizardPage_prefix=&Prefix:

ts.eclipse.ide.angular.cli/src/ts/eclipse/ide/angular/internal/cli/preferences/AngularCLIConfigurationBlock.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import ts.eclipse.ide.ui.preferences.BrowseButtonsComposite;
4444
import ts.eclipse.ide.ui.preferences.OptionsConfigurationBlock;
4545
import ts.eclipse.ide.ui.preferences.ScrolledPageContent;
46+
import ts.eclipse.ide.ui.preferences.StatusInfo;
4647
import ts.eclipse.ide.ui.widgets.IStatusChangeListener;
4748
import ts.utils.FileUtils;
4849
import ts.utils.StringUtils;
@@ -74,7 +75,6 @@ public class AngularCLIConfigurationBlock extends OptionsConfigurationBlock {
7475
private Text cliPath;
7576
private Text cliVersion;
7677
private NgVersionJob ngVersionJob;
77-
private File ngFile;
7878

7979
public AngularCLIConfigurationBlock(IStatusChangeListener context, IProject project,
8080
IWorkbenchPreferenceContainer container) {
@@ -255,13 +255,12 @@ private String[] getDefaultPaths() {
255255
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
256256
cliVersion.setText("");
257257
cliPath.setText("");
258-
ngFile = null;
259258
ngVersionJob.cancel();
260-
CLIStatus status = validateCLIPath();
261-
if (status.isOK()) {
262-
cliPath.setText(FileUtils.getPath(status.getNgFile()));
259+
IStatus status = validateCLIPath();
260+
if (status.isOK() && status instanceof CLIStatus) {
261+
File ngFile = ((CLIStatus)status).getNgFile();
262+
cliPath.setText(FileUtils.getPath(ngFile));
263263
cliVersion.setText("Executing 'ng --version'...");
264-
ngFile = status.getNgFile();
265264
ngVersionJob.setNgFile(ngFile);
266265
ngVersionJob.schedule();
267266
} else {
@@ -274,17 +273,18 @@ protected void validateSettings(Key changedKey, String oldValue, String newValue
274273
*
275274
* @return the status of the ng path.
276275
*/
277-
private CLIStatus validateCLIPath() {
276+
private IStatus validateCLIPath() {
278277
File ngFile = null;
279278
boolean useGlobal = ngUseGlobalInstallation.getSelection();
279+
boolean globalPrefs = getProject() == null;
280280
if (useGlobal) {
281281
ngFile = CLIProcessHelper.findNg();
282282
if (ngFile == null) {
283283
// ERROR: ng was not installed with "npm install @angular/cli
284284
// -g"
285285
return new CLIStatus(null, AngularCLIMessages.AngularCLIConfigurationBlock_ngGlobal_notFound_error);
286286
}
287-
} else {
287+
} else if (!globalPrefs) {
288288
String ngPath = ngCustomFilePath.getText();
289289
if (StringUtils.isEmpty(ngPath)) {
290290
// ERROR: the installed path is empty
@@ -301,14 +301,16 @@ private CLIStatus validateCLIPath() {
301301
ngFile = new File(ngFile, CLIProcessHelper.getNgFileName());
302302
}
303303
}
304-
305-
if (!ngFile.exists()) {
306-
// ERROR: ng file doesn't exists
307-
return new CLIStatus(null,
308-
NLS.bind(AngularCLIMessages.AngularCLIConfigurationBlock_ngCustomFile_exists_error,
309-
FileUtils.getPath(ngFile)));
310-
} else {
311-
304+
if (!globalPrefs) {
305+
if (!ngFile.exists()) {
306+
// ERROR: ng file doesn't exists
307+
return new CLIStatus(null,
308+
NLS.bind(AngularCLIMessages.AngularCLIConfigurationBlock_ngCustomFile_exists_error,
309+
FileUtils.getPath(ngFile)));
310+
}
311+
}
312+
else {
313+
return StatusInfo.OK_STATUS;
312314
}
313315
// ng path is valid
314316
return new CLIStatus(ngFile, null);

ts.eclipse.ide.angular.cli/src/ts/eclipse/ide/angular/internal/cli/wizards/WizardNewNgProjectCreationPage.java

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import org.eclipse.core.resources.IProject;
1717
import org.eclipse.core.resources.ProjectScope;
18+
import org.eclipse.core.runtime.CoreException;
1819
import org.eclipse.core.runtime.IStatus;
1920
import org.eclipse.core.runtime.Status;
2021
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
@@ -42,6 +43,9 @@
4243
import ts.eclipse.ide.angular.cli.utils.CLIStatus;
4344
import ts.eclipse.ide.angular.cli.utils.NgVersionJob;
4445
import ts.eclipse.ide.angular.internal.cli.AngularCLIMessages;
46+
import ts.eclipse.ide.angular.internal.cli.AngularCLIProject;
47+
import ts.eclipse.ide.angular.internal.cli.AngularCLIProjectSettings;
48+
import ts.eclipse.ide.angular.internal.cli.Trace;
4549
import ts.eclipse.ide.core.utils.WorkbenchResourceUtil;
4650
import ts.eclipse.ide.terminal.interpreter.EnvPath;
4751
import ts.eclipse.ide.terminal.interpreter.LineCommand;
@@ -63,12 +67,12 @@ public class WizardNewNgProjectCreationPage extends AbstractWizardNewTypeScriptP
6367
"app" };
6468

6569
// Angular CLI
66-
private Boolean hasGlobalAngularCLI;
67-
private Button useGlobalAngularCLIButton;
70+
private Boolean hasGlobalPreferencesCLI;
71+
private Button useGlobalCLIPreferencesButton;
6872
private Button useInstallAngularCLIButton;
6973
private Text globalAngularCLIVersion;
7074
private NpmInstallWidget installAngularCLI;
71-
private boolean useGlobalAngularCLI;
75+
private boolean useGlobalCLIPreferences;
7276

7377
private NgVersionJob ngVersionJob;
7478

@@ -98,10 +102,10 @@ protected void createPageBody(Composite parent) {
98102

99103
/** Creates the field for install Angular CLI. */
100104
private void createGlobalAngularCLIField(Composite parent) {
101-
useGlobalAngularCLIButton = new Button(parent, SWT.RADIO);
102-
useGlobalAngularCLIButton.setText(AngularCLIMessages.WizardNewNgProjectCreationPage_useGlobalAngularCLI);
103-
useGlobalAngularCLIButton.addListener(SWT.Selection, this);
104-
useGlobalAngularCLIButton.addSelectionListener(new SelectionAdapter() {
105+
useGlobalCLIPreferencesButton = new Button(parent, SWT.RADIO);
106+
useGlobalCLIPreferencesButton.setText(AngularCLIMessages.WizardNewNgProjectCreationPage_useGlobalPreferencesCLI);
107+
useGlobalCLIPreferencesButton.addListener(SWT.Selection, this);
108+
useGlobalCLIPreferencesButton.addSelectionListener(new SelectionAdapter() {
105109
@Override
106110
public void widgetSelected(SelectionEvent e) {
107111
updateAngularCLIMode();
@@ -134,56 +138,72 @@ public void statusChanged(IStatus status) {
134138
@Override
135139
protected void initializeDefaultValues() {
136140
super.initializeDefaultValues();
137-
useGlobalAngularCLIButton.setSelection(true);
141+
useGlobalCLIPreferencesButton.setSelection(true);
138142
}
139143

140144
@Override
141145
protected void nodeJsChanged(File nodeFile) {
142146
super.nodeJsChanged(nodeFile);
143-
if (hasGlobalAngularCLI == null && nodeFile != null && ngVersionJob == null) {
144-
ngVersionJob = new NgVersionJob();
145-
ngVersionJob.setNodeFile(nodeFile);
146-
ngVersionJob.setNgFile(CLIProcessHelper.findNg());
147-
ngVersionJob.addJobChangeListener(new JobChangeAdapter() {
148-
@Override
149-
public void done(IJobChangeEvent event) {
150-
super.done(event);
151-
IStatus status = event.getResult();
152-
final String version;
153-
if (status instanceof CLIStatus) {
154-
final CLIStatus s = (CLIStatus) status;
155-
version = s.getVersion();
156-
if (s.isOK())
157-
hasGlobalAngularCLI = Boolean.TRUE;
158-
} else {
159-
hasGlobalAngularCLI = Boolean.FALSE;
160-
version = "";
161-
}
162-
Display.getDefault().asyncExec(new Runnable() {
163-
@Override
164-
public void run() {
165-
if (!globalAngularCLIVersion.isDisposed())
166-
globalAngularCLIVersion.setText(version);
167-
validatePage();
147+
if (hasGlobalPreferencesCLI == null && nodeFile != null && ngVersionJob == null) {
148+
File ngFile = null;
149+
try {
150+
AngularCLIProjectSettings settings = AngularCLIProject.getAngularCLIProject(getProjectHandle()).getSettings();
151+
ngFile = settings.getNgFile();
152+
if (ngFile != null && ngFile.isDirectory())
153+
ngFile = new File(ngFile, CLIProcessHelper.getNgFileName());
154+
else
155+
ngFile = null;
156+
} catch (CoreException e) {
157+
Trace.trace(Trace.SEVERE, "Error while getting Project settings", e);
158+
ngFile = null;
159+
}
160+
if (ngFile == null || !ngFile.exists())
161+
hasGlobalPreferencesCLI = Boolean.FALSE;
162+
else {
163+
ngVersionJob = new NgVersionJob();
164+
ngVersionJob.setNodeFile(nodeFile);
165+
ngVersionJob.setNgFile(ngFile);
166+
ngVersionJob.addJobChangeListener(new JobChangeAdapter() {
167+
@Override
168+
public void done(IJobChangeEvent event) {
169+
super.done(event);
170+
IStatus status = event.getResult();
171+
final String version;
172+
if (status instanceof CLIStatus) {
173+
final CLIStatus s = (CLIStatus) status;
174+
version = s.getVersion();
175+
if (s.isOK())
176+
hasGlobalPreferencesCLI = Boolean.TRUE;
177+
} else {
178+
hasGlobalPreferencesCLI = Boolean.FALSE;
179+
version = "";
168180
}
169-
});
170-
}
171-
});
172-
ngVersionJob.schedule();
181+
Display.getDefault().asyncExec(new Runnable() {
182+
@Override
183+
public void run() {
184+
if (!globalAngularCLIVersion.isDisposed())
185+
globalAngularCLIVersion.setText(version);
186+
validatePage();
187+
}
188+
});
189+
}
190+
});
191+
ngVersionJob.schedule();
192+
}
173193
}
174194
}
175195

176196
@Override
177197
protected void updateComponents(Event event) {
178198
super.updateComponents(event);
179199
Widget item = event != null ? event.item : null;
180-
if (item == null || item == useGlobalAngularCLIButton)
200+
if (item == null || item == useGlobalCLIPreferencesButton)
181201
updateAngularCLIMode();
182202
}
183203

184204
private void updateAngularCLIMode() {
185-
useGlobalAngularCLI = useGlobalAngularCLIButton.getSelection();
186-
installAngularCLI.setEnabled(!useGlobalAngularCLI);
205+
useGlobalCLIPreferences = useGlobalCLIPreferencesButton.getSelection();
206+
installAngularCLI.setEnabled(!useGlobalCLIPreferences);
187207
}
188208

189209
@Override
@@ -217,13 +237,13 @@ private IStatus validateNgProjectName(String name) {
217237

218238
/** Validates the Angular CLI. */
219239
private IStatus validateAngularCLI() {
220-
if (useGlobalAngularCLI) {
221-
if (hasGlobalAngularCLI == null)
240+
if (useGlobalCLIPreferences) {
241+
if (hasGlobalPreferencesCLI == null)
222242
return new Status(IStatus.ERROR, AngularCLIPlugin.PLUGIN_ID,
223-
AngularCLIMessages.WizardNewNgProjectCreationPage_searchingForGlobalAngularCLI);
224-
else if (!hasGlobalAngularCLI.booleanValue())
243+
AngularCLIMessages.WizardNewNgProjectCreationPage_searchingForGlobalPreferencesCLI);
244+
else if (!hasGlobalPreferencesCLI.booleanValue())
225245
return new Status(IStatus.ERROR, AngularCLIPlugin.PLUGIN_ID,
226-
AngularCLIMessages.WizardNewNgProjectCreationPage_noGlobalAngularCLI);
246+
AngularCLIMessages.WizardNewNgProjectCreationPage_noGlobalPreferencesCLI);
227247
else
228248
return Status.OK_STATUS;
229249
}
@@ -232,7 +252,7 @@ else if (!hasGlobalAngularCLI.booleanValue())
232252

233253
@Override
234254
public void updateCommand(List<LineCommand> commands, final IProject project, String nodeFilePath) {
235-
if (!useGlobalAngularCLI) {
255+
if (!useGlobalCLIPreferences) {
236256
// when Angular CLI is installed, update the project Eclipse preferences
237257
// to consume this installed Angular CLI.
238258
commands.add(new LineCommand(installAngularCLI.getNpmInstallCommand(), new TerminalCommandAdapter() {
@@ -257,7 +277,7 @@ public void run() {
257277
}
258278
}));
259279
commands.add(EnvPath.createSetPathCommand(EnvPath.insertToEnvPath(nodeFilePath, FileUtils
260-
.getPath(WorkbenchResourceUtil.resolvePath("${project_loc:node_modules/.bin}", project)))));
280+
.getPath(WorkbenchResourceUtil.resolvePath("${project_loc:node_modules/.bin}", project)))));
261281
}
262282
}
263283

0 commit comments

Comments
 (0)