示例#1
0
 @Test
 public void testVaryFileResolve() {
   FileResolver resolver = new FileResolver(TestUtil.getTestFile("target"));
   File file = resolver.resolve(Key.create(URI.create("foo"), new Vary()));
   File file2 = resolver.resolve(Key.create(URI.create("foo"), new Vary()));
   File file3 =
       resolver.resolve(Key.create(URI.create("foo"), new Vary(new HashMap<String, String>())));
   File file4 =
       resolver.resolve(
           Key.create(
               URI.create("foo"), new Vary(Collections.singletonMap("Accept-Language", "en"))));
   Assert.assertEquals(file.getAbsolutePath(), file2.getAbsolutePath());
   Assert.assertEquals(file.getAbsolutePath(), file3.getAbsolutePath());
   Assert.assertEquals(file2.getAbsolutePath(), file3.getAbsolutePath());
   Assert.assertEquals(file2.getAbsolutePath(), file3.getAbsolutePath());
   Assert.assertFalse(file4.getAbsolutePath().equals(file3.getAbsolutePath()));
 }
  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);
    }
  }