@Test
 public void shouldNotSubstitute() throws Exception {
   String res =
       variableSubstitutor.substitute("string not substitute", SubstitutionType.TYPE_PLAIN);
   assertThat(res, Is.is("string not substitute"));
   res = variableSubstitutor.substitute("string not ${substitute}", SubstitutionType.TYPE_PLAIN);
   assertThat(res, Is.is("string not ${substitute}"));
 }
 @Test
 public void shouldSubstitutePlainText() throws Exception {
   assertThat(
       variableSubstitutor.substitute("${MY_PROP}${MY_PROP2}", SubstitutionType.TYPE_PLAIN),
       Is.is("onetwo"));
   assertThat(
       variableSubstitutor.substitute("$MY_PROP2$MY_PROP", SubstitutionType.TYPE_PLAIN),
       Is.is("twoone"));
 }
  /**
   * Attempt to read load specifications from OS specific shortcut specification file. If fail to
   * read from OS specific shortcut specification file, attempt to load general shortcut
   * specification file.
   *
   * @throws Exception for any problems in reading the specification TODO: If internal flag mapped
   *     installData.isDebug() print out information on substitutedSpec
   */
  private IXMLElement readShortcutSpec() throws Exception {
    IXMLElement spec = null;

    InputStream shortcutSpec = null;
    try {
      shortcutSpec = resources.getInputStream(TargetFactory.getCurrentOSPrefix() + SPEC_FILE_NAME);
    } catch (ResourceNotFoundException resourceNotFound) {
      try {
        shortcutSpec = resources.getInputStream(SPEC_FILE_NAME);
      } catch (ResourceNotFoundException shortcutsNotFound) {
        // Fail on next try block
      }
    }

    try {
      VariableSubstitutor replacer = new VariableSubstitutorImpl(installData.getVariables());
      String substitutedSpec = replacer.substitute(shortcutSpec, SubstitutionType.TYPE_XML);
      IXMLParser parser = new XMLParser();
      spec = parser.parse(substitutedSpec);
    } catch (Exception e) {
      return null;
    }

    shortcutSpec.close();
    return spec;
  }
  /**
   * resolve properties inside a properties object
   *
   * @param props properties to resolve
   * @param xmlProp
   * @param file
   */
  private void resolveAllProperties(Properties props, IXMLElement xmlProp, File file)
      throws CompilerException {
    variableSubstitutor.setBracesRequired(true);

    for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
      String name = (String) e.nextElement();
      String value = props.getProperty(name);

      int mods = -1;
      do {
        StringReader read = new StringReader(value);
        StringWriter write = new StringWriter();

        try {
          try {
            mods = variableSubstitutor.substitute(read, write, SubstitutionType.TYPE_AT);
          } catch (Exception e1) {
            throw new IOException(e1.getMessage());
          }
          // TODO: check for circular references. We need to know
          // which
          // variables were substituted to do that
          props.put(name, value);
        } catch (IOException ex) {
          assertionHelper.parseError(xmlProp, "Faild to load file: " + file.getAbsolutePath(), ex);
        }
      } while (mods != 0);
    }
  }
 /**
  * Add a name value pair to the project property set
  *
  * @param name name of property
  * @param value value to set
  */
 private void addPropertySubstitute(String name, String value) {
   try {
     value = variableSubstitutor.substitute(value, SubstitutionType.TYPE_AT);
   } catch (Exception e) {
     // ignore
   }
   properties.put(name, value);
 }
  @Override
  public String resolve(VariableSubstitutor... substitutors) throws Exception {
    String _value_ = value;
    for (VariableSubstitutor substitutor : substitutors) {
      _value_ = substitutor.substitute(_value_);
    }

    return _value_;
  }
 @Test
 public void testSystemPropertiesSubstition() throws Exception {
   String substituted = variableSubstitutor.substitute("${SYSTEM[user.dir]}");
   assertNotNull(substituted);
   if (substituted.trim().isEmpty() || substituted.startsWith("${SYSTEM[")) {
     fail(
         "The system variable resolution of ${SYSTEM[user.dir]} resulted in an invalid string '"
             + substituted
             + "\"");
   }
   // TODO: This is just for backward compatibility, remove in future
   substituted = variableSubstitutor.substitute("${SYSTEM_user_dir}");
   assertNotNull(substituted);
   if (substituted.trim().isEmpty() || substituted.startsWith("${SYSTEM_")) {
     fail(
         "The system variable resolution of ${SYSTEM_user_dir} resulted in an invalid string '"
             + substituted
             + "\"");
   }
 }
 @Test
 public void shouldSubstituteShellType() throws Exception {
   assertThat(
       variableSubstitutor.substitute("%MY_PROP%MY_PROP2", SubstitutionType.TYPE_SHELL),
       Is.is("onetwo"));
 }
 @Test
 public void shouldSubstituteAntType() throws Exception {
   assertThat(
       variableSubstitutor.substitute("@MY_PROP@@MY_PROP2@", SubstitutionType.TYPE_ANT),
       Is.is("onetwo"));
 }