Skip to content

Commit b39735a

Browse files
committed
Replace the use of deprecated methods.
Use JDK 17 feature Remove unused import
1 parent 6a0d987 commit b39735a

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -843,36 +843,35 @@ private void retrieveTags(final BitbucketSCMSourceRequest request) throws IOExce
843843
protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOException, InterruptedException {
844844
final BitbucketApi bitbucket = buildBitbucketClient();
845845
try {
846-
if (head instanceof PullRequestSCMHead) {
847-
PullRequestSCMHead h = (PullRequestSCMHead) head;
846+
if (head instanceof PullRequestSCMHead prHead) {
848847
BitbucketCommit sourceRevision;
849848
BitbucketCommit targetRevision;
850849

851850
if (bitbucket instanceof BitbucketCloudApiClient) {
852851
// Bitbucket Cloud /pullrequests/{id} API endpoint only returns short commit IDs of the source
853852
// and target branch. We therefore retrieve the branches directly
854-
BitbucketBranch targetBranch = bitbucket.getBranch(h.getTarget().getName());
853+
BitbucketBranch targetBranch = bitbucket.getBranch(prHead.getTarget().getName());
855854

856855
if(targetBranch == null) {
857856
listener.getLogger().format("No branch found in {0}/{1} with name [{2}]",
858-
repoOwner, repository, h.getTarget().getName());
857+
repoOwner, repository, prHead.getTarget().getName());
859858
return null;
860859
}
861860
targetRevision = findCommit(targetBranch, listener);
862861

863862
if (targetRevision == null) {
864863
listener.getLogger().format("No branch found in {0}/{1} with name [{2}]",
865-
repoOwner, repository, h.getTarget().getName());
864+
repoOwner, repository, prHead.getTarget().getName());
866865
return null;
867866
}
868867

869868
// Retrieve the source branch commit
870869
BitbucketBranch branch;
871870
if (head.getOrigin() == SCMHeadOrigin.DEFAULT) {
872-
branch = bitbucket.getBranch(h.getBranchName());
871+
branch = bitbucket.getBranch(prHead.getBranchName());
873872
} else {
874873
// In case of a forked branch, retrieve the branch as that owner
875-
branch = buildBitbucketClient(h).getBranch(h.getBranchName());
874+
branch = buildBitbucketClient(prHead).getBranch(prHead.getBranchName());
876875
}
877876

878877
if(branch == null) {
@@ -886,17 +885,17 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
886885
} else {
887886
BitbucketPullRequest pr;
888887
try {
889-
pr = bitbucket.getPullRequestById(Integer.parseInt(h.getId()));
888+
pr = bitbucket.getPullRequestById(Integer.parseInt(prHead.getId()));
890889
} catch (NumberFormatException nfe) {
891-
LOGGER.log(Level.WARNING, "Cannot parse the PR id {0}", h.getId());
890+
LOGGER.log(Level.WARNING, "Cannot parse the PR id {0}", prHead.getId());
892891
return null;
893892
}
894893

895894
targetRevision = findPRDestinationCommit(pr, listener);
896895

897896
if (targetRevision == null) {
898897
listener.getLogger().format("No branch found in {0}/{1} with name [{2}]",
899-
repoOwner, repository, h.getTarget().getName());
898+
repoOwner, repository, prHead.getTarget().getName());
900899
return null;
901900
}
902901

@@ -905,20 +904,19 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
905904

906905
if (sourceRevision == null) {
907906
listener.getLogger().format("No revision found in {0}/{1} for PR-{2} [{3}]",
908-
h.getRepoOwner(),
909-
h.getRepository(),
910-
h.getId(),
911-
h.getBranchName());
907+
prHead.getRepoOwner(),
908+
prHead.getRepository(),
909+
prHead.getId(),
910+
prHead.getBranchName());
912911
return null;
913912
}
914913

915914
return new PullRequestSCMRevision(
916-
h,
917-
new BitbucketGitSCMRevision(h.getTarget(), targetRevision),
918-
new BitbucketGitSCMRevision(h, sourceRevision)
915+
prHead,
916+
new BitbucketGitSCMRevision(prHead.getTarget(), targetRevision),
917+
new BitbucketGitSCMRevision(prHead, sourceRevision)
919918
);
920-
} else if (head instanceof BitbucketTagSCMHead) {
921-
BitbucketTagSCMHead tagHead = (BitbucketTagSCMHead) head;
919+
} else if (head instanceof BitbucketTagSCMHead tagHead) {
922920
BitbucketBranch tag = bitbucket.getTag(tagHead.getName());
923921
if(tag == null) {
924922
listener.getLogger().format( "No tag found in {0}/{1} with name [{2}]",
@@ -949,8 +947,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
949947
}
950948
} catch (IOException e) {
951949
// here we only want to display the job name to have it in the log
952-
if (e instanceof BitbucketRequestException) {
953-
BitbucketRequestException bre = (BitbucketRequestException) e;
950+
if (e instanceof BitbucketRequestException bre) {
954951
SCMSourceOwner scmSourceOwner = getOwner();
955952
if (bre.getHttpCode() == 401 && scmSourceOwner != null) {
956953
LOGGER.log(Level.WARNING, "BitbucketRequestException: Authz error. Status: 401 for Item '{0}' using credentialId '{1}'",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public AvatarImage fetch(StandardCredentials credentials) {
108108
}
109109

110110
private StandardCredentials findCredentials() {
111-
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
111+
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
112112
return CredentialsMatchers.firstOrNull(
113-
CredentialsProvider.lookupCredentials(
113+
CredentialsProvider.lookupCredentialsInItem(
114114
credentials.getClass(),
115115
(Item) null, // context
116-
ACL.SYSTEM,
116+
ACL.SYSTEM2,
117117
URIRequirementBuilder.fromUri(serverUrl).build()
118118
),
119119
CredentialsMatchers.allOf(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ public List<SCMHeadAuthorityDescriptor> getTrustDescriptors() {
234234
* <p>
235235
* This reduces generics in the databound constructor method signature as a workaround for JENKINS-26535
236236
*/
237-
@SuppressWarnings("rawtypes")
238237
public static abstract class BitbucketForkTrustPolicy extends SCMHeadAuthority<BitbucketSCMSourceRequest, PullRequestSCMHead, PullRequestSCMRevision> {
239238
}
240239

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.kohsuke.stapler.AncestorInPath;
5555
import org.kohsuke.stapler.DataBoundConstructor;
5656
import org.kohsuke.stapler.QueryParameter;
57+
import org.springframework.security.core.Authentication;
5758

5859
/**
5960
* A {@link SCMSourceTrait} for {@link BitbucketSCMSource} that causes the {@link GitSCM}
@@ -176,9 +177,9 @@ public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item
176177
StandardListBoxModel result = new StandardListBoxModel();
177178
result.add(Messages.SSHCheckoutTrait_useAgentKey(), "");
178179
return result.includeMatchingAs(
179-
context instanceof Queue.Task
180-
? ((Queue.Task) context).getDefaultAuthentication()
181-
: ACL.SYSTEM,
180+
context instanceof Queue.Task task
181+
? task.getDefaultAuthentication2()
182+
: ACL.SYSTEM2,
182183
context,
183184
StandardUsernameCredentials.class,
184185
URIRequirementBuilder.fromUri(serverUrl).build(),
@@ -208,18 +209,21 @@ public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item co
208209
// use agent key
209210
return FormValidation.ok();
210211
}
211-
if (CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(
212+
Authentication authentication = context instanceof Queue.Task task
213+
? task.getDefaultAuthentication2()
214+
: ACL.SYSTEM2;
215+
if (CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItem(
212216
SSHUserPrivateKey.class,
213217
context,
214-
context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
218+
authentication,
215219
URIRequirementBuilder.fromUri(serverUrl).build()),
216220
CredentialsMatchers.withId(value)) != null) {
217221
return FormValidation.ok();
218222
}
219-
if (CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(
223+
if (CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentialsInItem(
220224
StandardUsernameCredentials.class,
221225
context,
222-
context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
226+
authentication,
223227
URIRequirementBuilder.fromUri(serverUrl).build()),
224228
CredentialsMatchers.withId(value)) != null) {
225229
return FormValidation.error(Messages.SSHCheckoutTrait_incompatibleCredentials());

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/AbstractBitbucketTeam.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
package com.cloudbees.jenkins.plugins.bitbucket.api;
2525

26-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
27-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketTeam;
2826
import com.fasterxml.jackson.annotation.JsonIgnore;
2927
import com.fasterxml.jackson.annotation.JsonProperty;
3028
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

0 commit comments

Comments
 (0)