Commit 5249c9bc authored by Martti Käärik's avatar Martti Käärik
Browse files

enabled OCL validation + Workaround for Complete OCL validator initializer...

enabled OCL validation + Workaround for Complete OCL validator initializer configurator issue (see comment in code)
parent 1196c1ac
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -2,12 +2,20 @@ package org.etsi.mts.tdl;

import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.internal.utilities.EnvironmentFactoryInternal;
import org.eclipse.ocl.pivot.resource.CSResource;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.ocl.xtext.completeocl.validation.CompleteOCLEObjectValidator;
import org.etsi.mts.tdl.extendedconfigurations.ExtendedConfigurationsPackage;
import org.etsi.mts.tdl.structuredobjectives.StructuredObjectivesPackage;
@@ -19,10 +27,9 @@ public class Activator implements BundleActivator {
	@Override
	public void start(BundleContext context) throws Exception {

		// TODO disabled for now
//		registerValidator("model/tdl-structured-constraints.ocl", StructuredObjectivesPackage.eINSTANCE, context);
//		registerValidator("model/tdl-configurations-constraints.ocl", ExtendedConfigurationsPackage.eINSTANCE, context);
//		registerValidator("model/tdl-constraints.ocl", tdlPackage.eINSTANCE, context);
		registerValidator("model/tdl-constraints.ocl", tdlPackage.eINSTANCE, context);

	}

@@ -34,7 +41,25 @@ public class Activator implements BundleActivator {
		URI oclURI;
		try {
			oclURI = URI.createURI(oclURL.toURI().toString());
			CompleteOCLEObjectValidator validator = new CompleteOCLEObjectValidator(ePakcage, oclURI);
			CompleteOCLEObjectValidator validator = new CompleteOCLEObjectValidator(ePakcage, oclURI) {
				@Override
				public boolean initialize(@NonNull EnvironmentFactoryInternal environmentFactory) {
					boolean success = super.initialize(environmentFactory);
					if (success) {
						// This should happen in super.initialize(..) but under certain conditions it returns early
						ResourceSet resourceSet = environmentFactory.getResourceSet();
						CSResource xtextResource = (CSResource) resourceSet.getResource(oclURI, true);
						EList<Diagnostic> errors = xtextResource.getErrors();
						assert errors != null;
						String message = PivotUtil.formatResourceDiagnostics(errors, "", "\n");
						if (message != null) {
							System.err.println("Failed to load '" + oclURI + message);
							return false;
						}
					}
					return success;
				}
			};
			EValidator.Registry.INSTANCE.put(tdlPackage.eINSTANCE, validator);
		} catch (URISyntaxException e) {
			throw new RuntimeException(e);