$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 00040 public class LaunchFile_EglTransformOperationJob extends WorkspaceJob { 00041 00042 private String transformEntryPath = "epsilon/architecture.egl"; 00043 private IProject project; 00044 private InMemoryEmfModel sourceModel; 00045 00046 public LaunchFile_EglTransformOperationJob(String name) { 00047 super(name); 00048 } 00049 00050 @Override 00051 public IStatus runInWorkspace(IProgressMonitor monitor) 00052 throws CoreException { 00053 monitor.beginTask(getName(), 4); 00054 00055 URL transformationEntry = Activator.getDefault().getBundle() 00056 .getEntry(transformEntryPath); 00057 URL resolvedTransformationURL = null; 00058 URI transformURI = null; 00059 try { 00060 resolvedTransformationURL = FileLocator 00061 .resolve(transformationEntry); 00062 transformURI = resolvedTransformationURL.toURI(); 00063 } catch (IOException e) { 00064 e.printStackTrace(); 00065 } catch (URISyntaxException e) { 00066 e.printStackTrace(); 00067 } 00068 00069 monitor.worked(1); 00070 00071 EglFileGeneratingTemplateFactory eglTemplateFactory = new EglFileGeneratingTemplateFactory(); 00072 IEolExecutableModule eglModule = new EglTemplateFactoryModuleAdapter( 00073 eglTemplateFactory); 00074 try { 00075 eglTemplateFactory.setOutputRoot(project 00076 .getLocation().toOSString()); 00077 eglModule.parse(transformURI); 00078 } catch (EglRuntimeException e2) { 00079 e2.printStackTrace(); 00080 } catch (Exception e) { 00081 e.printStackTrace(); 00082 } 00083 00084 monitor.worked(1); 00085 00086 if (eglModule.getParseProblems().size() > 0) { 00087 System.err.println("Parse errors occured..."); 00088 for (ParseProblem problem : eglModule.getParseProblems()) { 00089 System.err.println(problem.toString()); 00090 } 00091 } 00092 eglModule.getContext().getModelRepository().addModel(sourceModel); 00093 try { 00094 eglModule.execute(); 00095 } catch (EolRuntimeException e) { 00096 e.printStackTrace(); 00097 } 00098 eglModule.getContext().getModelRepository().dispose(); 00099 monitor.done(); 00100 00101 00102 return Status.OK_STATUS; 00103 } 00104 00105 public void setProject(IProject project) { 00106 this.project = project; 00107 } 00108 00109 public void createSource(Resource resource) { 00110 if (resource != null) { 00111 sourceModel = new InMemoryEmfModel( 00112 "Source", resource, RosPackage.eINSTANCE); 00113 sourceModel.setReadOnLoad(true); 00114 sourceModel.setStoredOnDisposal(false); 00115 } 00116 00117 } 00118 00119 }