aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java
blob: ae3f90c7ab7ca022628e06f9ec6f601526347a27 (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
/*****************************************************************************
 * Copyright (c) 2009 Ken Gilmer
 * 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:
 *     Ken Gilmer - initial API and implementation
 *******************************************************************************/
package org.openembedded.bc.ui.wizards.newproject;

import java.io.Writer;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.openembedded.bc.bitbake.BBSession;
import org.openembedded.bc.bitbake.ProjectInfoHelper;
import org.openembedded.bc.ui.Activator;
import org.openembedded.bc.ui.model.ProjectInfo;


public class BBConfigurationInitializeOperation implements IRunnableWithProgress {

	private final ProjectInfo pinfo;
	private final Writer writer;

	public BBConfigurationInitializeOperation(ProjectInfo pinfo) {
		this.pinfo = pinfo;
		writer = null;
	}

	public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) {
		this.pinfo = pinfo;
		this.writer = writer;
	}

	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
		BBSession session;
		try {
			ProjectInfoHelper.store(pinfo.getRootPath(), pinfo);
			session = Activator.getBBSession(pinfo.getRootPath(), writer);

			if (!session.isInitialized()) {
				session.initialize();
			}
			
			if (session.isEmpty()) {
				Activator.clearBBSession(pinfo.getRootPath());
				throw new RuntimeException("Bitbake failed silently.  No configuration is availalbe.");
			}

		} catch (Exception e) {
			Activator.clearBBSession(pinfo.getRootPath());
			throw new InvocationTargetException(e);
		}
	}
}