summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java213
1 files changed, 213 insertions, 0 deletions
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}