Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 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.config;
 
 
 import java.io.File;
 import java.util.List;
 
 //CS IGNORE LineLength FOR NEXT 9 LINES. REASON: static import.
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_BUILD_SCHEDULE_DELAY;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_DYNAMIC_CONFIG_REFRESH_INTERVAL;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_GERRIT_AUTH_KEY_FILE;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_GERRIT_AUTH_KEY_FILE_PASSWORD;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_GERRIT_HOSTNAME;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_GERRIT_SSH_PORT;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_GERRIT_USERNAME;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_NR_OF_RECEIVING_WORKER_THREADS;
 import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_NR_OF_SENDING_WORKER_THREADS;

Configuration bean for the global configuration.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public class Config implements IGerritHudsonTriggerConfig {

    
Default verified vote to Gerrit when a build is started.
 
     public static final int DEFAULT_GERRIT_BUILD_STARTED_VERIFIED_VALUE = 0;
    
Default code review vote to Gerrit when a build is started.
 
     public static final int DEFAULT_GERRIT_BUILD_STARTED_CODE_REVIEW_VALUE = 0;
    
Default verified vote to Gerrit when a build is unstable.
 
     public static final int DEFAULT_GERRIT_BUILD_UNSTABLE_VERIFIED_VALUE = 0;
    
Default code review vote to Gerrit when a build is unstable.
 
     public static final int DEFAULT_GERRIT_BUILD_UNSTABLE_CODE_REVIEW_VALUE = -1;
    
Default verified vote to Gerrit when a build is failed.
 
     public static final int DEFAULT_GERRIT_BUILD_FAILURE_VERIFIED_VALUE = -1;
    
Default code review vote to Gerrit when a build is failed.
 
     public static final int DEFAULT_GERRIT_BUILD_FAILURE_CODE_REVIEW_VALUE = 0;
    
Default code review vote to Gerrit when a build is successful.
 
     public static final int DEFAULT_GERRIT_BUILD_SUCCESSFUL_CODE_REVIEW_VALUE = 0;
    
Default verified vote to Gerrit when a build is successful.
 
     public static final int DEFAULT_GERRIT_BUILD_SUCCESSFUL_VERIFIED_VALUE = 1;
    
Default verified vote to Gerrit when a build is not built.
 
     public static final int DEFAULT_GERRIT_BUILD_NOT_BUILT_VERIFIED_VALUE = 0;
    
Default code review vote to Gerrit when a build is not built.
 
     public static final int DEFAULT_GERRIT_BUILD_NOT_BUILT_CODE_REVIEW_VALUE = 0;
    
Default manual trigger enabled.
 
     public static final boolean DEFAULT_ENABLE_MANUAL_TRIGGER = true;
    
    public static final boolean DEFAULT_BUILD_CURRENT_PATCHES_ONLY = false;
    private String gerritHostName;
    private int gerritSshPort;
    private String gerritUserName;
    private File gerritAuthKeyFile;
    private boolean gerritBuildCurrentPatchesOnly;
    private int numberOfWorkerThreads;
    private String gerritFrontEndUrl;
    private int gerritBuildStartedVerifiedValue;
    private int gerritBuildFailedVerifiedValue;
    private boolean enableManualTrigger;
    private int numberOfSendingWorkerThreads;
    private int buildScheduleDelay;
    private int dynamicConfigRefreshInterval;
    private List<VerdictCategorycategories;



    
Constructor.

Parameters:
formData the data.
    public Config(JSONObject formData) {
        setValues(formData);
    }
    @Override
    public void setValues(JSONObject formData) {
         = formData.optString("gerritHostName");
         = formData.optInt("gerritSshPort");
         = formData.optString("gerritUserName");
        String file = formData.optString("gerritAuthKeyFile"null);
        if (file != null) {
             = new File(file);
        } else {
        }
         = formData.optString(
                "gerritAuthKeyFilePassword",
                );
        if ( != null && .length() <= 0) {
             = null;
        }
         = formData.optBoolean(
                "gerritBuildCurrentPatchesOnly",
                );
         = formData.optInt(
                "numberOfReceivingWorkerThreads",
                );
        if ( <= 0) {
        }
         = formData.optInt(
                "numberOfSendingWorkerThreads",
                );
        if ( <= 0) {
        }
         = formData.optInt(
                "gerritBuildStartedVerifiedValue",
                );
         = formData.optInt(
                "gerritBuildStartedCodeReviewValue",
                );
         = formData.optInt(
                "gerritBuildSuccessfulVerifiedValue",
                );
         = formData.optInt(
                "gerritBuildSuccessfulCodeReviewValue",
         = formData.optInt(
                "gerritBuildFailedVerifiedValue",
                );
         = formData.optInt(
                "gerritBuildFailedCodeReviewValue",
                );
         = formData.optInt(
                "gerritBuildUnstableVerifiedValue",
                );
         = formData.optInt(
                "gerritBuildUnstableCodeReviewValue",
                );
         = formData.optInt(
                "gerritBuildNotBuiltVerifiedValue",
                );
         = formData.optInt(
                "gerritBuildNotBuiltCodeReviewValue",
                );
         = formData.optString(
                "gerritVerifiedCmdBuildStarted",
                "gerrit review <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' "
                        + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
         = formData.optString(
                "gerritVerifiedCmdBuildFailed",
                "gerrit review <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' "
                        + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
         = formData.optString(
                "gerritVerifiedCmdBuildSuccessful",
                "gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' "
                        + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
         = formData.optString(
                "gerritVerifiedCmdBuildUnstable",
                "gerrit review <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' "
                        + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
         = formData.optString(
                "gerritVerifiedCmdBuildNotBuilt",
                "gerrit review <CHANGE>,<PATCHSET> --message 'No Builds Executed <BUILDS_STATS>' "
                        + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
         = formData.optString(
                "gerritFrontEndUrl",
                );
         = formData.optBoolean(
                "enableManualTrigger",
                );
         = formData.optInt(
                "buildScheduleDelay",
                );
        }
         = formData.optInt(
                "dynamicConfigRefreshInterval",
                );
         = new LinkedList<VerdictCategory>();
        if (formData.has("verdictCategories")) {
            Object cat = formData.get("verdictCategories");
            if (cat instanceof JSONArray) {
                for (Object jsonObject : (JSONArray)cat) {
                    .add(VerdictCategory.createVerdictCategoryFromJSON((JSONObject)jsonObject));
                }
            } else if (cat instanceof JSONObject) {
                .add(VerdictCategory.createVerdictCategoryFromJSON((JSONObject)cat));
            }
        }
    }



    
Constructs a config with default data.
    public Config() {
        this(new JSONObject(false));
    }

    
Unused Constructor?

Parameters:
formData the data
req a path.
    public Config(JSONObject formDataStaplerRequest req) {
        this(formData);
    }
    @Override
    public File getGerritAuthKeyFile() {
        return ;
    }

    
GerritAuthKeyFile.

Parameters:
gerritAuthKeyFile the file
See also:
getGerritAuthKeyFile()
    public void setGerritAuthKeyFile(File gerritAuthKeyFile) {
        this. = gerritAuthKeyFile;
    }
    @Override
        return ;
    }

    
GerritAuthKeyFilePassword.

Parameters:
gerritAuthKeyFilePassword the password
See also:
getGerritAuthKeyFilePassword()
    public void setGerritAuthKeyFilePassword(String gerritAuthKeyFilePassword) {
        this. = gerritAuthKeyFilePassword;
    }

    
GerritBuildCurrentPatchesOnly.

Parameters:
gerritBuildCurrentPatchesOnly whether to only build the current patch set
See also:
isGerritBuildCurrentPatchesOnly()
    public void setGerritBuildCurrentPatchesOnly(boolean gerritBuildCurrentPatchesOnly) {
        this. = gerritBuildCurrentPatchesOnly;
    }
    @Override
    public String getGerritFrontEndUrl() {
        String url = ;
        if (url != null && !url.equals("") && !url.endsWith("/")) {
            url += '/';
        }
        return url;
    }

    
GerritFrontEndURL.

Parameters:
gerritFrontEndURL the URL
See also:
getGerritFrontEndUrl()
    public void setGerritFrontEndURL(String gerritFrontEndURL) {
        this. = gerritFrontEndURL;
    }
    @Override
    public String getGerritHostName() {
        return ;
    }

    
GerritHostName.

Parameters:
gerritHostName the hostname
See also:
getGerritHostName()
    public void setGerritHostName(String gerritHostName) {
        this. = gerritHostName;
    }
    @Override
    public int getGerritSshPort() {
        return ;
    }

    
GerritSshPort.

Parameters:
gerritSshPort the port
See also:
getGerritSshPort()
    public void setGerritSshPort(int gerritSshPort) {
        this. = gerritSshPort;
    }
    @Override
    public int getBuildScheduleDelay() {
        return ;
    }

    
Setting buildScheduleDelay.

Parameters:
buildScheduleDelay the delay time
See also:
getBuildScheduleDelay()
    public void setBuildScheduleDelay(int buildScheduleDelay) {
        this. = buildScheduleDelay;
    }
    @Override
    public int getDynamicConfigRefreshInterval() {
        if ( == 0) {
        }
        return ;
    }

    
Setting dynamicConfigRefreshInterval.

Parameters:
dynamicConfigRefreshInterval the interval between the fetches.
See also:
getDynamicConfigRefreshInterval()
    public void setDynamicConfigRefreshInterval(int dynamicConfigRefreshInterval) {
        this. = dynamicConfigRefreshInterval;
    }
    @Override
    public String getGerritUserName() {
        return ;
    }

    
GerritUserName.

Parameters:
gerritUserName the username
See also:
getGerritUserName()
    public void setGerritUserName(String gerritUserName) {
        this. = gerritUserName;
    }
    @Override
    public int getNumberOfReceivingWorkerThreads() {
        if ( <= 0) {
        }
        return ;
    }
    @Override
    public int getNumberOfSendingWorkerThreads() {
        if ( <= 0) {
        }
        return ;
    }

    
NumberOfWorkerThreads.

Parameters:
numberOfReceivingWorkerThreads nr of threads.
See also:
getNumberOfReceivingWorkerThreads()
    public void setNumberOfReceivingWorkerThreads(int numberOfReceivingWorkerThreads) {
        this. = numberOfReceivingWorkerThreads;
    }
    @Override
    public boolean isGerritBuildCurrentPatchesOnly() {
        return ;
    }
    @Override
        return ;
    }

    
GerritVerifiedCmdBuildSuccessful.

Parameters:
cmd the command
See also:
getGerritCmdBuildSuccessful()
    public void setGerritVerifiedCmdBuildSuccessful(String cmd) {
         = cmd;
    }
    @Override
    public String getGerritCmdBuildUnstable() {
        return ;
    }

    
GerritVerifiedCmdBuildUnstable.

Parameters:
cmd the command
See also:
getGerritCmdBuildUnstable()
    public void setGerritVerifiedCmdBuildUnstable(String cmd) {
         = cmd;
    }
    @Override
    public String getGerritCmdBuildFailed() {
        return ;
    }

    
GerritVerifiedCmdBuildFailed.

Parameters:
cmd the command
See also:
setGerritVerifiedCmdBuildFailed(java.lang.String)
    public void setGerritVerifiedCmdBuildFailed(String cmd) {
         = cmd;
    }
    @Override
    public String getGerritCmdBuildStarted() {
        return ;
    }

    
GerritVerifiedCmdBuildStarted.

Parameters:
cmd the command
See also:
getGerritCmdBuildStarted()
    public void setGerritVerifiedCmdBuildStarted(String cmd) {
         = cmd;
    }
    @Override
    public String getGerritCmdBuildNotBuilt() {
        return ;
    }

    
GerritVerifiedCmdBuildNotBuilt.

Parameters:
cmd the command
See also:
getGerritCmdBuildNotBuilt()
    public void setGerritVerifiedCmdBuildNotBuilt(String cmd) {
         = cmd;
    }
    @Override
    public int getGerritBuildStartedVerifiedValue() {
        return ;
    }
    @Override
    public int getGerritBuildStartedCodeReviewValue() {
        return ;
    }
    @Override
        return ;
    }
    @Override
    }
    @Override
    public int getGerritBuildFailedVerifiedValue() {
        return ;
    }
    @Override
    public int getGerritBuildFailedCodeReviewValue() {
        return ;
    }
    @Override
    public int getGerritBuildUnstableVerifiedValue() {
        return ;
    }
    @Override
        return ;
    }
    @Override
    public int getGerritBuildNotBuiltVerifiedValue() {
        return ;
    }
    @Override
        return ;
    }
    @Override
    public String getGerritFrontEndUrlFor(String changeSetNumberString revision) {
        StringBuilder str = new StringBuilder(getGerritFrontEndUrl());
        str.append(changeSetNumber);
        return str.toString();
    }
    @Override
    public List<VerdictCategorygetCategories() {
        return ;
    }

    
Setter for the list of VerdictCategories, used to make testing easier.

Parameters:
categories the list.
    @Override
    public void setCategories(List<VerdictCategorycategories) {
        this. = categories;
    }

    
Getter for the enableManualTrigger value.

Returns:
true if manual triggering is enabled.
    @Override
    public boolean isEnableManualTrigger() {
        return ;
    }

    
Sets if the manual trigger should be enabled or not.

Parameters:
enableManualTrigger true if it should be enabled/shown.
See also:
isEnableManualTrigger()
    public void setEnableManualTrigger(boolean enableManualTrigger) {
        this. = enableManualTrigger;
    }
    @Override
    }
    @Override
    public boolean hasDefaultValues() {
        //both hostname and frontendurl should be null or "" for this to be true
        return ( == null
                || ().equals())
                && ( == null
                || ().equals());
    }
New to GrepCode? Check out our FAQ X