Example #1
0
  public void invoke(IWorkflowContext ctx) {
    ResourceSet resSet = getResourceSet();
    Resource resource = resSet.getResource(URI.createURI(genModel), true);
    final GenModel genModel = (GenModel) resource.getContents().get(0);
    genModel.setCanGenerate(true);
    genModel.reconcile();
    createGenModelSetup().registerGenModel(genModel);

    Generator generator =
        new Generator() {
          @Override
          public JControlModel getJControlModel() {
            return new JControlModel() {
              @Override
              public boolean canMerge() {
                return false;
              }
            };
          }
        };
    log.info("generating EMF code for " + this.genModel);
    generator
        .getAdapterFactoryDescriptorRegistry()
        .addDescriptor(
            GenModelPackage.eNS_URI,
            new GeneratorAdapterDescriptor(getTypeMapper(), getLineDelimiter()));
    generator.setInput(genModel);

    Diagnostic diagnostic =
        generator.generate(
            genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor());

    if (diagnostic.getSeverity() != Diagnostic.OK) log.info(diagnostic);

    if (generateEdit) {
      Diagnostic editDiag =
          generator.generate(
              genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, new BasicMonitor());
      if (editDiag.getSeverity() != Diagnostic.OK) log.info(editDiag);
    }

    if (generateEditor) {
      Diagnostic editorDiag =
          generator.generate(
              genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, new BasicMonitor());
      if (editorDiag.getSeverity() != Diagnostic.OK) log.info(editorDiag);
    }
  }
Example #2
0
 public void executeTransformation(IExecutionInformation executionInformation) throws Exception {
   ResourceSet resourceSet = new ResourceSetImpl();
   Resource resource =
       resourceSet.createResource(locator.getEMFURI(inputModels.get(0).getModel()));
   resource.load(null);
   EcoreUtil.resolveAll(resourceSet);
   GenModel genModel = (GenModel) resource.getContents().get(0);
   genModel.setCanGenerate(true);
   // generate the code
   Generator generator = new Generator();
   generator.setInput(genModel);
   generator.generate(
       genModel,
       GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
       new BasicMonitor.Printing(System.err));
   for (File file : outputFiles) {
     executionEnvironment.fileReady(file, transformation);
   }
 }
  public VirtualFile generate(VirtualFile basedir) throws DatabaseException {
    GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
    genModel.setRuntimeVersion(GenRuntimeVersion.EMF25);
    genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
    genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
    genModel.setRootExtendsClass("org.bimserver.emf.IdEObjectImpl");
    genModel.setRootExtendsInterface("org.bimserver.emf.IdEObject");
    genModel.setSuppressContainment(true);
    genModel.setCodeFormatting(true);
    genModel.setCopyrightText(StringUtils.readFromFile(new File("copyright.txt")));
    genModel.setCanGenerate(true);
    genModel.setModelDirectory("test");
    genModel.setModelName("model name");
    genModel.setForceOverwrite(true);
    genModel.setSuppressNotification(false);
    genModel.setContainmentProxies(false);
    genModel.setBinaryCompatibleReflectiveMethods(false);
    genModel.setPublicConstructors(false);
    genModel.setMinimalReflectiveMethods(true); // More code, but faster
    genModel.setUpdateClasspath(false);

    genModel.initialize(schema.getEPackages());

    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
    Generator generator = new Generator();
    generator.setInput(genModel);
    generator.generate(
        genModel,
        GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
        new BasicMonitor.Printing(System.out));

    //		List<GenPackage> genPackages = createGenPackages(genModel, basedir);
    //		generatePackages(genModel, genPackages, basedir);

    return basedir;
  }
Example #4
0
  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());
    }
  }