public void loadProperties(final Map<String, String> props, final boolean failIfMissing)
      throws CruiseControlException {

    final boolean toUpperValue = "true".equals(toupper);
    if (file != null && file.trim().length() > 0) {
      // TODO FIXME add exists check.
      try {
        final BufferedReader reader =
            new BufferedReader(new InputStreamReader(fileResolver.getInputStream(file)));
        try {
          // Read the theFile line by line, expanding macros
          // as we go. We must do this manually to preserve the
          // order of the properties.
          String line;
          while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.length() == 0 || line.charAt(0) == '#') {
              continue;
            }
            final int index = line.indexOf('=');
            if (index < 0) {
              continue;
            }
            final String parsedName =
                Util.parsePropertiesInString(props, line.substring(0, index).trim(), failIfMissing);
            final String parsedValue =
                Util.parsePropertiesInString(
                    props, line.substring(index + 1).trim(), failIfMissing);
            ProjectXMLHelper.setProperty(props, parsedName, parsedValue);
          }
        } finally {
          reader.close();
        }
      } catch (IOException e) {
        throw new CruiseControlException(
            "Could not load properties from theFile \"" + file + "\".", e);
      }
    } else if (environment != null) {
      // Load the environment into the project's properties
      for (final String line : new OSEnvironment().getEnvironment()) {
        int index = line.indexOf('=');
        if (index < 0) {
          continue;
        }
        // If the toupper attribute was set, upcase the variables
        final StringBuilder propName = new StringBuilder(environment);
        propName.append(".");
        if (toUpperValue) {
          propName.append(line.substring(0, index).toUpperCase());
        } else {
          propName.append(line.substring(0, index));
        }
        final String parsedValue =
            Util.parsePropertiesInString(props, line.substring(index + 1), failIfMissing);
        ProjectXMLHelper.setProperty(props, propName.toString(), parsedValue);
      }
    } else {
      final String parsedValue = Util.parsePropertiesInString(props, value, failIfMissing);
      ProjectXMLHelper.setProperty(props, name, parsedValue);
    }
  }