gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpander.java
/**
     * Creates the BUILD_STATS string to send in a message,
     * it contains the status of every build with its URL.
     * @param memoryImprint the memory of all the builds.
     * @param listener the taskListener
     * @param parameters the &lt;parameters&gt; from the trigger.
     * @return the string.
     */
Creates the BUILD_STATS string to send in a message,
it contains the status of every build with its URL.
@param memoryImprint the memory of all the builds.
@param listener the taskListener
@param parameters the <parameters> from the trigger.
@return the string.
Creates the BUILD_STATS string to send in a message it contains the status of every build with its URL . @param memoryImprint the memory of all the builds . @param listener the taskListener @param parameters the <parameters > from the trigger . @return the string .
private String createBuildsStats(MemoryImprint memoryImprint, TaskListener listener,
            Map<String, String> parameters) {
        StringBuilder str = new StringBuilder("");
        final String rootUrl = hudson.getRootUrl();
        String unsuccessfulMessage = null;
        Entry[] entries = memoryImprint.getEntries();
        if (entries.length > 0) {
            for (Entry entry : entries) {
                AbstractBuild build = entry.getBuild();
                if (build != null) {
                    GerritTrigger trigger = GerritTrigger.getTrigger(build.getProject());
                    Result res = build.getResult();
                    String customMessage = null;
                    /* Gerrit comments cannot contain single-newlines, as they will be joined
                     * together. Double newlines are interpreted as paragraph breaks. Lines that
                     * begin with a space (even if the space occurs somewhere in the middle of
                     * a multi-line paragraph) are interpreted as code blocks.
                     */
                    str.append("\n\n");
                    if (trigger.getCustomUrl() == null || trigger.getCustomUrl().isEmpty()) {
                        str.append(rootUrl).append(entry.getBuild().getUrl());
                    } else {
                        str.append(expandParameters(trigger.getCustomUrl(), build, listener, parameters));
                    }
                    str.append(MESSAGE_DELIMITER);
                    if (res == Result.SUCCESS) {
                        customMessage = trigger.getBuildSuccessfulMessage();
                    } else if (res == Result.FAILURE || res == Result.ABORTED) {
                        customMessage = trigger.getBuildFailureMessage();
                    } else if (res == Result.UNSTABLE) {
                        customMessage = trigger.getBuildUnstableMessage();
                    } else if (res == Result.NOT_BUILT) {
                        customMessage = trigger.getBuildNotBuiltMessage();
                    } else {
                        customMessage = trigger.getBuildFailureMessage();
                    }
                    if (customMessage == null || customMessage.isEmpty()) {
                        str.append(res.toString());
                        if (shouldSkip(trigger.getSkipVote(), res)) {
                            str.append(" (skipped)");
                        }
                    } else {
                        str.append(customMessage);
                    }
                    if (res.isWorseThan(Result.SUCCESS)) {
                        unsuccessfulMessage = entry.getUnsuccessfulMessage();
                        if (null != unsuccessfulMessage && !unsuccessfulMessage.isEmpty()) {
                            logger.trace("Using unsuccessful message from file.");
                            str.append(" <<<\n");
                            str.append(unsuccessfulMessage.trim());
                            str.append("\n>>>");
                        }
                    }
                    if (config.isEnablePluginMessages()) {
                        for (GerritMessageProvider messageProvider : emptyIfNull(GerritMessageProvider.all())) {
                            String extensionMessage = messageProvider.getBuildCompletedMessage(build);
                            if (extensionMessage != null) {
                                str.append("\n\n").append(extensionMessage);
                            }
                        }
                    }
                }
            }
        } else {
            logger.error("I got a request to create build statistics, but no entries where found!");
        }
        return str.toString();
    }
private String createBuildsStats ( MemoryImprint memoryImprint , TaskListener listener , Map < String , String > parameters ) { StringBuilder str = new StringBuilder ( "" ) ; final String rootUrl = hudson . getRootUrl ( ) ; String unsuccessfulMessage = null ; Entry [ ] entries = memoryImprint . getEntries ( ) ; if ( entries . length > 0 ) { for ( Entry entry : entries ) { AbstractBuild build = entry . getBuild ( ) ; if ( build != null ) { GerritTrigger trigger = GerritTrigger . getTrigger ( build . getProject ( ) ) ; Result res = build . getResult ( ) ; String customMessage = null ; /* Gerrit comments cannot contain single-newlines, as they will be joined
                     * together. Double newlines are interpreted as paragraph breaks. Lines that
                     * begin with a space (even if the space occurs somewhere in the middle of
                     * a multi-line paragraph) are interpreted as code blocks.
                     */ str . append ( "\n\n" ) ; if ( trigger . getCustomUrl ( ) == null || trigger . getCustomUrl ( ) . isEmpty ( ) ) { str . append ( rootUrl ) . append ( entry . getBuild ( ) . getUrl ( ) ) ; } else { str . append ( expandParameters ( trigger . getCustomUrl ( ) , build , listener , parameters ) ) ; } str . append ( MESSAGE_DELIMITER ) ; if ( res == Result . SUCCESS ) { customMessage = trigger . getBuildSuccessfulMessage ( ) ; } else if ( res == Result . FAILURE || res == Result . ABORTED ) { customMessage = trigger . getBuildFailureMessage ( ) ; } else if ( res == Result . UNSTABLE ) { customMessage = trigger . getBuildUnstableMessage ( ) ; } else if ( res == Result . NOT_BUILT ) { customMessage = trigger . getBuildNotBuiltMessage ( ) ; } else { customMessage = trigger . getBuildFailureMessage ( ) ; } if ( customMessage == null || customMessage . isEmpty ( ) ) { str . append ( res . toString ( ) ) ; if ( shouldSkip ( trigger . getSkipVote ( ) , res ) ) { str . append ( " (skipped)" ) ; } } else { str . append ( customMessage ) ; } if ( res . isWorseThan ( Result . SUCCESS ) ) { unsuccessfulMessage = entry . getUnsuccessfulMessage ( ) ; if ( null != unsuccessfulMessage && ! unsuccessfulMessage . isEmpty ( ) ) { logger . trace ( "Using unsuccessful message from file." ) ; str . append ( " <<<\n" ) ; str . append ( unsuccessfulMessage . trim ( ) ) ; str . append ( "\n>>>" ) ; } } if ( config . isEnablePluginMessages ( ) ) { for ( GerritMessageProvider messageProvider : emptyIfNull ( GerritMessageProvider . all ( ) ) ) { String extensionMessage = messageProvider . getBuildCompletedMessage ( build ) ; if ( extensionMessage != null ) { str . append ( "\n\n" ) . append ( extensionMessage ) ; } } } } } } else { logger . error ( "I got a request to create build statistics, but no entries where found!" ) ; } return str . toString ( ) ; }
Creates the BUILD_STATS string to send in a message,
 it contains the status of every build with its URL.
Creates the BUILD_STATS string to send in a message it contains the status of every build with its URL .
// In Gerrit, all lines before the first empty line are used as the summary. // For the summary all single linefeeds will be removed (only in Gerrit, not sent mails). // Hence, for the multi-builds, we will add a double linefeed before actually listing // the build results. // If the user has specified a message, use it // otherwise use a generic indicator