Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. import java.io.BufferedWriter;
  2. import java.io.FileWriter;
  3. import java.text.SimpleDateFormat;
  4. import java.util.*;
  5.  
  6. import utils.*;
  7.  
  8. /**
  9.  * A program for managing the can id database
  10.  *
  11.  * @author      Mattias Runge
  12.  * @version     0.1
  13.  */
  14. public class CanIdManager
  15. {
  16.     /**
  17.      * Main for this program
  18.      *
  19.      * @param args  The arguments specified at the command line
  20.      */
  21.     public static void main(String[] args)
  22.     {
  23.         System.out.println("Can Id Manager, version 0.1");
  24.         System.out.println();
  25.        
  26.         ArrayList<String> validFlags = new ArrayList<String>();
  27.        
  28.         validFlags.add("l");
  29.         validFlags.add("r");
  30.         validFlags.add("a");
  31.        
  32.         String changelogFilename = "../../EmbeddedSoftware/AVR/avr-lib/drivers/can/modules/changes.txt";
  33.         String xmlFilename = "../../EmbeddedSoftware/AVR/avr-lib/drivers/can/modules/canId.xml";
  34.         String cheaderFilename = "../../EmbeddedSoftware/AVR/avr-lib/drivers/can/modules/canId.h";
  35.        
  36.         try
  37.         {
  38.             Runtime runtime = Runtime.getRuntime();
  39.        
  40.             System.out.println("Running svn update on " + xmlFilename);
  41.            
  42.             Process proc = runtime.exec("svn update " + xmlFilename);
  43.        
  44.             proc.waitFor();
  45.            
  46.             System.out.println("svn update complete");
  47.             System.out.println();
  48.        
  49.             CommandLineParse clp = new CommandLineParse(args, validFlags);
  50.            
  51.             // Check for action flags, one must be set
  52.             if (!clp.isFlagSet("l") && !clp.isFlagSet("r") && !clp.isFlagSet("a"))
  53.             {
  54.                 System.out.println("Argument error: You must specify one and only one action flag");
  55.                 printCommandHelp();
  56.                 System.exit(1);
  57.             }
  58.            
  59.             Database db = new Database(xmlFilename);
  60.            
  61.             if (clp.isFlagSet("l"))
  62.             {
  63.                 ArrayList<String> arguments = clp.getFlagArguments("l");
  64.            
  65.                 ListOutput listOutput = new ListOutput();
  66.                
  67.                 if (arguments.size() == 0)
  68.                 {
  69.                     listOutput.listAll(db);
  70.                 }
  71.                 else
  72.                 {
  73.                     if (arguments.get(0).compareTo("commands") == 0)
  74.                     {
  75.                         listOutput.listCommands(db);
  76.                     }
  77.                     else if (arguments.get(0).compareTo("classes") == 0)
  78.                     {
  79.                         listOutput.listClasses(db);
  80.                     }
  81.                     else if (arguments.get(0).compareTo("modules") == 0)
  82.                     {
  83.                         listOutput.listModules(db);
  84.                     }
  85.                     else if (arguments.get(0).compareTo("commandtypes") == 0)
  86.                     {
  87.                         listOutput.listCommandTypes(db);
  88.                     }
  89.                     else if (arguments.get(0).compareTo("sendingtypes") == 0)
  90.                     {
  91.                         listOutput.listSendingTypes(db);
  92.                     }
  93.                     else if (arguments.get(0).compareTo("directiontypes") == 0)
  94.                     {
  95.                         listOutput.listDirectionTypes(db);
  96.                     }
  97.                     else
  98.                     {
  99.                         System.out.println("Argument error: Unknown listing type specified:" + arguments.get(0));
  100.                         printCommandHelp();
  101.                         System.exit(1);
  102.                     }
  103.                 }
  104.             }
  105.             else if (clp.isFlagSet("r"))
  106.             {
  107.                 CHeader cHeader = new CHeader(cheaderFilename);
  108.                 cHeader.build(db);
  109.             }
  110.             else if (clp.isFlagSet("a"))
  111.             {
  112.                 ArrayList<String> arguments = clp.getFlagArguments("a");
  113.                
  114.                 if (arguments.size() == 0)
  115.                 {
  116.                     System.out.println("Argument error: You must specify what you want to add");
  117.                     printCommandHelp();
  118.                     System.exit(1);
  119.                 }
  120.                
  121.                 if (arguments.get(0).compareTo("command") == 0)
  122.                 {
  123.                     Input.addCommand(db);
  124.                 }
  125.                 else if (arguments.get(0).compareTo("class") == 0)
  126.                 {
  127.                     Input.addClass(db);
  128.                 }
  129.                 else if (arguments.get(0).compareTo("module") == 0)
  130.                 {
  131.                     Input.addModule(db);
  132.                 }
  133.             }
  134.  
  135.             if (db.hasChanged())
  136.             {
  137.                 System.out.println("Writing new " + xmlFilename);
  138.                
  139.                 db.saveChanges(xmlFilename);
  140.                
  141.                 FileWriter fstream = new FileWriter(changelogFilename);
  142.                 BufferedWriter out = new BufferedWriter(fstream);
  143.                 out.write(db.getChangeLog());
  144.                 out.close();
  145.    
  146.                 System.out.println("Running svn commit on " + xmlFilename);
  147.                
  148.                 proc = runtime.exec("svn --file " + changelogFilename + " commit " + xmlFilename);
  149.  
  150.                 proc.waitFor();
  151.                
  152.                 System.out.println("svn commit complete");
  153.                 System.out.println();
  154.                
  155.                 CHeader cHeader = new CHeader(cheaderFilename);
  156.                 cHeader.build(db);
  157.             }
  158.         }
  159.         catch (Exception e)
  160.         {
  161.             System.out.println(e.getMessage());
  162.             System.exit(1);
  163.         }
  164.     }
  165.    
  166.     /**
  167.      * Prints the help text to standard out
  168.      *
  169.      */
  170.     private static void printCommandHelp()
  171.     {
  172.         System.out.println("usage: CanIdManager [-l [commands|classes|modules|commandtypes|sendingtypes|directiontypes]] [-r] [-a [command|class|module]");// [-d library name] [-d [suffix_1, suffix_2, ..., suffix_n]]");
  173.     }
  174. }
  175.