Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2011 Sony Ericsson Mobile Communications. All rights reserved.
   *  Copyright 2012 Sony Mobile Communications AB. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger;
 
 
 import java.util.List;

The parameters to add to a build.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public enum GerritTriggerParameters {
    
Parameter name for the commit subject (commit message's 1st line).
 
     GERRIT_CHANGE_SUBJECT,
    
Parameter name for the branch.
 
     GERRIT_BRANCH,
    
Parameter name for the change-id.
 
     GERRIT_CHANGE_ID,
    
Parameter name for the change number.
 
     GERRIT_CHANGE_NUMBER,
    
Parameter name for the URL to the change.
 
     GERRIT_CHANGE_URL,
    
Parameter name for the patch set number.
 
     GERRIT_PATCHSET_NUMBER,
    
Parameter name for the patch set revision.
 
     GERRIT_PATCHSET_REVISION,
    
Parameter name for the Gerrit project name.
 
     GERRIT_PROJECT,
    
Parameter name for the refspec.
 
     GERRIT_REFSPEC,
    
The name and email of the owner of the change.
 
     GERRIT_CHANGE_OWNER,
    
The name of the owner of the change.
 
     GERRIT_CHANGE_OWNER_NAME,
    
The email of the owner of the change.
 
     GERRIT_CHANGE_OWNER_EMAIL,
    
The name and email of the uploader of the patch-set.
 
     GERRIT_PATCHSET_UPLOADER,
    
The name of the uploader of the patch-set.
 
     GERRIT_PATCHSET_UPLOADER_NAME,
    
The email of the uploader of the patch-set.
    GERRIT_PATCHSET_UPLOADER_EMAIL,
    
The name and email of the person who triggered the event.
    GERRIT_EVENT_ACCOUNT,
    
The name of the person who triggered the event.
    GERRIT_EVENT_ACCOUNT_NAME,
    
The email of the person who triggered the event.
    GERRIT_EVENT_ACCOUNT_EMAIL,
    
The refname in a ref-updated event.
    GERRIT_REFNAME,
    
The old revision in a ref-updated event.
    GERRIT_OLDREV,
    
The new revision in a ref-updated event.
    GERRIT_NEWREV,
    
The submitter in a ref-updated event.
    GERRIT_SUBMITTER,
    
The name of the submitter in a ref-updated event.
    GERRIT_SUBMITTER_NAME,
    
The email of the submitter in a ref-updated event.
    GERRIT_SUBMITTER_EMAIL,
    
A hashcode of the gerrit event object, to make sure every set of parameters is unique (allowing jenkins to queue duplicate builds).
    GERRIT_EVENT_HASH;

    
Creates a hudson.model.StringParameterValue and adds it to the provided list. If the parameter with the same name already exists in the list it will be replaced by the new parameter, but its description will be used, unless the parameter type is something else than a StringParameterValue.

Parameters:
parameters the list of existing parameters.
value the value.
escapeQuotes if quote characters should be escaped.
    public void setOrCreateStringParameterValue(List<ParameterValueparametersString valueboolean escapeQuotes) {
        ParameterValue parameter = null;
        for (ParameterValue p : parameters) {
            if (p.getName().toUpperCase().equals(this.name())) {
                parameter = p;
                break;
            }
        }
        String description = null;
        if (parameter != null) {
            if (parameter instanceof StringParameterValue) {
                //Perhaps it is manually added to remind the user of what it is for.
                description = parameter.getDescription();
            }
            parameters.remove(parameter);
        }
        String stringValue;
        if (escapeQuotes) {
            stringValue = StringUtil.escapeQuotes(value);
        } else {
            stringValue = value;
        }
        if (stringValue == null) {
            stringValue = "";
        }
        parameter = new StringParameterValue(this.name(), stringValuedescription);
        parameters.add(parameter);
    }

    
Adds or sets all the Gerrit-parameter values to the provided list.

Parameters:
gerritEvent the event.
parameters the default parameters
escapeQuotes if quotes should be escaped or not.
See also:
setOrCreateStringParameterValue(java.util.List,java.lang.String,boolean)
    public static void setOrCreateParameters(GerritTriggeredEvent gerritEventList<ParameterValueparameters,
            boolean escapeQuotes) {
                parameters, String.valueOf(((java.lang.Object)gerritEvent).hashCode()), escapeQuotes);
        if (gerritEvent instanceof ChangeBasedEvent) {
            ChangeBasedEvent event = (ChangeBasedEvent)gerritEvent;
                    parametersevent.getChange().getBranch(), escapeQuotes);
                    parametersevent.getChange().getNumber(), escapeQuotes);
                    parametersevent.getChange().getId(), escapeQuotes);
                    parametersevent.getPatchSet().getNumber(), escapeQuotes);
                    parametersevent.getPatchSet().getRevision(), escapeQuotes);
                    parameters, StringUtil.makeRefSpec(event), escapeQuotes);
                    parametersevent.getChange().getProject(), escapeQuotes);
                    parametersevent.getChange().getSubject(), escapeQuotes);
            String url = PluginImpl.getInstance().getConfig().getGerritFrontEndUrlFor(event.getChange().getNumber(),
                    event.getPatchSet().getNumber());
                    parametersurlescapeQuotes);
                    parametersgetNameAndEmail(event.getChange().getOwner()), escapeQuotes);
                    parametersgetName(event.getChange().getOwner()), escapeQuotes);
                    parametersgetEmail(event.getChange().getOwner()), escapeQuotes);
            Account uploader = findUploader(event);
                    parametersgetNameAndEmail(uploader), escapeQuotes);
                    parametersgetName(uploader), escapeQuotes);
                    parametersgetEmail(uploader), escapeQuotes);
        } else if (gerritEvent instanceof RefUpdated) {
            RefUpdated event = (RefUpdated)gerritEvent;
                    parametersevent.getRefUpdate().getRefName(), escapeQuotes);
                    parametersevent.getRefUpdate().getProject(), escapeQuotes);
                    parametersevent.getRefUpdate().getOldRev(), escapeQuotes);
                    parametersevent.getRefUpdate().getNewRev(), escapeQuotes);
        }
        Account account = gerritEvent.getAccount();
        if (account != null) {
                    parametersgetNameAndEmail(account), escapeQuotes);
                    parametersgetName(account), escapeQuotes);
                    parametersgetEmail(account), escapeQuotes);
        }
    }

    
There are two uploader fields in the event, this method gets one of them if one is null.

Parameters:
event the event to search.
Returns:
the uploader if any.
    private static Account findUploader(ChangeBasedEvent event) {
        if (event.getPatchSet() != null && event.getPatchSet().getUploader() != null) {
            return event.getPatchSet().getUploader();
        } else {
            return event.getAccount();
        }
    }

    
Convenience method to avoid NPE on none existent accounts.

Parameters:
account the account.
Returns:
the name in the account or null if Account is null.
See also:
com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.attr.Account.getName()
    private static String getName(Account account) {
        if (account == null) {
            return "";
        } else {
            return account.getName();
        }
    }

    
Convenience method to avoid NPE on none existent accounts.

Parameters:
account the account.
Returns:
the name and email in the account or null if Account is null.
See also:
com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.attr.Account.getNameAndEmail()
    private static String getNameAndEmail(Account account) {
        if (account == null) {
            return "";
        } else {
            return account.getNameAndEmail();
        }
    }

    
Convenience method to avoid NPE on none existent accounts.

Parameters:
account the account.
Returns:
the email in the account or null if Account is null.
See also:
com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.attr.Account.getEmail()
    private static String getEmail(Account account) {
        if (account == null) {
            return "";
        } else {
            return account.getEmail();
        }
    }
New to GrepCode? Check out our FAQ X