$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 Python_EglTransformOperationJob extends WorkspaceJob { 00042 00043 private String transformEntryPath = "epsilon/python_package.egl"; 00044 private IProject project; 00045 private InMemoryEmfModel sourceModel; 00046 00047 public Python_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 EglFileGeneratingTemplateFactory eglTemplateFactory = new EglFileGeneratingTemplateFactory(); 00073 IEolExecutableModule eglModule = new EglTemplateFactoryModuleAdapter( 00074 eglTemplateFactory); 00075 try { 00076 eglTemplateFactory.setOutputRoot(project 00077 .getLocation().toOSString()); 00078 eglModule.parse(transformURI); 00079 } catch (EglRuntimeException e2) { 00080 e2.printStackTrace(); 00081 } catch (Exception e) { 00082 e.printStackTrace(); 00083 } 00084 00085 monitor.worked(1); 00086 00087 if (eglModule.getParseProblems().size() > 0) { 00088 System.err.println("Parse errors occured..."); 00089 for (ParseProblem problem : eglModule.getParseProblems()) { 00090 System.err.println(problem.toString()); 00091 } 00092 } 00093 00094 eglModule.getContext().getNativeTypeDelegates().add(new ExtensionPointToolNativeTypeDelegate()); 00095 00096 eglModule.getContext().getModelRepository().addModel(sourceModel); 00097 try { 00098 eglModule.execute(); 00099 } catch (EolRuntimeException e) { 00100 e.printStackTrace(); 00101 } 00102 eglModule.getContext().getModelRepository().dispose(); 00103 monitor.done(); 00104 return Status.OK_STATUS; 00105 } 00106 00107 public void setProject(IProject project) { 00108 this.project = project; 00109 } 00110 00111 public void createSource(Resource resource) { 00112 if (resource != null) { 00113 sourceModel = new InMemoryEmfModel( 00114 "Source", resource, RosPackage.eINSTANCE); 00115 sourceModel.setReadOnLoad(true); 00116 sourceModel.setStoredOnDisposal(false); 00117 } 00118 00119 } 00120 00121 }