| 1 | /** |
| 2 | * BSD-style license; for more info see http://xradar.sourceforge.net/license.html |
| 3 | */ |
| 4 | package org.sourceforge.xradar; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.Arrays; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import org.sourceforge.xradar.dynamics.XRadarDynamics; |
| 11 | |
| 12 | /** |
| 13 | * <p>Main to run XRadar as a command line tools (for the bravier men of all !)</p> |
| 14 | * |
| 15 | * @author Romain PELISSE <belaran@gmail.com> |
| 16 | * @author Zahir Nuckchady, zahir.nu@gmail.com |
| 17 | */ |
| 18 | public class XRadarExecute { |
| 19 | |
| 20 | private static final String STATIC = "static"; |
| 21 | private static final String DYNAMIC = "dynamic"; |
| 22 | |
| 23 | /** |
| 24 | * <p>Main method to run XRadar.</p> |
| 25 | * @param args |
| 26 | * @throws XRadarException |
| 27 | */ |
| 28 | public static void main(String[] args) throws XRadarException { |
| 29 | List<String> arguments = Arrays.asList(args); |
| 30 | List<String> argumentsWithoutParams = new ArrayList<String>(arguments); |
| 31 | if( ! (arguments.contains(STATIC) || arguments.contains(DYNAMIC))){ |
| 32 | throw new IllegalArgumentException("Specify if reports are either '" + STATIC + "' or '" + DYNAMIC + "'."); |
| 33 | } |
| 34 | if( (arguments.contains(STATIC) && arguments.contains(DYNAMIC))){ |
| 35 | throw new IllegalArgumentException("Reports should be either '" + STATIC + "' or '" + DYNAMIC + "', not both at the same time."); |
| 36 | } |
| 37 | for(String argument :arguments){ |
| 38 | if ( argument.contains(STATIC) ) { |
| 39 | //Removing keyword static from the arguments passed in the command line |
| 40 | argumentsWithoutParams.remove(STATIC); |
| 41 | //Converting the linked list into a String Array |
| 42 | String[] newArgs = new String[argumentsWithoutParams.size()]; |
| 43 | argumentsWithoutParams.toArray(newArgs); |
| 44 | //newArgs is sent as a String Array |
| 45 | XRadarStaticsCmdLine.runXRadarStatics(newArgs); |
| 46 | } |
| 47 | else if (argument.contains(DYNAMIC)){ |
| 48 | //Removing keyword dynamic from the arguments passed in the command line |
| 49 | argumentsWithoutParams.remove(DYNAMIC); |
| 50 | //Converting the linked list into a String Array |
| 51 | String[] newArgs = new String[argumentsWithoutParams.size()]; |
| 52 | argumentsWithoutParams.toArray(newArgs); |
| 53 | //newArgs is sent as a String Array |
| 54 | XRadarDynamics.runDynamics(newArgs); |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |