summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchToasterDialog.java
blob: 124ae3936c69b672c6d03448575d26f941076a1a (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
 * Copyright (c) 2011 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.bc.ui.actions;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.yocto.bc.ui.builder.BitbakeBuilder;
import org.yocto.bc.ui.builder.BitbakeCommanderNature;

public class LaunchToasterDialog extends Dialog {
	private String title;
	private Button buildButton;
	private Combo toaster_url;
	private IProject project;
	private Shell shell;
	private URL toaster_server;

	public LaunchToasterDialog(Shell parentShell, String dialogTitle, IProject project) {
        super(parentShell);
        this.shell = parentShell;
        this.project = project;
        this.title = dialogTitle;
        setShellStyle(getShellStyle() | SWT.RESIZE);
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		final Composite result = (Composite) super.createDialogArea(parent);

		try {
			createComposite(result);
		} catch (Exception e) {
			System.out.println("Have you ever set the project specific Yocto Settings?");
			System.out.println(e.getMessage());
		}

		return result;
	}

	private void createComposite(Composite composite) throws Exception{
		Label root_label, sysroot_label;
		GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
		GridLayout layout = new GridLayout(2, false);
		composite.setLayout(layout);

		gd= new GridData(SWT.FILL, SWT.CENTER, true, false);
		gd.horizontalSpan= 2;
		composite.setLayoutData(gd);

		Label build_dir_label = new Label(composite, SWT.NONE);
		build_dir_label.setText("Toaster Server URL: ");
		toaster_url = new Combo(composite, SWT.DROP_DOWN);
		toaster_url.setText("https://www.yoctoproject.org/toaster/");
	}

	protected void buttonPressed(int buttonId) {
		if (buttonId == IDialogConstants.OK_ID) {
			try {
				toaster_server = new URL(toaster_url.getText().toString()) ;
				super.buttonPressed(buttonId);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
		else if (buttonId == IDialogConstants.CANCEL_ID)
		{
			super.buttonPressed(buttonId);
		}
	}

	protected URL get_toaster_url() {
		return toaster_server ;
	}

	private boolean isSubDirectory(File baseDir, File subDir) throws IOException {
		baseDir = baseDir.getCanonicalFile();
		subDir = subDir.getCanonicalFile();

		File parentFile = subDir;
		while (parentFile != null) {
			if (baseDir.equals(parentFile)) {
				return true;
			}
			parentFile = parentFile.getParentFile();
		}
		return false;
	}

	private void initializeBuildCombo()
	{
		ArrayList<String> items = new ArrayList<String> ();

		try {
			IProjectDescription desc = project.getDescription();

			ICommand[] buildSpec = desc.getBuildSpec();
			if ((buildSpec != null) && (buildSpec.length != 0))
			{
				for (int i = 0; i < buildSpec.length; i++) {
					ICommand cmd = buildSpec[i];
					if (cmd.getBuilderName().equalsIgnoreCase(BitbakeBuilder.TOASTER_BUILD_ID))
					{
						Map<String, String> args = cmd.getArguments();
						if ((args != null) && !args.isEmpty())
						{
							Iterator entries = args.entrySet().iterator();
							while (entries.hasNext()) {
								Entry thisEntry = (Entry) entries.next();
								String key = (String)thisEntry.getKey();
							}
						}
					}
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	private String[] getValues(String value) {
		if ((value != null) && !value.isEmpty())
		{
			String[] pieces = value.split(",");
			for (int i = 0; i < pieces.length; i++)
			{
				int start = pieces[i].indexOf("[");
				if (start >= 0)
					pieces[i] = pieces[i].substring(start+1);
				int end = pieces[i].indexOf("]");
				if (end >= 0)
					pieces[i] = pieces[i].substring(0, end);
				pieces[i] = pieces[i].trim();
			}
			return pieces;
	    }
		return null;
	}
}