Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Wagelaar2018-04-28 13:49:21 +0000
committerDennis Wagelaar2018-04-28 13:49:21 +0000
commit378fa60405af9853f6b269df343790ed040af536 (patch)
treee896d250ea61b7ad4b6757e6e62332c9c5b8e07f /plugins
parente721c7f150d08cc22013e1f3ee8c630c91782b2d (diff)
downloadorg.eclipse.atl-378fa60405af9853f6b269df343790ed040af536.tar.gz
org.eclipse.atl-378fa60405af9853f6b269df343790ed040af536.tar.xz
org.eclipse.atl-378fa60405af9853f6b269df343790ed040af536.zip
534003: Add Maven/stand-alone support for EMFTVM Ant tasks
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=534003 Add emftvm.registerMetamodel task
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml5
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/RegisterMetamodelTask.java109
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml1
3 files changed, 115 insertions, 0 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml b/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml
index a59e2046..859c79da 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml
+++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/plugin.xml
@@ -33,6 +33,11 @@
library="lib/emftvmAntTasks.jar"
name="emftvm.compile">
</antTask>
+ <antTask
+ class="org.eclipse.m2m.atl.emftvm.ant.RegisterMetamodelTask"
+ library="lib/emftvmAntTasks.jar"
+ name="emftvm.registerMetamodel">
+ </antTask>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/RegisterMetamodelTask.java b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/RegisterMetamodelTask.java
new file mode 100644
index 00000000..0f05f4f9
--- /dev/null
+++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/RegisterMetamodelTask.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Dennis Wagelaar.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dennis Wagelaar - initial API and
+ * implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.m2m.atl.emftvm.ant;
+
+import java.lang.reflect.Field;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+
+/**
+ * Registers an EMF metamodel.
+ *
+ * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
+ */
+public class RegisterMetamodelTask extends EMFTVMTask {
+
+ private String packageClass;
+ private String resourceFactoryClass;
+ private String fileExtension;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void innerExecute() throws Exception {
+ final String packageClass = getPackageClass();
+ final Class<?> packageClazz = Class.forName(packageClass);
+ final Field eInstance = packageClazz.getDeclaredField("eINSTANCE");
+ final EPackage ePackage = (EPackage) eInstance.get(packageClazz);
+ if (ePackage == null) {
+ throw new IllegalArgumentException("Cannot find package class " + packageClass);
+ }
+
+ final String resourceFactoryClass = getResourceFactoryClass();
+ if (resourceFactoryClass != null) {
+ final Class<?> resourceFactoryClazz = Class.forName(resourceFactoryClass);
+ final Resource.Factory resourceFactory = (Resource.Factory) resourceFactoryClazz.newInstance();
+ final String fileExtension = getFileExtension();
+ if (fileExtension == null) {
+ throw new IllegalArgumentException("File extension cannot be null if resource factory class is set");
+ }
+ getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ resourceFactory);
+ }
+ }
+
+ /**
+ * Returns the {@link EPackage} class to register.
+ *
+ * @return the packageClass
+ */
+ public String getPackageClass() {
+ return packageClass;
+ }
+
+ /**
+ * Sets the {@link EPackage} class to register.
+ *
+ * @param packageClass
+ * the packageClass to set
+ */
+ public void setPackageClass(String packageClass) {
+ this.packageClass = packageClass;
+ }
+
+ /**
+ * @return the resourceFactoryClass
+ */
+ public String getResourceFactoryClass() {
+ return resourceFactoryClass;
+ }
+
+ /**
+ * @param resourceFactoryClass
+ * the resourceFactoryClass to set
+ */
+ public void setResourceFactoryClass(String resourceFactoryClass) {
+ this.resourceFactoryClass = resourceFactoryClass;
+ }
+
+ /**
+ * Returns the file extension of the instance models.
+ *
+ * @return the fileExtension
+ */
+ public String getFileExtension() {
+ return fileExtension;
+ }
+
+ /**
+ * Sets the file extension of the instance models.
+ *
+ * @param fileExtension
+ * the fileExtension to set
+ */
+ public void setFileExtension(String fileExtension) {
+ this.fileExtension = fileExtension;
+ }
+
+}
diff --git a/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml
index 4533f202..839dce2b 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml
+++ b/plugins/org.eclipse.m2m.atl.emftvm.ant/src_ant/org/eclipse/m2m/atl/emftvm/ant/antlib.xml
@@ -6,4 +6,5 @@
<taskdef name="emftvm.saveModel" classname="org.eclipse.m2m.atl.emftvm.ant.SaveModelTask" />
<taskdef name="emftvm.newModel" classname="org.eclipse.m2m.atl.emftvm.ant.NewModelTask" />
<taskdef name="emftvm.compile" classname="org.eclipse.m2m.atl.emftvm.ant.CompileTask" />
+ <taskdef name="emftvm.registerMetamodel" classname="org.eclipse.m2m.atl.emftvm.ant.RegisterMetamodelTask" />
</antlib> \ No newline at end of file

Back to the top