aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozsef Makai2014-05-06 18:07:44 (EDT)
committerJozsef Makai2014-05-07 13:14:49 (EDT)
commit2dd4642998193cd1da101c142907994b436e5afc (patch)
treed9999f8af6cbe60fa6559e82bf84395707feb9f2
parentfde8d4927728999a2224f5935abd0b16939294e4 (diff)
downloadorg.eclipse.incquery-2dd4642998193cd1da101c142907994b436e5afc.zip
org.eclipse.incquery-2dd4642998193cd1da101c142907994b436e5afc.tar.gz
org.eclipse.incquery-2dd4642998193cd1da101c142907994b436e5afc.tar.bz2
[398797] Maven compatible eiqgen "compiler" (generator)refs/changes/45/26145/2
Change-Id: Ie252c0d6533b1bb938accb8b3af9c1b9c27777b4 Signed-off-by: Jozsef Makai <reyuulol@gmail.com>
-rw-r--r--maven/incquery-maven-plugin/.classpath26
-rw-r--r--maven/incquery-maven-plugin/.project23
-rw-r--r--maven/incquery-maven-plugin/pom.xml67
-rw-r--r--maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/IncqueryBuilderMojo.java264
-rw-r--r--maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/helper/ModelPair.java44
-rw-r--r--maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/EMFPatternLanguageMavenStandaloneSetup.java36
-rw-r--r--maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/MavenBuilderGenmodelLoader.java45
7 files changed, 505 insertions, 0 deletions
diff --git a/maven/incquery-maven-plugin/.classpath b/maven/incquery-maven-plugin/.classpath
new file mode 100644
index 0000000..35bca5e
--- /dev/null
+++ b/maven/incquery-maven-plugin/.classpath
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/maven/incquery-maven-plugin/.project b/maven/incquery-maven-plugin/.project
new file mode 100644
index 0000000..37ab511
--- /dev/null
+++ b/maven/incquery-maven-plugin/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>incquery-maven-plugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/maven/incquery-maven-plugin/pom.xml b/maven/incquery-maven-plugin/pom.xml
new file mode 100644
index 0000000..7e5c05a
--- /dev/null
+++ b/maven/incquery-maven-plugin/pom.xml
@@ -0,0 +1,67 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>incquery-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>EMF-IncQuery Maven Plug-in</name>
+
+ <properties>
+ <xtend.compiler.version>2.5.3</xtend.compiler.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.emf</groupId>
+ <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
+ <version>2.9.1.v20130827-0309</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.xtend</groupId>
+ <artifactId>org.eclipse.xtend.lib</artifactId>
+ <version>${xtend.compiler.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>org.eclipse.core.resources</artifactId>
+ <version>3.7.100</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.emf</groupId>
+ <artifactId>org.eclipse.emf.codegen.ecore</artifactId>
+ <version>2.9.1-v20140203-1126</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.incquery</groupId>
+ <artifactId>incquery-runtime</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.incquery</groupId>
+ <artifactId>incquery-patternlanguage</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.xtext</groupId>
+ <artifactId>xtext-maven-plugin</artifactId>
+ <version>${xtend.compiler.version}</version>
+ </dependency>
+ </dependencies>
+ <parent>
+ <groupId>org.eclipse.incquery</groupId>
+ <artifactId>org.eclipse.incquery.parent</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <relativePath>../../releng/org.eclipse.incquery.parent/pom.xml</relativePath>
+ </parent>
+</project>
diff --git a/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/IncqueryBuilderMojo.java b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/IncqueryBuilderMojo.java
new file mode 100644
index 0000000..9b24cef
--- /dev/null
+++ b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/IncqueryBuilderMojo.java
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2014, Jozsef Makai, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
+ * 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:
+ * Jozsef Makai - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.maven.incquerybuilder;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.incquery.maven.incquerybuilder.helper.ModelPair;
+import org.eclipse.incquery.maven.incquerybuilder.setup.EMFPatternLanguageMavenStandaloneSetup;
+import org.eclipse.incquery.maven.incquerybuilder.setup.MavenBuilderGenmodelLoader;
+import org.eclipse.xtext.maven.Language;
+import org.eclipse.xtext.maven.OutputConfiguration;
+import org.eclipse.xtext.maven.XtextGenerator;
+
+/**
+ * Goal which generates Java code for EMF-IncQuery patterns
+ *
+ * @goal generate
+ * @phase generate-sources
+ * @requiresDependencyResolution compile
+ */
+public class IncqueryBuilderMojo extends AbstractMojo {
+ /**
+ * FQN-s of the EPackage classes
+ *
+ * @parameter
+ * @required
+ */
+ private List<String> ePackages;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private List<ModelPair> modelPairs;
+
+ /**
+ * the project relative path to the output directory
+ *
+ * @parameter
+ * @required
+ */
+ private String outputDirectory;
+
+ /**
+ * whether the output directory should be created if t doesn't already exist.
+ *
+ * @property
+ */
+ private boolean createOutputDirectory = true;
+
+ /**
+ * whether existing resources should be overridden.
+ *
+ * @property
+ */
+ private boolean overrideExistingResources = true;
+
+ /**
+ * The project itself. This parameter is set by maven.
+ *
+ * @parameter property="project"
+ * @readonly
+ * @required
+ */
+ protected MavenProject project;
+
+ /**
+ * Project classpath.
+ *
+ * @parameter property="project.compileClasspathElements"
+ * @readonly
+ * @required
+ */
+ private List<String> classpathElements;
+
+ /**
+ * Location of the generated source files.
+ *
+ * @parameter property="project.build.directory/xtext-temp"
+ */
+ private String tmpClassDirectory;
+
+ /**
+ * File encoding argument for the generator.
+ *
+ * @parameter property="xtext.encoding" default-value="${project.build.sourceEncoding}"
+ */
+ protected String encoding;
+
+ /**
+ * @parameter property="maven.compiler.source" default-value="1.5"
+ */
+ private String compilerSourceLevel;
+
+ /**
+ * @parameter property="maven.compiler.target" default-value="1.5"
+ */
+ private String compilerTargetLevel;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ registerGenmodelExtension();
+
+ resolveEPackages();
+
+ registerModelPairs();
+
+ XtextGenerator generator = new XtextGenerator();
+
+ setupXtextGenerator(generator);
+
+ generator.execute();
+
+ }
+
+ /**
+ * To parameterize the XtextGenerator object accordingly
+ *
+ * @param generator
+ * The XtextGenerator object
+ */
+ private void setupXtextGenerator(XtextGenerator generator) {
+ generator.setLog(getLog()); // it's needed to give our Logger to the
+ // other plugin to avoid exceptions
+
+ Language language = new Language();
+ language.setSetup(EMFPatternLanguageMavenStandaloneSetup.class.getCanonicalName());
+
+ OutputConfiguration outputConfiguration = new OutputConfiguration();
+ outputConfiguration.setOutputDirectory(outputDirectory);
+ outputConfiguration.setCreateOutputDirectory(createOutputDirectory);
+ outputConfiguration.setOverrideExistingResources(overrideExistingResources);
+
+ List<OutputConfiguration> ocList = new ArrayList<OutputConfiguration>();
+ ocList.add(outputConfiguration);
+
+ language.setOutputConfigurations(ocList);
+
+ List<Language> languageList = new ArrayList<Language>();
+ languageList.add(language);
+
+ generator.setLanguages(languageList);
+
+ try {
+
+ Class<?> generatorClass = generator.getClass();
+
+ Field skipField = generatorClass.getDeclaredField("skip");
+ skipField.setAccessible(true);
+ skipField.set(generator, new Boolean(false));
+
+ Field failOnErrorField = generatorClass.getDeclaredField("failOnValidationError");
+ failOnErrorField.setAccessible(true);
+ failOnErrorField.set(generator, new Boolean(true));
+
+ Field projectField = generatorClass.getDeclaredField("project");
+ projectField.setAccessible(true);
+ projectField.set(generator, project);
+
+ Field classpathField = generatorClass.getDeclaredField("classpathElements");
+ classpathField.setAccessible(true);
+ classpathField.set(generator, classpathElements);
+
+ Field tmpDirectoryField = generatorClass.getDeclaredField("tmpClassDirectory");
+ tmpDirectoryField.setAccessible(true);
+ tmpDirectoryField.set(generator, tmpClassDirectory);
+
+ Field encodingField = generatorClass.getDeclaredField("encoding");
+ encodingField.setAccessible(true);
+ encodingField.set(generator, encoding);
+
+ Field sourceLevelField = generatorClass.getDeclaredField("compilerSourceLevel");
+ sourceLevelField.setAccessible(true);
+ sourceLevelField.set(generator, compilerSourceLevel);
+
+ Field targetLevelField = generatorClass.getDeclaredField("compilerTargetLevel");
+ targetLevelField.setAccessible(true);
+ targetLevelField.set(generator, compilerTargetLevel);
+
+ } catch (NoSuchFieldException e1) {
+
+ } catch (SecurityException e1) {
+
+ } catch (IllegalArgumentException e) {
+
+ } catch (IllegalAccessException e) {
+
+ }
+ }
+
+ /**
+ * Register user given metamodel NSURI and genmodel URI pairs
+ */
+ private void registerModelPairs() {
+ for (ModelPair modelPair : modelPairs) {
+ MavenBuilderGenmodelLoader.addGenmodel(modelPair.getModelNsUri(), modelPair.getGenmodelUri());
+ }
+ }
+
+ /**
+ * To access the eINSTANCE field of the user given EPackage classes
+ *
+ * @throws MojoExecutionException
+ */
+ private void resolveEPackages() throws MojoExecutionException {
+ for (String fqnOfEPackageClass : ePackages) {
+ try {
+
+ Class<?> ePackageClass = Class.forName(fqnOfEPackageClass);
+
+ Field instanceField = ePackageClass.getDeclaredField("eINSTANCE");
+
+ Class<?> instanceFieldType = instanceField.getType();
+
+ if (ePackageClass != instanceFieldType) {
+ getLog().error(
+ "eINSTANCE is not type of " + fqnOfEPackageClass + " in class " + fqnOfEPackageClass
+ + ". It's type of " + instanceFieldType.getCanonicalName() + ".");
+ throw new MojoExecutionException("Execution failed due to wrong type of eINSTANCE");
+ }
+
+ instanceField.get(null);
+
+ } catch (ClassNotFoundException e) {
+ getLog().error("Couldn't find class " + fqnOfEPackageClass + " on the classpath.");
+ throw new MojoExecutionException("Execution failed due to wrong classname.");
+ } catch (NoSuchFieldException e) {
+ getLog().error("The " + fqnOfEPackageClass + " class doesn't have eINSTANCE field.");
+ } catch (SecurityException e) {
+
+ } catch (IllegalArgumentException e) {
+
+ } catch (IllegalAccessException e) {
+
+ }
+ }
+ }
+
+ /**
+ * To register genmodel extension and according factory to the extension factory
+ */
+ private void registerGenmodelExtension() {
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("genmodel", new EcoreResourceFactoryImpl());
+ GenModelPackage.eINSTANCE.eClass();
+ }
+}
diff --git a/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/helper/ModelPair.java b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/helper/ModelPair.java
new file mode 100644
index 0000000..08af597
--- /dev/null
+++ b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/helper/ModelPair.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2014, Jozsef Makai, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
+ * 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:
+ * Jozsef Makai - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.maven.incquerybuilder.helper;
+
+public class ModelPair {
+
+ /**
+ * @property
+ * @required
+ */
+ private String modelNsUri;
+
+ /**
+ * @property
+ * @required
+ */
+ private String genmodelUri;
+
+ public String getModelNsUri() {
+ return modelNsUri;
+ }
+
+ public void setModelNsUri(String modelNsUri) {
+ this.modelNsUri = modelNsUri;
+ }
+
+ public String getGenmodelUri() {
+ return genmodelUri;
+ }
+
+ public void setGenmodelUri(String genmodelUri) {
+ this.genmodelUri = genmodelUri;
+ }
+
+}
diff --git a/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/EMFPatternLanguageMavenStandaloneSetup.java b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/EMFPatternLanguageMavenStandaloneSetup.java
new file mode 100644
index 0000000..7dbdb6c
--- /dev/null
+++ b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/EMFPatternLanguageMavenStandaloneSetup.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2014, Jozsef Makai, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
+ * 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:
+ * Jozsef Makai - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.maven.incquerybuilder.setup;
+
+import org.eclipse.incquery.patternlanguage.emf.EMFPatternLanguageRuntimeModule;
+import org.eclipse.incquery.patternlanguage.emf.EMFPatternLanguageStandaloneSetup;
+import org.eclipse.incquery.patternlanguage.emf.IGenmodelMappingLoader;
+
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class EMFPatternLanguageMavenStandaloneSetup extends EMFPatternLanguageStandaloneSetup {
+
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(new EMFPatternLanguageRuntimeModule() {
+
+ @SuppressWarnings("unused")
+ public void configureIGenmodelMappingLoader(Binder bind) {
+ bind.bind(IGenmodelMappingLoader.class).toInstance(MavenBuilderGenmodelLoader.getInstance());
+ }
+
+ });
+ }
+
+}
diff --git a/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/MavenBuilderGenmodelLoader.java b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/MavenBuilderGenmodelLoader.java
new file mode 100644
index 0000000..e5f1bc8
--- /dev/null
+++ b/maven/incquery-maven-plugin/src/main/java/org/eclipse/incquery/maven/incquerybuilder/setup/MavenBuilderGenmodelLoader.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2014, Jozsef Makai, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
+ * 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:
+ * Jozsef Makai - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.maven.incquerybuilder.setup;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.incquery.patternlanguage.emf.IGenmodelMappingLoader;
+
+public class MavenBuilderGenmodelLoader implements IGenmodelMappingLoader {
+
+ protected static MavenBuilderGenmodelLoader genmodelLoader = new MavenBuilderGenmodelLoader();
+
+ private Map<String, String> genModels;
+
+ protected MavenBuilderGenmodelLoader() {
+ genModels = new HashMap<String, String>();
+ }
+
+ public static void addGenmodel(String modelNsUri, String genmodelUri) {
+ genmodelLoader.putGenmodel(modelNsUri, genmodelUri);
+ }
+
+ public Map<String, String> loadGenmodels() {
+ return genModels;
+ }
+
+ protected void putGenmodel(String modelNsUri, String genmodelUri) {
+ genModels.put(modelNsUri, genmodelUri);
+ }
+
+ public static MavenBuilderGenmodelLoader getInstance() {
+ return genmodelLoader;
+ }
+
+}