@SuppressWarnings({"unchecked", "rawtypes"})
  private void parseFile(
      Node technology,
      Object testFile,
      String testFilePath,
      Node regex,
      RegexConfiguration regexConfig)
      throws Exception {
    NodeService nodeService = CorePlugin.getInstance().getNodeService();
    IFileAccessController fileController = FileControllerUtils.getFileAccessController();

    // get test file node and test file resource uri
    Node testNode =
        CorePlugin.getInstance()
            .getResourceService()
            .getNode(
                FileControllerUtils.createFileNodeUri(
                    Utils.getRepo(technology.getNodeUri()), fileController.getPath(testFile)));
    List subscribableResources =
        (List) testNode.getPropertyValue(CoreConstants.SUBSCRIBABLE_RESOURCES);
    String testResourceUri = (String) ((Pair) subscribableResources.get(0)).a;

    // start session
    String testFileContent = IOUtils.toString((InputStream) fileController.getContent(testFile));
    RegexProcessingSession session = regexConfig.startSession(testFileContent);

    // prepare to collect model tree
    Node resultRoot =
        createResourceRoot(
            technology,
            String.format(REGEX_RESULT_FILES_FOLDER + "/%s.result", testFilePath),
            testResourceUri);
    ArrayList<Object> stateStack = new ArrayList<Object>();
    stateStack.add(0, new State(0, resultRoot));
    session.context.put(CodeSyncRegexConstants.STATE_STACK, stateStack);

    // prepare to collect match tree
    Node matchRoot =
        createResourceRoot(
            technology,
            String.format(REGEX_MATCH_FILES_FOLDER + "/%s.regexMatches", testFilePath),
            testResourceUri);
    session.find(new CodeSyncRegexMatcher(nodeService, session, testFileContent, matchRoot));

    // everything worked ok => save matches and result
    CorePlugin.getInstance()
        .getResourceService()
        .save(
            matchRoot.getNodeUri(),
            new ServiceContext<ResourceService>(CorePlugin.getInstance().getResourceService()));
    CorePlugin.getInstance()
        .getResourceService()
        .save(
            resultRoot.getNodeUri(),
            new ServiceContext<ResourceService>(CorePlugin.getInstance().getResourceService()));
  }
  /**
   * @param folder
   * @return a list of all files in that folder
   */
  public List<Object> getTestFiles(Object folder) {
    IFileAccessController controller = CorePlugin.getInstance().getFileAccessController();
    Object[] files = controller.listFiles(folder);
    if (files == null) {
      return Collections.emptyList();
    }

    List<Object> result = new ArrayList<Object>();
    for (Object file : files) {
      if (controller.isDirectory(file)) {
        // recurse for directories
        result.addAll(getTestFiles(file));
      } else {
        // keep child file
        result.add(file);
      }
    }
    return result;
  }
  /**
   * @param nodeUri
   * @throws Exception
   * @author Elena Posea
   * @author Mariana Gheorghe
   */
  public void generateMatches(String nodeUri, boolean all) throws Exception {
    IFileAccessController fileController = FileControllerUtils.getFileAccessController();

    // get repo and technology from node
    VirtualNodeResourceHandler virtualNodeHandler =
        CorePlugin.getInstance().getVirtualNodeResourceHandler();
    String repo = Utils.getRepo(nodeUri);
    String[] typeSpecificPart =
        virtualNodeHandler.getTypeSpecificPartFromNodeUri(nodeUri).split("\\$");
    String technology = typeSpecificPart[0];
    String regexUri =
        FileControllerUtils.createFileNodeUri(
            repo, REGEX_CONFIGS_FOLDER + "/" + technology + "/" + REGEX_CONFIG_FILE);
    regexUri = regexUri.replaceFirst(CoreConstants.FILE_SCHEME, "fpp");

    // get regex configuration file
    new ResourceServiceRemote().subscribeToParentResource(regexUri);
    Node regex = CorePlugin.getInstance().getResourceService().getResourceNode(regexUri);

    // create regEx configuration
    RegexConfiguration regexConfig = new RegexConfiguration();
    new ConfigProcessor().processConfigHierarchy(regex, regexConfig);

    regexConfig.compile(Pattern.DOTALL);

    String technologyPath = REGEX_CONFIGS_FOLDER + "/" + technology;
    Node technologyNode =
        CorePlugin.getInstance()
            .getResourceService()
            .getNode(FileControllerUtils.createFileNodeUri(repo, technologyPath));
    if (all) {
      // parse files contained in the test files directory
      Object file = fileController.getFile(FileControllerUtils.getFilePathWithRepo(regex));
      Object parentFile = fileController.getParentFile(file);
      Object testFilesFolder = fileController.getFile(parentFile, REGEX_TEST_FILES_FOLDER);
      List<Object> testFiles = getTestFiles(testFilesFolder);
      for (Object testFile : testFiles) {
        String relativePath = fileController.getPathRelativeToFile(testFile, testFilesFolder);
        parseFile(technologyNode, testFile, relativePath, regex, regexConfig);
      }
    } else {
      // parse only selected file
      String relativePath = typeSpecificPart[1];
      Object testFile =
          fileController.getFile(
              repo + "/" + technologyPath + "/" + REGEX_TEST_FILES_FOLDER + "/" + relativePath);
      parseFile(technologyNode, testFile, relativePath, regex, regexConfig);
    }
  }