ConfigFileCreator.java
Go to the documentation of this file.
00001 package org.best_of_robotics.transform.ros.to.cplusplus.tools;
00002 
00003 import java.io.BufferedReader;
00004 import java.io.BufferedWriter;
00005 import java.io.File;
00006 import java.io.FileWriter;
00007 import java.io.IOException;
00008 import java.io.InputStreamReader;
00009 import java.util.ArrayList;
00010 import java.util.Iterator;
00011 import java.util.List;
00012 
00013 import org.eclipse.epsilon.eol.tools.AbstractTool;
00014 
00015 public class ConfigFileCreator extends AbstractTool {
00016         protected String directory;
00017         private ArrayList<String> yaml_string = new ArrayList<String>();
00018   
00019   public void setDirectory(String directory) {
00020             this.directory = directory.replace("file:", "");
00021           }
00022   
00023   public ArrayList<String> getYaml(String type)
00024   {
00025           Process pr;
00026                 try {
00027                         String cmd = "rosmsg-proto msg -H " + type.replace("::", "/");
00028                         //System.out.println(cmd);
00029                         pr = Runtime.getRuntime().exec(cmd);
00030                         pr.waitFor();
00031                         BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
00032                         String temp;
00033                         yaml_string.clear();
00034                         while ((temp = buf.readLine()) != null) {
00035                                 yaml_string.add(temp);
00036                         }
00037                         //System.out.println(yaml_string.toString());
00038                         return yaml_string;
00039                 } catch (IOException e) {
00040                         e.printStackTrace();
00041                 } 
00042                 catch (InterruptedException e) {
00043                 // TODO Auto-generated catch block
00044                 e.printStackTrace();
00045                 }
00046                 return new ArrayList<String>();
00047   }
00048   
00049   public void write(String filename, String type)
00050   {
00051         File f = new File(directory+"/"+filename);
00052         if(f.exists()) {
00053                 return;
00054         }
00055         FileWriter fstream = null;
00056         try {
00057                 fstream = new FileWriter(f);
00058                 BufferedWriter out = new BufferedWriter(fstream);
00059                 out.write("#Generated once for configuration of goals");
00060                 out.newLine();
00061                 out.write("#Config " + filename);
00062                 out.newLine();
00063                 Iterator<String> itr = getYaml(type).iterator();
00064                 while (itr.hasNext()) {
00065                         out.write(itr.next());
00066                         out.newLine();
00067                 }
00068                 out.close();
00069                 
00070         } catch (IOException e1) {
00071                 // TODO Auto-generated catch block
00072                 e1.printStackTrace();
00073         }
00074   }
00075   
00076 
00077           
00078   
00079 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34