示例#1
0
 public static Properties expandPropertyVars(Properties props) {
   // Create a new Properties with variables expanded
   Properties expanded = new Properties();
   for (String str : props.stringPropertyNames()) {
     String value = props.getProperty(str);
     Set<String> vars = new HashSet<String>();
     Matcher m = varPattern.matcher(value);
     while (m.find()) {
       vars.add(m.group(1));
     }
     String expandedValue = value;
     if (vars.size() > 0) {
       String[] expandedValues = new String[] {value};
       for (String var : vars) {
         String varValue = props.getProperty(var);
         String[] varValueExpanded = varValue.split("[,\\s]+");
         String[] unexpandedValues = expandedValues;
         expandedValues = new String[unexpandedValues.length * varValueExpanded.length];
         int i = 0;
         String replaceRegex = Pattern.quote("${" + var + "}");
         for (String v : varValueExpanded) {
           for (String ex : unexpandedValues) {
             expandedValues[i] = ex.replaceAll(replaceRegex, v);
             i++;
           }
         }
       }
       expandedValue = StringUtils.join(expandedValues, ",");
       System.err.println("Expanded property " + str + ": " + value + " to " + expandedValue);
     }
     expanded.put(str, expandedValue);
   }
   return expanded;
 }
 @DataBoundConstructor
 public EnvParamValue(String envName, EnvParamDescriptor descriptor) {
   super("environment", envName);
   data = new HashMap<String, String>();
   data.put("environment", envName);
   Properties properties = searchPropertiesForEnvironment(envName, descriptor);
   for (String name : properties.stringPropertyNames()) {
     data.put(name, properties.getProperty(name));
   }
 }
  @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
  protected void loadDefaults(UIDefaults defaults) {
    final Properties properties = new Properties();
    final String osSuffix = SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux";
    try {
      InputStream stream = getClass().getResourceAsStream(getPrefix() + ".properties");
      properties.load(stream);
      stream.close();

      stream = getClass().getResourceAsStream(getPrefix() + "_" + osSuffix + ".properties");
      properties.load(stream);
      stream.close();

      HashMap<String, Object> darculaGlobalSettings = new HashMap<String, Object>();
      final String prefix = getPrefix() + ".";
      for (String key : properties.stringPropertyNames()) {
        if (key.startsWith(prefix)) {
          darculaGlobalSettings.put(
              key.substring(prefix.length()), parseValue(key, properties.getProperty(key)));
        }
      }

      for (Object key : defaults.keySet()) {
        if (key instanceof String && ((String) key).contains(".")) {
          final String s = (String) key;
          final String darculaKey = s.substring(s.lastIndexOf('.') + 1);
          if (darculaGlobalSettings.containsKey(darculaKey)) {
            defaults.put(key, darculaGlobalSettings.get(darculaKey));
          }
        }
      }

      for (String key : properties.stringPropertyNames()) {
        final String value = properties.getProperty(key);
        defaults.put(key, parseValue(key, value));
      }
    } catch (IOException e) {
      log(e);
    }
  }
示例#4
0
 public static void fillOptions(Properties props, String[] args) {
   // (convert to map)
   Map<String, String> options = new HashMap<String, String>();
   for (String key : props.stringPropertyNames()) {
     options.put(key, props.getProperty(key));
   }
   options.putAll(parseOptions(args));
   // (bootstrap)
   fillOptions(BOOTSTRAP_CLASSES, options, false); // bootstrap
   log.bootstrap();
   log.startTrack("init");
   // (fill options)
   Class<?>[] visibleClasses = getVisibleClasses(options); // get classes
   Map<String, Field> optionFields = fillOptions(visibleClasses, options); // fill
 }
示例#5
0
  Properties runProperties() {
    Properties props = new Properties();
    props.putAll(this.properties);

    Properties sysProps = System.getProperties();

    Set<String> names = sysProps.stringPropertyNames();
    for (String name : names) {
      if (name.startsWith("jboss") || name.startsWith("wildfly") || name.startsWith("swarm")) {
        props.put(name, sysProps.get(name));
      }
    }

    return props;
  }
 public static MobileOperation convertToMobileOperation(Operation operation) {
   MobileOperation mobileOperation = new MobileOperation();
   MobileOperationProperty operationProperty;
   List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
   mobileOperation.setFeatureCode(operation.getCode());
   mobileOperation.setCreatedDate(new Date().getTime());
   Properties operationProperties = operation.getProperties();
   for (String key : operationProperties.stringPropertyNames()) {
     operationProperty = new MobileOperationProperty();
     operationProperty.setProperty(key);
     operationProperty.setValue(operationProperties.getProperty(key));
     properties.add(operationProperty);
   }
   mobileOperation.setProperties(properties);
   return mobileOperation;
 }
  /**
   * This test case builds a custom suite, containing a collection of smaller suites (one for each
   * file in src/parser-tests).
   */
  public static Test suite() throws Exception {
    TestSuite result = new TestSuite(HTMLPageParserTest.class.getName());

    Properties props = new Properties();
    props.load(new FileInputStream("src/parser-tests/parsers.properties"));

    Collection<String> parsers = new ArrayList<String>();
    for (String key : props.stringPropertyNames()) {
      Matcher matcher = PARSER_PATTERN.matcher(key);
      if (matcher.matches()) {
        parsers.add(matcher.group(1));
      }
    }

    for (String p : parsers) {
      String name = props.getProperty("parser." + p + ".class");
      Class<? extends PageParser> parserClass = Class.forName(name).asSubclass(PageParser.class);
      PageParser parser = parserClass.newInstance();

      String filesPath = props.getProperty("parser." + p + ".tests", "src/parser-tests");
      List<File> files = new ArrayList<File>(Arrays.asList(listParserTests(new File(filesPath))));
      Collections.sort(files);

      TestSuite suiteForParser = new TestSuite(name);
      for (File file : files) {
        TestSuite suiteForFile = new TestSuite(file.getName().replace('.', '_'));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testTitle"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testBody"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testHead"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testFullPage"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testProperties"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testContentSanity"));
        suiteForParser.addTest(suiteForFile);
      }
      result.addTest(suiteForParser);
    }

    return result;
  }
示例#8
0
 /**
  * Given a file that the preferences are supposedly stored in, this function will try to load the
  * preferences. If the preferences don't exist, or they are incomplete, this will also fill in the
  * missing values, and store the now complete preferences in the file location specified.
  *
  * @param prefFile
  * @throws Exception
  */
 public void init(File prefFile) throws IOException {
   this.prefFile = prefFile;
   if (prefFile.exists()) {
     Properties userProperties = new Properties();
     FileInputStream in = new FileInputStream(prefFile);
     userProperties.load(in);
     in.close();
     for (String key : userProperties.stringPropertyNames()) {
       String val = userProperties.getProperty(key);
       String value = getObject(val, ((Preference) prefs.get(key))).toString();
       Object ovalue = getObject(val, ((Preference) prefs.get(key)));
       Preference p1 = prefs.get(key);
       Preference p2;
       if (p1 != null) {
         p2 = new Preference(p1.name, value, p1.allowed, p1.description);
       } else {
         p2 = new Preference(key, val, Type.STRING, "");
       }
       p2.objectValue = ovalue;
       prefs.put(key, p2);
     }
   }
   save();
 }
 private static void merge(Properties properties, Map<String, String> options) {
   for (String propertyName : properties.stringPropertyNames()) {
     options.put(propertyName, properties.getProperty(propertyName));
   }
 }
示例#10
0
  public void load(String queryFile, String modules, String tables)
      throws SQLException, IOException, InterruptedException, ExecutionException {
    Properties properties = new Properties();
    properties.load(new FileInputStream(queryFile));

    Collection<String> keys = properties.stringPropertyNames();

    // Filtering by validating if property starts with any of the module names
    if (!Config.ALL.equalsIgnoreCase(modules)) {
      keys =
          Util.filter(
              keys, "^(" + modules.replaceAll(Config.COMMA_SEPARATOR, Config.MODULE_SUFFIX) + ")");
    }

    // Filtering by table names
    if (!Config.ALL.equalsIgnoreCase(tables)) {
      keys =
          Util.filter(
              keys, "(" + tables.replaceAll(Config.COMMA_SEPARATOR, Config.TABLE_SUFFIX) + ")$");
    }

    logger.info("The final modules and tables that are being considered" + keys.toString());

    ExecutorService executor = Executors.newFixedThreadPool(keys.size() * 3);
    CompletionService completion = new ExecutorCompletionService(executor);

    for (String key : keys) {
      String query = properties.getProperty(key);
      key =
          (key.contains(Config.DOT_SEPARATOR)
              ? key.substring(key.indexOf(Config.DOT_SEPARATOR) + 1)
              : key);

      while (query.contains("[:")) {
        String param = query.substring(query.indexOf("[:") + 2, query.indexOf("]"));

        query = query.replaceFirst("\\[\\:" + param + "\\]", properties.getProperty(param));
      }
      int pages = 1;
      String base = "";
      if (config.srisvoltdb) {
        if (config.isPaginated) {
          try {
            // find count
            String countquery = query;
            if (countquery.contains("<") || countquery.contains(">")) {
              int bracketOpen = countquery.indexOf("<");
              int bracketClose = countquery.indexOf(">");
              String orderCol = countquery.substring(bracketOpen + 1, bracketClose);
              countquery = countquery.replace("<" + orderCol + ">", "");
            }
            VoltTable vcount = client.callProcedure("@AdHoc", countquery).getResults()[0];
            int count = vcount.getRowCount();
            pages = (int) Math.ceil((double) count / config.pageSize);
          } catch (Exception e) {
            System.out.println("Count formation failure!");
          }
        }
        // set up data in order
      } else {
        // find count
        String countquery = query.replace("*", "COUNT(*)");
        Connection conn =
            DriverManager.getConnection(config.jdbcurl, config.jdbcuser, config.jdbcpassword);
        base = conn.getMetaData().getDatabaseProductName().toLowerCase();
        System.out.println("BASE: " + base);
        Statement jdbcStmt =
            conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        if (countquery.contains("<") || countquery.contains(">")) {
          int bracketOpen = countquery.indexOf("<");
          int bracketClose = countquery.indexOf(">");
          String orderCol = countquery.substring(bracketOpen + 1, bracketClose);
          countquery = countquery.replace("<" + orderCol + ">", "");
        }
        ResultSet rcount = jdbcStmt.executeQuery(countquery);
        rcount.next();
        int count = Integer.parseInt(rcount.getArray(1).toString());

        // THIS IF NEEDS A WAY TO DETERMINE IF POSTGRES
        if (base.contains("postgres") && config.isPaginated) {
          pages = (int) Math.ceil((double) count / config.pageSize);
        }
        // set up data in order
      }
      // establish new SourceReaders and DestinationWriters for pages
      SourceReader[] sr = new SourceReader[pages];
      DestinationWriter[] cr = new DestinationWriter[pages];
      for (int i = 0; i < pages; i++) {
        sr[i] = new SourceReader();
        cr[i] = new DestinationWriter();
      }
      Controller processor =
          new Controller<ArrayList<Object[]>>(
              client, sr, cr, query, key.toUpperCase() + ".insert", config, pages, base);
      completion.submit(processor);
    }

    // wait for all tasks to complete.
    for (int i = 0; i < keys.size(); ++i) {
      logger.info(
          "****************"
              + completion.take().get()
              + " completed *****************"); // will block until the next sub task has
      // completed.
    }

    executor.shutdown();
  }