Skip to content

Move endpoint implementations to impl package #1058

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

Merged
merged 1 commit into from
Jun 10, 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 @@ -29,9 +29,9 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
import com.cloudbees.jenkins.plugins.bitbucket.api.PullRequestBranchType;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.FallbackToOtherRepositoryGitSCMExtension;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketCredentials;
Expand Down Expand Up @@ -112,11 +112,10 @@ public BitbucketGitSCMBuilder(@NonNull BitbucketSCMSource scmSource, @NonNull SC
this.scmSource = scmSource;

String serverURL = scmSource.getServerUrl();
AbstractBitbucketEndpoint endpoint = (AbstractBitbucketEndpoint) BitbucketEndpointProvider
.lookupEndpoint(serverURL)
BitbucketEndpoint endpoint = BitbucketEndpointProvider.lookupEndpoint(serverURL)
.orElse(new BitbucketServerEndpoint(null, serverURL, false, null, false, null));

String repositoryURL = endpoint.getRepositoryUrl(scmSource.getRepoOwner(), scmSource.getRepository());
String repositoryURL = endpoint.getRepositoryURL(scmSource.getRepoOwner(), scmSource.getRepository());
if (BitbucketApiUtils.isCloud(endpoint.getServerURL())) {
withBrowser(new BitbucketWeb(repositoryURL));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketTeam;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.avatars.BitbucketTeamAvatarMetadataAction;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketCredentials;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.MirrorListSupplier;
Expand Down Expand Up @@ -232,7 +231,7 @@
@Deprecated(since = "936.4.0", forRemoval = true)
@NonNull
public String getEndpointJenkinsRootUrl() {
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(serverUrl);

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

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 234 is not covered by tests
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.PullRequestBranchType;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.hooks.HasPullRequests;
import com.cloudbees.jenkins.plugins.bitbucket.impl.avatars.BitbucketRepoAvatarMetadataAction;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.BitbucketEnvVarExtension;
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.GitClientAuthenticatorExtension;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
Expand Down Expand Up @@ -295,9 +294,10 @@ public void setServerUrl(@CheckForNull String serverUrl) {
}
}

@Deprecated(since = "936.4.0", forRemoval = true)
@NonNull
public String getEndpointJenkinsRootURL() {
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(serverUrl);
}

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

import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import hudson.plugins.git.GitSCM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface BitbucketEndpoint extends Describable<BitbucketEndpoint> {
*
* @return the verbatim setting provided by endpoint configuration
*/
@CheckForNull
@NonNull
String getEndpointJenkinsRootURL();

boolean isEnableHookSignature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.api.endpoint;

import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.URLUtils;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Util;
import hudson.util.ListBoxModel;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.UnaryOperator;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;

/**
* A provider of {@link BitbucketEndpoint}s
Expand Down Expand Up @@ -94,6 +96,21 @@ public static <T extends BitbucketEndpoint> Optional<T> lookupEndpoint(@CheckFor
.findFirst();
}

/**
* Jenkins Server Root URL to be used by the Bitbucket endpoint that matches
* the given serverURL. The global setting from Jenkins.get().getRootUrl()
* will be used if this field is null or equals an empty string.
*
* @param serverURL the server url to check.
* @return the verbatim setting provided by endpoint configuration
*/
@NonNull
public static String lookupEndpointJenkinsRootURL(@CheckForNull String serverURL) {
return lookupEndpoint(serverURL)
.map(BitbucketEndpoint::getEndpointJenkinsRootURL)
.orElse(Util.ensureEndsWith(URLUtils.normalizeURL(Util.fixEmptyAndTrim(DisplayURLProvider.get().getRoot())), "/"));
}

/**
* Checks to see if the supplied server URL is defined in the global
* configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@

import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.URLUtils;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.Util;
import hudson.XmlFile;
import hudson.security.ACL;
import hudson.security.Permission;
import hudson.util.ListBoxModel;
import hudson.util.XStream2;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -73,6 +78,17 @@
load();
}

// TODO remove within a year

Check warning on line 81 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketEndpointConfiguration.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: remove within a year
@Restricted(NoExternalUse.class)
@Override
public XmlFile getConfigFile() {
File cfgFile = new File(Jenkins.get().getRootDir(), getId() + ".xml");
XStream2 xs = new XStream2(XStream2.getDefaultDriver());
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint", BitbucketCloudEndpoint.class);
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint", BitbucketServerEndpoint.class);
return new XmlFile(xs, cfgFile);
}

/**
* Gets the {@link BitbucketEndpointConfiguration} singleton.
*
Expand Down Expand Up @@ -156,9 +172,9 @@
* @return the list of endpoints
*/
@NonNull
public List<AbstractBitbucketEndpoint /*BitbucketEndpoint*/> getEndpoints() {
public List<BitbucketEndpoint /*BitbucketEndpoint*/> getEndpoints() {
// make a local copy so if changes in meanwhile you do not get NPE
List/*<BitbucketEndpoint>*/ localEndpoints = this.endpoints;
List<BitbucketEndpoint> localEndpoints = this.endpoints;
return CollectionUtils.isEmpty(localEndpoints)
? List.of(new BitbucketCloudEndpoint())
: Collections.unmodifiableList(localEndpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.DateUtils;
import com.cloudbees.jenkins.plugins.bitbucket.server.BitbucketServerVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import hudson.util.DaemonThreadFactory;
import hudson.util.NamingThreadFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -133,7 +132,7 @@
return;
}
for (BitbucketSCMSource source : sources) {
String rootUrl = source.getEndpointJenkinsRootURL();
String rootUrl = BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(source.getServerUrl());
if (!rootUrl.startsWith("http://localhost") && !rootUrl.startsWith("http://unconfigured-jenkins-location")) {
registerHook(source);
} else {
Expand Down Expand Up @@ -161,13 +160,13 @@
}

private void registerHook(BitbucketSCMSource source) throws IOException {
BitbucketApi bitbucket = bitbucketApiFor(source);
BitbucketApi bitbucket = getClientBySource(source);
if (bitbucket == null) {
return;
}

BitbucketWebHook existingHook;
String hookReceiverURL = source.getEndpointJenkinsRootURL() + BitbucketSCMSourcePushHookReceiver.FULL_PATH;
String hookReceiverURL = getHookReceiverURL(source.getServerUrl());
// Check for all hooks pointing to us
existingHook = bitbucket.getWebHooks().stream()
.filter(hook -> hook.getUrl() != null)
Expand All @@ -187,16 +186,20 @@
}
}

private String getHookReceiverURL(String endpointURL) {
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(endpointURL) + BitbucketSCMSourcePushHookReceiver.FULL_PATH;
}

private void removeHooks(SCMSourceOwner owner) throws IOException {
List<BitbucketSCMSource> sources = getBitbucketSCMSources(owner);
for (BitbucketSCMSource source : sources) {
BitbucketApi bitbucket = bitbucketApiFor(source);
BitbucketApi bitbucket = getClientBySource(source);
if (bitbucket != null) {
List<? extends BitbucketWebHook> existent = bitbucket.getWebHooks();
BitbucketWebHook hook = null;
for (BitbucketWebHook h : existent) {
// Check if there is a hook pointing to us
if (h.getUrl().startsWith(source.getEndpointJenkinsRootURL() + BitbucketSCMSourcePushHookReceiver.FULL_PATH)) {
if (h.getUrl().startsWith(getHookReceiverURL(source.getServerUrl()))) {

Check warning on line 202 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookAutoRegisterListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 202 is not covered by tests
hook = h;
break;
}
Expand All @@ -214,7 +217,7 @@
}

@CheckForNull
private BitbucketApi bitbucketApiFor(@NonNull BitbucketSCMSource source) {
private BitbucketApi getClientBySource(@NonNull BitbucketSCMSource source) {
switch (new BitbucketSCMSourceContext(null, SCMHeadObserver.none())
.withTraits(source.getTraits())
.webhookRegistration()) {
Expand Down Expand Up @@ -257,13 +260,10 @@
}

private List<BitbucketSCMSource> getBitbucketSCMSources(SCMSourceOwner owner) {
List<BitbucketSCMSource> sources = new ArrayList<>();
for (SCMSource source : owner.getSCMSources()) {
if (source instanceof BitbucketSCMSource) {
sources.add((BitbucketSCMSource) source);
}
}
return sources;
return owner.getSCMSources().stream()
.filter(BitbucketSCMSource.class::isInstance)
.map(BitbucketSCMSource.class::cast)
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketRepositoryHook;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerWebhook;
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.NativeBitbucketServerWebhook;
Expand Down Expand Up @@ -147,7 +147,7 @@ boolean updateHook(BitbucketWebHook hook, BitbucketSCMSource owner) {
}
} else if (hook instanceof NativeBitbucketServerWebhook serverHook) {
String serverURL = owner.getServerUrl();
String url = getNativeServerWebhookUrl(serverURL, owner.getEndpointJenkinsRootURL());
String url = getNativeServerWebhookUrl(serverURL, BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(owner.getServerUrl()));

if (!url.equals(serverHook.getUrl())) {
serverHook.setUrl(url);
Expand Down Expand Up @@ -176,7 +176,7 @@ boolean updateHook(BitbucketWebHook hook, BitbucketSCMSource owner) {

public BitbucketWebHook getHook(BitbucketSCMSource owner) {
final String serverUrl = owner.getServerUrl();
final String rootUrl = owner.getEndpointJenkinsRootURL();
final String rootUrl = BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(owner.getServerUrl());
final String signatureSecret = getSecret(owner.getServerUrl());

if (BitbucketApiUtils.isCloud(serverUrl)) {
Expand Down
Loading
Loading