Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-12-21 15:29:19 -0500
committerpelder2007-12-21 15:29:19 -0500
commit36e54e0479983b001954befbba3772f2f7a14de1 (patch)
tree9e0ff1e41fc3c51541227374001a19f9b8876f3a
parent1ae2768a7d3609e1d4b911a34e5e0882c2f0535d (diff)
downloadorg.eclipse.jet-36e54e0479983b001954befbba3772f2f7a14de1.tar.gz
org.eclipse.jet-36e54e0479983b001954befbba3772f2f7a14de1.tar.xz
org.eclipse.jet-36e54e0479983b001954befbba3772f2f7a14de1.zip
[213728] Improve logging of exceptions that have nested causes
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/ContextLogEntry.java9
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/ContextLogEntryFactoryManager.java54
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/DefaultContextLogEntryFactory.java24
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/IContextLogEntryFactory.java23
-rw-r--r--plugins/org.eclipse.jet/plugin.xml17
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/ContextLogEntryAdapterFactory.java87
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/EquinoxContextLogEntryFactory.java43
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/emf/ContextLogEntryAdapterFactory.java90
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java27
10 files changed, 371 insertions, 7 deletions
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/ContextLogEntry.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/ContextLogEntry.java
index 91f71a5..baed232 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/ContextLogEntry.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/ContextLogEntry.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
*/
package org.eclipse.jet;
+import org.eclipse.jet.internal.core.ContextLogEntryFactoryManager;
import org.eclipse.jet.taglib.TagInfo;
/**
@@ -214,17 +215,15 @@ public final class ContextLogEntry {
* @param builder
*/
private ContextLogEntry(Builder builder) {
- // TODO Auto-generated constructor stub
this.severity = builder.severity;
if(builder.children.length > 0) {
this.children = new ContextLogEntry[builder.children.length];
System.arraycopy(builder.children, 0, this.children, 0, builder.children.length);
} else if(builder.exception != null && builder.exception.getCause() != null) {
- ContextLogEntry.Builder childEntryBuilder = new ContextLogEntry.Builder(builder.getSeverity());
- childEntryBuilder.exception(builder.exception.getCause());
- this.children = new ContextLogEntry[] {childEntryBuilder.build()};
-
+ final ContextLogEntry childEntry = ContextLogEntryFactoryManager
+ .getFactory().create(builder.exception.getCause());
+ this.children = new ContextLogEntry[] {childEntry};
} else {
children = EMPTY_ENTRIES_ARRAY;
}
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/ContextLogEntryFactoryManager.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/ContextLogEntryFactoryManager.java
new file mode 100644
index 0000000..f87d33e
--- /dev/null
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/ContextLogEntryFactoryManager.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.internal.core;
+
+/**
+ * Manager for the {@link IContextLogEntryFactory}. This class allows the replacement of the
+ * default context log entry factory with a factory more tighly adapted to the execution enviornment.
+ * <p>
+ * This manager is type safe.
+ * </p>
+ *
+ */
+public class ContextLogEntryFactoryManager {
+
+ private static IContextLogEntryFactory factory = new DefaultContextLogEntryFactory();
+
+ /**
+ * Prevent instantiation
+ */
+ private ContextLogEntryFactoryManager() {
+ // do nothing
+ }
+
+ /**
+ * Return the context log entry factory
+ * @return on instance of {@link IContextLogEntryFactory}. Will not be <code>null</code>.
+ */
+ public static synchronized IContextLogEntryFactory getFactory() {
+ return factory;
+ }
+
+ /**
+ * Set the context log entry factory
+ * @param factory an implementation of {@link IContextLogEntryFactory}. Cannot be <code>null</code>.
+ * @throws NullPointerException if <code>factory</code> is <code>null</code>
+ */
+ public static synchronized void setFactory(IContextLogEntryFactory factory) {
+ if(factory == null) {
+ throw new NullPointerException();
+ }
+ ContextLogEntryFactoryManager.factory = factory;
+ }
+
+
+
+}
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/DefaultContextLogEntryFactory.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/DefaultContextLogEntryFactory.java
new file mode 100644
index 0000000..16e45cd
--- /dev/null
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/DefaultContextLogEntryFactory.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.internal.core;
+
+import org.eclipse.jet.ContextLogEntry;
+
+/**
+ * A default implementation of {@link IContextLogEntryFactory} that is independent of OSGi and Eclipse.
+ *
+ */
+public class DefaultContextLogEntryFactory implements IContextLogEntryFactory {
+
+ public ContextLogEntry create(Throwable t) {
+ return new ContextLogEntry.Builder(ContextLogEntry.ERROR).exception(t).build();
+ }
+}
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/IContextLogEntryFactory.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/IContextLogEntryFactory.java
new file mode 100644
index 0000000..2e84997
--- /dev/null
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/IContextLogEntryFactory.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.internal.core;
+
+import org.eclipse.jet.ContextLogEntry;
+
+/**
+ * Define protocol for a factory that creates {@link ContextLogEntry} elements from an Exception
+ *
+ */
+public interface IContextLogEntryFactory {
+
+ ContextLogEntry create(Throwable t);
+
+}
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index b44d4f0..4a724e0 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1203,6 +1203,23 @@ if 'length' is specified, convert only the specified number of characters, other
</run>
</runtime>
</extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.core.runtime.CoreException"
+ class="org.eclipse.jet.internal.core.equinox.ContextLogEntryAdapterFactory">
+ <adapter
+ type="org.eclipse.jet.ContextLogEntry">
+ </adapter>
+ </factory>
+ <factory
+ adaptableType="org.eclipse.emf.common.util.DiagnosticException"
+ class="org.eclipse.jet.internal.core.equinox.emf.ContextLogEntryAdapterFactory">
+ <adapter
+ type="org.eclipse.jet.ContextLogEntry">
+ </adapter>
+ </factory>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
index 6f0f29a..a9b89a8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/InternalJET2Platform.java
@@ -20,9 +20,12 @@ package org.eclipse.jet.internal;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.internal.core.ContextLogEntryFactoryManager;
+import org.eclipse.jet.internal.core.equinox.EquinoxContextLogEntryFactory;
import org.eclipse.jet.internal.extensionpoints.ModelInspectorsManager;
import org.eclipse.jet.internal.extensionpoints.ModelLoaderExtManager;
import org.eclipse.jet.internal.extensionpoints.PluginProjectMonitor;
@@ -262,6 +265,7 @@ public class InternalJET2Platform extends EMFPlugin.EclipsePlugin
savedStateManager = new SavedStateManager(this);
savedStateManager.startup();
+ ContextLogEntryFactoryManager.setFactory(new EquinoxContextLogEntryFactory(Platform.getAdapterManager()));
}
/**
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/ContextLogEntryAdapterFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/ContextLogEntryAdapterFactory.java
new file mode 100644
index 0000000..e76cd4d
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/ContextLogEntryAdapterFactory.java
@@ -0,0 +1,87 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ContextLogEntryAdapterFactory.java,v 1.1 2007/12/21 20:29:19 pelder Exp $
+ */
+package org.eclipse.jet.internal.core.equinox;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jet.ContextLogEntry;
+
+/**
+ * Adapter factory that creates a {@link ContextLogEntry} for a CoreException
+ */
+public class ContextLogEntryAdapterFactory implements IAdapterFactory
+{
+
+ private static final Class[] adapterList = new Class[] {
+ ContextLogEntry.class,
+ };
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ public Object getAdapter(Object adaptableObject, Class adapterType)
+ {
+ if(!(adaptableObject instanceof CoreException)
+ || !ContextLogEntry.class.equals(adapterType)) {
+ throw new IllegalArgumentException();
+ }
+ final CoreException ex = (CoreException)adaptableObject;
+ return buildLogEntry(ex.getStatus());
+ }
+
+ /**
+ * @param status
+ * @return
+ */
+ private ContextLogEntry buildLogEntry(IStatus status)
+ {
+ final ContextLogEntry.Builder builder;
+ if(status.isMultiStatus()) {
+ final IStatus[] childStatus = status.getChildren();
+ ContextLogEntry[] childEntries = new ContextLogEntry[childStatus.length];
+ for (int i = 0; i < childStatus.length; i++)
+ {
+ childEntries[i] = buildLogEntry(childStatus[i]);
+ }
+ builder = new ContextLogEntry.Builder(childEntries);
+ } else {
+ builder = new ContextLogEntry.Builder(ContextLogEntry.ERROR);
+ }
+ final String message = status.getMessage();
+ final Throwable exception = status.getException();
+ if(exception != null) {
+ builder.exception(exception);
+ }
+ if(message != null && message.length() >= 0) {
+ builder.message(message);
+ }
+ else if(exception != null ) {
+ builder.message(exception.toString());
+ }
+ return builder.build();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ public Class[] getAdapterList()
+ {
+ return adapterList;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/EquinoxContextLogEntryFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/EquinoxContextLogEntryFactory.java
new file mode 100644
index 0000000..99a2c68
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/EquinoxContextLogEntryFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.internal.core.equinox;
+
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.jet.ContextLogEntry;
+import org.eclipse.jet.internal.core.DefaultContextLogEntryFactory;
+import org.eclipse.jet.internal.core.IContextLogEntryFactory;
+
+/**
+ * An implementatino of {@link IContextLogEntryFactory} that is Equinox (OSGi) aware. In particular, it
+ * makes use of the Equinox IAdaptable interfaces.
+ *
+ */
+public class EquinoxContextLogEntryFactory implements IContextLogEntryFactory {
+
+ private final IAdapterManager adapterManager;
+ private IContextLogEntryFactory defaultContextLogEntryFactory;
+
+ public EquinoxContextLogEntryFactory(IAdapterManager adapterManager) {
+ this.adapterManager = adapterManager;
+ this.defaultContextLogEntryFactory = new DefaultContextLogEntryFactory();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.core.IContextLogEntryFactory#create(java.lang.Throwable)
+ */
+ public ContextLogEntry create(Throwable t) {
+ // TODO Auto-generated method stub
+ final Object adapter = adapterManager.getAdapter(t, ContextLogEntry.class);
+
+ return adapter != null ? (ContextLogEntry)adapter : defaultContextLogEntryFactory.create(t);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/emf/ContextLogEntryAdapterFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/emf/ContextLogEntryAdapterFactory.java
new file mode 100644
index 0000000..de130ad
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/core/equinox/emf/ContextLogEntryAdapterFactory.java
@@ -0,0 +1,90 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ContextLogEntryAdapterFactory.java,v 1.1 2007/12/21 20:29:19 pelder Exp $
+ */
+package org.eclipse.jet.internal.core.equinox.emf;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.DiagnosticException;
+import org.eclipse.jet.ContextLogEntry;
+
+/**
+ * @author pelder
+ */
+public class ContextLogEntryAdapterFactory implements IAdapterFactory
+{
+
+ private static final Class[] adapterList = new Class[] {
+ ContextLogEntry.class,
+ };
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ public Object getAdapter(Object adaptableObject, Class adapterType)
+ {
+ if(!(adaptableObject instanceof DiagnosticException)
+ || !ContextLogEntry.class.equals(adapterType)) {
+ throw new IllegalArgumentException();
+ }
+ final DiagnosticException ex = (DiagnosticException)adaptableObject;
+ return buildLogEntry(ex.getDiagnostic());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ public Class[] getAdapterList()
+ {
+ return adapterList;
+ }
+
+ /**
+ * @param diagnostic
+ * @return
+ */
+ private ContextLogEntry buildLogEntry(Diagnostic diagnostic)
+ {
+ final ContextLogEntry.Builder builder;
+ if(diagnostic.getChildren().size() > 0) {
+ final List childDiagnostic = diagnostic.getChildren();
+ ContextLogEntry[] childEntries = new ContextLogEntry[childDiagnostic.size()];
+ for (int i = 0; i < childDiagnostic.size(); i++)
+ {
+ childEntries[i] = buildLogEntry((Diagnostic)childDiagnostic.get(i));
+ }
+ builder = new ContextLogEntry.Builder(childEntries);
+ } else {
+ builder = new ContextLogEntry.Builder(ContextLogEntry.ERROR);
+ }
+ final String message = diagnostic.getMessage();
+ final Throwable exception = diagnostic.getException();
+ if(exception != null) {
+ builder.exception(exception);
+ }
+ if(message != null && message.length() >= 0) {
+ builder.message(message);
+ }
+ else if(exception != null ) {
+ builder.message(exception.toString());
+ }
+ return builder.build();
+ }
+
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
index c0fd4c8..2fe7d2b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/RuntimeLoggerContextExtender.java
@@ -17,7 +17,6 @@ package org.eclipse.jet.internal.runtime;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.jet.ContextLogEntry;
@@ -103,7 +102,31 @@ public final class RuntimeLoggerContextExtender
public void log(ContextLogEntry entry)
{
- state.log(entry.getMessage(), entry.getTagInfo(), entry.getTemplatePath(), getLevel(entry.getSeverity()));
+ StringBuffer logMessage = new StringBuffer(entry.getMessage());
+ final ContextLogEntry[] children = entry.getChildren();
+ for (int i = 0; i < children.length; i++)
+ {
+ appendChildMessage(logMessage, children[i], 1);
+ }
+ state.log(logMessage.toString(), entry.getTagInfo(), entry.getTemplatePath(), getLevel(entry.getSeverity()));
+ }
+
+ private void appendChildMessage(StringBuffer logMessage, ContextLogEntry entry, int depth)
+ {
+ if(logMessage.charAt(logMessage.length() - 1) != '\n') {
+ logMessage.append('\n');
+ }
+ for (int i = 0; i < depth; i++)
+ {
+ logMessage.append('\t');
+ }
+ logMessage.append(entry.getMessage());
+ final ContextLogEntry[] children = entry.getChildren();
+ for (int i = 0; i < children.length; i++)
+ {
+ appendChildMessage(logMessage, children[i], depth + 1);
+ }
+
}
private int getLevel(int severity)

Back to the top