@Override protected void tearDown() throws Exception { if (metaModelManager != null) { metaModelManager.dispose(); metaModelManager = null; } StandardLibraryContribution.REGISTRY.remove(MetaModelManager.DEFAULT_OCL_STDLIB_URI); super.tearDown(); }
public void invokeInternal(WorkflowContext ctx, ProgressMonitor arg1, Issues arg2) { OCLstdlib.install(); Resource resource = (Resource) ctx.get(getUmlSlot()); log.info("Pivoting '" + resource.getURI() + "'"); MetaModelManager metaModelManager = MetaModelManager.getAdapter(resource.getResourceSet()); UML2Ecore2Pivot uml2pivot = UML2Ecore2Pivot.getAdapter(resource, metaModelManager); org.eclipse.ocl.examples.pivot.Package root = uml2pivot.getPivotRoot(); Resource resource2 = root.eResource(); ctx.set(getModelSlot(), resource2); }
public static ExpressionInOcl resolveMessage( MetaModelManager metaModelManager, URI uri, ExpressionInOcl specification, String expression) throws ParserException { try { Resource resource = createXtextResource(metaModelManager, uri, specification, expression); checkResourceErrors(NLS.bind(OCLMessages.ErrorsInResource, expression), resource); return getExpressionInOcl(resource); } catch (IOException e) { // throw new ParserException("Failed to load expression", e); OclExpression invalidValueBody = metaModelManager.createInvalidExpression(); specification.setBodyExpression(invalidValueBody); return specification; } }
public static ExpressionInOcl resolveSpecification( MetaModelManager metaModelManager, URI uri, NamedElement contextClassifier, String expression) throws ParserException { Resource resource = null; try { resource = createXtextResource(metaModelManager, uri, contextClassifier, expression); checkResourceErrors(NLS.bind(OCLMessages.ErrorsInResource, expression), resource); return getExpressionInOcl(resource); } catch (IOException e) { // throw new ParserException("Failed to load expression", e); ExpressionInOcl specification = PivotFactory.eINSTANCE.createExpressionInOcl(); OclExpression invalidValueBody = metaModelManager.createInvalidExpression(); specification.setBodyExpression(invalidValueBody); return specification; } finally { if (resource != null) { MetaModelManagerResourceAdapter adapter = MetaModelManagerResourceAdapter.findAdapter(resource); if (adapter != null) { adapter.dispose(); } } } }
public void testBug370824() throws Exception { if (EMFPlugin.IS_ECLIPSE_RUNNING) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject("org.eclipse.ocl.examples.xtext.tests"); if (!project.exists()) { project.create(null); } } metaModelManager = new MetaModelManager(); String oclinecoreFile = "package bug370824 : bug370824 = 'http://bug370824'\n" + "{\n" + " class Clase1\n" + " {\n" + " invariant : self.name.size() > 0;\n" + " attribute name : String[?] { ordered };\n" + " }\n" + "}\n"; createEcoreFile(metaModelManager, "Bug370824", oclinecoreFile); String genmodelFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<genmodel:GenModel xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\"\n" + " xmlns:genmodel=\"http://www.eclipse.org/emf/2002/GenModel\" modelDirectory=\"/org.eclipse.ocl.examples.xtext.tests/src-gen\" modelPluginID=\"org.eclipse.ocl.examples.xtext.tests.bug370824\"\n" + " modelName=\"Bug370824\" importerID=\"org.eclipse.emf.importer.ecore\" complianceLevel=\"5.0\"\n" + " copyrightFields=\"false\">\n" + " <foreignModel>Bug370824.ecore</foreignModel>\n" + " <genPackages prefix=\"Bug370824\" disposableProviderFactory=\"true\" ecorePackage=\"Bug370824.ecore#/\">\n" + " </genPackages>\n" + "</genmodel:GenModel>\n" + "\n"; createGenModelFile("Bug370824.genmodel", genmodelFile); GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor( GenModelPackage.eNS_URI, OCLGeneratorAdapterFactory.DESCRIPTOR); URI fileURI = getProjectFileURI("Bug370824.genmodel"); // System.out.println("Generating Ecore Model using '" + fileURI + "'"); metaModelManager.dispose(); metaModelManager = new MetaModelManager(); ResourceSet resourceSet = metaModelManager.getExternalResourceSet(); resourceSet.getPackageRegistry().put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE); resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put("genmodel", new EcoreResourceFactoryImpl()); GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor( GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR); GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor( GenModelPackage.eNS_URI, OCLGeneratorAdapterFactory.DESCRIPTOR); if (resourceSet instanceof ResourceSetImpl) { ResourceSetImpl resourceSetImpl = (ResourceSetImpl) resourceSet; Map<URI, Resource> uriResourceMap = resourceSetImpl.getURIResourceMap(); if (uriResourceMap != null) { uriResourceMap.clear(); } } resourceSet.getResources().clear(); Resource resource = resourceSet.getResource(fileURI, true); // EcoreUtil.resolveAll(resourceSet); -- genModel can fail if // proxies resolved here // problem arises if genmodel has an obsolete feature for a feature // moved up the inheritance hierarchy // since the proxy seems to be successfully resolved giving a double // feature checkResourceSet(resourceSet); EObject eObject = resource.getContents().get(0); if (!(eObject instanceof GenModel)) { throw new ConfigurationException("No GenModel found in '" + resource.getURI() + "'"); } GenModel genModel = (GenModel) eObject; genModel.reconcile(); checkResourceSet(resourceSet); // genModel.setCanGenerate(true); // validate(); genModel.setValidateModel(true); // The more checks the better // genModel.setCodeFormatting(true); // Normalize layout genModel.setForceOverwrite(false); // Don't overwrite read-only // files genModel.setCanGenerate(true); // genModel.setFacadeHelperClass(null); // Non-null gives JDT // default NPEs // genModel.setFacadeHelperClass(StandaloneASTFacadeHelper.class.getName()); // Bug 308069 // genModel.setValidateModel(true); genModel.setBundleManifest(false); // New manifests should be // generated manually genModel.setUpdateClasspath(false); // New class-paths should be // generated manually genModel.setComplianceLevel(GenJDKLevel.JDK50_LITERAL); // genModel.setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"); Diagnostic diagnostic = genModel.diagnose(); if (diagnostic.getSeverity() != Diagnostic.OK) { fail(diagnostic.toString()); } /* * JavaModelManager.getJavaModelManager().initializePreferences(); * new * JavaCorePreferenceInitializer().initializeDefaultPreferences(); * * GenJDKLevel genSDKcomplianceLevel = * genModel.getComplianceLevel(); String complianceLevel = * JavaCore.VERSION_1_5; switch (genSDKcomplianceLevel) { case * JDK60_LITERAL: complianceLevel = JavaCore.VERSION_1_6; case * JDK14_LITERAL: complianceLevel = JavaCore.VERSION_1_4; default: * complianceLevel = JavaCore.VERSION_1_5; } // Hashtable<?,?> * defaultOptions = JavaCore.getDefaultOptions(); // * JavaCore.setComplianceOptions(complianceLevel, defaultOptions); * // JavaCore.setOptions(defaultOptions); */ Generator generator = GenModelUtil.createGenerator(genModel); Monitor monitor = new BasicMonitor(); diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, monitor); if (diagnostic.getSeverity() != Diagnostic.OK) { fail(diagnostic.toString()); } }