public static void createComponentsConfig(String configFile,
                                              String componentsFile,
                                              String componentType,
                                              boolean append) throws IOException {
        StringBuilder buf = new StringBuilder();
        String line;
        int i = 0;
        if (append) {
            Pattern p = Pattern.compile("^[a-z]+" + "\\[\\d+\\]\\.id (.+)");
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                                                       new FileInputStream(componentsFile), StandardCharsets.UTF_8));
            while ((line = reader.readLine()) != null) {
                Matcher m = p.matcher(line);
                if (m.matches() && !m.group(1).equals(HandlersConfigurerDi.RegistriesHack.class.getName())) {
                    buf.append("components[").append(i).append("].id ").append(m.group(1)).append("\n");
                    i++;
                }
            }
            reader.close();
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                new FileInputStream(configFile), StandardCharsets.UTF_8));
        Pattern component = Pattern.compile("^" + componentType + "\\[\\d+\\]\\.id (.+)");
        while ((line = reader.readLine()) != null) {
            Matcher m = component.matcher(line);
            if (m.matches()) {
                buf.append("components[").append(i).append("].id ").append(m.group(1)).append("\n");
                i++;
            }
        }
        reader.close();

        buf.append("components[").append(i++).append("].id ").append(HandlersConfigurerDi.RegistriesHack.class.getName()).append("\n");
        if (componentType.equals("components"))
            i = addStandardComponents(i, buf);
        buf.insert(0, "components["+i+"]\n");

        Writer writer = new OutputStreamWriter(new FileOutputStream(componentsFile), StandardCharsets.UTF_8);
        writer.write(buf.toString());
        writer.flush();
        writer.close();
    }
Copies the component ids from another config, e.g. 'handlers' to a 'components' array in a new components file,
to avoid a manually written 'components' file for tests where the bundle spec is given by the component id.

@param configFile  Full path to the original config file, e.g. 'handlers'
@param componentsFile  Full path to the new 'components' file
@param componentType   The type of component, e.g. 'handler'
@param append  'true' will append to an already existing 'componentsFile'
container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java