summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/YoctoBSPWizard.java
blob: 3ab24c04a560f43aeb78defa1cab944f1b8ae743 (plain)
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
/*******************************************************************************
 * Copyright (c) 2010 Intel Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intel - initial API and implementation
 *******************************************************************************/
package org.yocto.sdk.remotetools.wizards.bsp;

import java.util.HashSet;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.yocto.sdk.remotetools.YoctoBspElement;
import org.yocto.sdk.remotetools.YoctoBspPropertyElement;
import org.yocto.sdk.remotetools.YoctoJSONHelper;

/**
 * A wizard for creating Yocto BSP.
 *
 * @author jzhang
 *
 */
public class YoctoBSPWizard extends Wizard {
	private static final String CREATE_CMD = "/scripts/yocto-bsp create ";
	private static final String PROPERTY_VALUE_FILE = "/tmp/propertyvalues.json";

	private MainPage mainPage;
	private PropertiesPage propertiesPage;
	private final YoctoBspElement bspElem;

	public YoctoBSPWizard() {
		super();
		bspElem = new YoctoBspElement();
	}

	@Override
	public IWizardPage getNextPage(IWizardPage page) {
		propertiesPage.onEnterPage(mainPage.getBSPElement());
		return propertiesPage;
	}

	@Override
	public void addPages() {
		mainPage = new MainPage(bspElem);
		addPage(mainPage);
		propertiesPage = new PropertiesPage(bspElem);
		addPage(propertiesPage);
	}

	private BSPAction createBSP(){
		YoctoBspElement element = mainPage.getBSPElement();
		String createBspCmd = element.getMetadataLoc() + CREATE_CMD +
								element.getBspName() + " " + element.getKarch();

		if (!element.getBspOutLoc().isEmpty())
			createBspCmd = createBspCmd + " -o " + element.getBspOutLoc();
		else
			createBspCmd = createBspCmd + " -o " + element.getMetadataLoc() + "/meta-" + element.getBspName();
		createBspCmd = createBspCmd + " -i " + PROPERTY_VALUE_FILE;

		BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(),  new OutputCollectorThread(createBspCmd), "Creating BSP ");
		progressDialog.run(true);
		return progressDialog.getBspAction();
	}

	@Override
	public boolean performFinish() {
		if (propertiesPage.validatePage()) {
			HashSet<YoctoBspPropertyElement> properties = propertiesPage.getProperties();
			YoctoJSONHelper.createBspJSONFile(properties);

			BSPAction createBSPAction = createBSP();
			if (createBSPAction.getMessage() !=  null && !createBSPAction.getMessage().isEmpty()) {
				MessageDialog.openError(getShell(),"Yocto-BSP", createBSPAction.getMessage());
				return false;
			} else {
				String message = "";
				for (String item : createBSPAction.getItems())
					message += item + "\n";
				MessageDialog.openInformation(getShell(), "Yocto-BSP", message);
				return true;
			}
		} else {
			MessageDialog.openError(getShell(), "Yocto-BSP", "Property settings contains error!");
			return false;
		}

	}

	@Override
	public boolean canFinish() {
		return (mainPage.validatePage() && propertiesPage.validatePage());
	}
}