diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/builder/BitbakeBuilder.java | 177 |
1 files changed, 177 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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.builder; | ||
12 | |||
13 | import java.util.Map; | ||
14 | |||
15 | import javax.xml.parsers.ParserConfigurationException; | ||
16 | import javax.xml.parsers.SAXParser; | ||
17 | import javax.xml.parsers.SAXParserFactory; | ||
18 | |||
19 | import org.eclipse.core.resources.IFile; | ||
20 | import org.eclipse.core.resources.IMarker; | ||
21 | import org.eclipse.core.resources.IProject; | ||
22 | import org.eclipse.core.resources.IResource; | ||
23 | import org.eclipse.core.resources.IResourceDelta; | ||
24 | import org.eclipse.core.resources.IResourceDeltaVisitor; | ||
25 | import org.eclipse.core.resources.IncrementalProjectBuilder; | ||
26 | import org.eclipse.core.runtime.CoreException; | ||
27 | import org.eclipse.core.runtime.IProgressMonitor; | ||
28 | import org.xml.sax.SAXException; | ||
29 | |||
30 | public 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 | } | ||