Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 167972 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/validation/service/ModelValidationService.java (-2 / +73 lines)
Lines 12-27 Link Here
12
12
13
package org.eclipse.emf.validation.service;
13
package org.eclipse.emf.validation.service;
14
14
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.net.URL;
18
import java.net.URLClassLoader;
15
import java.util.ArrayList;
19
import java.util.ArrayList;
16
import java.util.Collection;
20
import java.util.Collection;
17
import java.util.Iterator;
21
import java.util.Iterator;
18
import java.util.List;
22
import java.util.List;
19
import java.util.Map;
23
import java.util.Map;
20
24
25
import org.eclipse.core.internal.registry.RegistryProviderFactory;
21
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.IConfigurationElement;
28
import org.eclipse.core.runtime.IContributor;
29
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.core.runtime.RegistryFactory;
33
import org.eclipse.core.runtime.spi.IRegistryProvider;
34
import org.eclipse.core.runtime.spi.RegistryContributor;
35
import org.eclipse.core.runtime.spi.RegistryStrategy;
36
import org.eclipse.emf.common.EMFPlugin;
25
import org.eclipse.emf.ecore.EClass;
37
import org.eclipse.emf.ecore.EClass;
26
import org.eclipse.emf.ecore.EClassifier;
38
import org.eclipse.emf.ecore.EClassifier;
27
import org.eclipse.emf.ecore.EPackage;
39
import org.eclipse.emf.ecore.EPackage;
Lines 89-98 Link Here
89
	private ModelValidationService() {
101
	private ModelValidationService() {
90
		super();
102
		super();
91
		
103
		
104
		configureStandaloneRegistry();
105
		
92
		configureConstraints();
106
		configureConstraints();
93
		configureListeners();
107
		configureListeners();
94
	}
108
	}
109
	
110
	/**
111
     * Sets up the registry when running in stand alone mode. It populates the registry with 
112
     * every plugin descriptor in the classpath (jar or directory)
113
     */
114
    @SuppressWarnings("restriction")
115
	private void configureStandaloneRegistry() {
116
        if (EMFPlugin.IS_ECLIPSE_RUNNING == false) {
117
            // Standalone mode
118
            RegistryStrategy strategy = new RegistryStrategy(null, null);
119
            final IExtensionRegistry registry = RegistryFactory.createRegistry(strategy, null, null);
120
            // Locate all plugins in the path
121
            ClassLoader classLoader = ModelValidationService.class.getClassLoader();
122
            if (classLoader instanceof URLClassLoader) {
123
                URL[] urls = ((URLClassLoader) classLoader).getURLs();
124
                for (int i = 0; i < urls.length; i++) {
125
                    String pluginLocation = urls[i].toExternalForm();
126
                    if (pluginLocation.endsWith(".jar")) {
127
                        pluginLocation = "jar:" + pluginLocation + "!/plugin.xml";
128
                    }
129
                    else if (pluginLocation.endsWith("/bin/")){
130
                        pluginLocation += "../plugin.xml";
131
                    }
132
                    else {
133
                        pluginLocation += "plugin.xml";
134
                    }
135
                    try {
136
                        URL pluginURL = new URL(pluginLocation);
137
                        InputStream is = pluginURL.openStream();
138
                        IContributor contribution = new RegistryContributor(String.valueOf(i), EMFModelValidationPlugin.getPluginId(),
139
                                null, null);
140
                        registry.addContribution(is, contribution, false, null, null, null);
141
                    } 
142
                    catch (IOException io) {
143
                        // pluginLocation is not valid, ignore
144
                    }
145
                    catch (Exception e) {
146
                        e.printStackTrace();
147
                    }
148
                }
149
            }
150
            // Register standalone registry provider
151
            IRegistryProvider standaloneProvider = new IRegistryProvider() {
95
152
153
				public IExtensionRegistry getRegistry() {
154
					return registry;
155
				}
156
            	
157
            };
158
            try {
159
            	RegistryProviderFactory.setDefault(standaloneProvider);
160
            }
161
            catch (Exception e) {
162
            	e.printStackTrace();
163
            }
164
        }
165
    }
166
96
    /**
167
    /**
97
     * Configures validation constraint providers based on the
168
     * Configures validation constraint providers based on the
98
     * <tt>constraintProviders</tt> extension configurations.
169
     * <tt>constraintProviders</tt> extension configurations.
Lines 102-110 Link Here
102
            Platform.getExtensionRegistry().getConfigurationElementsFor(
173
            Platform.getExtensionRegistry().getConfigurationElementsFor(
103
                EMFModelValidationPlugin.getPluginId(),
174
                EMFModelValidationPlugin.getPluginId(),
104
                EMFModelValidationPlugin.CONSTRAINT_PROVIDERS_EXT_P_NAME);
175
                EMFModelValidationPlugin.CONSTRAINT_PROVIDERS_EXT_P_NAME);
105
        
176
106
        constraintCache = new ConstraintCache();
177
        constraintCache = new ConstraintCache();
107
        
178
               
108
        Collection<IProviderDescriptor> providers = getProviders();
179
        Collection<IProviderDescriptor> providers = getProviders();
109
180
110
        // include the cache in my collection of providers
181
        // include the cache in my collection of providers
(-)src/org/eclipse/emf/validation/internal/EMFModelValidationPlugin.java (-4 / +9 lines)
Lines 166-179 Link Here
166
		new EMFModelValidationPlugin();
166
		new EMFModelValidationPlugin();
167
167
168
	private static Implementation plugin;
168
	private static Implementation plugin;
169
169
	
170
	/**
170
	/**
171
	 * Initializes me.
171
	 * Initializes me.
172
	 */
172
	 */
173
	public EMFModelValidationPlugin() {
173
	public EMFModelValidationPlugin() {
174
		super(new ResourceLocator[]{});
174
		super(new ResourceLocator[]{});
175
	}
175
	}
176
176
	
177
	// implements the inherited method
177
	// implements the inherited method
178
	@Override
178
	@Override
179
	public ResourceLocator getPluginResourceLocator() {
179
	public ResourceLocator getPluginResourceLocator() {
Lines 195-201 Link Here
195
	 * @return my plug-in unique ID
195
	 * @return my plug-in unique ID
196
	 */
196
	 */
197
	public static String getPluginId() {
197
	public static String getPluginId() {
198
		return getPlugin().getBundle().getSymbolicName();
198
		if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
199
			return "org.eclipse.emf.validation";
200
		}
201
		else {
202
			return getPlugin().getBundle().getSymbolicName();
203
		}
199
	}
204
	}
200
205
201
	/**
206
	/**
Lines 229-235 Link Here
229
    	 * 
234
    	 * 
230
    	 */
235
    	 */
231
    	protected static boolean shouldTrace() {
236
    	protected static boolean shouldTrace() {
232
    		return plugin.isDebugging();
237
    		return (!EMFPlugin.IS_ECLIPSE_RUNNING)?false:plugin.isDebugging();
233
    	}
238
    	}
234
239
235
    	/**
240
    	/**
(-)src/org/eclipse/emf/validation/internal/util/ConstraintsContentHandler.java (+5 lines)
Lines 31-36 Link Here
31
import org.xml.sax.SAXParseException;
31
import org.xml.sax.SAXParseException;
32
import org.xml.sax.helpers.DefaultHandler;
32
import org.xml.sax.helpers.DefaultHandler;
33
33
34
import org.eclipse.emf.common.EMFPlugin;
34
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
35
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
35
import org.eclipse.emf.validation.internal.EMFModelValidationStatusCodes;
36
import org.eclipse.emf.validation.internal.EMFModelValidationStatusCodes;
36
37
Lines 529-534 Link Here
529
		if ((s == null) || !s.startsWith("%")) { //$NON-NLS-1$
530
		if ((s == null) || !s.startsWith("%")) { //$NON-NLS-1$
530
			return s;
531
			return s;
531
		} else if (resourceBundle == null) {
532
		} else if (resourceBundle == null) {
533
			// FIXME Localize in standalone mode           
534
			if (!EMFPlugin.IS_ECLIPSE_RUNNING) {                
535
				return s;               
536
			}     			
532
			return Platform.getResourceString(
537
			return Platform.getResourceString(
533
					Platform.getBundle(extension.getNamespaceIdentifier()),
538
					Platform.getBundle(extension.getNamespaceIdentifier()),
534
					s);
539
					s);
(-)src/org/eclipse/emf/validation/internal/util/Log.java (-3 / +23 lines)
Lines 16-21 Link Here
16
16
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.emf.common.EMFPlugin;
19
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
20
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
20
21
21
/**
22
/**
Lines 141-148 Link Here
141
		
142
		
142
		Status s = new Status(severity, EMFModelValidationPlugin.getPluginId(),
143
		Status s = new Status(severity, EMFModelValidationPlugin.getPluginId(),
143
			code, message, throwable);
144
			code, message, throwable);
144
145
		if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
145
		EMFModelValidationPlugin.getPlugin().log(s);
146
			if (s.isOK()) {
147
				System.out.println(s);
148
			}
149
			else {
150
				System.err.println(s);
151
			}			
152
		}
153
		else {
154
			EMFModelValidationPlugin.getPlugin().log(s);
155
		}
146
	}
156
	}
147
157
148
	/**
158
	/**
Lines 154-160 Link Here
154
	 * @param status The status object on which to base the log.
164
	 * @param status The status object on which to base the log.
155
	 */
165
	 */
156
	public static void log(IStatus status) {
166
	public static void log(IStatus status) {
157
		EMFModelValidationPlugin.getPlugin().log(status);
167
		if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
168
			if (status.isOK()) {
169
				System.out.println(status);
170
			}
171
			else {
172
				System.err.println(status);
173
			}						
174
		}
175
		else {
176
			EMFModelValidationPlugin.getPlugin().log(status);
177
		}
158
	}
178
	}
159
179
160
	/**
180
	/**
(-)src/org/eclipse/emf/validation/internal/util/JavaConstraintParser.java (-2 / +7 lines)
Lines 157-164 Link Here
157
		Bundle bundle = Platform.getBundle(bundleName);
157
		Bundle bundle = Platform.getBundle(bundleName);
158
		
158
		
159
		try {
159
		try {
160
			Class<?> resultType = bundle.loadClass(className);
160
			Class<?> resultType = null;
161
161
			if (bundle == null) {
162
				resultType = this.getClass().getClassLoader().loadClass(className);
163
			}
164
			else {
165
				resultType = bundle.loadClass(className);
166
			}			
162
			if (AbstractModelConstraint.class.isAssignableFrom(resultType)) {
167
			if (AbstractModelConstraint.class.isAssignableFrom(resultType)) {
163
				// instantiate the class extending AbstractModelConstraint
168
				// instantiate the class extending AbstractModelConstraint
164
				result = new ConstraintAdapter(
169
				result = new ConstraintAdapter(
(-)src/org/eclipse/emf/validation/preferences/EMFModelValidationPreferences.java (-1 / +2 lines)
Lines 14-19 Link Here
14
14
15
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.core.runtime.Preferences;
16
16
17
import org.eclipse.emf.common.EMFPlugin;
17
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
18
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
18
import org.eclipse.emf.validation.service.ConstraintRegistry;
19
import org.eclipse.emf.validation.service.ConstraintRegistry;
19
import org.eclipse.emf.validation.service.IConstraintDescriptor;
20
import org.eclipse.emf.validation.service.IConstraintDescriptor;
Lines 27-33 Link Here
27
	static final String CONSTRAINT_DISABLED_PREFIX = "con.disabled/"; //$NON-NLS-1$
28
	static final String CONSTRAINT_DISABLED_PREFIX = "con.disabled/"; //$NON-NLS-1$
28
	
29
	
29
	private static final Preferences prefs =
30
	private static final Preferences prefs =
30
		EMFModelValidationPlugin.getPlugin().getPluginPreferences();
31
		(!EMFPlugin.IS_ECLIPSE_RUNNING)?new Preferences():EMFModelValidationPlugin.getPlugin().getPluginPreferences();
31
	
32
	
32
	/**
33
	/**
33
	 * Not instantiable, as all features are static.
34
	 * Not instantiable, as all features are static.

Return to bug 167972