Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-04-14 06:02:01 +0000
committerEike Stepper2018-04-14 06:02:01 +0000
commit57f6c5c32db8d477cccb6eb0bd9acbc19c747228 (patch)
tree7cb67d979088c5b29fcbf9830567e543d647f789 /plugins
parentdfdd2931254edde04b2109931c08e188f37cf0fe (diff)
downloadcdo-57f6c5c32db8d477cccb6eb0bd9acbc19c747228.tar.gz
cdo-57f6c5c32db8d477cccb6eb0bd9acbc19c747228.tar.xz
cdo-57f6c5c32db8d477cccb6eb0bd9acbc19c747228.zip
[Releng] Add Ant task to generate GenModels
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/plugin.xml1
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/CDOMigratorUtil.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/CDOTask.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/GenerateModelTask.java61
4 files changed, 77 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
index db4bc62772..7ddf71bc50 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.migrator/plugin.xml
@@ -62,6 +62,7 @@
<antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.ProjectImport" headless="true" class="org.eclipse.emf.cdo.internal.migrator.tasks.ProjectImportTask" />
<antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.ProjectDelete" headless="true" class="org.eclipse.emf.cdo.internal.migrator.tasks.ProjectDeleteTask" />
<antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.MigrateModel" headless="true" class="org.eclipse.emf.cdo.internal.migrator.tasks.MigrateModelTask" />
+ <antTask library="ant_tasks/cdo.ant.tasks.jar" name="cdo.GenerateModel" headless="true" class="org.eclipse.emf.cdo.internal.migrator.tasks.GenerateModelTask" />
</extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/CDOMigratorUtil.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/CDOMigratorUtil.java
index 52483d9a6e..9e7c31a926 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/CDOMigratorUtil.java
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/CDOMigratorUtil.java
@@ -18,9 +18,11 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.core.resources.IFolder;
@@ -31,8 +33,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
-import java.util.Map;
-
/**
* @author Eike Stepper
*/
@@ -53,13 +53,18 @@ public abstract class CDOMigratorUtil
public static GenModel getGenModel(String path)
{
ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
- Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
- map.put("*", new XMIResourceFactoryImpl()); //$NON-NLS-1$
+ Resource.Factory factory = new XMIResourceFactoryImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", factory); //$NON-NLS-1$
+ resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("*", factory); //$NON-NLS-1$
+ resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put("*", factory); //$NON-NLS-1$
URI uri = URI.createPlatformResourceURI(path, false);
Resource resource = resourceSet.getResource(uri, true);
+ EcoreUtil.resolveAll(resourceSet);
+
EList<EObject> contents = resource.getContents();
if (!contents.isEmpty())
{
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/CDOTask.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/CDOTask.java
index f5d5e06b8a..ed83e6d210 100644
--- a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/CDOTask.java
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/CDOTask.java
@@ -39,14 +39,16 @@ public abstract class CDOTask extends Task
doExecute();
}
- catch (Exception e)
+ catch (Exception ex)
{
- if (e instanceof BuildException)
+ ex.printStackTrace();
+
+ if (ex instanceof BuildException)
{
- throw (BuildException)e;
+ throw (BuildException)ex;
}
- throw new BuildException(e);
+ throw new BuildException(ex);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/GenerateModelTask.java b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/GenerateModelTask.java
new file mode 100644
index 0000000000..89f420ce49
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.migrator/src/org/eclipse/emf/cdo/internal/migrator/tasks/GenerateModelTask.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2018 Eike Stepper (Berlin, Germany) and others.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.migrator.tasks;
+
+import org.eclipse.emf.cdo.internal.migrator.CDOMigratorUtil;
+
+import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin;
+import org.eclipse.emf.codegen.ecore.generator.Generator;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
+import org.eclipse.emf.codegen.ecore.genmodel.util.GenModelUtil;
+import org.eclipse.emf.common.util.BasicMonitor;
+import org.eclipse.emf.common.util.Diagnostic;
+
+import org.apache.tools.ant.BuildException;
+
+/**
+ * @author Eike Stepper
+ */
+public class GenerateModelTask extends CDOTask
+{
+ private String modelPath;
+
+ public void setModelPath(String modelPath)
+ {
+ this.modelPath = modelPath;
+ }
+
+ @Override
+ protected void checkAttributes() throws BuildException
+ {
+ assertTrue("'modelPath' must be specified.", modelPath != null && modelPath.length() != 0);
+ }
+
+ @Override
+ protected void doExecute() throws Exception
+ {
+ GenModel genModel = CDOMigratorUtil.getGenModel(modelPath);
+ genModel.setCanGenerate(true);
+ genModel.setValidateModel(true);
+
+ Diagnostic diagnostic = genModel.diagnose();
+ if (diagnostic.getSeverity() != Diagnostic.OK)
+ {
+ System.err.println(diagnostic);
+ throw new BuildException(diagnostic.getException());
+ }
+
+ Generator generator = GenModelUtil.createGenerator(genModel);
+ generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, CodeGenEcorePlugin.INSTANCE.getString("_UI_ModelProject_name"),
+ new BasicMonitor.Printing(System.out));
+ }
+}

Back to the top