<commit_before>package jade;

import java.util.*;
import java.net.*;

    /**
       This class collects all the command line arguments into a single
       object, just for convenience purposes.
       @author <NAME> - TILab
     **/
public class BootArguments {
	
	//This separates the single arguments in a list of arguments
	private static final String ARGUMENT_SEPARATOR = ";";
	public static final String SEPARATOR = ":";

	private static int platformPort = 1099; //default value for the port 
    
    String hostName;
    int    portNo;
    boolean startRMAGUI;
    boolean isContainer;
    boolean startConfGUI;
    String  confFileName;
    boolean printVersionInfo;
    boolean printUsageInfo;
    boolean noMTP;
    String[] MTPs;  //FIXME.To improve
    String[] aclCodecs; //FIXME to improve
    ArrayList agents; //FIXME to improve the data structure
	
	/** constructor of the class. It sets all the arguments to
	 * the default value
	 **/
	BootArguments() {
	    try {
		hostName= InetAddress.getLocalHost().getHostName();      
	    } catch(UnknownHostException uhe) {
		System.out.print("Unknown host exception in getLocalHost(): ");
		System.out.println(" please use '-host' and/or '-port' options to setup JADE host and port");
		System.exit(1);
	    }
	    portNo = platformPort;
	    startRMAGUI = false;
	    isContainer = false;
	    startConfGUI = false;
	    confFileName = null;
	    printVersionInfo = false;
	    printUsageInfo = false;
	    noMTP = false;
	    MTPs = null;
	    aclCodecs = null;
	    agents = new ArrayList();
	}   
	
	/**
	 * return a String representation for debugging purposes
	 **/
	public String toString() {
	    String tmp = new String();
	    tmp = tmp + " :host "+hostName;
	    tmp = tmp + " :portNumber "+portNo;
	    tmp = tmp + " :startRMAGUI "+startRMAGUI;
	    tmp = tmp + " :isContainer "+isContainer;
	    tmp = tmp + " :startConfGUI "+startConfGUI;
	    tmp = tmp + " :confFileName "+confFileName;
	    tmp = tmp + " :printVersionInfo "+printVersionInfo;
	    tmp = tmp + " :printUsageInfo "+printUsageInfo;
	    tmp = tmp + " :noMTP "+noMTP;
	    if (MTPs != null) {
		tmp = tmp + " :MTPs ";
		for (int i=0; i<MTPs.length; i++)
		    tmp = tmp + MTPs[i] + " ";
	    }
	    if (aclCodecs != null) {
		tmp = tmp + " :aclCodecs ";
		for (int i=0; i<aclCodecs.length; i++)
		    tmp = tmp + aclCodecs[i] + " ";
	    }
	  
	  Iterator agentSpecifiers = agents.iterator();
	    while(agentSpecifiers.hasNext()) {
		Iterator i = ((List)agentSpecifiers.next()).iterator();
		tmp = tmp + " :agentName "+(String)i.next();
		tmp = tmp + " :agentClass "+(String)i.next();
		tmp = tmp + " :agentArguments ";
		for ( ; i.hasNext(); )	         
		    tmp = tmp + (String)i.next() + " ";
	    }
	    return tmp;
	}

    /**
     * returns a list of PropertyType used by the BootGUI to initialize the GUI.
     **/
  public   List getPropertyTypeVector() {
  	
		List propertyVector = new ArrayList();
		PropertyType HostProperty = new PropertyType("host",PropertyType.STRING_TYPE,hostName, "Host Name of the main-container", false);
		PropertyType GuiProperty = new PropertyType("gui",PropertyType.BOOLEAN_TYPE,new Boolean(startRMAGUI).toString(), "Select to launch the RMA Gui", false);
		PropertyType PortProperty = new PropertyType("port",PropertyType.STRING_TYPE,new Integer(portNo).toString(), "Port Number of the main-container", false);
		PropertyType ContainerProperty = new PropertyType("container", PropertyType.BOOLEAN_TYPE, new Boolean(isContainer).toString(), "Select to launch an agent-container",false);
		PropertyType MTPProperty = new PropertyType("mtp", PropertyType.STRING_TYPE, toMTPsString(), "List of MTPs to activate", false); 
		PropertyType NoMTPProperty = new PropertyType("nomtp", PropertyType.BOOLEAN_TYPE, new Boolean(noMTP).toString(), "Disable all external MTPs on this container", false);		
		PropertyType ACLCodecProperty = new PropertyType("aclcodec", PropertyType.STRING_TYPE, toACLCodecsString(),"List of ACLCodec to install",false); 
		PropertyType AgentProperty = new PropertyType("agents",PropertyType.STRING_TYPE,toAgentString(),"Agents to launch",false);
		//update the propertyVector with all the -option 
		propertyVector.add(HostProperty);
		propertyVector.add(PortProperty);
		propertyVector.add(GuiProperty);
		propertyVector.add(ContainerProperty);
		propertyVector.add(MTPProperty);
		propertyVector.add(NoMTPProperty);
		propertyVector.add(ACLCodecProperty);
		propertyVector.add(AgentProperty);
		
		return propertyVector;
  }

    
    
  /**
  * This method verifies the configuration properties and eventually correct them.
  * It checks if the port number is a number greater than 0 otherwise it throws a BootException,
  * and if the -nomtp has been set, then delete some other mtp wrongly set. 
  * 
  */
    public void check() throws BootException{
    	
    
  		if(portNo <= 0)
  		{		
	  		portNo = platformPort;	
  			throw new BootException("WARNING: Port number must be a number > 0.");
  		}
  		

			// Remove the MTP list if '-nomtp' is specified
			if(noMTP && !(MTPs == null || MTPs.length == 0))
	  	{
	  		MTPs = null;
	  		throw new BootException("WARNING: If the option noMTP is on, then no MTP can be inserted.");
	  	}
    }
    
    
    //parser a string of arguments of the type property1(arg1);property2(arg2);property3
		//if  the property can have arguments set arguments to true, false otherwise
    public static String[] parseArgumentList(String argList, boolean arguments) throws BootException {<commit_msg>Added check for launching a platform on the local host (<NAME>, HP Palo Alto)<commit_after>package jade;

import java.util.*;
import java.net.*;

    /**
       This class collects all the command line arguments into a single
       object, just for convenience purposes.
       @author <NAME> - TILab
     **/
public class BootArguments {
	
	//This separates the single arguments in a list of arguments
	private static final String ARGUMENT_SEPARATOR = ";";
	public static final String SEPARATOR = ":";

	private static int platformPort = 1099; //default value for the port 
    
    String hostName;
    int    portNo;
    boolean startRMAGUI;
    boolean isContainer;
    boolean startConfGUI;
    String  confFileName;
    boolean printVersionInfo;
    boolean printUsageInfo;
    boolean noMTP;
    String[] MTPs;  //FIXME.To improve
    String[] aclCodecs; //FIXME to improve
    ArrayList agents; //FIXME to improve the data structure
	
	/** constructor of the class. It sets all the arguments to
	 * the default value
	 **/
	BootArguments() {
	    try {
		hostName= InetAddress.getLocalHost().getHostName();      
	    } catch(UnknownHostException uhe) {
		System.out.print("Unknown host exception in getLocalHost(): ");
		System.out.println(" please use '-host' and/or '-port' options to setup JADE host and port");
		System.exit(1);
	    }
	    portNo = platformPort;
	    startRMAGUI = false;
	    isContainer = false;
	    startConfGUI = false;
	    confFileName = null;
	    printVersionInfo = false;
	    printUsageInfo = false;
	    noMTP = false;
	    MTPs = null;
	    aclCodecs = null;
	    agents = new ArrayList();
	}   
	
	/**
	 * return a String representation for debugging purposes
	 **/
	public String toString() {
	    String tmp = new String();
	    tmp = tmp + " :host "+hostName;
	    tmp = tmp + " :portNumber "+portNo;
	    tmp = tmp + " :startRMAGUI "+startRMAGUI;
	    tmp = tmp + " :isContainer "+isContainer;
	    tmp = tmp + " :startConfGUI "+startConfGUI;
	    tmp = tmp + " :confFileName "+confFileName;
	    tmp = tmp + " :printVersionInfo "+printVersionInfo;
	    tmp = tmp + " :printUsageInfo "+printUsageInfo;
	    tmp = tmp + " :noMTP "+noMTP;
	    if (MTPs != null) {
		tmp = tmp + " :MTPs ";
		for (int i=0; i<MTPs.length; i++)
		    tmp = tmp + MTPs[i] + " ";
	    }
	    if (aclCodecs != null) {
		tmp = tmp + " :aclCodecs ";
		for (int i=0; i<aclCodecs.length; i++)
		    tmp = tmp + aclCodecs[i] + " ";
	    }
	  
	  Iterator agentSpecifiers = agents.iterator();
	    while(agentSpecifiers.hasNext()) {
		Iterator i = ((List)agentSpecifiers.next()).iterator();
		tmp = tmp + " :agentName "+(String)i.next();
		tmp = tmp + " :agentClass "+(String)i.next();
		tmp = tmp + " :agentArguments ";
		for ( ; i.hasNext(); )	         
		    tmp = tmp + (String)i.next() + " ";
	    }
	    return tmp;
	}

    /**
     * returns a list of PropertyType used by the BootGUI to initialize the GUI.
     **/
  public   List getPropertyTypeVector() {
  	
		List propertyVector = new ArrayList();
		PropertyType HostProperty = new PropertyType("host",PropertyType.STRING_TYPE,hostName, "Host Name of the main-container", false);
		PropertyType GuiProperty = new PropertyType("gui",PropertyType.BOOLEAN_TYPE,new Boolean(startRMAGUI).toString(), "Select to launch the RMA Gui", false);
		PropertyType PortProperty = new PropertyType("port",PropertyType.STRING_TYPE,new Integer(portNo).toString(), "Port Number of the main-container", false);
		PropertyType ContainerProperty = new PropertyType("container", PropertyType.BOOLEAN_TYPE, new Boolean(isContainer).toString(), "Select to launch an agent-container",false);
		PropertyType MTPProperty = new PropertyType("mtp", PropertyType.STRING_TYPE, toMTPsString(), "List of MTPs to activate", false); 
		PropertyType NoMTPProperty = new PropertyType("nomtp", PropertyType.BOOLEAN_TYPE, new Boolean(noMTP).toString(), "Disable all external MTPs on this container", false);		
		PropertyType ACLCodecProperty = new PropertyType("aclcodec", PropertyType.STRING_TYPE, toACLCodecsString(),"List of ACLCodec to install",false); 
		PropertyType AgentProperty = new PropertyType("agents",PropertyType.STRING_TYPE,toAgentString(),"Agents to launch",false);
		//update the propertyVector with all the -option 
		propertyVector.add(HostProperty);
		propertyVector.add(PortProperty);
		propertyVector.add(GuiProperty);
		propertyVector.add(ContainerProperty);
		propertyVector.add(MTPProperty);
		propertyVector.add(NoMTPProperty);
		propertyVector.add(ACLCodecProperty);
		propertyVector.add(AgentProperty);
		
		return propertyVector;
  }

    
    
  /**
  * This method verifies the configuration properties and eventually correct them.
  * It checks if the port number is a number greater than 0 otherwise it throws a BootException,
  * and if the -nomtp has been set, then delete some other mtp wrongly set.
  * If the user wants to start a platform the host
  * must be the local host so if a different name is speficied it
  * will be corrected and an exception will be thrown.   
  * 
  */
    public void check() throws BootException{
    	
    
  		if(portNo <= 0)
  		{		
	  		portNo = platformPort;	
  			throw new BootException("WARNING: Port number must be a number > 0.");
  		}
  		

			// Remove the MTP list if '-nomtp' is specified
			if(noMTP && !(MTPs == null || MTPs.length == 0))
	  	{
	  		MTPs = null;
	  		throw new BootException("WARNING: If the option noMTP is on, then no MTP can be inserted.");
	  	}

      if (!isContainer) { // then it is a platform
	  try {
	      InetAddress myPlatformAddrs[] =
		  InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
	      InetAddress hostAddrs[] = InetAddress.getAllByName(hostName);
	      
	      // If the platform address equals the host address, then
	      // the user is starting the main container (platform) on
	      // the local host.  The trick here is to compare the InetAddress
	      // objects, not the strings since the one string might be a
	      // fully qualified Internet domain name for the host and the 
	      // other might be a simple name.  
	      // Example: myHost.hpl.hp.com and myHost might
	      // acutally be the same host even though the hostname strings do
	      // not match.  When the InetAddress objects are compared, the IP
	      // addresses will be compared.
	      int i = 0;
	      boolean isLocal = false;
	      while ( (!isLocal) && (i < myPlatformAddrs.length) ) {
		  int j = 0;
		  while ( (!isLocal) && (j < hostAddrs.length) ) {
		      isLocal = myPlatformAddrs[i].equals(hostAddrs[j]);
		      j++;
		  }
		  i++;
	      }

	      if( !isLocal ) {
		  hostName = myPlatformAddrs[0].getHostName();
		  throw new BootException("WARNING: Not possible to launch a platform"
					  + "\n"
					  + "on a different host."
					  + "\n"
					  + "A platform must be launched on local host."
					  );
	      }
	  } catch(UnknownHostException uhe) {
	      // uhe.printStackTrace();
	      //hostName = myPlatformAddrs[0].getHostName();
	      throw new BootException("WARNING: Not possible to launch a platform"
				      + "\n"
				      + "on a different host."
				      + "\n"
				      + "A platform must be launched on local host."
				      );
	  }
      } //END if(!isContainer) -- i.e. (this is a platform)
    }
    
    
    //parser a string of arguments of the type property1(arg1);property2(arg2);property3
		//if  the property can have arguments set arguments to true, false otherwise
    public static String[] parseArgumentList(String argList, boolean arguments) throws BootException {
{'fraction_non_alphanumeric': 0.1094807268303809, 'fraction_numerical': 0.0027370181707595228, 'mean_word_length': 3.1209273182957395, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2105473', 'n_tokens_mistral': 4179, 'n_tokens_neox': 3803, 'n_words': 1232}