Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 110386 Details for
Bug 167972
EMF Validation standalone Submission
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Standalone support patch against EMF Validation 1.2
standalone.patch (text/plain), 9.85 KB, created by
Horacio Blanco
on 2008-08-19 15:39:04 EDT
(
hide
)
Description:
Standalone support patch against EMF Validation 1.2
Filename:
MIME Type:
Creator:
Horacio Blanco
Created:
2008-08-19 15:39:04 EDT
Size:
9.85 KB
patch
obsolete
>Index: src/org/eclipse/emf/validation/service/ModelValidationService.java >=================================================================== >--- src/org/eclipse/emf/validation/service/ModelValidationService.java (revision 1515) >+++ src/org/eclipse/emf/validation/service/ModelValidationService.java (working copy) >@@ -12,16 +12,28 @@ > > package org.eclipse.emf.validation.service; > >+import java.io.IOException; >+import java.io.InputStream; >+import java.net.URL; >+import java.net.URLClassLoader; > import java.util.ArrayList; > import java.util.Collection; > import java.util.Iterator; > import java.util.List; > import java.util.Map; > >+import org.eclipse.core.internal.registry.RegistryProviderFactory; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IContributor; >+import org.eclipse.core.runtime.IExtensionRegistry; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.RegistryFactory; >+import org.eclipse.core.runtime.spi.IRegistryProvider; >+import org.eclipse.core.runtime.spi.RegistryContributor; >+import org.eclipse.core.runtime.spi.RegistryStrategy; >+import org.eclipse.emf.common.EMFPlugin; > import org.eclipse.emf.ecore.EClass; > import org.eclipse.emf.ecore.EClassifier; > import org.eclipse.emf.ecore.EPackage; >@@ -89,10 +101,69 @@ > private ModelValidationService() { > super(); > >+ configureStandaloneRegistry(); >+ > configureConstraints(); > configureListeners(); > } >+ >+ /** >+ * Sets up the registry when running in stand alone mode. It populates the registry with >+ * every plugin descriptor in the classpath (jar or directory) >+ */ >+ @SuppressWarnings("restriction") >+ private void configureStandaloneRegistry() { >+ if (EMFPlugin.IS_ECLIPSE_RUNNING == false) { >+ // Standalone mode >+ RegistryStrategy strategy = new RegistryStrategy(null, null); >+ final IExtensionRegistry registry = RegistryFactory.createRegistry(strategy, null, null); >+ // Locate all plugins in the path >+ ClassLoader classLoader = ModelValidationService.class.getClassLoader(); >+ if (classLoader instanceof URLClassLoader) { >+ URL[] urls = ((URLClassLoader) classLoader).getURLs(); >+ for (int i = 0; i < urls.length; i++) { >+ String pluginLocation = urls[i].toExternalForm(); >+ if (pluginLocation.endsWith(".jar")) { >+ pluginLocation = "jar:" + pluginLocation + "!/plugin.xml"; >+ } >+ else if (pluginLocation.endsWith("/bin/")){ >+ pluginLocation += "../plugin.xml"; >+ } >+ else { >+ pluginLocation += "plugin.xml"; >+ } >+ try { >+ URL pluginURL = new URL(pluginLocation); >+ InputStream is = pluginURL.openStream(); >+ IContributor contribution = new RegistryContributor(String.valueOf(i), EMFModelValidationPlugin.getPluginId(), >+ null, null); >+ registry.addContribution(is, contribution, false, null, null, null); >+ } >+ catch (IOException io) { >+ // pluginLocation is not valid, ignore >+ } >+ catch (Exception e) { >+ e.printStackTrace(); >+ } >+ } >+ } >+ // Register standalone registry provider >+ IRegistryProvider standaloneProvider = new IRegistryProvider() { > >+ public IExtensionRegistry getRegistry() { >+ return registry; >+ } >+ >+ }; >+ try { >+ RegistryProviderFactory.setDefault(standaloneProvider); >+ } >+ catch (Exception e) { >+ e.printStackTrace(); >+ } >+ } >+ } >+ > /** > * Configures validation constraint providers based on the > * <tt>constraintProviders</tt> extension configurations. >@@ -102,9 +173,9 @@ > Platform.getExtensionRegistry().getConfigurationElementsFor( > EMFModelValidationPlugin.getPluginId(), > EMFModelValidationPlugin.CONSTRAINT_PROVIDERS_EXT_P_NAME); >- >+ > constraintCache = new ConstraintCache(); >- >+ > Collection<IProviderDescriptor> providers = getProviders(); > > // include the cache in my collection of providers >Index: src/org/eclipse/emf/validation/internal/EMFModelValidationPlugin.java >=================================================================== >--- src/org/eclipse/emf/validation/internal/EMFModelValidationPlugin.java (revision 1515) >+++ src/org/eclipse/emf/validation/internal/EMFModelValidationPlugin.java (working copy) >@@ -166,14 +166,14 @@ > new EMFModelValidationPlugin(); > > private static Implementation plugin; >- >+ > /** > * Initializes me. > */ > public EMFModelValidationPlugin() { > super(new ResourceLocator[]{}); > } >- >+ > // implements the inherited method > @Override > public ResourceLocator getPluginResourceLocator() { >@@ -195,7 +195,12 @@ > * @return my plug-in unique ID > */ > public static String getPluginId() { >- return getPlugin().getBundle().getSymbolicName(); >+ if (!EMFPlugin.IS_ECLIPSE_RUNNING) { >+ return "org.eclipse.emf.validation"; >+ } >+ else { >+ return getPlugin().getBundle().getSymbolicName(); >+ } > } > > /** >@@ -229,7 +234,7 @@ > * > */ > protected static boolean shouldTrace() { >- return plugin.isDebugging(); >+ return (!EMFPlugin.IS_ECLIPSE_RUNNING)?false:plugin.isDebugging(); > } > > /** >Index: src/org/eclipse/emf/validation/internal/util/ConstraintsContentHandler.java >=================================================================== >--- src/org/eclipse/emf/validation/internal/util/ConstraintsContentHandler.java (revision 1515) >+++ src/org/eclipse/emf/validation/internal/util/ConstraintsContentHandler.java (working copy) >@@ -31,6 +31,7 @@ > import org.xml.sax.SAXParseException; > import org.xml.sax.helpers.DefaultHandler; > >+import org.eclipse.emf.common.EMFPlugin; > import org.eclipse.emf.validation.internal.EMFModelValidationPlugin; > import org.eclipse.emf.validation.internal.EMFModelValidationStatusCodes; > >@@ -529,6 +530,10 @@ > if ((s == null) || !s.startsWith("%")) { //$NON-NLS-1$ > return s; > } else if (resourceBundle == null) { >+ // FIXME Localize in standalone mode >+ if (!EMFPlugin.IS_ECLIPSE_RUNNING) { >+ return s; >+ } > return Platform.getResourceString( > Platform.getBundle(extension.getNamespaceIdentifier()), > s); >Index: src/org/eclipse/emf/validation/internal/util/Log.java >=================================================================== >--- src/org/eclipse/emf/validation/internal/util/Log.java (revision 1515) >+++ src/org/eclipse/emf/validation/internal/util/Log.java (working copy) >@@ -16,6 +16,7 @@ > > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.common.EMFPlugin; > import org.eclipse.emf.validation.internal.EMFModelValidationPlugin; > > /** >@@ -141,8 +142,17 @@ > > Status s = new Status(severity, EMFModelValidationPlugin.getPluginId(), > code, message, throwable); >- >- EMFModelValidationPlugin.getPlugin().log(s); >+ if (!EMFPlugin.IS_ECLIPSE_RUNNING) { >+ if (s.isOK()) { >+ System.out.println(s); >+ } >+ else { >+ System.err.println(s); >+ } >+ } >+ else { >+ EMFModelValidationPlugin.getPlugin().log(s); >+ } > } > > /** >@@ -154,7 +164,17 @@ > * @param status The status object on which to base the log. > */ > public static void log(IStatus status) { >- EMFModelValidationPlugin.getPlugin().log(status); >+ if (!EMFPlugin.IS_ECLIPSE_RUNNING) { >+ if (status.isOK()) { >+ System.out.println(status); >+ } >+ else { >+ System.err.println(status); >+ } >+ } >+ else { >+ EMFModelValidationPlugin.getPlugin().log(status); >+ } > } > > /** >Index: src/org/eclipse/emf/validation/internal/util/JavaConstraintParser.java >=================================================================== >--- src/org/eclipse/emf/validation/internal/util/JavaConstraintParser.java (revision 1515) >+++ src/org/eclipse/emf/validation/internal/util/JavaConstraintParser.java (working copy) >@@ -157,8 +157,13 @@ > Bundle bundle = Platform.getBundle(bundleName); > > try { >- Class<?> resultType = bundle.loadClass(className); >- >+ Class<?> resultType = null; >+ if (bundle == null) { >+ resultType = this.getClass().getClassLoader().loadClass(className); >+ } >+ else { >+ resultType = bundle.loadClass(className); >+ } > if (AbstractModelConstraint.class.isAssignableFrom(resultType)) { > // instantiate the class extending AbstractModelConstraint > result = new ConstraintAdapter( >Index: src/org/eclipse/emf/validation/preferences/EMFModelValidationPreferences.java >=================================================================== >--- src/org/eclipse/emf/validation/preferences/EMFModelValidationPreferences.java (revision 1515) >+++ src/org/eclipse/emf/validation/preferences/EMFModelValidationPreferences.java (working copy) >@@ -14,6 +14,7 @@ > > import org.eclipse.core.runtime.Preferences; > >+import org.eclipse.emf.common.EMFPlugin; > import org.eclipse.emf.validation.internal.EMFModelValidationPlugin; > import org.eclipse.emf.validation.service.ConstraintRegistry; > import org.eclipse.emf.validation.service.IConstraintDescriptor; >@@ -27,7 +28,7 @@ > static final String CONSTRAINT_DISABLED_PREFIX = "con.disabled/"; //$NON-NLS-1$ > > private static final Preferences prefs = >- EMFModelValidationPlugin.getPlugin().getPluginPreferences(); >+ (!EMFPlugin.IS_ECLIPSE_RUNNING)?new Preferences():EMFModelValidationPlugin.getPlugin().getPluginPreferences(); > > /** > * Not instantiable, as all features are static.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 167972
:
55617
|
55618
|
71491
|
110276
| 110386