diff options
author | rescobar | 2010-03-12 18:27:25 +0000 |
---|---|---|
committer | rescobar | 2010-03-12 18:27:25 +0000 |
commit | 205aa057fa925d37a3a5375aa8418b9567e99c6d (patch) | |
tree | d33f80b9f727c479b8031aeb352494c38ad9878d /plugins/org.eclipse.osee.ote.ui.markers | |
parent | 0e6d2b595cfb4d54eccdf3479e7c5d74d9c736a5 (diff) | |
download | org.eclipse.osee-205aa057fa925d37a3a5375aa8418b9567e99c6d.tar.gz org.eclipse.osee-205aa057fa925d37a3a5375aa8418b9567e99c6d.tar.xz org.eclipse.osee-205aa057fa925d37a3a5375aa8418b9567e99c6d.zip |
Diffstat (limited to 'plugins/org.eclipse.osee.ote.ui.markers')
13 files changed, 970 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/.classpath b/plugins/org.eclipse.osee.ote.ui.markers/.classpath new file mode 100644 index 00000000000..02159672985 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/.project b/plugins/org.eclipse.osee.ote.ui.markers/.project new file mode 100644 index 00000000000..2cf24a360a4 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.ote.ui.markers</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.ui.markers/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..57646f9d11b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Markers Plug-in (Incubation) +Bundle-SymbolicName: org.eclipse.osee.ote.ui.markers;singleton:=true +Bundle-Version: 0.9.2.qualifier +Bundle-Activator: org.eclipse.osee.ote.ui.markers.MarkerPlugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.osee.framework.jdk.core, + org.eclipse.osee.framework.plugin.core, + org.eclipse.ui, + org.eclipse.osee.framework.ui.plugin +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.osee.ote.ui.markers +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.osee.framework.core.operation, + org.eclipse.osee.framework.logging, + org.eclipse.osee.ote.core.framework.saxparse, + org.eclipse.osee.ote.core.framework.saxparse.elements +Bundle-Vendor: Eclipse.org diff --git a/plugins/org.eclipse.osee.ote.ui.markers/build.properties b/plugins/org.eclipse.osee.ote.ui.markers/build.properties new file mode 100644 index 00000000000..41eb6ade2b4 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/build.properties @@ -0,0 +1,4 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointData.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointData.java new file mode 100644 index 00000000000..fac38d9fee8 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointData.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers; + +/** + * @author Andrew M. Finkbeiner + * + */ +public class CheckPointData { + + private boolean isFailed = false; + private String name; + private String expected; + private String actual; + + public boolean isFailed() { + return isFailed; + } + + public void setFailed(boolean failed) { + this.isFailed = failed; + } + + public void setName(String name) { + this.name = name; + } + + public void setExpected(String expected) { + this.expected = expected; + } + + public void setActual(String actual) { + this.actual = actual; + } + + public String getName() { + return name; + } + + public String getExpected() { + return expected; + } + + public String getActual() { + return actual; + } + +} diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointHelper.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointHelper.java new file mode 100644 index 00000000000..6c388bf7fd9 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/CheckPointHelper.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers;
+
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.w3c.dom.Element;
+
+public class CheckPointHelper implements Comparable<CheckPointHelper> {
+
+ @Override
+ public String toString() {
+ return String.format("%s[%s, %s]", testPointName, expected, actual);
+ }
+
+ /**
+ *
+ */
+ public void increment() {
+ count++;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof CheckPointHelper) {
+ return key.equals(((CheckPointHelper) obj).key);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
+
+ private String testPointName;
+ private String expected;
+ private String actual;
+ private String key;
+ private int count = 1;
+
+ public CheckPointHelper(Element el) {
+ testPointName = Jaxp.getChildText(el, "TestPointName");
+ expected = Jaxp.getChildText(el, "Expected");
+ actual = Jaxp.getChildText(el, "Actual");
+ key = testPointName + expected + actual;
+ }
+
+ public CheckPointHelper(CheckPointData data){
+ testPointName = data.getName();
+ expected = data.getExpected();
+ actual = data.getActual();
+ key = testPointName + expected + actual;
+ }
+
+ public int compareTo(CheckPointHelper o) {
+ return o.count - this.count;
+ }
+
+ }
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/FileWatchList.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/FileWatchList.java new file mode 100644 index 00000000000..69d5d17bfe9 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/FileWatchList.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Andrew M. Finkbeiner + */ +public class FileWatchList { + + private class FileWatchItem { + IFile file; + List<IMarker> markers; + long timeUpdated; + + FileWatchItem(IFile file, List<IMarker> markers) { + this.file = file; + this.markers = markers; + timeUpdated = System.currentTimeMillis(); + } + } + + private final List<FileWatchItem> fileWatchItems; + + public FileWatchList() { + fileWatchItems = new CopyOnWriteArrayList<FileWatchItem>(); + } + + public void put(IFile file, List<IMarker> markers) { + FileWatchItem item = findWatchItem(file); + if (item == null) { + if (isListTooBig()) { + removeOldestWatchItem(); + } + fileWatchItems.add(new FileWatchItem(file, markers)); + } else { + item.markers = markers; + item.timeUpdated = System.currentTimeMillis(); + } + } + + /** + * + */ + private void removeOldestWatchItem() { + FileWatchItem oldest = null; + for (FileWatchItem item : fileWatchItems) { + if (oldest == null) { + oldest = item; + } else { + if (oldest.timeUpdated > item.timeUpdated) { + oldest = item; + } + } + } + if (oldest != null) { + OseeLog.log(FileWatchList.class, Level.INFO, String.format( + "Removing markers from [%s] because maximium marker watch list size has been reached.", + oldest.file.getName())); + fileWatchItems.remove(oldest); + if (oldest.markers != null) { + for (IMarker marker : oldest.markers) { + try { + marker.delete(); + } catch (CoreException ex) { + OseeLog.log(FileWatchList.class, Level.SEVERE, ex); + } + } + } + } + } + + /** + * @return + */ + private boolean isListTooBig() { + return fileWatchItems.size() > 20; + } + + public List<IMarker> get(IFile file) { + FileWatchItem item = findWatchItem(file); + if (item != null) { + return item.markers; + } else { + return null; + } + } + + /** + * @param file + * @return + */ + private FileWatchItem findWatchItem(IFile file) { + for (FileWatchItem item : fileWatchItems) { + if (item.file.equals(file)) { + return item; + } + } + return null; + } + +} diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerInfo.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerInfo.java new file mode 100644 index 00000000000..1e2a0f00eab --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerInfo.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers;
+
+public class MarkerInfo {
+ private String file;
+ private int line;
+ private String message;
+
+ public MarkerInfo(String file, int line, String message) {
+ this.file = file;
+ this.line = line;
+ this.message = message;
+ }
+
+ /**
+ * @return the file
+ */
+ public String getFile() {
+ return file;
+ }
+
+ /**
+ * @return the line
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * @return the message
+ */
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerPlugin.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerPlugin.java new file mode 100644 index 00000000000..e351a7b3918 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/MarkerPlugin.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers;
+
+import java.util.List; +import java.util.logging.Level; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.plugin.core.util.Jobs; +import org.eclipse.osee.framework.ui.plugin.OseeUiActivator; +import org.osgi.framework.BundleContext; +
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class MarkerPlugin extends OseeUiActivator {
+
+ private FileWatchList filesToWatch;
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.osee.ote.ui.markers";
+
+ // The shared instance
+ private static MarkerPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public MarkerPlugin() {
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ filesToWatch = new FileWatchList();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
+
+ public void resourceChanged(final IResourceChangeEvent event) {
+ IResourceDelta delta = event.getDelta();
+ try {
+ delta.accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IPath path = delta.getFullPath();
+ String extension = path.getFileExtension();
+ if (extension != null) {
+ if ("tmo".equals(extension)) {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ // file.refreshLocal(depth, monitor);
+ if (file != null) {
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ // OseeLog.log(Activator.class, Level.INFO, String.format("ADDED %s updating
+ // markers - delta kind: %d", file.getName(), delta.getKind()));
+ // addMarkers(file);
+ break;
+ case IResourceDelta.CHANGED:
+ // OseeLog.log(Activator.class, Level.INFO, String.format("CHANGED %s updating
+ // markers - delta kind: %d", file.getName(), delta.getKind()));
+ // updateMarkers(file);
+ break;
+ case IResourceDelta.REMOVED:
+ // OseeLog.log(Activator.class, Level.INFO, String.format("removing %s markers -
+ // delta kind: %d", file.getName(), delta.getKind()));
+ removeMarkers(file);
+ break;
+ }
+ }
+ }
+ }
+ if (delta.getAffectedChildren().length > 0) return true;
+ return false;
+ }
+ });
+ } catch (CoreException ex) {
+ OseeLog.log(MarkerPlugin.class, Level.SEVERE, ex);
+ }
+ }
+
+ }, IResourceChangeEvent.POST_CHANGE);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static MarkerPlugin getDefault() {
+ return plugin;
+ }
+
+ public void addMarkers(IFile file) {
+ removeMarkers(file);
+ Jobs.runInJob("OTE Marker Processing", new ProcessOutfileSax(this, file), MarkerPlugin.class, MarkerPlugin.PLUGIN_ID, false);
+ }
+
+ public void removeMarkers(IFile file) {
+ List<IMarker> markers = filesToWatch.get(file);
+ if (markers != null) {
+ for (IMarker marker : markers) {
+ try {
+ marker.delete();
+ } catch (CoreException ex) {
+ }
+ }
+ }
+ }
+
+ synchronized void updateMarkerInfo(IFile file, List<IMarker> markers) { + List<IMarker> oldMarkers = filesToWatch.get(file); + if(oldMarkers != null){ + oldMarkers.addAll(markers); + } else {
+ filesToWatch.put(file, markers); + }
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/OteMarkerHelper.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/OteMarkerHelper.java new file mode 100644 index 00000000000..310746681e4 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/OteMarkerHelper.java @@ -0,0 +1,136 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.ui.markers;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.ui.plugin.util.AWorkspace;
+import org.eclipse.osee.ote.core.framework.saxparse.elements.StacktraceData;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class OteMarkerHelper {
+
+ private List<MarkerInfo> markerInfo;
+ private List<IMarker> markersToDelete;
+ private Map<CheckPointHelper, CheckPointHelper> count = new HashMap<CheckPointHelper, CheckPointHelper>();
+ private StringBuilder builder = new StringBuilder();
+ private List<TestPointData> testPonitDatas;
+
+ /**
+ * @param testPointDatas
+ */
+ public OteMarkerHelper(List<TestPointData> testPointDatas) {
+ this.testPonitDatas = testPointDatas;
+ markerInfo = new ArrayList<MarkerInfo>();
+ markersToDelete = new ArrayList<IMarker>();
+
+ doWork();
+ }
+
+ private void doWork() {
+ for (TestPointData data : testPonitDatas) {
+ String description = getDescription(data.getCheckPointData());
+ String number = data.getNumber();
+ int num = Integer.parseInt(number);
+ String details = String.format("#%03d %s", num, description);
+
+ for (StacktraceData stackLocation : data.getStacktraceCollection().getStackTrace()) {
+ String file = stackLocation.getSource();
+ String line = stackLocation.getLine();
+ //pull out the java file name
+ file = file.substring(file.lastIndexOf(".") + 1);
+ int innerMarker = file.indexOf("$");
+ if (innerMarker > 0) {
+ file = file.substring(0, file.indexOf("$"));
+ }
+ file += ".java";
+ int linenumber = Integer.parseInt(line);
+
+ markerInfo.add(new MarkerInfo(file, linenumber, details));
+ }
+ }
+ finish();
+ }
+
+ private String getDescription(List<CheckPointData> datas) {
+ count.clear();
+ for (CheckPointData data : datas) {
+ CheckPointHelper check = new CheckPointHelper(data);
+ if (count.containsKey(check)) {
+ count.get(check).increment();
+ } else {
+ count.put(check, check);
+ }
+ }
+
+ CheckPointHelper[] helper = count.values().toArray(new CheckPointHelper[count.values().size()]);
+ Arrays.sort(helper);
+ int maxNumber = 2;
+ builder.setLength(0);
+ for (int i = 0; i < helper.length && i < maxNumber; i++) {
+ builder.append(helper[i].toString());
+ if ((i + 1) < Math.min(helper.length, maxNumber)) {
+ builder.append(", ");
+ }
+ if ((i + 1) < helper.length && (i + 1) >= maxNumber) {
+ builder.append("...");
+ }
+ }
+ return builder.toString();
+ }
+
+ private void finish() {
+
+ Set<String> fileAlreadyLookedFor = new HashSet<String>();
+ Map<String, IResource> resources = new HashMap<String, IResource>();
+
+ for (MarkerInfo marker : markerInfo) {
+ try {
+ if (!fileAlreadyLookedFor.contains(marker.getFile())) {
+ fileAlreadyLookedFor.add(marker.getFile());
+ IResource resource = AWorkspace.findWorkspaceFile(marker.getFile());
+ if (resource != null) {
+ resources.put(marker.getFile(), resource);
+ }
+ }
+
+ IResource resourceToMark = resources.get(marker.getFile());
+ if (resourceToMark != null) {
+ Map<String, Object> scriptMarkerMap = new HashMap<String, Object>();
+ scriptMarkerMap.put(IMarker.MESSAGE, marker.getMessage());
+ scriptMarkerMap.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
+ scriptMarkerMap.put(IMarker.LINE_NUMBER, marker.getLine());
+ IMarker markerToDelete = resourceToMark.createMarker("org.eclipse.osee.ote.ui.output.errorMarker");
+ markerToDelete.setAttributes(scriptMarkerMap);
+ markersToDelete.add(markerToDelete);
+ }
+ } catch (Exception ex) {
+ OseeLog.log(MarkerPlugin.class, Level.SEVERE, "Error adding markers from outfile", ex);
+ }
+ }
+ }
+
+ public List<IMarker> getMarkers() {
+ return markersToDelete;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/ProcessOutfileSax.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/ProcessOutfileSax.java new file mode 100644 index 00000000000..129ca9c150d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/ProcessOutfileSax.java @@ -0,0 +1,264 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.logging.Level; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.plugin.core.util.IExceptionableRunnable; +import org.eclipse.osee.framework.ui.plugin.util.AWorkspace; +import org.eclipse.osee.ote.core.framework.saxparse.IBaseSaxElementListener; +import org.eclipse.osee.ote.core.framework.saxparse.OteSaxHandler; +import org.eclipse.osee.ote.core.framework.saxparse.elements.StacktraceData; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * @author Andrew M. Finkbeiner + */ +public class ProcessOutfileSax implements IExceptionableRunnable { + + private IFile file; + private MarkerPlugin plugin; + + private static final int _1_MB = 1048576; + private static final int _20_MB = _1_MB * 20; + private static final int _30_MB = _1_MB * 30; + + private List<TestPointData> testPointDatas = new ArrayList<TestPointData>(); + private TestPointData currentData = null; + private CheckPointData currentCheckPoint = null; + protected StackTraceCollection currentStackTrace; + + public ProcessOutfileSax(MarkerPlugin plugin, IFile file) { + this.file = file; + this.plugin = plugin; + } + + public IStatus run(IProgressMonitor monitor) throws Exception { + File outfile = AWorkspace.iFileToFile(file); + if (outfile.length() > _20_MB) { + OseeLog.log(MarkerPlugin.class, Level.WARNING, String.format( + "%s has a length of [%d], the max size processed is [%d].", file.getName(), outfile.length(), _20_MB)); + return Status.OK_STATUS; + } + if (!file.isSynchronized(0)) { + OseeLog.log(MarkerPlugin.class, Level.WARNING, String.format("%s is not synchronized.", file.getName())); + file.refreshLocal(0, monitor); + } + + monitor.setTaskName(String.format("Computing overview information for [%s].", file.getName())); + + InputStream contents = file.getContents(); + + parseContents(contents); + + OteMarkerHelper helper = new OteMarkerHelper(this.testPointDatas); + plugin.updateMarkerInfo(file, helper.getMarkers()); + + return Status.OK_STATUS; + } + + /** + * @param contents + * @throws SAXException + * @throws Exception + * @throws SAXNotRecognizedException + * @throws SAXNotSupportedException + * @throws IOException + */ + private void parseContents(InputStream contents) throws SAXException, Exception, SAXNotRecognizedException, SAXNotSupportedException, IOException { + XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + OteSaxHandler handler = new OteSaxHandler(); + xmlReader.setContentHandler(handler); + xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); // This is the important part + + final Stack<String> elementStack = new Stack<String>(); + handler.getHandler("*").addListener(new IBaseSaxElementListener() { + + @Override + public void onStartElement(Object obj) { + elementStack.push((String)obj); + } + + @Override + public void onEndElement(Object obj) { + elementStack.pop(); + } + }); + + handler.getHandler("TestPoint").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentData.isFailed()) { + testPointDatas.add(currentData); + } + currentData = null; + } + + @Override + public void onStartElement(Object obj) { + currentData = new TestPointData(); + } + }); + handler.getHandler("CheckPoint").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentCheckPoint.isFailed()) { + currentData.add(currentCheckPoint); + } + currentCheckPoint = null; + } + + @Override + public void onStartElement(Object obj) { + if (currentData != null) { + currentCheckPoint = new CheckPointData(); + } + } + }); + + handler.getHandler("Result").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + boolean failed = false; + if ("FAILED".equals(obj)) { + failed = true; + } + + if (currentCheckPoint != null) { + currentCheckPoint.setFailed(failed); + } else if (currentData != null && elementStack.peek().equals("TestPoint")) { + currentData.setFailed(failed); + } + } + + @Override + public void onStartElement(Object obj) { + } + }); + + handler.getHandler("TestPointName").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentCheckPoint != null) { + currentCheckPoint.setName(obj.toString()); + } + } + + @Override + public void onStartElement(Object obj) { + } + }); + handler.getHandler("Expected").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentCheckPoint != null) { + currentCheckPoint.setExpected(spaceProcessing(obj.toString())); + } + } + + @Override + public void onStartElement(Object obj) { + } + }); + handler.getHandler("Actual").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentCheckPoint != null) { + currentCheckPoint.setActual(spaceProcessing(obj.toString())); + } + } + + @Override + public void onStartElement(Object obj) { + } + }); + handler.getHandler("Number").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentData != null) { + currentData.setNumber(obj.toString()); + } + } + + @Override + public void onStartElement(Object obj) { + } + }); + handler.getHandler("Location").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + if (currentStackTrace != null) { + currentData.setStackTrace(currentStackTrace); + currentStackTrace = null; + } + } + + @Override + public void onStartElement(Object obj) { + if (currentData != null) { + currentStackTrace = new StackTraceCollection(); + } + } + }); + handler.getHandler("Stacktrace").addListener(new IBaseSaxElementListener() { + @Override + public void onEndElement(Object obj) { + } + + @Override + public void onStartElement(Object obj) { + if (currentStackTrace != null) { + currentStackTrace.addTrace((StacktraceData) obj); + } + } + }); + + xmlReader.parse(new InputSource(contents)); + } + + private String spaceProcessing(String expected) { + int index = 0, preCount = 0, postCount = 0; + while (index < expected.length() && expected.charAt(index) == ' ') { + index++; + preCount++; + } + index = expected.length() - 1; + while (index >= 0 && expected.charAt(index) == ' ') { + index--; + postCount++; + } + + expected = expected.trim(); + if (preCount > 0) { + expected = String.format("#sp%d#%s", preCount, expected); + } + if (postCount > 0) { + expected = String.format("%s#sp%d#", expected, postCount); + } + + return expected; + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/StackTraceCollection.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/StackTraceCollection.java new file mode 100644 index 00000000000..fa7287e351b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/StackTraceCollection.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.ote.core.framework.saxparse.elements.StacktraceData; + +/** + * @author Andrew M. Finkbeiner + * + */ +public class StackTraceCollection { + + public List<StacktraceData> data = new ArrayList<StacktraceData>(); + + public void addTrace(StacktraceData obj) { + data.add(obj); + } + + public List<StacktraceData> getStackTrace() { + return data; + } + +} diff --git a/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/TestPointData.java b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/TestPointData.java new file mode 100644 index 00000000000..16347264f9c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui.markers/src/org/eclipse/osee/ote/ui/markers/TestPointData.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.markers; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Andrew M. Finkbeiner + * + */ +public class TestPointData { + + private boolean isFailed; + private List<CheckPointData> data = new ArrayList<CheckPointData>(); + private String number; + private StackTraceCollection stacktrace; + + public boolean isFailed() { + return isFailed; + } + + public void add(CheckPointData checkPoint) { + data.add(checkPoint); + } + + public void setFailed(boolean failed) { + isFailed = failed; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getNumber(){ + return number; + } + + public void setStackTrace(StackTraceCollection currentStackTrace) { + this.stacktrace = currentStackTrace; + } + + public List<CheckPointData> getCheckPointData() { + return data; + } + + public StackTraceCollection getStacktraceCollection() { + return stacktrace; + } +} |