Skip to content

Commit

Permalink
Deprecate redundant methods & make commands static
Browse files Browse the repository at this point in the history
- some methods are redundant (containing 'verified' name although
a simpler form already exists)
- extact default gerrit commands to static fields instead
  • Loading branch information
shemuwel committed Feb 5, 2024
1 parent 0aa5310 commit 446a306
Showing 1 changed file with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.config;

import com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.BuildCancellationPolicy;
import com.sonymobile.tools.gerrit.gerritevents.GerritDefaultValues;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Provider;
Expand All @@ -33,8 +34,6 @@
import com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData;
import com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData.Time;
import com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData.TimeSpan;
import com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory;

import hudson.util.Secret;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -165,6 +164,25 @@ public class Config implements IGerritHudsonTriggerConfig {
*/
public static final Notify DEFAULT_NOTIFICATION_LEVEL = Notify.ALL;

private static final String GERRIT_CMD_BUILD_STARTED_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'Build Started <BUILDURL> <STARTED_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;
private static final String GERRIT_CMD_BUILD_SUCCESSFUL_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'Build Successful <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;
private static final String GERRIT_CMD_BUILD_FAILED_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'Build Failed <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;
private static final String GERRIT_CMD_BUILD_UNSTABLE_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'Build Unstable <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;
private static final String GERRIT_CMD_BUILD_NOT_BUILT_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'No Builds Executed <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;
private static final String GERRIT_CMD_BUILD_ABORTED_DEFAULT_VALUE = "gerrit review <CHANGE>,<PATCHSET> "
+ "--message 'Build Aborted <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE;

private String gerritHostName;
private int gerritSshPort;
private String gerritProxy;
Expand Down Expand Up @@ -320,30 +338,6 @@ public void setValues(JSONObject formData) {
numberOfSendingWorkerThreads = DEFAULT_NR_OF_SENDING_WORKER_THREADS;
}

gerritVerifiedCmdBuildStarted = formData.optString(
"gerritVerifiedCmdBuildStarted",
"gerrit review <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritVerifiedCmdBuildFailed = formData.optString(
"gerritVerifiedCmdBuildFailed",
"gerrit review <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritVerifiedCmdBuildSuccessful = formData.optString(
"gerritVerifiedCmdBuildSuccessful",
"gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritVerifiedCmdBuildUnstable = formData.optString(
"gerritVerifiedCmdBuildUnstable",
"gerrit review <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritVerifiedCmdBuildNotBuilt = formData.optString(
"gerritVerifiedCmdBuildNotBuilt",
"gerrit review <CHANGE>,<PATCHSET> --message 'No Builds Executed <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritVerifiedCmdBuildAborted = formData.optString(
"gerritVerifiedCmdBuildAborted",
"gerrit review <CHANGE>,<PATCHSET> --message 'Build Aborted <BUILDS_STATS>' "
+ "--verified <VERIFIED> --code-review <CODE_REVIEW> --tag " + Constants.TAG_VALUE);
gerritFrontEndUrl = formData.optString(
"gerritFrontEndUrl",
DEFAULT_GERRIT_HOSTNAME);
Expand Down Expand Up @@ -377,7 +371,8 @@ public void setValues(JSONObject formData) {
"enableProjectAutoCompletion",
DEFAULT_ENABLE_PROJECT_AUTO_COMPLETION);

addCategories(formData);
setCategories(formData);
updateGerritCommands(formData);

watchdogTimeoutMinutes = formData.optInt("watchdogTimeoutMinutes", DEFAULT_GERRIT_WATCHDOG_TIMEOUT_MINUTES);
watchTimeExceptionData = addWatchTimeExceptionData(formData);
Expand All @@ -396,14 +391,29 @@ public void setValues(JSONObject formData) {
replicationConfig = ReplicationConfig.createReplicationConfigFromJSON(formData);
}

private void updateGerritCommands(JSONObject formData) {
gerritVerifiedCmdBuildStarted = formData.optString("gerritVerifiedCmdBuildStarted",
GERRIT_CMD_BUILD_STARTED_DEFAULT_VALUE);
gerritVerifiedCmdBuildFailed = formData.optString("gerritVerifiedCmdBuildFailed",
GERRIT_CMD_BUILD_FAILED_DEFAULT_VALUE);
gerritVerifiedCmdBuildSuccessful = formData.optString("gerritVerifiedCmdBuildSuccessful",
GERRIT_CMD_BUILD_SUCCESSFUL_DEFAULT_VALUE);
gerritVerifiedCmdBuildUnstable = formData.optString("gerritVerifiedCmdBuildUnstable",
GERRIT_CMD_BUILD_UNSTABLE_DEFAULT_VALUE);
gerritVerifiedCmdBuildNotBuilt = formData.optString("gerritVerifiedCmdBuildNotBuilt",
GERRIT_CMD_BUILD_NOT_BUILT_DEFAULT_VALUE);
gerritVerifiedCmdBuildAborted = formData.optString("gerritVerifiedCmdBuildAborted",
GERRIT_CMD_BUILD_ABORTED_DEFAULT_VALUE);
}

/**
* Adds {@link VerdictCategory}s to the categories based on the formData.
* @param formData the formData as a JSONObject.
*/
private void addCategories(JSONObject formData) {
private void setCategories(JSONObject formData) {
categories = new LinkedList<>();
if (formData.isEmpty())
{
categories = new LinkedList<>();
categories.add(new VerdictCategory(CODE_REVIEW_LABEL,
CODE_REVIEW_LABEL,
DEFAULT_GERRIT_BUILD_STARTED_CODE_REVIEW_VALUE,
Expand All @@ -422,8 +432,6 @@ private void addCategories(JSONObject formData) {
}

if (formData.has("verdictCategories")) {
categories = new LinkedList<>();

Object cat = formData.get("verdictCategories");
if (cat instanceof JSONArray) {
for (Object jsonObject : (JSONArray)cat) {
Expand Down Expand Up @@ -889,6 +897,7 @@ public String getGerritCmdBuildSuccessful() {
*
* @param cmd the command
* @see #getGerritCmdBuildSuccessful()
* @deprecated use {@link Config#setGerritCmdBuildSuccessful(String) } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildSuccessful(String cmd) {
Expand All @@ -915,6 +924,7 @@ public String getGerritCmdBuildUnstable() {
*
* @param cmd the command
* @see #getGerritCmdBuildUnstable()
* @deprecated use {@link Config#setGerritCmdBuildUnstable(String) } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildUnstable(String cmd) {
Expand All @@ -941,6 +951,7 @@ public String getGerritCmdBuildFailed() {
*
* @param cmd the command
* @see #getGerritCmdBuildFailed()
* @deprecated use {@link Config#setGerritCmdBuildFailed(String) } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildFailed(String cmd) {
Expand All @@ -967,6 +978,7 @@ public String getGerritCmdBuildStarted() {
*
* @param cmd the command
* @see #getGerritCmdBuildStarted()
* @deprecated use {@link Config#setGerritCmdBuildStarted(String)} } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildStarted(String cmd) {
Expand All @@ -993,6 +1005,7 @@ public String getGerritCmdBuildNotBuilt() {
*
* @param cmd the command
* @see #getGerritCmdBuildNotBuilt()
* @deprecated use {@link Config#setGerritCmdBuildNotBuilt(String)} } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildNotBuilt(String cmd) {
Expand All @@ -1019,6 +1032,7 @@ public String getGerritCmdBuildAborted() {
*
* @param cmd the command
* @see #getGerritCmdBuildAborted()
* @deprecated use {@link Config#setGerritCmdBuildAborted(String) } instead.
*/
@Deprecated
public void setGerritVerifiedCmdBuildAborted(String cmd) {
Expand Down

0 comments on commit 446a306

Please sign in to comment.