summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java177
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java118
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java106
3 files changed, 401 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java
new file mode 100644
index 0000000..3705d9b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java
@@ -0,0 +1,177 @@
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 *******************************************************************************/
11package org.yocto.bc.ui.builder;
12
13import java.util.Map;
14
15import javax.xml.parsers.ParserConfigurationException;
16import javax.xml.parsers.SAXParser;
17import javax.xml.parsers.SAXParserFactory;
18
19import org.eclipse.core.resources.IFile;
20import org.eclipse.core.resources.IMarker;
21import org.eclipse.core.resources.IProject;
22import org.eclipse.core.resources.IResource;
23import org.eclipse.core.resources.IResourceDelta;
24import org.eclipse.core.resources.IResourceDeltaVisitor;
25import org.eclipse.core.resources.IncrementalProjectBuilder;
26import org.eclipse.core.runtime.CoreException;
27import org.eclipse.core.runtime.IProgressMonitor;
28import org.xml.sax.SAXException;
29
30public class BitbakeBuilder extends IncrementalProjectBuilder {
31
32 class SampleDeltaVisitor implements IResourceDeltaVisitor {
33 /*
34 * (non-Javadoc)
35 *
36 * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
37 */
38 public boolean visit(IResourceDelta delta) throws CoreException {
39 IResource resource = delta.getResource();
40 switch (delta.getKind()) {
41 case IResourceDelta.ADDED:
42 // handle added resource
43 //checkXML(resource);
44 break;
45 case IResourceDelta.REMOVED:
46 // handle removed resource
47 break;
48 case IResourceDelta.CHANGED:
49 // handle changed resource
50 //checkXML(resource);
51 break;
52 }
53 //return true to continue visiting children.
54 return true;
55 }
56 }
57/*
58 class SampleResourceVisitor implements IResourceVisitor {
59 public boolean visit(IResource resource) {
60
61 return true;
62 }
63 }
64*/
65/* class XMLErrorHandler extends DefaultHandler {
66
67 private IFile file;
68
69 public XMLErrorHandler(IFile file) {
70 this.file = file;
71 }
72
73 private void addMarker(SAXParseException e, int severity) {
74 BitbakeBuilder.this.addMarker(file, e.getMessage(), e
75 .getLineNumber(), severity);
76 }
77
78 @Override
79 public void error(SAXParseException exception) throws SAXException {
80 addMarker(exception, IMarker.SEVERITY_ERROR);
81 }
82
83 @Override
84 public void fatalError(SAXParseException exception) throws SAXException {
85 addMarker(exception, IMarker.SEVERITY_ERROR);
86 }
87
88 @Override
89 public void warning(SAXParseException exception) throws SAXException {
90 addMarker(exception, IMarker.SEVERITY_WARNING);
91 }
92 }
93*/
94 public static final String BUILDER_ID = "org.yocto.bc.ui.builder.BitbakeBuilder";
95 public static final String HOB_BUILD_ID = "org.yocto.bc.ui.builder.HOB";
96
97 private static final String MARKER_TYPE = "org.yocto.bc.ui.xmlProblem";
98
99 private SAXParserFactory parserFactory;
100
101 private void addMarker(IFile file, String message, int lineNumber,
102 int severity) {
103 try {
104 IMarker marker = file.createMarker(MARKER_TYPE);
105 marker.setAttribute(IMarker.MESSAGE, message);
106 marker.setAttribute(IMarker.SEVERITY, severity);
107 if (lineNumber == -1) {
108 lineNumber = 1;
109 }
110 marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
111 } catch (CoreException e) {
112 }
113 }
114
115 /*
116 * (non-Javadoc)
117 *
118 * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
119 * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
120 */
121 @Override
122 protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
123 throws CoreException {
124 if (kind == FULL_BUILD) {
125 fullBuild(monitor);
126 } else {
127 IResourceDelta delta = getDelta(getProject());
128 if (delta == null) {
129 fullBuild(monitor);
130 } else {
131 incrementalBuild(delta, monitor);
132 }
133 }
134 return null;
135 }
136
137 /*void checkXML(IResource resource) {
138 if (resource instanceof IFile && resource.getName().endsWith(".xml")) {
139 IFile file = (IFile) resource;
140 deleteMarkers(file);
141 XMLErrorHandler reporter = new XMLErrorHandler(file);
142 try {
143 getParser().parse(file.getContents(), reporter);
144 } catch (Exception e1) {
145 }
146 }
147 }*/
148
149 private void deleteMarkers(IFile file) {
150 try {
151 file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);
152 } catch (CoreException ce) {
153 }
154 }
155
156 protected void fullBuild(final IProgressMonitor monitor)
157 throws CoreException {
158 /*try {
159 getProject().accept(new SampleResourceVisitor());
160 } catch (CoreException e) {
161 }*/
162 }
163
164 private SAXParser getParser() throws ParserConfigurationException,
165 SAXException {
166 if (parserFactory == null) {
167 parserFactory = SAXParserFactory.newInstance();
168 }
169 return parserFactory.newSAXParser();
170 }
171
172 protected void incrementalBuild(IResourceDelta delta,
173 IProgressMonitor monitor) throws CoreException {
174 // the visitor does the work.
175 delta.accept(new SampleDeltaVisitor());
176 }
177}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java
new file mode 100644
index 0000000..fe2a997
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java
@@ -0,0 +1,118 @@
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 * Jessica Zhang - extend to support HOB build
11 *******************************************************************************/
12package org.yocto.bc.ui.builder;
13
14import java.util.ArrayList;
15
16import org.eclipse.core.resources.ICommand;
17import org.eclipse.core.resources.IProject;
18import org.eclipse.core.resources.IProjectDescription;
19import org.eclipse.core.resources.IProjectNature;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.debug.core.DebugPlugin;
22import org.eclipse.debug.core.ILaunchConfigurationType;
23import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24import org.eclipse.debug.core.ILaunchManager;
25
26
27public class BitbakeCommanderNature implements IProjectNature {
28
29 /**
30 * ID of this project nature
31 */
32 public static final String NATURE_ID = "org.yocto.bc.ui.builder.BitbakeCommanderNature";
33 public static final String BUILD_DIR_KEY = "org.yocto.bc.ui.builder.BitbakeCommander.BuildDir";
34 private IProject project;
35
36 public static void launchHob(IProject project, String buildDir) {
37 try {
38 ILaunchManager lManager = DebugPlugin.getDefault().getLaunchManager();
39 ILaunchConfigurationType configType =
40 lManager.getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType");
41 ILaunchConfigurationWorkingCopy w_copy = configType.newInstance(null, "hob");
42 ArrayList<String> listValue = new ArrayList<String>();
43 listValue.add(new String("org.eclipse.ui.externaltools.launchGroup"));
44 w_copy.setAttribute("org.eclipse.debug.ui.favoriteGroups", listValue);
45 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", "/usr/bin/xterm");
46
47 String init_script = project.getLocation().toString() + "/oe-init-build-env ";
48 String argument = "-e \"source " + init_script + buildDir + ";hob";// + ";bash\"";
49
50 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", argument);
51 w_copy.launch(ILaunchManager.RUN_MODE, null);
52
53 } catch (CoreException e) {
54 System.out.println(e.getMessage());
55 }
56 }
57 /*
58 * (non-Javadoc)
59 *
60 * @see org.eclipse.core.resources.IProjectNature#configure()
61 */
62 public void configure() throws CoreException {
63 IProjectDescription desc = project.getDescription();
64 ICommand[] commands = desc.getBuildSpec();
65
66 for (int i = 0; i < commands.length; ++i) {
67 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
68 return;
69 }
70 }
71
72 ICommand[] newCommands = new ICommand[commands.length + 1];
73 System.arraycopy(commands, 0, newCommands, 0, commands.length);
74 ICommand command = desc.newCommand();
75 command.setBuilderName(BitbakeBuilder.BUILDER_ID);
76 newCommands[newCommands.length - 1] = command;
77 desc.setBuildSpec(newCommands);
78 project.setDescription(desc, null);
79 }
80
81 /*
82 * (non-Javadoc)
83 *
84 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
85 */
86 public void deconfigure() throws CoreException {
87 IProjectDescription description = getProject().getDescription();
88 ICommand[] commands = description.getBuildSpec();
89 for (int i = 0; i < commands.length; ++i) {
90 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
91 ICommand[] newCommands = new ICommand[commands.length - 1];
92 System.arraycopy(commands, 0, newCommands, 0, i);
93 System.arraycopy(commands, i + 1, newCommands, i,
94 commands.length - i - 1);
95 description.setBuildSpec(newCommands);
96 return;
97 }
98 }
99 }
100
101 /*
102 * (non-Javadoc)
103 *
104 * @see org.eclipse.core.resources.IProjectNature#getProject()
105 */
106 public IProject getProject() {
107 return project;
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
114 */
115 public void setProject(IProject project) {
116 this.project = project;
117 }
118}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java
new file mode 100644
index 0000000..f25148d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java
@@ -0,0 +1,106 @@
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 *******************************************************************************/
11package org.yocto.bc.ui.builder;
12
13import java.util.Iterator;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IProjectDescription;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.core.runtime.IAdaptable;
19import org.eclipse.jface.action.IAction;
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.IStructuredSelection;
22import org.eclipse.ui.IObjectActionDelegate;
23import org.eclipse.ui.IWorkbenchPart;
24
25public class ToggleNatureAction implements IObjectActionDelegate {
26
27 private ISelection selection;
28
29 /*
30 * (non-Javadoc)
31 *
32 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
33 */
34 public void run(IAction action) {
35 if (selection instanceof IStructuredSelection) {
36 for (Iterator it = ((IStructuredSelection) selection).iterator(); it
37 .hasNext();) {
38 Object element = it.next();
39 IProject project = null;
40 if (element instanceof IProject) {
41 project = (IProject) element;
42 } else if (element instanceof IAdaptable) {
43 project = (IProject) ((IAdaptable) element)
44 .getAdapter(IProject.class);
45 }
46 if (project != null) {
47 toggleNature(project);
48 }
49 }
50 }
51 }
52
53 /*
54 * (non-Javadoc)
55 *
56 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
57 * org.eclipse.jface.viewers.ISelection)
58 */
59 public void selectionChanged(IAction action, ISelection selection) {
60 this.selection = selection;
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
67 * org.eclipse.ui.IWorkbenchPart)
68 */
69 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
70 }
71
72 /**
73 * Toggles sample nature on a project
74 *
75 * @param project
76 * to have sample nature added or removed
77 */
78 private void toggleNature(IProject project) {
79 try {
80 IProjectDescription description = project.getDescription();
81 String[] natures = description.getNatureIds();
82
83 for (int i = 0; i < natures.length; ++i) {
84 if (BitbakeCommanderNature.NATURE_ID.equals(natures[i])) {
85 // Remove the nature
86 String[] newNatures = new String[natures.length - 1];
87 System.arraycopy(natures, 0, newNatures, 0, i);
88 System.arraycopy(natures, i + 1, newNatures, i,
89 natures.length - i - 1);
90 description.setNatureIds(newNatures);
91 project.setDescription(description, null);
92 return;
93 }
94 }
95
96 // Add the nature
97 String[] newNatures = new String[natures.length + 1];
98 System.arraycopy(natures, 0, newNatures, 0, natures.length);
99 newNatures[natures.length] = BitbakeCommanderNature.NATURE_ID;
100 description.setNatureIds(newNatures);
101 project.setDescription(description, null);
102 } catch (CoreException e) {
103 }
104 }
105
106}