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.java119
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/ToggleNatureAction.java106
3 files changed, 402 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..25f7894
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeCommanderNature.java
@@ -0,0 +1,119 @@
1/*****************************************************************************
2 * Copyright (c) 2013 Ken Gilmer, Intel Corporation
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 * Ioana Grigoropol (Intel) - adapt class for remote support
12 *******************************************************************************/
13package org.yocto.bc.ui.builder;
14
15import java.util.ArrayList;
16
17import org.eclipse.core.resources.ICommand;
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IProjectDescription;
20import org.eclipse.core.resources.IProjectNature;
21import org.eclipse.core.runtime.CoreException;
22import org.eclipse.debug.core.DebugPlugin;
23import org.eclipse.debug.core.ILaunchConfigurationType;
24import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
25import org.eclipse.debug.core.ILaunchManager;
26
27
28public class BitbakeCommanderNature implements IProjectNature {
29
30 /**
31 * ID of this project nature
32 */
33 public static final String NATURE_ID = "org.yocto.bc.ui.builder.BitbakeCommanderNature";
34 public static final String BUILD_DIR_KEY = "org.yocto.bc.ui.builder.BitbakeCommander.BuildDir";
35 private IProject project;
36
37 public static void launchHob(IProject project, String buildDir) {
38 try {
39 ILaunchManager lManager = DebugPlugin.getDefault().getLaunchManager();
40 ILaunchConfigurationType configType =
41 lManager.getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType");
42 ILaunchConfigurationWorkingCopy w_copy = configType.newInstance(null, "hob");
43 ArrayList<String> listValue = new ArrayList<String>();
44 listValue.add(new String("org.eclipse.ui.externaltools.launchGroup"));
45 w_copy.setAttribute("org.eclipse.debug.ui.favoriteGroups", listValue);
46 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", "/usr/bin/xterm");
47
48 String init_script = project.getLocationURI().getPath() + "/oe-init-build-env ";
49 String argument = "-e \"source " + init_script + buildDir + ";hob";// + ";bash\"";
50
51 w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", argument);
52 w_copy.launch(ILaunchManager.RUN_MODE, null);
53
54 } catch (CoreException e) {
55 System.out.println(e.getMessage());
56 }
57 }
58 /*
59 * (non-Javadoc)
60 *
61 * @see org.eclipse.core.resources.IProjectNature#configure()
62 */
63 public void configure() throws CoreException {
64 IProjectDescription desc = project.getDescription();
65 ICommand[] commands = desc.getBuildSpec();
66
67 for (int i = 0; i < commands.length; ++i) {
68 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
69 return;
70 }
71 }
72
73 ICommand[] newCommands = new ICommand[commands.length + 1];
74 System.arraycopy(commands, 0, newCommands, 0, commands.length);
75 ICommand command = desc.newCommand();
76 command.setBuilderName(BitbakeBuilder.BUILDER_ID);
77 newCommands[newCommands.length - 1] = command;
78 desc.setBuildSpec(newCommands);
79 project.setDescription(desc, null);
80 }
81
82 /*
83 * (non-Javadoc)
84 *
85 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
86 */
87 public void deconfigure() throws CoreException {
88 IProjectDescription description = getProject().getDescription();
89 ICommand[] commands = description.getBuildSpec();
90 for (int i = 0; i < commands.length; ++i) {
91 if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
92 ICommand[] newCommands = new ICommand[commands.length - 1];
93 System.arraycopy(commands, 0, newCommands, 0, i);
94 System.arraycopy(commands, i + 1, newCommands, i,
95 commands.length - i - 1);
96 description.setBuildSpec(newCommands);
97 return;
98 }
99 }
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see org.eclipse.core.resources.IProjectNature#getProject()
106 */
107 public IProject getProject() {
108 return project;
109 }
110
111 /*
112 * (non-Javadoc)
113 *
114 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
115 */
116 public void setProject(IProject project) {
117 this.project = project;
118 }
119}
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}