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
|
/*****************************************************************************
* Copyright (c) 2013 Ken Gilmer, 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:
* Ken Gilmer - initial API and implementation
* Ioana Grigoropol (Intel) - adapt class for remote support
*******************************************************************************/
package org.yocto.bc.ui.wizards.newproject;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Vector;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.yocto.bc.bitbake.ProjectInfoHelper;
import org.yocto.bc.ui.Activator;
import org.yocto.bc.ui.builder.BitbakeCommanderNature;
import org.yocto.bc.ui.model.ProjectInfo;
/**
* Creates a bbc project
* @author kgilmer
*
*/
public class CreateBBCProjectOperation extends WorkspaceModifyOperation {
public static final String OEFS_SCHEME = "OEFS://";
public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT");
public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException {
IProjectDescription desc = proj.getDescription();
Vector natureIds = new Vector();
natureIds.add(nature_id);
natureIds.addAll(Arrays.asList(desc.getNatureIds()));
desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()]));
proj.setDescription(desc, monitor);
}
private ProjectInfo projInfo;
public CreateBBCProjectOperation(ProjectInfo projInfo) {
this.projInfo = projInfo;
}
protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException {
addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor);
}
private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo) throws CoreException {
IProjectDescription desc = workspace.newProjectDescription(projInfo.getProjectName());
desc.setLocationURI(projInfo.getOEFSURI());
return desc;
}
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo);
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
IProject proj = wsroot.getProject(projInfo.getProjectName());
proj.create(desc, monitor);
proj.open(monitor);
addNatures(proj, monitor);
}
public ProjectInfo getProjectInfo() {
return projInfo;
}
}
|