Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2013-01-16 21:32:25 +0000
committerBrian Vosburgh2013-01-17 20:25:14 +0000
commit07ac1ac57fd1bca3c1e9c2ea36a111b79bd50a9b (patch)
treedcae268b7c4a4fe0c969bda35c09417321cce506
parenta134fe095080495f5724fafa36a889cc94faa093 (diff)
downloadwebtools.dali-07ac1ac57fd1bca3c1e9c2ea36a111b79bd50a9b.tar.gz
webtools.dali-07ac1ac57fd1bca3c1e9c2ea36a111b79bd50a9b.tar.xz
webtools.dali-07ac1ac57fd1bca3c1e9c2ea36a111b79bd50a9b.zip
fix IllegalStateException that occurs when validation executes after
Dali plug-ins are stopped
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JptPlugin.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java23
2 files changed, 50 insertions, 25 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JptPlugin.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JptPlugin.java
index 87dabb09da..248030ae1d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JptPlugin.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JptPlugin.java
@@ -42,7 +42,7 @@ import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleReference;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.util.tracker.ServiceTracker;
@@ -71,7 +71,7 @@ import org.osgi.util.tracker.ServiceTracker;
public abstract class JptPlugin
implements BundleActivator
{
- private volatile BundleContext bundleContext;
+ private volatile Bundle bundle;
// NB: the plug-in must be synchronized whenever accessing any of this state
private ExceptionHandler exceptionHandler;
@@ -97,7 +97,7 @@ public abstract class JptPlugin
* <strong>NB:</strong> Most state should be built lazily....
*/
public void start(BundleContext context) throws Exception {
- this.bundleContext = context;
+ this.bundle = context.getBundle();
// make the instance available immediately; although nothing *should*
// retrieve it during start-up, as most state should be populated lazily...
this.setInstance(this);
@@ -824,7 +824,7 @@ public abstract class JptPlugin
/**
* Log the specified message and exception with the specified severity
* and code.
- * If the plug-in has {@link #getBundle() bundle}, log the information
+ * If the plug-in has no {@link #getBundle() bundle}, log the information
* to the appropriate Java system log (instead of the Eclise platform log).
* Return the logged status.
* @see IStatus#getSeverity()
@@ -837,7 +837,7 @@ public abstract class JptPlugin
/**
* Log the specified message and exception with the specified severity
* and code. Bind the message to the specified arguments.
- * If the plug-in has {@link #getBundle() bundle}, log the information
+ * If the plug-in has no {@link #getBundle() bundle}, log the information
* to the appropriate Java system log (instead of the Eclise platform log).
* Return the logged status.
* @see IStatus#getSeverity()
@@ -869,8 +869,8 @@ public abstract class JptPlugin
* @see Platform#getLog(Bundle)
*/
public ILog getLog() {
- Bundle bundle = this.getBundle();
- return (bundle == null) ? null : Platform.getLog(bundle);
+ Bundle b = this.getBundle();
+ return (b == null) ? null : Platform.getLog(b);
}
/**
@@ -1478,11 +1478,15 @@ public abstract class JptPlugin
}
/**
- * @exception RuntimeException if the plug-in's {@link #bundleContext
- * bundle context} is missing or invalid
+ * @exception RuntimeException if the plug-in's
+ * bundle context is missing or invalid
*/
private ServiceTracker<DebugOptions, DebugOptions> buildDebugOptionsTracker_() {
- ServiceTracker<DebugOptions, DebugOptions> tracker = new ServiceTracker<DebugOptions, DebugOptions>(this.bundleContext, DebugOptions.class, null);
+ Bundle b = this.getBundle();
+ if (b == null) {
+ return null;
+ }
+ ServiceTracker<DebugOptions, DebugOptions> tracker = new ServiceTracker<DebugOptions, DebugOptions>(b.getBundleContext(), DebugOptions.class, null);
tracker.open();
return tracker;
}
@@ -1785,7 +1789,7 @@ public abstract class JptPlugin
* Return the plug-in's bundle.
*/
public Bundle getBundle() {
- return (this.bundleContext != null) ? this.bundleContext.getBundle() : this.getBundle_();
+ return (this.bundle != null) ? this.bundle : this.getBundle_();
}
/**
@@ -1793,8 +1797,9 @@ public abstract class JptPlugin
* can still get the bundle from the classloader....
*/
private Bundle getBundle_() {
- ClassLoader cl = this.getClass().getClassLoader();
- return (cl instanceof BundleReference) ? ((BundleReference) cl).getBundle() : null;
+ return FrameworkUtil.getBundle(this.getClass());
+// ClassLoader cl = this.getClass().getClassLoader();
+// return (cl instanceof BundleReference) ? ((BundleReference) cl).getBundle() : null;
}
/**
@@ -1803,8 +1808,8 @@ public abstract class JptPlugin
* @see Bundle#getSymbolicName()
*/
public String getPluginID() {
- Bundle bundle = this.getBundle();
- return (bundle == null) ? null : bundle.getSymbolicName();
+ Bundle b = this.getBundle();
+ return (b == null) ? null : b.getSymbolicName();
}
/**
@@ -1814,8 +1819,8 @@ public abstract class JptPlugin
* Return <code>null</code> if the plug-in has no bundle.
*/
public final String getOriginalPluginID() {
- Bundle bundle = this.getBundle();
- return (bundle == null) ? null : this.getOriginalPluginID_();
+ Bundle b = this.getBundle();
+ return (b == null) ? null : this.getOriginalPluginID_();
}
/**
@@ -1829,7 +1834,7 @@ public abstract class JptPlugin
}
/**
- * Return whether the plug-in is active; i.e. it has been
+ * Return whether the plug-in has a bundle and is active; i.e. it has been
* {@link #start(BundleContext) started}.
* <p>
* <strong>NB:</strong> The plug-in is <em>not</em> active during the
@@ -1840,11 +1845,12 @@ public abstract class JptPlugin
* @see Bundle#ACTIVE
*/
public boolean isActive() {
- return this.getBundle().getState() == Bundle.ACTIVE;
+ Bundle b = this.getBundle();
+ return (b != null) && (b.getState() == Bundle.ACTIVE);
}
/**
- * Return whether the plug-in is inactive; i.e. it has been
+ * Return whether the plug-in has no bundle or is inactive; i.e. it has been
* {@link #stop(BundleContext) stopped} or not yet
* {@link #start(BundleContext) started}.
* <p>
@@ -1869,7 +1875,7 @@ public abstract class JptPlugin
}
/**
- * Return <code>null</code> if the plug-in has no corresponding bundle
+ * Return <code>null</code> if the plug-in has no bundle
* or if the platform is running with no data area (<code>-data @none</code>).
* @see org.eclipse.core.runtime.Plugin#getStateLocation()
* @see Platform#getStateLocation(Bundle)
@@ -1883,8 +1889,8 @@ public abstract class JptPlugin
}
protected IPath getStateLocation_() {
- Bundle bundle = this.getBundle();
- return (bundle == null) ? null : Platform.getStateLocation(bundle);
+ Bundle b = this.getBundle();
+ return (b == null) ? null : Platform.getStateLocation(b);
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
index 6d7a779111..9901792f59 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 Oracle. 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.
@@ -16,6 +16,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable;
import org.eclipse.jpt.jpa.core.JpaPreferences;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.internal.plugin.JptJpaCorePlugin;
@@ -112,7 +113,25 @@ public class JpaValidator
}
private Iterable<IMessage> buildValidationMessages_(IReporter reporter, IProject project) throws InterruptedException {
- return this.getJpaProjectReference(project).buildValidationMessages(reporter);
+ JpaProject.Reference ref = this.getJpaProjectReference(project);
+ return (ref != null) ? ref.buildValidationMessages(reporter) : this.buildValidationFailedMessages(project);
+ }
+
+ /**
+ * This can happen when validation is executed during workbench shutdown
+ * (e.g. when the user "exits and saves")
+ * and the Dali plug-ins have been "stopped" before this validator is invoked.
+ */
+ private Iterable<IMessage> buildValidationFailedMessages(IProject project) {
+ return new SingleElementIterable<IMessage>(this.buildValidationFailedMessage(project));
+ }
+
+ private IMessage buildValidationFailedMessage(IProject project) {
+ return DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.JPA_VALIDATION_FAILED,
+ project
+ );
}
private JpaProject.Reference getJpaProjectReference(IProject project) {

Back to the top