private void doFilterText(Pattern pattern,
                              String text,
                              @Nullable Map<String, String> resolvedPropertiesParam,
                              Appendable out) throws IOException {
      Map<String, String> resolvedProperties = resolvedPropertiesParam;

      Matcher matcher = pattern.matcher(text);
      int groupCount = matcher.groupCount();

      int last = 0;
      while (matcher.find()) {
        out.append(text, last, matcher.start());
        last = matcher.end();

        String propertyName = null;

        for (int i = 0; i < groupCount; i++) {
          propertyName = matcher.group(i + 1);
          if (propertyName != null) {
            break;
          }
        }

        assert propertyName != null;

        if (resolvedProperties == null) {
          resolvedProperties = new HashMap<>();
        }

        String propertyValue = resolvedProperties.get(propertyName);
        if (propertyValue == null) {
          if (resolvedProperties.containsKey(propertyName)) { // if cyclic property dependencies
            out.append(matcher.group());
            continue;
          }


          String resolved;
          if (mavenProject != null) {
            resolved = doResolvePropertyForMavenProject(propertyName);
          }
          else {
            resolved = doResolvePropertyForMavenDomModel(propertyName);
          }

          if (resolved == null) {
            out.append(matcher.group());
            continue;
          }

          resolvedProperties.put(propertyName, null);

          StringBuilder sb = new StringBuilder();
          doFilterText(pattern, resolved, resolvedProperties, sb);
          propertyValue = sb.toString();

          resolvedProperties.put(propertyName, propertyValue);
        }

        out.append(propertyValue);
      }

      out.append(text, last, text.length());
    }
private void doFilterText(Pattern pattern,
                              String text,
                              @Nullable Map<String, String> resolvedPropertiesParam,
                              Appendable out)