Skip to content

Commit 8ce1332

Browse files
authored
Reduce usage of deprecated BitbucketRepositoryType. (#520)
* Reduce usage of deprecated BitbucketRepositoryType. * Fix org.junit.Assert.assertThat deprecation.
1 parent 9b438e8 commit 8ce1332

37 files changed

+128
-252
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ class Skip extends IOException {
660660
branchName, //
661661
pullRepoOwner, //
662662
pullRepository, //
663-
repositoryType, //
664663
originalBranchName, //
665664
pull, //
666665
originOf(pullRepoOwner, pullRepository), //
@@ -670,7 +669,6 @@ class Skip extends IOException {
670669
branchName, //
671670
repoOwner, //
672671
repository, //
673-
repositoryType, //
674672
originalBranchName, //
675673
pull, //
676674
originOf(pullRepoOwner, pullRepository), //
@@ -749,8 +747,7 @@ private void retrieveBranches(final BitbucketSCMSourceRequest request)
749747
for (final BitbucketBranch branch : request.getBranches()) {
750748
request.listener().getLogger().println("Checking branch " + branch.getName() + " from " + fullName);
751749
count++;
752-
if (request.process( //
753-
new BranchSCMHead(branch.getName(), repositoryType), //
750+
if (request.process(new BranchSCMHead(branch.getName()), //
754751
(IntermediateLambda<BitbucketCommit>) () -> new BranchHeadCommit(branch), //
755752
new BitbucketProbeFactory<>(bitbucket, request), //
756753
new BitbucketRevisionFactory<>(bitbucket), //
@@ -763,8 +760,7 @@ private void retrieveBranches(final BitbucketSCMSourceRequest request)
763760
}
764761

765762

766-
private void retrieveTags(final BitbucketSCMSourceRequest request)
767-
throws IOException, InterruptedException {
763+
private void retrieveTags(final BitbucketSCMSourceRequest request) throws IOException, InterruptedException {
768764
String fullName = repoOwner + "/" + repository;
769765
request.listener().getLogger().println("Looking up " + fullName + " for tags");
770766

@@ -777,7 +773,7 @@ private void retrieveTags(final BitbucketSCMSourceRequest request)
777773
for (final BitbucketBranch tag : request.getTags()) {
778774
request.listener().getLogger().println("Checking tag " + tag.getName() + " from " + fullName);
779775
count++;
780-
if (request.process(new BitbucketTagSCMHead(tag.getName(), tag.getDateMillis(), repositoryType), //
776+
if (request.process(new BitbucketTagSCMHead(tag.getName(), tag.getDateMillis()), //
781777
tag::getRawNode, //
782778
new BitbucketProbeFactory<>(bitbucket, request), //
783779
new BitbucketRevisionFactory<>(bitbucket), //
@@ -934,20 +930,12 @@ public SCM build(SCMHead head, SCMRevision revision) {
934930
e);
935931
cloneLinks = new ArrayList<>();
936932
cloneLinks.add(new BitbucketHref("ssh",
937-
bitbucket.getRepositoryUri(
938-
BitbucketRepositoryProtocol.SSH,
939-
null,
940-
getRepoOwner(),
941-
getRepository()
942-
)
933+
bitbucket.getRepositoryUri(BitbucketRepositoryProtocol.SSH, null,
934+
getRepoOwner(), getRepository())
943935
));
944936
cloneLinks.add(new BitbucketHref("https",
945-
bitbucket.getRepositoryUri(
946-
BitbucketRepositoryProtocol.HTTP,
947-
null,
948-
getRepoOwner(),
949-
getRepository()
950-
)
937+
bitbucket.getRepositoryUri(BitbucketRepositoryProtocol.HTTP, null,
938+
getRepoOwner(), getRepository())
951939
));
952940
}
953941
}

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,8 @@ public class BitbucketTagSCMHead extends GitTagSCMHead implements TagSCMHead {
5555
* @param timestamp the timestamp of tag
5656
*/
5757
public BitbucketTagSCMHead(@NonNull String tagName, long timestamp) {
58-
this(tagName, timestamp, BitbucketRepositoryType.GIT);
59-
}
60-
61-
/**
62-
* Constructor.
63-
*
64-
* @param tagName the tag name
65-
* @param timestamp the timestamp of tag
66-
* @param repositoryType the repository type.
67-
*/
68-
public BitbucketTagSCMHead(String tagName, long timestamp, BitbucketRepositoryType repositoryType) {
6958
super(tagName, timestamp);
70-
this.repositoryType = repositoryType;
59+
this.repositoryType = BitbucketRepositoryType.GIT;
7160
}
7261

7362
/**

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
2727
import edu.umd.cs.findbugs.annotations.CheckForNull;
2828
import jenkins.scm.api.SCMHead;
29-
import org.kohsuke.accmod.Restricted;
30-
import org.kohsuke.accmod.restrictions.DoNotUse;
3129

3230
/**
3331
* {@link SCMHead} for a Bitbucket branch.
@@ -51,23 +49,10 @@ public class BranchSCMHead extends SCMHead {
5149
* Constructor.
5250
*
5351
* @param branchName the branch name
54-
* @deprecated use {@link #BranchSCMHead(String, BitbucketRepositoryType)}
5552
*/
56-
@Deprecated
57-
@Restricted(DoNotUse.class)
5853
public BranchSCMHead(String branchName) {
59-
this(branchName, null);
60-
}
61-
62-
/**
63-
* Constructor.
64-
*
65-
* @param branchName the branch name
66-
* @param repositoryType the repository type.
67-
*/
68-
public BranchSCMHead(String branchName, BitbucketRepositoryType repositoryType) {
6954
super(branchName);
70-
this.repositoryType = repositoryType;
55+
this.repositoryType = BitbucketRepositoryType.GIT;
7156
}
7257

7358
/**

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,15 @@ public PullRequestSCMHead(String name, String repoOwner, String repository, Stri
8181
this.strategy = strategy;
8282
}
8383

84-
public PullRequestSCMHead(String name, String repoOwner, String repository, BitbucketRepositoryType repositoryType,
85-
String branchName, BitbucketPullRequest pr, SCMHeadOrigin origin,
86-
ChangeRequestCheckoutStrategy strategy) {
84+
public PullRequestSCMHead(String name, String repoOwner, String repository, String branchName,
85+
BitbucketPullRequest pr, SCMHeadOrigin origin, ChangeRequestCheckoutStrategy strategy) {
8786
super(name);
8887
this.repoOwner = repoOwner;
8988
this.repository = repository;
9089
this.branchName = branchName;
9190
this.number = pr.getId();
9291
this.title = pr.getTitle();
93-
this.target = new BranchSCMHead(pr.getDestination().getBranch().getName(), repositoryType);
92+
this.target = new BranchSCMHead(pr.getDestination().getBranch().getName());
9493
this.origin = origin;
9594
this.strategy = strategy;
9695
}
@@ -121,22 +120,15 @@ public PullRequestSCMHead(String repoOwner, String repository, String branchName
121120
@Deprecated
122121
@Restricted(DoNotUse.class)
123122
public PullRequestSCMHead(String repoOwner, String repository, String branchName, BitbucketPullRequest pr) {
124-
this(repoOwner, repository, null, branchName, pr, null);
123+
this(repoOwner, repository, branchName, pr, null);
125124
}
126125

127126
@Deprecated
128127
@Restricted(DoNotUse.class)
129-
public PullRequestSCMHead(String repoOwner, String repository, BitbucketRepositoryType repositoryType,
130-
String branchName, BitbucketPullRequest pr) {
131-
this(repoOwner, repository, repositoryType, branchName, pr, null);
132-
}
133-
134-
@Deprecated
135-
@Restricted(DoNotUse.class)
136-
public PullRequestSCMHead(String repoOwner, String repository, BitbucketRepositoryType repositoryType,
137-
String branchName, BitbucketPullRequest pr, SCMHeadOrigin origin) {
138-
this(PR_BRANCH_PREFIX + pr.getId(), repoOwner, repository, repositoryType, branchName, pr, origin,
139-
ChangeRequestCheckoutStrategy.HEAD);
128+
public PullRequestSCMHead(String repoOwner, String repository, String branchName, BitbucketPullRequest pr,
129+
SCMHeadOrigin origin) {
130+
this(PR_BRANCH_PREFIX + pr.getId(), repoOwner, repository, branchName, pr, origin,
131+
ChangeRequestCheckoutStrategy.HEAD);
140132
}
141133

142134
@SuppressWarnings("deprecation")

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApi;
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
2828
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest;
29-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
3029
import edu.umd.cs.findbugs.annotations.NonNull;
3130
import hudson.Extension;
3231
import java.io.IOException;
@@ -76,9 +75,9 @@ private Object readResolve() throws ObjectStreamException {
7675
// then the temporary PR class will be resolved by GitMigrationImpl when the
7776
// context to look up the correct target is (hopefully) available. If the context is not available
7877
// then worst case we will end up triggering a rebuild on next index / event via take-over
79-
return new PR(repoOwner, repoName, getName(), metadata.getId(), new BranchSCMHead("\u0000", null));
78+
return new PR(repoOwner, repoName, getName(), metadata.getId(), new BranchSCMHead("\u0000"));
8079
}
81-
return new BranchSCMHead(getName(), null);
80+
return new BranchSCMHead(getName());
8281
}
8382

8483
/**
@@ -150,7 +149,7 @@ public PullRequestSCMHead migrate(@NonNull BitbucketSCMSource source, @NonNull P
150149
head.getBranchName(),
151150
head.getId(),
152151
head.getTitle(),
153-
new BranchSCMHead(target, BitbucketRepositoryType.GIT),
152+
new BranchSCMHead(target),
154153
source.originOf(head.getRepoOwner(), head.getRepository()),
155154
ChangeRequestCheckoutStrategy.HEAD
156155
);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ protected CloseableHttpResponse executeMethod(HttpRequestBase httpMethod) throws
844844

845845
@Restricted(ProtectedExternally.class)
846846
protected CloseableHttpResponse executeMethod(HttpHost host, HttpRequestBase httpMethod) throws InterruptedException, IOException {
847-
848847
HttpClientContext requestContext = null;
849848
if (API_HOST.equals(host)) {
850849
requestContext = context;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
2828
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceContext;
2929
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
30-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
3130
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
3231
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerRepository;
3332
import edu.umd.cs.findbugs.annotations.NonNull;
3433
import hudson.scm.SCM;
3534
import java.util.Collections;
3635
import java.util.Map;
37-
import java.util.logging.Level;
3836
import java.util.logging.Logger;
3937
import jenkins.scm.api.SCMHead;
4038
import jenkins.scm.api.SCMHeadEvent;
@@ -117,12 +115,6 @@ private BitbucketSCMSource getMatchingBitbucketSource(SCMSource source) {
117115
return null;
118116
}
119117

120-
final BitbucketRepositoryType type = BitbucketRepositoryType.fromString(getRepository().getScm());
121-
if (type != BitbucketRepositoryType.GIT) {
122-
LOGGER.log(Level.INFO, "Received event for unknown repository type: {0}", getRepository().getScm());
123-
return null;
124-
}
125-
126118
return src;
127119
}
128120
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMRevision;
3131
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest;
3232
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
33-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
3433
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerRepository;
3534
import com.cloudbees.jenkins.plugins.bitbucket.server.events.NativeServerPullRequestEvent;
3635
import com.google.common.base.Ascii;
@@ -126,8 +125,8 @@ protected Map<SCMHead, SCMRevision> heads(@NonNull BitbucketSCMSource source) {
126125
final String originalBranchName = pullRequest.getSource().getBranch().getName();
127126
final String branchName = String.format("PR-%s%s", pullRequest.getId(),
128127
strategies.size() > 1 ? "-" + Ascii.toLowerCase(strategy.name()) : "");
129-
final PullRequestSCMHead head = new PullRequestSCMHead(branchName, source.getRepoOwner(), source.getRepository(),
130-
BitbucketRepositoryType.GIT, originalBranchName, pullRequest, headOrigin, strategy);
128+
final PullRequestSCMHead head = new PullRequestSCMHead(branchName, source.getRepoOwner(),
129+
source.getRepository(), originalBranchName, pullRequest, headOrigin, strategy);
131130

132131
switch (getType()) {
133132
case CREATED:

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMHead;
3232
import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMRevision;
3333
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest;
34-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
3534
import com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient;
3635
import com.cloudbees.jenkins.plugins.bitbucket.server.client.pullrequest.BitbucketServerPullRequest;
3736
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerRepository;
@@ -150,13 +149,12 @@ private void addBranchesAndTags(BitbucketSCMSource src, Map<SCMHead, SCMRevision
150149
String refType = change.getRef().getType();
151150

152151
if ("BRANCH".equals(refType)) {
153-
final BranchSCMHead head = new BranchSCMHead(change.getRef().getDisplayId(),
154-
BitbucketRepositoryType.GIT);
152+
final BranchSCMHead head = new BranchSCMHead(change.getRef().getDisplayId());
155153
final SCMRevision revision = getType() == SCMEvent.Type.REMOVED ? null
156154
: new AbstractGitSCMSource.SCMRevisionImpl(head, change.getToHash());
157155
result.put(head, revision);
158156
} else if ("TAG".equals(refType)) {
159-
SCMHead head = new BitbucketTagSCMHead(change.getRef().getDisplayId(), 0, BitbucketRepositoryType.GIT);
157+
SCMHead head = new BitbucketTagSCMHead(change.getRef().getDisplayId(), 0);
160158
final SCMRevision revision = getType() == SCMEvent.Type.REMOVED ? null
161159
: new AbstractGitSCMSource.SCMRevisionImpl(head, change.getToHash());
162160
result.put(head, revision);
@@ -210,8 +208,8 @@ private void addPullRequests(BitbucketSCMSource src, Map<SCMHead, SCMRevision> r
210208
final String branchName = String.format("PR-%s%s", pullRequest.getId(),
211209
strategies.size() > 1 ? "-" + Ascii.toLowerCase(strategy.name()) : "");
212210

213-
final PullRequestSCMHead head = new PullRequestSCMHead(branchName, sourceOwnerName, sourceRepoName,
214-
BitbucketRepositoryType.GIT, originalBranchName, pullRequest, headOrigin, strategy);
211+
final PullRequestSCMHead head = new PullRequestSCMHead(branchName, sourceOwnerName,
212+
sourceRepoName, originalBranchName, pullRequest, headOrigin, strategy);
215213

216214
final String targetHash = pullRequest.getDestination().getCommit().getHash();
217215
final String pullHash = pullRequest.getSource().getCommit().getHash();

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

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
3232
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest;
3333
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequestEvent;
34-
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
3534
import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudWebhookPayload;
3635
import com.cloudbees.jenkins.plugins.bitbucket.client.events.BitbucketCloudPullRequestEvent;
3736
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
@@ -47,7 +46,6 @@
4746
import java.util.Locale;
4847
import java.util.Map;
4948
import java.util.Set;
50-
import java.util.logging.Level;
5149
import java.util.logging.Logger;
5250
import jenkins.plugins.git.AbstractGitSCMSource;
5351
import jenkins.scm.api.SCMEvent;
@@ -174,13 +172,7 @@ public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
174172
if (!src.getRepository().equalsIgnoreCase(getPayload().getRepository().getRepositoryName())) {
175173
return Collections.emptyMap();
176174
}
177-
BitbucketRepositoryType type =
178-
BitbucketRepositoryType.fromString(getPayload().getRepository().getScm());
179-
if (type == null) {
180-
LOGGER.log(Level.INFO, "Received event for unknown repository type: {0}",
181-
getPayload().getRepository().getScm());
182-
return Collections.emptyMap();
183-
}
175+
184176
BitbucketSCMSourceContext ctx = new BitbucketSCMSourceContext(null, SCMHeadObserver.none())
185177
.withTraits(src.getTraits());
186178
if (!ctx.wantPRs()) {
@@ -208,7 +200,6 @@ public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
208200
branchName,
209201
pullRepoOwner,
210202
pullRepository,
211-
type,
212203
originalBranchName,
213204
pull,
214205
headOrigin,
@@ -219,7 +210,6 @@ public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
219210
branchName,
220211
src.getRepoOwner(),
221212
src.getRepository(),
222-
type,
223213
originalBranchName,
224214
pull,
225215
headOrigin,
@@ -230,28 +220,14 @@ public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
230220
// special case for repo being deleted
231221
result.put(head, null);
232222
} else {
233-
String targetHash =
234-
pull.getDestination().getCommit().getHash();
223+
String targetHash = pull.getDestination().getCommit().getHash();
235224
String pullHash = pull.getSource().getCommit().getHash();
236-
switch (type) {
237-
case GIT:
238-
result.put(head, new PullRequestSCMRevision<>(
239-
head,
240-
new AbstractGitSCMSource.SCMRevisionImpl(
241-
head.getTarget(),
242-
targetHash
243-
),
244-
new AbstractGitSCMSource.SCMRevisionImpl(
245-
head,
246-
pullHash
247-
)
248-
)
249-
);
250-
break;
251-
default:
252-
LOGGER.log(Level.INFO, "Received event for unknown repository type: {0}", type);
253-
break;
254-
}
225+
226+
SCMRevision revision = new PullRequestSCMRevision<>(head,
227+
new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(), targetHash),
228+
new AbstractGitSCMSource.SCMRevisionImpl(head, pullHash)
229+
);
230+
result.put(head, revision);
255231
}
256232
}
257233
return result;

0 commit comments

Comments
 (0)