Giter VIP home page Giter VIP logo

classmaker's Introduction

ClassMaker Java CI & CD with Maven Open Source Helpers

ClassMaker is an Eclipse plug-in that allows to create classes programmatically, providing them to client bundle.

ClassMaker, automatically, generates the source code from the provided model, compiles and releases binary, then installs it into its own runtime, and loads classes, making available to client's code, through model reflective API.

Here is how you can use it:

// Design a blueprint model - dynamic EMF EPackage
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
ePackage.setName("library");
ePackage.setNsPrefix("library");
ePackage.setNsURI("http://library/1.0");
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Book");
EAttribute eAttr = EcoreFactory.eINSTANCE.createEAttribute();
eAttr.setName("pages");
eAttr.setEType(EcorePackage.Literals.EINT);
eClass.getEStructuralFeatures().add(eAttr);
ePackage.getEClassifiers().add(eClass);

// Acquire ClassMaker's OSGi service
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
                            .getBundleContext();
ServiceReference<?> serviceReference = bundleContext
                            .getServiceReference(ClassMakerService.class);
ClassMakerService classMaker = (ClassMakerService) bundleContext
                            .getService(serviceReference);

// Produce the result by combining them
EPackage jPackage = (EPackage) classMaker.make(ePackage, progressMonitor);

...
// Use the generated model at runtime
EClass jClass = (EClass) jPackage.getEClassifier(eClass.getName());
EObject jObject = jPackage.getEFactoryInstance().create(jClass); 
int pages = 500;
EStructuralFeature jAttr = jClass.getEStructuralFeature(eAttr
    .getName());
jObject.eSet(jAttr, pages);
assertEquals(pages, jObject.eGet(jAttr));
assertEquals(eClass.getName(), jObject.getClass().getSimpleName());  

There is more code, where you can specify a method body and call a method or create a meta-model of any meta-level.

Download

Download latest release.

Feedback

If you have anything to complain or suggest, please feel free to file a bug at GitHub.

classmaker's People

Contributors

kirillzotkin avatar kyrillzotkin avatar nizanth94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

classmaker's Issues

java.lang.NoClassDefFoundError: org/eclipse/emf/common/notify/Notification

Describe the bug
java.lang.NoClassDefFoundError: org/eclipse/emf/common/notify/Notification at org.enterprisedomain.classmaker.tests.TestEnterpriseDomain.recreate(TestEnterpriseDomain.java:560)
Caused by: java.lang.ClassNotFoundException: org.eclipse.emf.common.notify.Notification cannot be found by dir_1.0.0.201909100914 at org.enterprisedomain.classmaker.tests.TestEnterpriseDomain.recreate(TestEnterpriseDomain.java:560)

To Reproduce
https://travis-ci.org/enterpriseDomain/ClassMaker/builds/583072688

Expected behavior
Shouldn't happen.

eclipse IDE UI Front-end

It is possible to create a menu item like 'Load into self' to invoke ClassMaker from eclipse UI. This would allow to load EMF models into running eclipse IDE instance's EPackage registry and could be a handful feature.

Restore project from git after deletion

Currently .git is stored in the project workspace folder but ResourcesPlugin doesn't delete it with projects. It could checkout previous state as a restoration.

New Root menu in model editor

A New Root context menu with drop-down menu of EPackages Ns_URIs and EClasses to create a new object in Ecore Model editor. Similar to CDO's in CDO Editor.

Extensibility

Currently the creation of Generator, Exporter and Installer ("Loader" not even refactored) objects are hard-coded in StateImpl.make() method. Available implementations must be configured somehow.
Perhaps, in extension point, or in OSGi service, or, maybe, in configuration XML.
The choice of implementation may vary between State instances (should be specific to State instance), but could have been configured also on Revision, Contribution and Workspace levels. The default implementation should be set.

Multi-metamodel

There is a possibility to create a feature like: model (M0) is an instance of meta-model (M1), which, in turn an in instance of meta-metamodel (M2) and so on.
For this, a representation of model of any layer of abstraction should be specified explicitly. Where under representation is meant a template for generation, genmodel properties, input syntax, mapping to Ecore, etc.

More informative EMFStore Model Editor's contents

By default the contents of the ModelEditor showing resource by normalized with custom URIConverter URI is not displaying EMFStore project's resource model elements. Compatibility of ModelEditor with enterpriseDomain ECP Provider should be kept.

Generated code customization

To allow generated code customization there several approaches exist. Current default generator uses Ecore JET templates GenModel's "model" project generation. It could be extended by dynamic templates, which are enough for basic customizations. It's better to have an API for constructing such customizations.
Further may include custom GenModels, generators using other code generation technologies (such as Xtend) and generating additional code of various domain-specific parts of container application.

Logging

Replace System.out calls with logger.
OSGi.getInstance().getLog() might be used.

NPE at org.eclipse.osgi.internal.loader.BundleLoader.findRequiredSource

java.lang.NullPointerException
	at org.eclipse.osgi.internal.loader.BundleLoader.findRequiredSource(BundleLoader.java:1140)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:413)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getField0(Class.java:2975)
	at java.lang.Class.getField(Class.java:1701)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader.doLoad(OSGiEPackageLoader.java:156)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader.access$0(OSGiEPackageLoader.java:141)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader$1.bundleChanged(OSGiEPackageLoader.java:57)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:903)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Difficult to reproduce.

Workspace target platform

In order to support provisioning of dependencies of generated projects there are need to apply some target platform to projects workspace. This should allow for programmatic PDE Export task to complete successfully and thus enable maven build to run.

Runtime class modification

Classes should not only be created but also edited.
The Database Refactoring book might be useful as a theoretic basis.

ClassCastException: <packagename>.<PackagePrefix>Factory cannot be cast to <packagename>.<PackagePrefix>Factory

java.lang.ClassCastException: some.SomeFactory cannot be cast to some.SomeFactory
	at some.SomeFactory.init(SomeFactory.java:38)
	at some.SomeFactory.<clinit>(SomeFactory.java:28)
	at some.SomePackage.<init>(SomePackage.java:119)
	at some.SomePackage.init(SomePackage.java:147)
	at some.SomePackage.<clinit>(SomePackage.java:57)
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
	at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:156)
	at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
	at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
	at java.lang.reflect.Field.get(Field.java:393)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader.doLoad(OSGiEPackageLoader.java:157)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader.access$0(OSGiEPackageLoader.java:142)
	at org.enterprisedomain.classmaker.jobs.load.OSGiEPackageLoader$1.bundleChanged(OSGiEPackageLoader.java:57)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:903)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.