-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement setters instead of constructor for optional parameters #246
Merged
scaytrase
merged 6 commits into
jenkinsci:release/1.x
from
westarne:feature/optional-parameters
Jan 22, 2022
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d34dbce
Implement setters instead of constructor for optional parameters
fc16285
Merge branch 'release/1.x' into feature/optional-parameters
westarne 615d351
Optimize setters
ed5bde5
Remove unnecessary constructor
e3c5982
Merge branch 'release/1.x' into feature/optional-parameters
westarne a6e1355
Fix missing brace
westarne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,61 +104,61 @@ public class StashNotifier extends Notifier implements SimpleBuildStep { | |
/** | ||
* base url of Bitbucket server, e. g. <tt>http://localhost:7990</tt>. | ||
*/ | ||
private final String stashServerBaseUrl; | ||
private String stashServerBaseUrl; | ||
|
||
/** | ||
* The id of the credentials to use. | ||
*/ | ||
private final String credentialsId; | ||
private String credentialsId; | ||
|
||
/** | ||
* if true, ignore exception thrown in case of an unverified SSL peer. | ||
*/ | ||
private final boolean ignoreUnverifiedSSLPeer; | ||
private boolean ignoreUnverifiedSSLPeer; | ||
|
||
/** | ||
* specify the commit from config | ||
*/ | ||
private final String commitSha1; | ||
private String commitSha1; | ||
|
||
/** | ||
* specify a specific build state to be pushed. | ||
* If null, the current build result will be used. | ||
*/ | ||
private final StashBuildState buildStatus; | ||
private StashBuildState buildStatus; | ||
|
||
/** | ||
* specify a build name to be included in the Bitbucket notification. | ||
* If null, the usual full project name will be used. | ||
*/ | ||
private final String buildName; | ||
private String buildName; | ||
|
||
/** | ||
* if true, the build number is included in the Bitbucket notification. | ||
*/ | ||
private final boolean includeBuildNumberInKey; | ||
private boolean includeBuildNumberInKey; | ||
|
||
/** | ||
* specify project key manually | ||
*/ | ||
private final String projectKey; | ||
private String projectKey; | ||
|
||
/** | ||
* append parent project key to key formation | ||
*/ | ||
private final boolean prependParentProjectKey; | ||
private boolean prependParentProjectKey; | ||
|
||
/** | ||
* whether to send INPROGRESS notification at the build start | ||
*/ | ||
private final boolean disableInprogressNotification; | ||
private boolean disableInprogressNotification; | ||
|
||
/** | ||
* whether to consider UNSTABLE builds as failures or success | ||
*/ | ||
private final boolean considerUnstableAsSuccess; | ||
private boolean considerUnstableAsSuccess; | ||
|
||
private final JenkinsLocationConfiguration globalConfig; | ||
private JenkinsLocationConfiguration globalConfig; | ||
|
||
// public members ---------------------------------------------------------- | ||
|
||
|
@@ -181,105 +181,144 @@ public BuildStepMonitor getRequiredMonitorService() { | |
boolean considerUnstableAsSuccess, | ||
JenkinsLocationConfiguration globalConfig | ||
) { | ||
this.globalConfig = globalConfig; | ||
setStashServerBaseUrl(stashServerBaseUrl); | ||
setCredentialsId(credentialsId); | ||
setIgnoreUnverifiedSSLPeer(ignoreUnverifiedSSLPeer); | ||
setCommitSha1(commitSha1); | ||
setBuildStatus(buildStatus); | ||
setBuildName(buildName); | ||
setIncludeBuildNumberInKey(includeBuildNumberInKey); | ||
setProjectKey(projectKey); | ||
setPrependParentProjectKey(prependParentProjectKey); | ||
setDisableInprogressNotification(disableInprogressNotification); | ||
setConsiderUnstableAsSuccess(considerUnstableAsSuccess); | ||
} | ||
|
||
this.stashServerBaseUrl = stashServerBaseUrl != null && stashServerBaseUrl.endsWith("/") | ||
? stashServerBaseUrl.substring(0, stashServerBaseUrl.length() - 1) | ||
: stashServerBaseUrl; | ||
this.credentialsId = credentialsId; | ||
this.ignoreUnverifiedSSLPeer = ignoreUnverifiedSSLPeer; | ||
this.commitSha1 = commitSha1; | ||
|
||
StashBuildState overwrittenBuildState = null; | ||
try { | ||
overwrittenBuildState = StashBuildState.valueOf(buildStatus); | ||
} catch (Exception e) { | ||
// ignore unknown or null values | ||
} | ||
this.buildStatus = overwrittenBuildState; | ||
|
||
this.buildName = buildName; | ||
this.includeBuildNumberInKey = includeBuildNumberInKey; | ||
this.projectKey = projectKey; | ||
this.prependParentProjectKey = prependParentProjectKey; | ||
this.disableInprogressNotification = disableInprogressNotification; | ||
this.considerUnstableAsSuccess = considerUnstableAsSuccess; | ||
StashNotifier( | ||
JenkinsLocationConfiguration globalConfig | ||
) { | ||
this.globalConfig = globalConfig; | ||
} | ||
|
||
@DataBoundConstructor | ||
public StashNotifier( | ||
String stashServerBaseUrl, | ||
String credentialsId, | ||
boolean ignoreUnverifiedSSLPeer, | ||
String commitSha1, | ||
String buildStatus, | ||
String buildName, | ||
boolean includeBuildNumberInKey, | ||
String projectKey, | ||
boolean prependParentProjectKey, | ||
boolean disableInprogressNotification, | ||
boolean considerUnstableAsSuccess | ||
) { | ||
public StashNotifier() { | ||
this( | ||
stashServerBaseUrl, | ||
credentialsId, | ||
ignoreUnverifiedSSLPeer, | ||
commitSha1, | ||
buildStatus, | ||
buildName, | ||
includeBuildNumberInKey, | ||
projectKey, | ||
prependParentProjectKey, | ||
disableInprogressNotification, | ||
considerUnstableAsSuccess, | ||
JenkinsLocationConfiguration.get() | ||
); | ||
} | ||
|
||
public boolean isDisableInprogressNotification() { | ||
return disableInprogressNotification; | ||
public String getStashServerBaseUrl() { | ||
return stashServerBaseUrl; | ||
} | ||
|
||
public boolean isConsiderUnstableAsSuccess() { | ||
return considerUnstableAsSuccess; | ||
@DataBoundSetter | ||
public void setStashServerBaseUrl(String stashServerBaseUrl) { | ||
this.stashServerBaseUrl = stashServerBaseUrl != null && stashServerBaseUrl.endsWith("/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StringUtils#stripEnd could be used. |
||
? stashServerBaseUrl.substring(0, stashServerBaseUrl.length() - 1) | ||
: stashServerBaseUrl; | ||
} | ||
|
||
public String getCredentialsId() { | ||
return credentialsId; | ||
} | ||
|
||
public String getStashServerBaseUrl() { | ||
return stashServerBaseUrl; | ||
@DataBoundSetter | ||
public void setCredentialsId(String credentialsId) { | ||
this.credentialsId = credentialsId; | ||
} | ||
|
||
public boolean getIgnoreUnverifiedSSLPeer() { | ||
public boolean isIgnoreUnverifiedSSLPeer() { | ||
return ignoreUnverifiedSSLPeer; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setIgnoreUnverifiedSSLPeer(boolean ignoreUnverifiedSSLPeer) { | ||
this.ignoreUnverifiedSSLPeer = ignoreUnverifiedSSLPeer; | ||
} | ||
|
||
public String getCommitSha1() { | ||
return commitSha1; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setCommitSha1(String commitSha1) { | ||
this.commitSha1 = commitSha1; | ||
} | ||
|
||
public StashBuildState getBuildStatus() { | ||
return buildStatus; | ||
} | ||
|
||
public void setBuildStatus(StashBuildState buildStatus) { | ||
this.buildStatus = buildStatus; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setBuildStatus(String buildStatus) { | ||
scaytrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
StashBuildState overwrittenBuildState = null; | ||
try { | ||
overwrittenBuildState = StashBuildState.valueOf(buildStatus); | ||
} catch (Exception e) { | ||
// ignore unknown or null values | ||
} | ||
this.buildStatus = overwrittenBuildState; | ||
} | ||
|
||
public String getBuildName() { | ||
return buildName; | ||
} | ||
|
||
public boolean getIncludeBuildNumberInKey() { | ||
@DataBoundSetter | ||
public void setBuildName(String buildName) { | ||
this.buildName = buildName; | ||
} | ||
|
||
public boolean isIncludeBuildNumberInKey() { | ||
return includeBuildNumberInKey; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setIncludeBuildNumberInKey(boolean includeBuildNumberInKey) { | ||
this.includeBuildNumberInKey = includeBuildNumberInKey; | ||
} | ||
|
||
public String getProjectKey() { | ||
return projectKey; | ||
} | ||
|
||
public boolean getPrependParentProjectKey() { | ||
@DataBoundSetter | ||
public void setProjectKey(String projectKey) { | ||
this.projectKey = projectKey; | ||
} | ||
|
||
public boolean isPrependParentProjectKey() { | ||
return prependParentProjectKey; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setPrependParentProjectKey(boolean prependParentProjectKey) { | ||
this.prependParentProjectKey = prependParentProjectKey; | ||
} | ||
|
||
public boolean isDisableInprogressNotification() { | ||
return disableInprogressNotification; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setDisableInprogressNotification(boolean disableInprogressNotification) { | ||
this.disableInprogressNotification = disableInprogressNotification; | ||
} | ||
|
||
public boolean isConsiderUnstableAsSuccess() { | ||
return considerUnstableAsSuccess; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setConsiderUnstableAsSuccess(boolean considerUnstableAsSuccess) { | ||
this.considerUnstableAsSuccess = considerUnstableAsSuccess; | ||
} | ||
|
||
@Override | ||
public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) { | ||
return disableInprogressNotification || processJenkinsEvent(build, null, listener, StashBuildState.INPROGRESS); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/org/jenkinsci/plugins/stashNotifier/StashNotifier/help-buildName.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
If not empty, this will overwrite the default build name sent to Bitbucket. | ||
</div> |
3 changes: 3 additions & 0 deletions
3
src/main/resources/org/jenkinsci/plugins/stashNotifier/StashNotifier/help-buildStatus.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
If not empty, this status will be sent to Bitbucket instead of the <code>currentBuild.result</code>. | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking if the number of constructors can be reduced even more? Is this one really required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about that, and neither am I that the test cases existing as well as the ones I can do locally cover all potential use cases. So I've kept it to be on the safe side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is a new one and another one has been removed.
In other plugins it's often handled the way to keep all old constructors for backward compatibility and annotate them with
@Deprecated
. That's something the maintainers should decide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you're right. Then I'm not totally sure, what the constructor was meant for. I think it's just the old
DataBoundConstructor
without all of the optional parameters. So I could just move the logic in the no-argument constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was some time out of the country and noticed that I did not push the change before. Done that now.