diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java new file mode 100644 index 0000000..dc0153b --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java | |||
@@ -0,0 +1,102 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | * Ken Gilmer - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.wizards.newproject; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.lang.reflect.InvocationTargetException; | ||
15 | import java.net.URI; | ||
16 | import java.net.URISyntaxException; | ||
17 | import java.util.Arrays; | ||
18 | import java.util.Vector; | ||
19 | |||
20 | import org.eclipse.core.resources.IProject; | ||
21 | import org.eclipse.core.resources.IProjectDescription; | ||
22 | import org.eclipse.core.resources.IWorkspace; | ||
23 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
24 | import org.eclipse.core.resources.ResourcesPlugin; | ||
25 | import org.eclipse.core.runtime.CoreException; | ||
26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
27 | import org.eclipse.core.runtime.IStatus; | ||
28 | import org.eclipse.core.runtime.QualifiedName; | ||
29 | import org.eclipse.core.runtime.Status; | ||
30 | import org.eclipse.ui.actions.WorkspaceModifyOperation; | ||
31 | |||
32 | import org.yocto.bc.bitbake.ProjectInfoHelper; | ||
33 | import org.yocto.bc.ui.Activator; | ||
34 | import org.yocto.bc.ui.builder.BitbakeCommanderNature; | ||
35 | import org.yocto.bc.ui.model.ProjectInfo; | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Creates a bbc project | ||
40 | * @author kgilmer | ||
41 | * | ||
42 | */ | ||
43 | public class CreateBBCProjectOperation extends WorkspaceModifyOperation { | ||
44 | |||
45 | public static final String OEFS_SCHEME = "OEFS://"; | ||
46 | public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT"); | ||
47 | public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException { | ||
48 | IProjectDescription desc = proj.getDescription(); | ||
49 | Vector natureIds = new Vector(); | ||
50 | |||
51 | natureIds.add(nature_id); | ||
52 | natureIds.addAll(Arrays.asList(desc.getNatureIds())); | ||
53 | desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()])); | ||
54 | |||
55 | proj.setDescription(desc, monitor); | ||
56 | } | ||
57 | |||
58 | private ProjectInfo projInfo; | ||
59 | |||
60 | public CreateBBCProjectOperation(ProjectInfo projInfo) { | ||
61 | this.projInfo = projInfo; | ||
62 | } | ||
63 | |||
64 | protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException { | ||
65 | addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor); | ||
66 | } | ||
67 | |||
68 | private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo2) throws CoreException { | ||
69 | IProjectDescription desc = workspace.newProjectDescription(projInfo2.getProjectName()); | ||
70 | |||
71 | try { | ||
72 | desc.setLocationURI(new URI(OEFS_SCHEME + projInfo2.getRootPath())); | ||
73 | } catch (URISyntaxException e) { | ||
74 | throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to load filesystem.", e)); | ||
75 | } | ||
76 | |||
77 | return desc; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { | ||
82 | IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo); | ||
83 | |||
84 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
85 | |||
86 | IProject proj = wsroot.getProject(projInfo.getProjectName()); | ||
87 | proj.create(desc, monitor); | ||
88 | try { | ||
89 | ProjectInfoHelper.store(proj.getLocationURI().getPath(), projInfo); | ||
90 | } catch (IOException e) { | ||
91 | throw new InvocationTargetException(e); | ||
92 | } | ||
93 | |||
94 | proj.open(monitor); | ||
95 | |||
96 | addNatures(proj, monitor); | ||
97 | } | ||
98 | |||
99 | public ProjectInfo getProjectInfo() { | ||
100 | return projInfo; | ||
101 | } | ||
102 | } | ||