Search in sources :

Example 1 with BugtraqConfig

use of com.syntevo.bugtraq.BugtraqConfig in project gitblit by gitblit.

the class BugtraqProcessor method processTextRegex.

/**
	 * Apply globally or per-repository specified regex substitutions to the
	 * text.
	 *
	 * @param repository
	 * @param repositoryName
	 * @param text
	 * @return the processed text
	 */
protected String processTextRegex(Repository repository, String repositoryName, String text) {
    Map<String, String> map = new HashMap<String, String>();
    // global regex keys
    if (settings.getBoolean(Keys.regex.global, false)) {
        for (String key : settings.getAllKeys(Keys.regex.global)) {
            if (!key.equals(Keys.regex.global)) {
                String subKey = key.substring(key.lastIndexOf('.') + 1);
                map.put(subKey, settings.getString(key, ""));
            }
        }
    }
    // repository-specific regex keys
    List<String> keys = settings.getAllKeys(Keys.regex._ROOT + "." + repositoryName.toLowerCase());
    for (String key : keys) {
        String subKey = key.substring(key.lastIndexOf('.') + 1);
        map.put(subKey, settings.getString(key, ""));
    }
    for (Entry<String, String> entry : map.entrySet()) {
        String definition = entry.getValue().trim();
        String[] chunks = definition.split("!!!");
        if (chunks.length == 2) {
            text = text.replaceAll(chunks[0], chunks[1]);
        } else {
            logger.warn(entry.getKey() + " improperly formatted.  Use !!! to separate match from replacement: " + definition);
        }
    }
    try {
        // parse bugtraq repo config
        BugtraqConfig config = BugtraqConfig.read(repository);
        if (config != null) {
            BugtraqFormatter formatter = new BugtraqFormatter(config);
            StringBuilder sb = new StringBuilder();
            formatter.formatLogMessage(text, new BugtraqOutputHandler(sb));
            text = sb.toString();
        }
    } catch (IOException e) {
        logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
    } catch (ConfigInvalidException e) {
        logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
    }
    return text;
}
Also used : BugtraqFormatter(com.syntevo.bugtraq.BugtraqFormatter) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) HashMap(java.util.HashMap) BugtraqConfig(com.syntevo.bugtraq.BugtraqConfig) IOException(java.io.IOException)

Aggregations

BugtraqConfig (com.syntevo.bugtraq.BugtraqConfig)1 BugtraqFormatter (com.syntevo.bugtraq.BugtraqFormatter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1