Skip to content
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

Remove legacy code, methods deprecated since 2.2.0 #1002

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BitbucketBuildStatusNotificationsTrait extends SCMSourceTrait {
private boolean sendStoppedNotificationForAbortBuild;
private boolean disableNotificationForNotBuildJobs;
private boolean useReadableNotificationIds = false;
// seems that this attribute as been moved out to plugin skip-notifications-trait-plugin
// seems that this attribute has been moved out to plugin skip-notifications-trait-plugin
@SuppressFBWarnings("UUF_UNUSED_FIELD")
private transient boolean disableNotifications;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.DescriptorImpl;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
Expand Down Expand Up @@ -168,7 +167,7 @@ public BitbucketGitSCMBuilder withCredentials(String credentialsId, BitbucketRep
StandardCredentials credentials = BitbucketCredentials.lookupCredentials(
scmSource.getServerUrl(),
scmSource.getOwner(),
DescriptorImpl.SAME.equals(scmSource.getCheckoutCredentialsId()) ? credentialsId : scmSource.getCheckoutCredentialsId(),
credentialsId,
StandardCredentials.class
);

Expand Down Expand Up @@ -259,9 +258,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) {
}
}
if (head.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.MERGE) {
String hash = revision instanceof PullRequestSCMRevision
? ((PullRequestSCMRevision) revision).getTargetImpl().getHash()
: null;
String hash = revision instanceof PullRequestSCMRevision prRevision ? prRevision.getTargetImpl().getHash() : null;
String refSpec = "+refs/heads/" + targetBranch + ":refs/remotes/@{remote}/" + targetBranch;
if (!prFromTargetRepository && scmSource.isCloud()) {
String upstreamRemoteName = remoteName().equals("upstream") ? "upstream-upstream" : "upstream";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.RestrictedSince;
import hudson.Util;
import hudson.console.HyperlinkNote;
import hudson.model.Action;
Expand All @@ -58,7 +56,6 @@
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -67,8 +64,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.authentication.tokens.api.AuthenticationTokens;
import jenkins.model.Jenkins;
import jenkins.plugins.git.traits.GitBrowserSCMSourceTrait;
Expand All @@ -91,16 +86,11 @@
import jenkins.scm.impl.UncategorizedSCMSourceCategory;
import jenkins.scm.impl.form.NamedArrayList;
import jenkins.scm.impl.trait.Discovery;
import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait;
import jenkins.scm.impl.trait.Selection;
import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand All @@ -111,8 +101,6 @@

public class BitbucketSCMNavigator extends SCMNavigator {

private static final Logger LOGGER = Logger.getLogger(BitbucketSCMSource.class.getName());

@NonNull
private String serverUrl;
@CheckForNull
Expand All @@ -125,31 +113,6 @@
private String projectKey;
@NonNull
private List<SCMTrait<? extends SCMTrait<?>>> traits;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient String checkoutCredentialsId;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient String pattern;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient boolean autoRegisterHooks;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient String includes;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient String excludes;
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
private transient String bitbucketServerUrl;


@DataBoundConstructor
public BitbucketSCMNavigator(String repoOwner) {
Expand Down Expand Up @@ -177,46 +140,6 @@
}
}

@SuppressWarnings({"ConstantConditions", "deprecation"})
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
justification = "Only non-null after we set them here!")
private Object readResolve() throws ObjectStreamException {
if (serverUrl == null) {
serverUrl = BitbucketEndpointConfiguration.get().readResolveServerUrl(bitbucketServerUrl);
}
if (serverUrl == null) {
LOGGER.log(Level.WARNING, "BitbucketSCMNavigator::readResolve : serverUrl is still empty");
}
if (traits == null) {
// legacy instance, reconstruct traits to reflect legacy behaviour
traits = new ArrayList<>();
this.traits.add(new BranchDiscoveryTrait(true, true));
this.traits.add(new OriginPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.HEAD)));
this.traits.add(new ForkPullRequestDiscoveryTrait(
EnumSet.of(ChangeRequestCheckoutStrategy.HEAD),
new ForkPullRequestDiscoveryTrait.TrustEveryone())
);
this.traits.add(new PublicRepoPullRequestFilterTrait());
if ((includes != null && !"*".equals(includes)) || (excludes != null && !"".equals(excludes))) {
traits.add(new WildcardSCMHeadFilterTrait(
StringUtils.defaultIfBlank(includes, "*"),
StringUtils.defaultIfBlank(excludes, "")));
}
if (checkoutCredentialsId != null
&& !BitbucketSCMSource.DescriptorImpl.SAME.equals(checkoutCredentialsId)
&& !checkoutCredentialsId.equals(credentialsId)) {
traits.add(new SSHCheckoutTrait(checkoutCredentialsId));
}
traits.add(new WebhookRegistrationTrait(
autoRegisterHooks ? WebhookRegistration.ITEM : WebhookRegistration.DISABLE)
);
if (pattern != null && !".*".equals(pattern)) {
traits.add(new RegexSCMSourceFilterTrait(pattern));
}
}
return this;
}

@CheckForNull
public String getCredentialsId() {
return credentialsId;
Expand Down Expand Up @@ -284,7 +207,7 @@
*/
@Override
public void setTraits(@CheckForNull List<SCMTrait<? extends SCMTrait<?>>> traits) {
this.traits = traits != null ? new ArrayList<>(traits) : new ArrayList<SCMTrait<? extends SCMTrait<?>>>();
this.traits = traits != null ? new ArrayList<>(traits) : new ArrayList<>();

Check warning on line 210 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 210 is only partially covered, one branch is missing
}

public String getServerUrl() {
Expand All @@ -300,193 +223,11 @@
}
}

@Deprecated
@Restricted(DoNotUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setPattern(String pattern) {
for (int i = 0; i < traits.size(); i++) {
SCMTrait<?> trait = traits.get(i);
if (trait instanceof RegexSCMSourceFilterTrait) {
if (".*".equals(pattern)) {
traits.remove(i);
} else {
traits.set(i, new RegexSCMSourceFilterTrait(pattern));
}
return;
}
}
if (!".*".equals(pattern)) {
traits.add(new RegexSCMSourceFilterTrait(pattern));
}
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setAutoRegisterHooks(boolean autoRegisterHook) {
traits.removeIf(WebhookRegistrationTrait.class::isInstance);
traits.add(new WebhookRegistrationTrait(
autoRegisterHook ? WebhookRegistration.ITEM : WebhookRegistration.DISABLE
));
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
public boolean isAutoRegisterHooks() {
for (SCMTrait<? extends SCMTrait<?>> t : traits) {
if (t instanceof WebhookRegistrationTrait hookTrait) {
return hookTrait.getMode() != WebhookRegistration.DISABLE;
}
}
return true;
}


@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@NonNull
public String getCheckoutCredentialsId() {
for (SCMTrait<?> t : traits) {
if (t instanceof SSHCheckoutTrait sshTrait) {
return StringUtils.defaultString(sshTrait.getCredentialsId(), BitbucketSCMSource
.DescriptorImpl.ANONYMOUS);
}
}
return BitbucketSCMSource.DescriptorImpl.SAME;
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setCheckoutCredentialsId(String checkoutCredentialsId) {
traits.removeIf(SSHCheckoutTrait.class::isInstance);
if (checkoutCredentialsId != null && !BitbucketSCMSource.DescriptorImpl.SAME.equals(checkoutCredentialsId)) {
traits.add(new SSHCheckoutTrait(checkoutCredentialsId));
}
}

@Deprecated
@Restricted(DoNotUse.class)
@RestrictedSince("2.2.0")
public String getPattern() {
for (SCMTrait<?> trait : traits) {
if (trait instanceof RegexSCMSourceFilterTrait regexTrait) {
return regexTrait.getRegex();
}
}
return ".*";
}

@Deprecated
@Restricted(DoNotUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setBitbucketServerUrl(String url) {
url = BitbucketEndpointConfiguration.normalizeServerUrl(url);
url = StringUtils.defaultIfBlank(url, BitbucketCloudEndpoint.SERVER_URL); // when BitbucketServerUrl was null means cloud was configured
AbstractBitbucketEndpoint endpoint = BitbucketEndpointConfiguration.get()
.findEndpoint(url)
.orElse(null);
if (endpoint == null) {
LOGGER.log(Level.WARNING, "Call to legacy setBitbucketServerUrl({0}) method is configuring a url missing "
+ "from the global configuration.", url);
}
setServerUrl(url);
}

@Deprecated
@Restricted(DoNotUse.class)
@RestrictedSince("2.2.0")
@CheckForNull
public String getBitbucketServerUrl() {
if (BitbucketEndpointConfiguration.get()
.findEndpoint(serverUrl)
.filter(BitbucketCloudEndpoint.class::isInstance)
.isPresent()) {
return null;
}
return serverUrl;
}

@NonNull
public String getEndpointJenkinsRootUrl() {
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@NonNull
public String getIncludes() {
for (SCMTrait<?> trait : traits) {
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
return wildcardTrait.getIncludes();
}
}
return "*";
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setIncludes(@NonNull String includes) {
for (int i = 0; i < traits.size(); i++) {
SCMTrait<?> trait = traits.get(i);
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
if ("*".equals(includes) && "".equals(wildcardTrait.getExcludes())) {
traits.remove(i);
} else {
traits.set(i, new WildcardSCMHeadFilterTrait(includes, wildcardTrait.getExcludes()));
}
return;
}
}
if (!"*".equals(includes)) {
traits.add(new WildcardSCMHeadFilterTrait(includes, ""));
}
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@NonNull
public String getExcludes() {
for (SCMTrait<?> trait : traits) {
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
return wildcardTrait.getExcludes();
}
}
return "";
}

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@DataBoundSetter
public void setExcludes(@NonNull String excludes) {
for (int i = 0; i < traits.size(); i++) {
SCMTrait<?> trait = traits.get(i);
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
if ("*".equals(wildcardTrait.getIncludes()) && "".equals(excludes)) {
traits.remove(i);
} else {
traits.set(i, new WildcardSCMHeadFilterTrait(wildcardTrait.getIncludes(), excludes));
}
return;
}
}
if (!"".equals(excludes)) {
traits.add(new WildcardSCMHeadFilterTrait("*", excludes));
}
}


@NonNull
@Override
protected String id() {
Expand Down Expand Up @@ -522,16 +263,17 @@

BitbucketAuthenticator authenticator = AuthenticationTokens.convert(BitbucketAuthenticator.authenticationContext(serverUrl), credentials);

BitbucketApi bitbucket = BitbucketApiFactory.newInstance(serverUrl, authenticator, repoOwner, projectKey, null);
BitbucketTeam team = bitbucket.getTeam();
if (team != null) {
// Navigate repositories of the team
listener.getLogger().format("Looking up repositories of team %s%n", repoOwner);
request.withRepositories(bitbucket.getRepositories());
} else {
// Navigate the repositories of the repoOwner as a user
listener.getLogger().format("Looking up repositories of user %s%n", repoOwner);
request.withRepositories(bitbucket.getRepositories(UserRoleInRepository.ADMIN));
try (BitbucketApi bitbucket = BitbucketApiFactory.newInstance(serverUrl, authenticator, repoOwner, projectKey, null)) {
BitbucketTeam team = bitbucket.getTeam();
if (team != null) {
// Navigate repositories of the team
listener.getLogger().format("Looking up repositories of team %s%n", repoOwner);
request.withRepositories(bitbucket.getRepositories());
} else {
// Navigate the repositories of the repoOwner as a user
listener.getLogger().format("Looking up repositories of user %s%n", repoOwner);
request.withRepositories(bitbucket.getRepositories(UserRoleInRepository.ADMIN));
}
}
for (BitbucketRepository repo : request.repositories()) {
if (request.process(repo.getRepositoryName(), sourceFactory, null, witness)) {
Expand Down
Loading
Loading