aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder
diff options
context:
space:
mode:
authorKen Gilmer <kgilmer@gmail.com>2010-05-18 21:53:22 -0400
committerKen Gilmer <kgilmer@gmail.com>2010-05-18 21:53:22 -0400
commita7e84830627e50adac5c81ae4dad69aa350933fb (patch)
tree219aa86f4d5f03b29d7bc56f8cdba2702d67082c /org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder
parente27a6dcce13930bfa711a6e72992597a8d1d07c5 (diff)
downloadeclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.gz
eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.tar.bz2
eclipsetools-a7e84830627e50adac5c81ae4dad69aa350933fb.zip
org.openembedded.bc.ui: initial commit
Diffstat (limited to 'org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder')
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeBuilder.java178
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeCommanderNature.java89
-rw-r--r--org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/ToggleNatureAction.java107
3 files changed, 374 insertions, 0 deletions
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeBuilder.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeBuilder.java
new file mode 100644
index 0000000..40ece69
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeBuilder.java
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * 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.builder;
+
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.xml.sax.SAXException;
+
+public class BitbakeBuilder extends IncrementalProjectBuilder {
+
+ class SampleDeltaVisitor implements IResourceDeltaVisitor {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+ */
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource resource = delta.getResource();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ // handle added resource
+ //checkXML(resource);
+ break;
+ case IResourceDelta.REMOVED:
+ // handle removed resource
+ break;
+ case IResourceDelta.CHANGED:
+ // handle changed resource
+ //checkXML(resource);
+ break;
+ }
+ //return true to continue visiting children.
+ return true;
+ }
+ }
+/*
+ class SampleResourceVisitor implements IResourceVisitor {
+ public boolean visit(IResource resource) {
+
+ return true;
+ }
+ }
+*/
+/* class XMLErrorHandler extends DefaultHandler {
+
+ private IFile file;
+
+ public XMLErrorHandler(IFile file) {
+ this.file = file;
+ }
+
+ private void addMarker(SAXParseException e, int severity) {
+ BitbakeBuilder.this.addMarker(file, e.getMessage(), e
+ .getLineNumber(), severity);
+ }
+
+ @Override
+ public void error(SAXParseException exception) throws SAXException {
+ addMarker(exception, IMarker.SEVERITY_ERROR);
+ }
+
+ @Override
+ public void fatalError(SAXParseException exception) throws SAXException {
+ addMarker(exception, IMarker.SEVERITY_ERROR);
+ }
+
+ @Override
+ public void warning(SAXParseException exception) throws SAXException {
+ addMarker(exception, IMarker.SEVERITY_WARNING);
+ }
+ }
+*/
+ public static final String BUILDER_ID = "org.openembedded.bc.ui.builder.BitbakeBuilder";
+
+ private static final String MARKER_TYPE = "org.openembedded.bc.ui.xmlProblem";
+
+ private SAXParserFactory parserFactory;
+
+ private void addMarker(IFile file, String message, int lineNumber,
+ int severity) {
+ try {
+ IMarker marker = file.createMarker(MARKER_TYPE);
+ marker.setAttribute(IMarker.MESSAGE, message);
+ marker.setAttribute(IMarker.SEVERITY, severity);
+ if (lineNumber == -1) {
+ lineNumber = 1;
+ }
+ marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
+ * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
+ throws CoreException {
+ if (kind == FULL_BUILD) {
+ fullBuild(monitor);
+ } else {
+ IResourceDelta delta = getDelta(getProject());
+ if (delta == null) {
+ fullBuild(monitor);
+ } else {
+ incrementalBuild(delta, monitor);
+ }
+ }
+ return null;
+ }
+
+ /*void checkXML(IResource resource) {
+ if (resource instanceof IFile && resource.getName().endsWith(".xml")) {
+ IFile file = (IFile) resource;
+ deleteMarkers(file);
+ XMLErrorHandler reporter = new XMLErrorHandler(file);
+ try {
+ getParser().parse(file.getContents(), reporter);
+ } catch (Exception e1) {
+ }
+ }
+ }*/
+
+ private void deleteMarkers(IFile file) {
+ try {
+ file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);
+ } catch (CoreException ce) {
+ ce.printStackTrace();
+ }
+ }
+
+ protected void fullBuild(final IProgressMonitor monitor)
+ throws CoreException {
+ /*try {
+ getProject().accept(new SampleResourceVisitor());
+ } catch (CoreException e) {
+ }*/
+ }
+
+ private SAXParser getParser() throws ParserConfigurationException,
+ SAXException {
+ if (parserFactory == null) {
+ parserFactory = SAXParserFactory.newInstance();
+ }
+ return parserFactory.newSAXParser();
+ }
+
+ protected void incrementalBuild(IResourceDelta delta,
+ IProgressMonitor monitor) throws CoreException {
+ // the visitor does the work.
+ delta.accept(new SampleDeltaVisitor());
+ }
+}
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeCommanderNature.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeCommanderNature.java
new file mode 100644
index 0000000..ccaba8d
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/BitbakeCommanderNature.java
@@ -0,0 +1,89 @@
+ /*****************************************************************************
+ * 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.builder;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class BitbakeCommanderNature implements IProjectNature {
+
+ /**
+ * ID of this project nature
+ */
+ public static final String NATURE_ID = "org.openembedded.bc.ui.builder.BitbakeCommanderNature";
+
+ private IProject project;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#configure()
+ */
+ public void configure() throws CoreException {
+ IProjectDescription desc = project.getDescription();
+ ICommand[] commands = desc.getBuildSpec();
+
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
+ return;
+ }
+ }
+
+ ICommand[] newCommands = new ICommand[commands.length + 1];
+ System.arraycopy(commands, 0, newCommands, 0, commands.length);
+ ICommand command = desc.newCommand();
+ command.setBuilderName(BitbakeBuilder.BUILDER_ID);
+ newCommands[newCommands.length - 1] = command;
+ desc.setBuildSpec(newCommands);
+ project.setDescription(desc, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#deconfigure()
+ */
+ public void deconfigure() throws CoreException {
+ IProjectDescription description = getProject().getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(BitbakeBuilder.BUILDER_ID)) {
+ ICommand[] newCommands = new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i,
+ commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ return;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#getProject()
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+}
diff --git a/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/ToggleNatureAction.java b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/ToggleNatureAction.java
new file mode 100644
index 0000000..38f8409
--- /dev/null
+++ b/org.openembedded.bc.ui/src/org/openembedded/bc/ui/builder/ToggleNatureAction.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * 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.builder;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class ToggleNatureAction implements IObjectActionDelegate {
+
+ private ISelection selection;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (selection instanceof IStructuredSelection) {
+ for (Iterator it = ((IStructuredSelection) selection).iterator(); it
+ .hasNext();) {
+ Object element = it.next();
+ IProject project = null;
+ if (element instanceof IProject) {
+ project = (IProject) element;
+ } else if (element instanceof IAdaptable) {
+ project = (IProject) ((IAdaptable) element)
+ .getAdapter(IProject.class);
+ }
+ if (project != null) {
+ toggleNature(project);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.selection = selection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /**
+ * Toggles sample nature on a project
+ *
+ * @param project
+ * to have sample nature added or removed
+ */
+ private void toggleNature(IProject project) {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] natures = description.getNatureIds();
+
+ for (int i = 0; i < natures.length; ++i) {
+ if (BitbakeCommanderNature.NATURE_ID.equals(natures[i])) {
+ // Remove the nature
+ String[] newNatures = new String[natures.length - 1];
+ System.arraycopy(natures, 0, newNatures, 0, i);
+ System.arraycopy(natures, i + 1, newNatures, i,
+ natures.length - i - 1);
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ return;
+ }
+ }
+
+ // Add the nature
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy(natures, 0, newNatures, 0, natures.length);
+ newNatures[natures.length] = BitbakeCommanderNature.NATURE_ID;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+}