Skip to content

Commit 88e3abc

Browse files
authored
CQI Replace commons-lang deprecated methods (#1120)
1 parent 6727b21 commit 88e3abc

20 files changed

+47
-42
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
6161
import jenkins.scm.api.mixin.TagSCMHead;
6262
import org.apache.commons.lang3.StringUtils;
63+
import org.apache.commons.lang3.Strings;
6364

6465
/**
6566
* A {@link GitSCMBuilder} specialized for bitbucket.
@@ -222,7 +223,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) { /
222223
String scmSourceRepository = scmSource.getRepository();
223224
String pullRequestRepoOwner = head.getRepoOwner();
224225
String pullRequestRepository = head.getRepository();
225-
boolean prFromTargetRepository = StringUtils.equalsIgnoreCase(pullRequestRepoOwner, scmSourceRepoOwner)
226+
boolean prFromTargetRepository = Strings.CI.equals(pullRequestRepoOwner, scmSourceRepoOwner)
226227
&& pullRequestRepository.equalsIgnoreCase(scmSourceRepository);
227228
SCMRevision revision = revision();
228229
ChangeRequestCheckoutStrategy checkoutStrategy = head.getCheckoutStrategy();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.util.HashSet;
6767
import java.util.Iterator;
6868
import java.util.List;
69+
import java.util.Objects;
6970
import java.util.Set;
7071
import jenkins.authentication.tokens.api.AuthenticationTokens;
7172
import jenkins.model.Jenkins;
@@ -218,10 +219,10 @@ public String getServerUrl() {
218219
}
219220

220221
@DataBoundSetter
221-
public void setServerUrl(@CheckForNull String serverUrl) {
222-
serverUrl = Util.fixEmpty(URLUtils.normalizeURL(serverUrl));
223-
if (serverUrl != null && !StringUtils.equals(this.serverUrl, serverUrl)) {
224-
this.serverUrl = serverUrl;
222+
public void setServerUrl(@CheckForNull String serverURL) {
223+
serverURL = Util.fixEmpty(URLUtils.normalizeURL(serverURL));
224+
if (serverURL != null && !Objects.equals(this.serverUrl, serverURL)) {
225+
this.serverUrl = serverURL;
225226
resetId();
226227
}
227228
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import java.util.List;
9191
import java.util.Locale;
9292
import java.util.Map;
93+
import java.util.Objects;
9394
import java.util.Optional;
9495
import java.util.Set;
9596
import java.util.concurrent.ConcurrentHashMap;
@@ -126,6 +127,7 @@
126127
import jenkins.scm.impl.trait.Discovery;
127128
import jenkins.scm.impl.trait.Selection;
128129
import org.apache.commons.lang3.StringUtils;
130+
import org.apache.commons.lang3.Strings;
129131
import org.eclipse.jgit.lib.Constants;
130132
import org.jenkinsci.Symbol;
131133
import org.kohsuke.accmod.Restricted;
@@ -414,7 +416,7 @@ class Skip extends IOException {
414416
pull.getSource().getBranchType() == PullRequestBranchType.TAG ? "tag" : "branch",
415417
originalBranchName
416418
);
417-
boolean fork = !StringUtils.equalsIgnoreCase(fullName, pull.getSource().getRepository().getFullName());
419+
boolean fork = !Strings.CI.equals(fullName, pull.getSource().getRepository().getFullName());
418420
String pullRepoOwner = pull.getSource().getRepository().getOwnerName();
419421
String pullRepository = pull.getSource().getRepository().getRepositoryName();
420422
final BitbucketApi forkClient = fork && BitbucketApiUtils.isCloud(getServerUrl())
@@ -750,7 +752,7 @@ protected String getProjectKey() {
750752

751753
private void setPrimaryCloneLinks(List<BitbucketHref> links) {
752754
links.forEach(link -> {
753-
if (StringUtils.startsWithIgnoreCase(link.getName(), "http")) {
755+
if (Strings.CI.startsWith(link.getName(), "http")) {
754756
// Remove the username from URL because it will be set into the GIT_URL variable
755757
// credentials used to git clone or push/pull operation could be different than this (for example SSH)
756758
// and will run into a failure
@@ -893,9 +895,9 @@ protected List<Action> retrieveActions(@NonNull SCMHead head,
893895
SCMSourceOwner owner = getOwner();
894896
if (owner instanceof Actionable actionable) {
895897
for (BitbucketDefaultBranch p : actionable.getActions(BitbucketDefaultBranch.class)) {
896-
if (StringUtils.equalsIgnoreCase(getRepoOwner(), p.getRepoOwner())
897-
&& StringUtils.equals(repository, p.getRepository())
898-
&& StringUtils.equals(p.getDefaultBranch(), head.getName())) {
898+
if (Strings.CI.equals(getRepoOwner(), p.getRepoOwner())
899+
&& Objects.equals(repository, p.getRepository())
900+
&& Objects.equals(p.getDefaultBranch(), head.getName())) {
899901
result.add(new PrimaryInstanceMetadataAction());
900902
break;
901903
}
@@ -923,7 +925,7 @@ private synchronized Map<String, ContributorMetadataAction> getPullRequestContri
923925
@NonNull
924926
public SCMHeadOrigin originOf(@NonNull String repoOwner, @NonNull String repository) {
925927
if (this.repository.equalsIgnoreCase(repository)) {
926-
if (StringUtils.equalsIgnoreCase(this.repoOwner, repoOwner)) {
928+
if (Strings.CI.equals(this.repoOwner, repoOwner)) {
927929
return SCMHeadOrigin.DEFAULT;
928930
}
929931
return new SCMHeadOrigin.Fork(repoOwner);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/endpoint/BitbucketEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import hudson.Util;
3434
import hudson.model.Describable;
3535
import jenkins.model.Jenkins;
36-
import org.apache.commons.lang3.StringUtils;
36+
import org.apache.commons.lang3.Strings;
3737

3838
/**
3939
* The implementation represents an endpoint configuration to be used in
@@ -156,7 +156,7 @@ default StandardCredentials credentials() {
156156
* @return {@code true} if endpoint are the same, {@code false} otherwise
157157
*/
158158
default boolean isEquals(BitbucketEndpoint endpoint) {
159-
return StringUtils.equalsIgnoreCase(getServerURL(), endpoint.getServerURL());
159+
return Strings.CI.equals(getServerURL(), endpoint.getServerURL());
160160
}
161161

162162
/**

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/branch/BitbucketCloudBranch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private void initHeadCommitInfo() {
136136
try {
137137
BitbucketCommit commit = commitClosure.call();
138138

139-
this.dateInMillis = commit.getDateMillis();
139+
this.dateInMillis = commit.getCommitterDate() != null ? commit.getCommitterDate().getTime() : 0;
140140
this.message = commit.getMessage();
141141
this.author = commit.getAuthor();
142142
} catch (Exception e) {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepository;
3535
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepositoryOwner;
3636
import com.fasterxml.jackson.annotation.JsonProperty;
37-
import org.apache.commons.lang3.StringUtils;
37+
import org.apache.commons.lang3.Strings;
3838

3939
public class BitbucketCloudPullRequestEvent implements BitbucketPullRequestEvent {
4040

@@ -73,7 +73,7 @@ private void reconstructMissingData() {
7373
sourceRepository.setScm(repository.getScm());
7474
}
7575
if (sourceRepository.getOwner() == null) {
76-
if (!StringUtils.equalsIgnoreCase(sourceRepository.getOwnerName(), repository.getOwnerName())) { // i.e., a fork
76+
if (!Strings.CI.equals(sourceRepository.getOwnerName(), repository.getOwnerName())) { // i.e., a fork
7777
BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner();
7878
owner.setUsername(sourceRepository.getOwnerName());
7979
owner.setDisplayName(this.pullRequest.getAuthorLogin());
@@ -108,7 +108,7 @@ private void reconstructMissingData() {
108108
destination.getRepository().setScm(repository.getScm());
109109
}
110110
if (destination.getRepository().getOwner() == null
111-
&& StringUtils.equalsIgnoreCase(destination.getRepository().getOwnerName(), repository.getOwnerName())) {
111+
&& Strings.CI.equals(destination.getRepository().getOwnerName(), repository.getOwnerName())) {
112112
destination.getRepository().setOwner(repository.getOwner());
113113
destination.getRepository().setPrivate(repository.isPrivate());
114114
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import jenkins.scm.api.SCMSourceDescriptor;
6363
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
6464
import org.apache.commons.lang3.StringUtils;
65+
import org.apache.commons.lang3.Strings;
6566

6667
import static org.apache.commons.lang3.StringUtils.defaultString;
6768

@@ -276,7 +277,7 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
276277
if (BitbucketApiUtils.isCloud(serverURL)) {
277278
// support lightweight checkout for branches with same owner and repository
278279
if (prHead.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.HEAD &&
279-
StringUtils.equalsIgnoreCase(prHead.getRepoOwner(), src.getRepoOwner()) &&
280+
Strings.CI.equals(prHead.getRepoOwner(), src.getRepoOwner()) &&
280281
prHead.getRepository().equals(src.getRepository())) {
281282
ref = prHead.getOriginName();
282283
} else {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookAutoRegisterListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import jenkins.scm.api.SCMSourceOwner;
6363
import jenkins.scm.api.SCMSourceOwners;
6464
import org.apache.commons.lang3.ObjectUtils;
65-
import org.apache.commons.lang3.StringUtils;
65+
import org.apache.commons.lang3.Strings;
6666
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
6767

6868
/**
@@ -286,7 +286,7 @@ private boolean isUsedSomewhereElse(SCMSourceOwner owner, String repoOwner, Stri
286286
if (owner != other) {
287287
for(SCMSource otherSource : other.getSCMSources()) {
288288
if (otherSource instanceof BitbucketSCMSource bbSCMSource
289-
&& StringUtils.equalsIgnoreCase(bbSCMSource.getRepoOwner(), repoOwner)
289+
&& Strings.CI.equals(bbSCMSource.getRepoOwner(), repoOwner)
290290
&& bbSCMSource.getRepository().equals(repoName)) {
291291
return true;
292292
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/AbstractWebhookProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.commons.collections4.MultiValuedMap;
5656
import org.apache.commons.lang3.ObjectUtils;
5757
import org.apache.commons.lang3.StringUtils;
58+
import org.apache.commons.lang3.Strings;
5859
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
5960
import org.kohsuke.accmod.Restricted;
6061
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -93,9 +94,9 @@ protected void scmSourceReIndex(final String owner, final String repository, fin
9394
for (SCMSource source : sources) {
9495
// Search for the correct SCM source
9596
if (source instanceof BitbucketSCMSource scmSource
96-
&& StringUtils.equalsIgnoreCase(scmSource.getRepoOwner(), owner)
97+
&& Strings.CI.equals(scmSource.getRepoOwner(), owner)
9798
&& scmSource.getRepository().equals(repository)
98-
&& (mirrorId == null || StringUtils.equalsIgnoreCase(mirrorId, scmSource.getMirrorId()))) {
99+
&& (mirrorId == null || Strings.CI.equals(mirrorId, scmSource.getMirrorId()))) {
99100
logger.log(Level.INFO, "Multibranch project found, reindexing {0}", scmOwner.getName());
100101
// TODO: SCMSourceOwner.onSCMSourceUpdated is deprecated. We may explore options with an
101102
// SCMEventListener extension and firing SCMSourceEvents.

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/cloud/AbstractSCMHeadEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import jenkins.scm.api.SCMHeadEvent;
4141
import jenkins.scm.api.SCMNavigator;
4242
import org.apache.commons.lang3.StringUtils;
43+
import org.apache.commons.lang3.Strings;
4344

4445
public abstract class AbstractSCMHeadEvent<P> extends SCMHeadEvent<P> {
4546

@@ -60,7 +61,7 @@ public boolean isMatch(@NonNull SCMNavigator navigator) {
6061
if (!isServerURLMatch(bbNav.getServerUrl())) {
6162
return false;
6263
}
63-
return StringUtils.equalsIgnoreCase(bbNav.getRepoOwner(), getRepository().getOwnerName());
64+
return Strings.CI.equals(bbNav.getRepoOwner(), getRepository().getOwnerName());
6465
}
6566

6667
protected abstract BitbucketRepository getRepository();

0 commit comments

Comments
 (0)