$search
00001 00015 package org.best_of_robotics.transform.ros.to.cplusplus.jobs; 00016 00017 import java.io.IOException; 00018 import java.net.URI; 00019 import java.net.URISyntaxException; 00020 import java.net.URL; 00021 00022 import org.best_of_robotics.transform.ros.to.cplusplus.Activator; 00023 import org.eclipse.core.resources.IProject; 00024 import org.eclipse.core.resources.WorkspaceJob; 00025 import org.eclipse.core.runtime.CoreException; 00026 import org.eclipse.core.runtime.FileLocator; 00027 import org.eclipse.core.runtime.IProgressMonitor; 00028 import org.eclipse.core.runtime.IStatus; 00029 import org.eclipse.core.runtime.Status; 00030 import org.eclipse.emf.ecore.resource.Resource; 00031 import org.eclipse.epsilon.common.parse.problem.ParseProblem; 00032 import org.eclipse.epsilon.egl.EglFileGeneratingTemplateFactory; 00033 import org.eclipse.epsilon.egl.EglTemplateFactoryModuleAdapter; 00034 import org.eclipse.epsilon.egl.exceptions.EglRuntimeException; 00035 import org.eclipse.epsilon.emc.emf.InMemoryEmfModel; 00036 import org.eclipse.epsilon.eol.IEolExecutableModule; 00037 import org.eclipse.epsilon.eol.exceptions.EolRuntimeException; 00038 import org.ros.model.ros.RosPackage; 00039 import org.eclipse.epsilon.eol.dt.*; 00040 00041 public class EglTransformOperationJob extends WorkspaceJob { 00042 00043 private String transformEntryPath = "epsilon/package.egl"; 00044 private IProject project; 00045 private InMemoryEmfModel sourceModel; 00046 00047 public EglTransformOperationJob(String name) { 00048 super(name); 00049 } 00050 00051 @Override 00052 public IStatus runInWorkspace(IProgressMonitor monitor) 00053 throws CoreException { 00054 monitor.beginTask(getName(), 4); 00055 00056 URL transformationEntry = Activator.getDefault().getBundle() 00057 .getEntry(transformEntryPath); 00058 URL resolvedTransformationURL = null; 00059 URI transformURI = null; 00060 try { 00061 resolvedTransformationURL = FileLocator 00062 .resolve(transformationEntry); 00063 transformURI = resolvedTransformationURL.toURI(); 00064 } catch (IOException e) { 00065 e.printStackTrace(); 00066 } catch (URISyntaxException e) { 00067 e.printStackTrace(); 00068 } 00069 00070 monitor.worked(1); 00071 00072 00073 EglFileGeneratingTemplateFactory eglTemplateFactory = new EglFileGeneratingTemplateFactory(); 00074 IEolExecutableModule eglModule = new EglTemplateFactoryModuleAdapter( 00075 eglTemplateFactory); 00076 try { 00077 eglTemplateFactory.setOutputRoot(project 00078 .getLocation().toOSString()); 00079 eglModule.parse(transformURI); 00080 } catch (EglRuntimeException e2) { 00081 e2.printStackTrace(); 00082 } catch (Exception e) { 00083 e.printStackTrace(); 00084 } 00085 00086 monitor.worked(1); 00087 00088 if (eglModule.getParseProblems().size() > 0) { 00089 System.err.println("Parse errors occured..."); 00090 for (ParseProblem problem : eglModule.getParseProblems()) { 00091 System.err.println(problem.toString()); 00092 } 00093 } 00094 00095 eglModule.getContext().getNativeTypeDelegates().add(new ExtensionPointToolNativeTypeDelegate()); 00096 00097 eglModule.getContext().getModelRepository().addModel(sourceModel); 00098 try { 00099 eglModule.execute(); 00100 } catch (EolRuntimeException e) { 00101 e.printStackTrace(); 00102 } 00103 eglModule.getContext().getModelRepository().dispose(); 00104 monitor.done(); 00105 00106 00107 return Status.OK_STATUS; 00108 } 00109 00110 public void setProject(IProject project) { 00111 this.project = project; 00112 } 00113 00114 public void createSource(Resource resource) { 00115 if (resource != null) { 00116 sourceModel = new InMemoryEmfModel( 00117 "Source", resource, RosPackage.eINSTANCE); 00118 sourceModel.setReadOnLoad(true); 00119 sourceModel.setStoredOnDisposal(false); 00120 } 00121 00122 } 00123 00124 }