Ejemplo n.º 1
0
 /**
  * Initialize options from properties object
  *
  * @param properties
  * @throws IOException
  * @throws FileNotFoundException
  * @throws CmdLineException
  */
 public MolgenisOptions(Properties properties) {
   CmdLineParser parser;
   try {
     parser = new CmdLineParser(this);
     parser.parse(properties);
     Logger.getLogger(this.getClass().getSimpleName()).debug("parsed properties file.");
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     throw new RuntimeException("Cannot find property file: " + e.getMessage());
   }
 }
Ejemplo n.º 2
0
  /**
   * Initialize options from properties file
   *
   * @param propertiesFile the path string to molgenis.properties file
   * @throws IOException
   * @throws FileNotFoundException
   * @throws CmdLineException
   */
  public MolgenisOptions(String propertiesFile)
      throws FileNotFoundException, IOException, CmdLineException {
    this.molgenis_properties = propertiesFile;
    Properties props = new Properties();
    try {
      // try to load from local files
      props.load(new FileInputStream(propertiesFile.trim()));
    } catch (FileNotFoundException e) {
      try {
        // try to load from classpath
        props.load(ClassLoader.getSystemResourceAsStream(propertiesFile.trim()));
      } catch (Exception e2) {
        throw new IOException("couldn't find file " + new File(propertiesFile).getAbsolutePath());
      }
    }

    CmdLineParser parser = new CmdLineParser(this);
    parser.parse(props);
    this.molgenis_properties = propertiesFile;

    // parse passwordfile
    String passwordFile = propertiesFile.replace(".properties", ".passwd");
    this.molgenis_passwd = passwordFile;
    props = new Properties();
    try {
      // try to load from local files
      props.load(new FileInputStream(passwordFile.trim()));
    } catch (FileNotFoundException e) {
      try {
        // try to load from classpath
        props.load(ClassLoader.getSystemResourceAsStream(passwordFile.trim()));
      } catch (Exception e2) {
        // no biggie
      }
    }
    parser = new CmdLineParser(this);
    parser.parse(props);

    // warn if no password was provided
    if ("".equals(this.db_password))
      System.err.println(
          "WARNING: db_password was not provided in neither "
              + propertiesFile
              + " nor "
              + passwordFile);

    Logger.getLogger(this.getClass().getSimpleName()).debug("parsed properties file.");
  }