summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java371
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java213
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java327
3 files changed, 911 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java
new file mode 100644
index 0000000..6d7c440
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java
@@ -0,0 +1,371 @@
1/*******************************************************************************
2 * Copyright (c) 2013 Intel Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - Initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.wizards.install;
12
13import java.net.URI;
14
15import org.eclipse.core.filesystem.URIUtil;
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.runtime.Path;
18import org.eclipse.core.runtime.Platform;
19import org.eclipse.jface.operation.IRunnableContext;
20import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea;
21import org.eclipse.ptp.remote.core.IRemoteFileManager;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.events.ModifyEvent;
24import org.eclipse.swt.events.ModifyListener;
25import org.eclipse.swt.events.SelectionAdapter;
26import org.eclipse.swt.events.SelectionEvent;
27import org.eclipse.swt.layout.GridData;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.widgets.Button;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Group;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.Text;
35import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
36import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
37
38import java.net.URI;
39
40import org.eclipse.core.filesystem.URIUtil;
41import org.eclipse.core.resources.IProject;
42import org.eclipse.core.runtime.Path;
43import org.eclipse.core.runtime.Platform;
44import org.eclipse.jface.operation.IRunnableContext;
45import org.eclipse.ptp.rdt.ui.messages.Messages;
46//import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
47//import org.eclipse.ptp.rdt.core.serviceproviders.
48import org.eclipse.ptp.remote.core.IRemoteConnection;
49import org.eclipse.ptp.remote.core.IRemoteFileManager;
50import org.eclipse.ptp.remote.core.IRemoteServices;
51import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
52import org.eclipse.ptp.remote.ui.IRemoteUIConstants;
53import org.eclipse.ptp.remote.ui.IRemoteUIFileManager;
54import org.eclipse.ptp.remote.ui.IRemoteUIServices;
55import org.eclipse.ptp.remote.ui.RemoteUIServices;
56import org.eclipse.ptp.remote.ui.widgets.RemoteConnectionWidget;
57import org.eclipse.swt.SWT;
58import org.eclipse.swt.events.ModifyEvent;
59import org.eclipse.swt.events.ModifyListener;
60import org.eclipse.swt.events.SelectionAdapter;
61import org.eclipse.swt.events.SelectionEvent;
62import org.eclipse.swt.layout.GridData;
63import org.eclipse.swt.layout.GridLayout;
64import org.eclipse.swt.widgets.Button;
65import org.eclipse.swt.widgets.Composite;
66import org.eclipse.swt.widgets.Control;
67import org.eclipse.swt.widgets.Group;
68import org.eclipse.swt.widgets.Label;
69import org.eclipse.swt.widgets.Text;
70import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
71import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
72
73
74public class BBCRemoteProjectContentsLocationArea {
75
76 /**
77 * IErrorMessageReporter is an interface for type that allow message
78 * reporting.
79 *
80 */
81 public interface IErrorMessageReporter {
82 /**
83 * Report the error message
84 *
85 * @param errorMessage
86 * String or <code>null</code>. If the errorMessage is null
87 * then clear any error state.
88 * @param infoOnly
89 * the message is an informational message, but the dialog
90 * cannot continue
91 *
92 */
93 public void reportError(String errorMessage, boolean infoOnly);
94 }
95
96 private static final String FILE_SCHEME = "file"; //$NON-NLS-1$
97
98 private IProject fExistingProject;
99
100 private final IErrorMessageReporter fErrorReporter;
101
102 private final IRunnableContext fContext;
103
104 //private RemoteBuildServiceProvider fProvider;
105
106 private IRemoteConnection fSelectedConnection;
107
108 private String fProjectName = IDEResourceInfoUtils.EMPTY_STRING;
109
110 private Button fBrowseButton;
111
112 private Text fLocationText;
113
114 private RemoteConnectionWidget fRemoteConnectionWidget;
115
116 // public RemoteProjectContentsLocationArea(IServiceProvider provider,
117 // Composite composite) {
118 // if(provider instanceof RemoteBuildServiceProvider)
119 // fProvider = (RemoteBuildServiceProvider) provider;
120 // else
121 // throw new IllegalArgumentException(); // should never happen
122 // createContents(composite);
123 // }
124 /**
125 * @since 3.1
126 */
127 public BBCRemoteProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite, IRunnableContext context) {
128 fErrorReporter = reporter;
129 fContext = context;
130 createContents(composite);
131 }
132
133 /**
134 * Check if the entry in the widget location is valid. If it is valid return
135 * null. Otherwise return a string that indicates the problem.
136 *
137 * @return String
138 */
139 public String checkValidLocation() {
140
141 String locationFieldContents = fLocationText.getText();
142 if (locationFieldContents.length() == 0) {
143 return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty;
144 }
145
146 URI newPath = getProjectLocationURI();
147 if (newPath == null) {
148 return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError;
149 }
150
151 if (fExistingProject != null) {
152 URI projectPath = fExistingProject.getLocationURI();
153 if (projectPath != null && URIUtil.equals(projectPath, newPath)) {
154 return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf;
155 }
156 }
157
158 return null;
159 }
160
161 /**
162 * Return the browse button. Usually referenced in order to set the layout
163 * data for a dialog.
164 *
165 * @return Button
166 */
167 public Button[] getButtons() {
168 return new Button[] { fBrowseButton, fRemoteConnectionWidget.getButton() };
169 }
170
171 /**
172 * Returns the name of the selected connection.
173 */
174 public IRemoteConnection getConnection() {
175 return fSelectedConnection;
176 }
177
178 /**
179 * Return the location for the project.
180 *
181 * @return String
182 */
183 public String getProjectLocation() {
184 return fLocationText.getText();
185 }
186
187 /**
188 * Get the URI for the location field if possible.
189 *
190 * @return URI or <code>null</code> if it is not valid.
191 */
192 public URI getProjectLocationURI() {
193 if (fSelectedConnection == null)
194 return null;
195 return fSelectedConnection.getRemoteServices().getFileManager(fSelectedConnection).toURI(fLocationText.getText());
196 }
197
198 public IRemoteConnection getRemoteConnection() {
199 return fSelectedConnection;
200 }
201
202 public IRemoteServices getRemoteServices() {
203 if (fSelectedConnection != null)
204 return fSelectedConnection.getRemoteServices();
205 return null;
206 }
207
208 /**
209 * Return whether or not we are currently showing the default location for
210 * the project.
211 *
212 * @return boolean
213 */
214 public boolean isDefault() {
215 // return useDefaultsButton.getSelection();
216 return false;
217 }
218
219 /**
220 * Set the project to base the contents off of.
221 *
222 * @param existingProject
223 */
224 public void setExistingProject(IProject existingProject) {
225 fProjectName = existingProject.getName();
226 fExistingProject = existingProject;
227 }
228
229 /**
230 * Set the text to the default or clear it if not using the defaults.
231 *
232 * @param newName
233 * the name of the project to use. If <code>null</code> use the
234 * existing project name.
235 */
236 public void updateProjectName(String newName) {
237 fProjectName = newName;
238 if (isDefault()) {
239 fLocationText.setText(getDefaultPathDisplayString());
240 }
241
242 }
243
244 /**
245 * Attempt to open a connection.
246 */
247 private void checkConnection() {
248 IRemoteUIConnectionManager mgr = getUIConnectionManager();
249 if (mgr != null) {
250 mgr.openConnectionWithProgress(fRemoteConnectionWidget.getShell(), fContext, fSelectedConnection);
251 }
252 }
253
254 /**
255 * Return the path we are going to display. If it is a file URI then remove
256 * the file prefix.
257 *
258 * Only do this if the connection is open. Otherwise we will attempt to
259 * connect to the first machine in the list, which is annoying.
260 *
261 * @return String
262 */
263 private String getDefaultPathDisplayString() {
264 if (getRemoteConnection() != null && getRemoteConnection().isOpen()) {
265 IRemoteFileManager fileMgr = fSelectedConnection.getRemoteServices().getFileManager(getRemoteConnection());
266 URI defaultURI = fileMgr.toURI(getRemoteConnection().getWorkingDirectory());
267
268 // Handle files specially. Assume a file if there is no project to
269 // query
270 if (defaultURI != null && defaultURI.getScheme().equals(FILE_SCHEME)) {
271 return Platform.getLocation().append(fProjectName).toOSString();
272 }
273 if (defaultURI == null) {
274 return ""; //$NON-NLS-1$
275 }
276 return new Path(defaultURI.getPath()).append(fProjectName).toOSString();
277 }
278 return ""; //$NON-NLS-1$
279 }
280
281 /**
282 * @return
283 */
284 private IRemoteUIConnectionManager getUIConnectionManager() {
285 IRemoteUIConnectionManager connectionManager = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices())
286 .getUIConnectionManager();
287 return connectionManager;
288 }
289
290 private void handleConnectionSelected() {
291 fSelectedConnection = fRemoteConnectionWidget.getConnection();
292 fLocationText.setText(getDefaultPathDisplayString());
293 }
294
295 protected Control createContents(Composite parent) {
296 Group container = new Group(parent, SWT.SHADOW_ETCHED_IN);
297
298 GridLayout layout = new GridLayout();
299 layout.numColumns = 3;
300 container.setLayout(layout);
301 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
302 container.setLayoutData(gd);
303
304 fRemoteConnectionWidget = new RemoteConnectionWidget(container, SWT.NONE, null, RemoteConnectionWidget.FLAG_FORCE_PROVIDER_SELECTION, null);
305 gd = new GridData();
306 gd.horizontalSpan = 3;
307 fRemoteConnectionWidget.setLayoutData(gd);
308 fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() {
309 @Override
310 public void widgetSelected(SelectionEvent e) {
311 handleConnectionSelected();
312 }
313 });
314
315 Label locationLabel = new Label(container, SWT.LEFT);
316 locationLabel.setText(Messages.getString("RemoteProjectContentsLocationArea.3")); //$NON-NLS-1$
317
318 fLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
319 gd = new GridData(GridData.FILL_HORIZONTAL);
320 gd.horizontalSpan = 1;
321 gd.grabExcessHorizontalSpace = true;
322 gd.widthHint = 250;
323 fLocationText.setLayoutData(gd);
324 fLocationText.addModifyListener(new ModifyListener() {
325 public void modifyText(ModifyEvent e) {
326 fErrorReporter.reportError(checkValidLocation(), false);
327 }
328 });
329
330 // new connection button
331 fBrowseButton = new Button(container, SWT.PUSH);
332 fBrowseButton.setText(Messages.getString("RemoteProjectContentsLocationArea.4")); //$NON-NLS-1$
333 fBrowseButton.addSelectionListener(new SelectionAdapter() {
334 @Override
335 public void widgetSelected(SelectionEvent e) {
336 if (fSelectedConnection != null) {
337 checkConnection();
338 if (fSelectedConnection.isOpen()) {
339 IRemoteUIServices remoteUIServices = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices());
340 if (remoteUIServices != null) {
341 IRemoteUIFileManager fileMgr = remoteUIServices.getUIFileManager();
342 if (fileMgr != null) {
343 fileMgr.setConnection(fSelectedConnection);
344 String correctPath = fLocationText.getText();
345 String selectedPath = fileMgr.browseDirectory(
346 fLocationText.getShell(),
347 Messages.getString("RemoteProjectContentsLocationArea.5", fSelectedConnection.getName()), correctPath, IRemoteUIConstants.NONE); //$NON-NLS-1$
348 if (selectedPath != null) {
349 fLocationText.setText(selectedPath);
350 }
351 }
352 }
353 }
354 }
355 }
356 });
357
358 return container;
359 }
360
361 /*
362 * (non-Javadoc)
363 *
364 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
365 */
366 protected void okPressed() {
367 // set the connection
368 //fProvider.setRemoteToolsConnection(fSelectedConnection);
369
370 }
371}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
new file mode 100644
index 0000000..f64401c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
@@ -0,0 +1,213 @@
1/*******************************************************************************
2 * Copyright (c) 2013 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.install;
13
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.IOException;
17import java.io.InputStreamReader;
18import java.io.Writer;
19import java.lang.reflect.InvocationTargetException;
20import java.net.URI;
21import java.util.Hashtable;
22import java.util.Map;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25
26import org.eclipse.core.runtime.IProgressMonitor;
27import org.eclipse.core.runtime.IStatus;
28import org.eclipse.core.runtime.Status;
29import org.eclipse.jface.operation.IRunnableWithProgress;
30import org.eclipse.jface.viewers.IStructuredSelection;
31import org.eclipse.jface.wizard.IWizardContainer;
32import org.eclipse.jface.wizard.WizardPage;
33import org.eclipse.ptp.remote.core.IRemoteConnection;
34import org.eclipse.ptp.remote.core.IRemoteServices;
35import org.eclipse.rse.core.model.IHost;
36import org.eclipse.ui.IWorkbench;
37import org.eclipse.ui.IWorkbenchPage;
38import org.eclipse.ui.IWorkbenchWindow;
39import org.eclipse.ui.IWorkbenchWizard;
40import org.eclipse.ui.PlatformUI;
41import org.eclipse.ui.console.ConsolePlugin;
42import org.eclipse.ui.console.IConsole;
43import org.eclipse.ui.console.IConsoleConstants;
44import org.eclipse.ui.console.IConsoleManager;
45import org.eclipse.ui.console.IConsoleView;
46import org.eclipse.ui.console.MessageConsole;
47import org.eclipse.ui.console.MessageConsoleStream;
48import org.yocto.bc.remote.utils.YoctoRunnableWithProgress;
49import org.yocto.bc.ui.Activator;
50import org.yocto.bc.ui.model.ProjectInfo;
51import org.yocto.bc.ui.wizards.FiniteStateWizard;
52import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation;
53import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation;
54import org.yocto.remote.utils.CommandResponseHandler;
55import org.yocto.remote.utils.ICommandResponseHandler;
56import org.yocto.remote.utils.RemoteHelper;
57import org.yocto.remote.utils.YoctoCommand;
58import org.yocto.bc.remote.utils.ConsoleWriter;
59
60/**
61 * A wizard for installing a fresh copy of an OE system.
62 *
63 * @author kgilmer
64 *
65 * A Wizard for creating a fresh Yocto bitbake project and new poky build tree from git
66 *
67 * @modified jzhang
68 *
69 */
70public class InstallWizard extends FiniteStateWizard implements
71 IWorkbenchWizard {
72
73 static final String KEY_PINFO = "KEY_PINFO";
74 protected static final String OPTION_MAP = "OPTION_MAP";
75 protected static final String INSTALL_SCRIPT = "INSTALL_SCRIPT";
76 protected static final String INSTALL_DIRECTORY = "Install Directory";
77 protected static final String INIT_SCRIPT = "Init Script";
78
79 protected static final String SELECTED_CONNECTION = "SEL_CONNECTION";
80 protected static final String SELECTED_REMOTE_SERVICE = "SEL_REMOTE_SERVICE";
81
82 protected static final String PROJECT_NAME = "Project Name";
83 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
84 protected static final String DEFAULT_INSTALL_DIR = "~/yocto";
85
86 protected static final String GIT_CLONE = "Git Clone";
87 public static final String VALIDATION_FILE = DEFAULT_INIT_SCRIPT;
88
89 private Map model;
90 private MessageConsole myConsole;
91 private OptionsPage optionsPage;
92
93 public InstallWizard() {
94 this.model = new Hashtable();
95 model.put(INSTALL_DIRECTORY, DEFAULT_INSTALL_DIR);
96 model.put(INIT_SCRIPT, DEFAULT_INIT_SCRIPT);
97
98 setWindowTitle("Yocto Project BitBake Commander");
99 setNeedsProgressMonitor(true);
100 }
101
102
103
104 public InstallWizard(IStructuredSelection selection) {
105 model = new Hashtable();
106 }
107
108 /*
109 * @Override public IWizardPage getNextPage(IWizardPage page) { if (page
110 * instanceof WelcomePage) { if (model.containsKey(WelcomePage.ACTION_USE))
111 * { return bbcProjectPage; } } else if (page instanceof ProgressPage) {
112 * return bitbakePage; }
113 *
114 * if (super.getNextPage(page) != null) { System.out.println("next page: " +
115 * super.getNextPage(page).getClass().getName()); } else {
116 * System.out.println("end page"); }
117 *
118 * return super.getNextPage(page); }
119 *
120 * @Override public boolean canFinish() { System.out.println("can finish: "
121 * + super.canFinish()); return super.canFinish(); }
122 */
123 @Override
124 public void addPages() {
125 optionsPage = new OptionsPage(model);
126 addPage(optionsPage);
127 }
128
129 @Override
130 public Map getModel() {
131 return model;
132 }
133
134 @Override
135 public boolean performFinish() {
136 WizardPage page = (WizardPage) getPage("Options");
137 page.setPageComplete(true);
138 Map<String, Object> options = model;
139
140 try {
141 URI uri = new URI("");
142 if (options.containsKey(INSTALL_DIRECTORY)) {
143 uri = (URI) options.get(INSTALL_DIRECTORY);
144 }
145 IRemoteConnection remoteConnection = ((IRemoteConnection)model.get(InstallWizard.SELECTED_CONNECTION));
146 IRemoteServices remoteServices = ((IRemoteServices)model.get(InstallWizard.SELECTED_REMOTE_SERVICE));
147 IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
148 CommandResponseHandler cmdHandler = new CommandResponseHandler(RemoteHelper.getConsole(connection));
149 IWizardContainer container = this.getContainer();
150 if (((Boolean)options.get(GIT_CLONE)).booleanValue()) {
151 String cmd = "git clone --progress git://git.yoctoproject.org/poky.git " + uri.getPath();
152 String taskName = "Checking out Yocto git repository";
153
154 YoctoRunnableWithProgress adapter = new YoctoRunnableWithProgress(new YoctoCommand(cmd, "", ""));
155
156 adapter.setRemoteConnection(remoteConnection);
157 adapter.setRemoteServices(remoteServices);
158 adapter.setTaskName(taskName);
159 try {
160 container.run(true, true, adapter);
161 } catch (InvocationTargetException e) {
162 e.printStackTrace();
163 } catch (InterruptedException e) {
164 e.printStackTrace();
165 }
166 }
167 if (!cmdHandler.hasError()) {
168 String initPath = "";
169 if (uri.getPath() != null) {
170 initPath = uri.getPath() + "/" + (String) options.get(INIT_SCRIPT);
171 } else {
172 initPath = uri.getFragment() + "/" + (String) options.get(INIT_SCRIPT);
173 }
174 String prjName = (String) options.get(PROJECT_NAME);
175 ProjectInfo pinfo = new ProjectInfo();
176 pinfo.setInitScriptPath(initPath);
177 pinfo.setLocationURI(uri);
178 pinfo.setName(prjName);
179 pinfo.setConnection(connection);
180 pinfo.setRemoteServices(remoteServices);
181
182 final ConsoleWriter cw = new ConsoleWriter();
183 BBConfigurationInitializeOperation configInitOp = new BBConfigurationInitializeOperation(pinfo, null);
184 container.run(false, false, configInitOp);
185 myConsole = RemoteHelper.getConsole(connection);
186 myConsole.newMessageStream().println(cw.getContents());
187
188 if (configInitOp.hasErrorOccured()) {
189 optionsPage.setErrorMessage(configInitOp.getErrorMessage());
190 return false;
191 }
192
193 model.put(InstallWizard.KEY_PINFO, pinfo);
194 Activator.putProjInfo(pinfo.getOEFSURI(), pinfo);
195
196 container.run(false, false, new CreateBBCProjectOperation(pinfo));
197 RemoteHelper.storeURIInMetaArea(pinfo.getProjectName(), uri);
198 RemoteHelper.storeProjDescrInMetaArea(pinfo.getConnection(), pinfo.getProjectName(), pinfo.getOriginalURI().getPath());
199 return true;
200 }
201 } catch (Exception e) {
202 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
203 IStatus.ERROR, e.getMessage(), e));
204 this.getContainer().getCurrentPage().setDescription(
205 "Failed to create project: " + e.getMessage());
206 }
207 return false;
208 }
209
210 public void init(IWorkbench workbench, IStructuredSelection selection) {
211 }
212
213}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
new file mode 100644
index 0000000..75d9f99
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java
@@ -0,0 +1,327 @@
1/*******************************************************************************
2 * Copyright (c) 2013 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 * Ioana Grigoropol (Intel) - adapt class for remote support
11 *******************************************************************************/
12package org.yocto.bc.ui.wizards.install;
13
14import java.io.IOException;
15import java.io.File;
16import java.net.URI;
17import java.net.URISyntaxException;
18import java.util.ArrayList;
19import java.util.Hashtable;
20import java.util.Iterator;
21import java.util.List;
22import java.util.Map;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25
26import org.eclipse.core.resources.IProject;
27import org.eclipse.core.resources.IProjectDescription;
28import org.eclipse.core.resources.IResource;
29import org.eclipse.core.resources.IWorkspaceRoot;
30import org.eclipse.core.resources.ResourcesPlugin;
31import org.eclipse.core.runtime.CoreException;
32import org.eclipse.core.runtime.IStatus;
33import org.eclipse.core.runtime.NullProgressMonitor;
34import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea;
35import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea.IErrorMessageReporter;
36import org.eclipse.ptp.remote.core.IRemoteConnection;
37import org.eclipse.ptp.internal.remote.rse.core.RSEConnection;
38import org.eclipse.rse.core.model.IHost;
39import org.eclipse.rse.services.files.IFileService;
40import org.eclipse.rse.services.files.IHostFile;
41import org.eclipse.swt.SWT;
42import org.eclipse.swt.events.SelectionAdapter;
43import org.eclipse.swt.events.SelectionEvent;
44import org.eclipse.swt.layout.GridData;
45import org.eclipse.swt.layout.GridLayout;
46import org.eclipse.swt.widgets.Button;
47import org.eclipse.swt.widgets.Composite;
48import org.eclipse.swt.widgets.Control;
49import org.eclipse.swt.widgets.DirectoryDialog;
50import org.eclipse.swt.widgets.FileDialog;
51import org.eclipse.swt.widgets.Label;
52import org.eclipse.swt.widgets.Text;
53import org.eclipse.ui.PlatformUI;
54
55import org.yocto.bc.ui.wizards.FiniteStateWizard;
56import org.yocto.bc.ui.wizards.FiniteStateWizardPage;
57import org.yocto.bc.ui.wizards.FiniteStateWizardPage.ValidationListener;
58import org.yocto.remote.utils.RemoteHelper;
59
60/**
61 * Select which flavor of OE is to be installed.
62 *
63 * @author kgilmer
64 *
65 * Setting up the parameters for creating the new Yocto Bitbake project
66 *
67 * @modified jzhang
68 */
69public class OptionsPage extends FiniteStateWizardPage {
70
71 public static final String URI_SEPARATOR = "/";
72 public static final String LOCALHOST = "LOCALHOST";
73
74 private Composite top;
75
76 private RemoteProjectContentsLocationArea locationArea;
77
78 private ValidationListener validationListener;
79 private Text txtProjectName;
80 private Button btnGit;
81
82 protected OptionsPage(Map model) {
83 super("Options", model);
84 //setTitle("Create new yocto bitbake project");
85 setMessage("Enter these parameters to create new Yocto Project BitBake commander project");
86 }
87
88 @Override
89 public void createControl(Composite parent) {
90 top = new Composite(parent, SWT.None);
91 top.setLayout(new GridLayout());
92 top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
93
94 GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL);
95
96 Composite projectNameComp = new Composite(top, SWT.NONE);
97 GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL);
98 projectNameComp.setLayoutData(gdProjName);
99 projectNameComp.setLayout(new GridLayout(2, false));
100 Label lblProjectName = new Label(projectNameComp, SWT.NONE);
101 lblProjectName.setText("Project N&ame:");
102
103 txtProjectName = new Text(projectNameComp, SWT.BORDER);
104 txtProjectName.setLayoutData(gdFillH);
105 txtProjectName.setFocus();
106 validationListener = new ValidationListener();
107
108 txtProjectName.addModifyListener(validationListener);
109
110 IErrorMessageReporter errorReporter = new IErrorMessageReporter() {
111
112 @Override
113 public void reportError(String errorMessage, boolean infoOnly) {
114 setMessage(errorMessage);
115 if (validatePage()) {
116 updateModel();
117 setPageComplete(true);
118 return;
119 }
120
121 setPageComplete(false);
122 }
123 };
124
125 locationArea = new RemoteProjectContentsLocationArea(errorReporter, top, null);
126
127 btnGit = new Button(top, SWT.CHECK);
128 btnGit.setText("Clone from Yocto Project &Git Repository into new location");
129 btnGit.setEnabled(true);
130 btnGit.setSelection(true);
131 btnGit.addSelectionListener(validationListener);
132 GridData gd = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_HORIZONTAL);
133 btnGit.setLayoutData(gd);
134
135 setControl(top);
136 }
137
138 @Override
139 public void pageCleanup() {
140
141 }
142
143 @Override
144 public void pageDisplay() {
145 }
146
147 @Override
148
149 protected void updateModel() {
150 try {
151 URI uri = getProjectLocationURI();
152 if (uri != null)
153 model.put(InstallWizard.INSTALL_DIRECTORY, getProjectLocationURI());
154 } catch (Exception e){
155 e.printStackTrace();
156 }
157 model.put(InstallWizard.PROJECT_NAME, txtProjectName.getText());
158 model.put(InstallWizard.GIT_CLONE, new Boolean(btnGit.getSelection()));
159 model.put(InstallWizard.SELECTED_CONNECTION, locationArea.getRemoteConnection());
160 model.put(InstallWizard.SELECTED_REMOTE_SERVICE, locationArea.getRemoteServices());
161 }
162
163 public URI getProjectLocationURI() throws URISyntaxException {
164 URI uri = locationArea.getProjectLocationURI();
165
166 if (uri != null) {
167 String location = locationArea.getProjectLocation();
168 if (!uri.getPath().isEmpty()) {
169 String separator = uri.getPath().endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
170
171 return new URI( uri.getScheme(),
172 uri.getHost(),
173 uri.getPath() + separator + txtProjectName.getText(),
174 uri.getFragment());
175 } else {
176 return null;
177 }
178 } else {
179 String location = locationArea.getProjectLocation();
180 String separator = location.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
181
182 IRemoteConnection conn = locationArea.getConnection();
183 if (conn instanceof RSEConnection) {
184 RSEConnection rseConn = (RSEConnection)conn;
185 return new URI("rse", rseConn.getHost().getHostName(), location);
186 } else {
187 return new URI( "file", location + separator + txtProjectName.getText(),"");
188 }
189 }
190 }
191
192 private boolean isValidProjectName(String projectName) {
193 if (projectName.indexOf('$') > -1) {
194 return false;
195 }
196
197 return true;
198 }
199
200 private boolean validateProjectName() {
201 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
202
203 IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT);
204
205 if (txtProjectName.getText().trim().isEmpty()) {
206 setErrorMessage("Project name cannot be empty!");
207 return false;
208 }
209
210 if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) {
211 setErrorMessage("Invalid project name: " + txtProjectName.getText());
212 return false;
213 }
214
215 IProject proj = wsroot.getProject(txtProjectName.getText());
216 if (proj.exists()) {
217 setErrorMessage("A project with the name " + txtProjectName.getText() + " already exists");
218 return false;
219 }
220 return true;
221 }
222 private String convertToRealPath(String path) {
223 String patternStr = File.separator + File.separator;
224 if (patternStr.equals(URI_SEPARATOR))
225 return path;
226 String replaceStr = URI_SEPARATOR;
227 String convertedpath;
228
229 //Compile regular expression
230 Pattern pattern = Pattern.compile(patternStr); //pattern to look for
231
232 //replace all occurance of percentage character to file separator
233 Matcher matcher = pattern.matcher(path);
234 convertedpath = matcher.replaceAll(replaceStr);
235
236 return convertedpath;
237 }
238
239 public String getProjectName(){
240 return txtProjectName.getText().trim();
241 }
242
243 protected boolean validateProjectLocation() {
244
245 String projectLoc = locationArea.getProjectLocation().trim();
246
247 IRemoteConnection remoteConnection = locationArea.getRemoteConnection();
248 if (remoteConnection == null)
249 return false;
250
251 if (projectLoc.isEmpty())
252 return true;
253
254 IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName());
255
256 projectLoc = convertToRealPath(projectLoc);
257 String separator = projectLoc.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR;
258 String projectPath = projectLoc + separator + getProjectName();
259 IHostFile repoDest = RemoteHelper.getRemoteHostFile(connection, projectPath, new NullProgressMonitor());
260
261 if(!btnGit.getSelection()) {
262 if (repoDest == null || !repoDest.exists()) {
263 setErrorMessage("Directory " + projectPath + " does not exist, please select git clone.");
264 return false;
265 }
266
267 IHostFile validationFile = RemoteHelper.getRemoteHostFile(connection, projectPath + URI_SEPARATOR + InstallWizard.VALIDATION_FILE, new NullProgressMonitor());
268 if (validationFile == null || !validationFile.exists()) {
269 setErrorMessage("Directory " + projectPath + " seems invalid, please use other directory or project name.");
270 return false;
271 }
272 } else { //git clone
273 if (repoDest != null && repoDest.exists() && repoDest.isDirectory()) {
274 IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, repoDest.getAbsolutePath(), "", IFileService.FILE_TYPE_FILES_AND_FOLDERS, new NullProgressMonitor());
275 if (hostFiles.length != 0) {
276 setErrorMessage("Directory " + projectPath + " is not empty, please choose another location.");
277 return false;
278 }
279 IHostFile gitDescr = RemoteHelper.getRemoteHostFile(connection, projectPath + "/.git", new NullProgressMonitor());
280 if (gitDescr != null && gitDescr.exists()) {
281 setErrorMessage("Directory " + projectPath + " contains a repository, please choose another location or skip cloning the repository.");
282 return false;
283 }
284 }
285 }
286
287 try {
288 String projName = txtProjectName.getText();
289 if (!projName.trim().isEmpty() && validateProjectName()) {
290 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
291 IProject proj = wsroot.getProject();
292 if (proj != null && proj.exists()) {
293 setErrorMessage("A project with the name " + projName + " already exists");
294 return false;
295 }
296 URI location = new URI("file:" + URI_SEPARATOR + URI_SEPARATOR + convertToRealPath(projectLoc) + URI_SEPARATOR + txtProjectName.getText());
297
298 IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocationURI(proj, location);
299 if (!status.isOK()) {
300 setErrorMessage(status.getMessage());
301 return false;
302 }
303 }
304 } catch (Exception e) {
305 e.printStackTrace();
306 setErrorMessage("Run into error while trying to validate entries!");
307 return false;
308 }
309
310 setErrorMessage(null);
311 return true;
312 }
313 @Override
314 protected boolean validatePage() {
315 if (!validateProjectName())
316 return false;
317
318 if (!validateProjectLocation())
319 return false;
320
321 setErrorMessage(null);
322 setMessage("All the entries are valid, press \"Finish\" to start the process, "+
323 "this will take a while. Please don't interrupt till there's output in the Yocto Console window...");
324 return true;
325 }
326
327}