├── ATLauncher ├── bin │ └── .gitignore ├── transformations │ ├── Composed2Simple.asm │ ├── Composed2Simple.emftvm │ └── Composed2Simple.atl ├── lib │ ├── org.objectweb.asm_3.3.1.v201105211655.jar │ ├── org.eclipse.emf.common_2.10.0.v20140514-1158.jar │ ├── org.eclipse.emf.ecore_2.10.0.v20140514-1158.jar │ ├── org.eclipse.m2m.atl.common_3.3.1.v201209061455.jar │ ├── org.eclipse.m2m.atl.emftvm_3.6.0.v201501081942.jar │ ├── org.eclipse.emf.ecore.xmi_2.10.0.v20140514-1158.jar │ └── org.eclipse.m2m.atl.emftvm.trace_3.6.0.v201501081942.jar ├── models │ ├── simple.xmi │ └── composed.xmi ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── metamodels │ ├── Simple.ecore │ └── Composed.ecore ├── .classpath └── src │ └── ualberta │ └── edu │ └── guana │ └── tools │ └── atl │ └── ATLLauncher.java ├── README.md └── LICENSE /ATLauncher/bin/.gitignore: -------------------------------------------------------------------------------- 1 | /ualberta 2 | -------------------------------------------------------------------------------- /ATLauncher/transformations/Composed2Simple.asm: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ATLauncher 2 | A Java project ready to run ATL/EMFVM transformations 3 | -------------------------------------------------------------------------------- /ATLauncher/transformations/Composed2Simple.emftvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/transformations/Composed2Simple.emftvm -------------------------------------------------------------------------------- /ATLauncher/lib/org.objectweb.asm_3.3.1.v201105211655.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.objectweb.asm_3.3.1.v201105211655.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.emf.common_2.10.0.v20140514-1158.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.emf.common_2.10.0.v20140514-1158.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.emf.ecore_2.10.0.v20140514-1158.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.emf.ecore_2.10.0.v20140514-1158.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.m2m.atl.common_3.3.1.v201209061455.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.m2m.atl.common_3.3.1.v201209061455.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.m2m.atl.emftvm_3.6.0.v201501081942.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.m2m.atl.emftvm_3.6.0.v201501081942.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.emf.ecore.xmi_2.10.0.v20140514-1158.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.emf.ecore.xmi_2.10.0.v20140514-1158.jar -------------------------------------------------------------------------------- /ATLauncher/lib/org.eclipse.m2m.atl.emftvm.trace_3.6.0.v201501081942.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guana/ATLauncher/HEAD/ATLauncher/lib/org.eclipse.m2m.atl.emftvm.trace_3.6.0.v201501081942.jar -------------------------------------------------------------------------------- /ATLauncher/models/simple.xmi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /ATLauncher/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ATLauncher 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /ATLauncher/transformations/Composed2Simple.atl: -------------------------------------------------------------------------------- 1 | -- @path Composed=/Test/transformations/Composed.ecore 2 | -- @path Simple=/Test/transformations/Simple.ecore 3 | -- @atlcompiler emftvm 4 | 5 | module Composed2Simple; 6 | create OUT : Simple from IN : Composed; 7 | 8 | rule Composed2Simple { 9 | from 10 | composed : Composed!Student 11 | to 12 | simple : Simple!StudentSimple ( 13 | name <- composed.name, 14 | supervisor <- composed.supervisor.name, 15 | affiliation <- composed.supervisor.affiliation.name 16 | 17 | ) 18 | } -------------------------------------------------------------------------------- /ATLauncher/models/composed.xmi: -------------------------------------------------------------------------------- 1 | 2 | 9 | 11 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ATLauncher/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Wed Feb 11 12:22:48 MST 2015 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.7 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | -------------------------------------------------------------------------------- /ATLauncher/metamodels/Simple.ecore: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ATLauncher/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Victor Guana 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /ATLauncher/metamodels/Composed.ecore: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ATLauncher/src/ualberta/edu/guana/tools/atl/ATLLauncher.java: -------------------------------------------------------------------------------- 1 | package ualberta.edu.guana.tools.atl; 2 | 3 | import java.io.IOException; 4 | import java.util.Collections; 5 | import org.eclipse.emf.common.util.URI; 6 | import org.eclipse.emf.ecore.EObject; 7 | import org.eclipse.emf.ecore.EPackage; 8 | import org.eclipse.emf.ecore.resource.Resource; 9 | import org.eclipse.emf.ecore.resource.ResourceSet; 10 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; 11 | import org.eclipse.emf.ecore.util.BasicExtendedMetaData; 12 | import org.eclipse.emf.ecore.util.ExtendedMetaData; 13 | import org.eclipse.emf.ecore.xmi.XMLResource; 14 | import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl; 15 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; 16 | import org.eclipse.m2m.atl.emftvm.EmftvmFactory; 17 | import org.eclipse.m2m.atl.emftvm.ExecEnv; 18 | import org.eclipse.m2m.atl.emftvm.Metamodel; 19 | import org.eclipse.m2m.atl.emftvm.Model; 20 | import org.eclipse.m2m.atl.emftvm.impl.resource.EMFTVMResourceFactoryImpl; 21 | import org.eclipse.m2m.atl.emftvm.util.DefaultModuleResolver; 22 | import org.eclipse.m2m.atl.emftvm.util.ModuleResolver; 23 | import org.eclipse.m2m.atl.emftvm.util.TimingData; 24 | 25 | /** 26 | * An off-the-shelf launcher for ATL/EMFTVM transformations 27 | * @author Victor Guana - guana@ualberta.ca 28 | * University of Alberta - SSRG Lab. 29 | * Edmonton, Alberta. Canada 30 | * Using code examples from: https://wiki.eclipse.org/ATL/EMFTVM 31 | */ 32 | public class ATLLauncher { 33 | 34 | // Some constants for quick initialization and testing. 35 | public final static String IN_METAMODEL = "./metamodels/Composed.ecore"; 36 | public final static String IN_METAMODEL_NAME = "Composed"; 37 | public final static String OUT_METAMODEL = "./metamodels/Simple.ecore"; 38 | public final static String OUT_METAMODEL_NAME = "Simple"; 39 | 40 | public final static String IN_MODEL = "./models/composed.xmi"; 41 | public final static String OUT_MODEL = "./models/simple.xmi"; 42 | 43 | public final static String TRANSFORMATION_DIR = "./transformations/"; 44 | public final static String TRANSFORMATION_MODULE= "Composed2Simple"; 45 | 46 | // The input and output metamodel nsURIs are resolved using lazy registration of metamodels, see below. 47 | private String inputMetamodelNsURI; 48 | private String outputMetamodelNsURI; 49 | 50 | //Main transformation launch method 51 | public void launch(String inMetamodelPath, String inModelPath, String outMetamodelPath, 52 | String outModelPath, String transformationDir, String transformationModule){ 53 | 54 | /* 55 | * Creates the execution environment where the transformation is going to be executed, 56 | * you could use an execution pool if you want to run multiple transformations in parallel, 57 | * but for the purpose of the example let's keep it simple. 58 | */ 59 | ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv(); 60 | ResourceSet rs = new ResourceSetImpl(); 61 | 62 | /* 63 | * Load meta-models in the resource set we just created, the idea here is to make the meta-models 64 | * available in the context of the execution environment, the ResourceSet is later passed to the 65 | * ModuleResolver that is the actual class that will run the transformation. 66 | * Notice that we use the nsUris to locate the metamodels in the package registry, we initialize them 67 | * from Ecore files that we registered lazily as shown below in e.g. registerInputMetamodel(...) 68 | */ 69 | Metamodel inMetamodel = EmftvmFactory.eINSTANCE.createMetamodel(); 70 | inMetamodel.setResource(rs.getResource(URI.createURI(inputMetamodelNsURI), true)); 71 | env.registerMetaModel(IN_METAMODEL_NAME, inMetamodel); 72 | 73 | Metamodel outMetamodel = EmftvmFactory.eINSTANCE.createMetamodel(); 74 | outMetamodel.setResource(rs.getResource(URI.createURI(outputMetamodelNsURI), true)); 75 | env.registerMetaModel(OUT_METAMODEL_NAME, outMetamodel); 76 | 77 | /* 78 | * Create and register resource factories to read/parse .xmi and .emftvm files, 79 | * we need an .xmi parser because our in/output models are .xmi and our transformations are 80 | * compiled using the ATL-EMFTV compiler that generates .emftvm files 81 | */ 82 | rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); 83 | rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("emftvm", new EMFTVMResourceFactoryImpl()); 84 | 85 | // Load models 86 | Model inModel = EmftvmFactory.eINSTANCE.createModel(); 87 | inModel.setResource(rs.getResource(URI.createURI(inModelPath, true), true)); 88 | env.registerInputModel("IN", inModel); 89 | 90 | Model outModel = EmftvmFactory.eINSTANCE.createModel(); 91 | outModel.setResource(rs.createResource(URI.createURI(outModelPath))); 92 | env.registerOutputModel("OUT", outModel); 93 | 94 | /* 95 | * Load and run the transformation module 96 | * Point at the directory your transformations are stored, the ModuleResolver will 97 | * look for the .emftvm file corresponding to the module you want to load and run 98 | */ 99 | ModuleResolver mr = new DefaultModuleResolver(transformationDir, rs); 100 | TimingData td = new TimingData(); 101 | env.loadModule(mr, TRANSFORMATION_MODULE); 102 | td.finishLoading(); 103 | env.run(td); 104 | td.finish(); 105 | 106 | // Save models 107 | try { 108 | outModel.getResource().save(Collections.emptyMap()); 109 | } catch (IOException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | /* 115 | * I seriously hate relying on the eclipse facilities, and if you're not building an eclipse plugin 116 | * you can't rely on eclipse's registry (let's say you're building a stand-alone tool that needs to run ATL 117 | * transformation, you need to 'manually' register your metamodels) 118 | * This method does two things, it initializes an Ecore parser and then programmatically looks for 119 | * the package definition on it, obtains the NsUri and registers it. 120 | */ 121 | private String lazyMetamodelRegistration(String metamodelPath){ 122 | 123 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); 124 | 125 | ResourceSet rs = new ResourceSetImpl(); 126 | // Enables extended meta-data, weird we have to do this but well... 127 | final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(EPackage.Registry.INSTANCE); 128 | rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); 129 | 130 | Resource r = rs.getResource(URI.createFileURI(metamodelPath), true); 131 | EObject eObject = r.getContents().get(0); 132 | // A meta-model might have multiple packages we assume the main package is the first one listed 133 | if (eObject instanceof EPackage) { 134 | EPackage p = (EPackage)eObject; 135 | System.out.println(p.getNsURI()); 136 | EPackage.Registry.INSTANCE.put(p.getNsURI(), p); 137 | return p.getNsURI(); 138 | } 139 | return null; 140 | } 141 | 142 | /* 143 | * As shown above we need the inputMetamodelNsURI and the outputMetamodelNsURI to create the context of 144 | * the transformation, so we simply use the return value of lazyMetamodelRegistration to store them. 145 | * -- Notice that the lazyMetamodelRegistration(..) implementation may return null in case it doesn't 146 | * find a package in the given metamodel, so watch out for malformed metamodels. 147 | * 148 | */ 149 | public void registerInputMetamodel(String inputMetamodelPath){ 150 | inputMetamodelNsURI = lazyMetamodelRegistration(inputMetamodelPath); 151 | } 152 | 153 | public void registerOutputMetamodel(String outputMetamodelPath){ 154 | outputMetamodelNsURI = lazyMetamodelRegistration(outputMetamodelPath); 155 | } 156 | 157 | /* 158 | * A test main method, I'm using constants so I can quickly change the case study by simply 159 | * modifying the header of the class. 160 | */ 161 | public static void main(String ... args){ 162 | ATLLauncher l = new ATLLauncher(); 163 | l.registerInputMetamodel(IN_METAMODEL); 164 | l.registerOutputMetamodel(OUT_METAMODEL); 165 | l.launch(IN_METAMODEL, IN_MODEL, OUT_METAMODEL, OUT_MODEL, TRANSFORMATION_DIR, TRANSFORMATION_MODULE); 166 | } 167 | } 168 | --------------------------------------------------------------------------------