Skip to content

Commit 24931a4

Browse files
authored
Move endpoint implementations to impl package (#1058)
1 parent 9888e21 commit 24931a4

File tree

61 files changed

+172
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+172
-188
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
3030
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
3131
import com.cloudbees.jenkins.plugins.bitbucket.api.PullRequestBranchType;
32+
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
3233
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
33-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
34-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
34+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
3535
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.FallbackToOtherRepositoryGitSCMExtension;
3636
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
3737
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketCredentials;
@@ -112,11 +112,10 @@ public BitbucketGitSCMBuilder(@NonNull BitbucketSCMSource scmSource, @NonNull SC
112112
this.scmSource = scmSource;
113113

114114
String serverURL = scmSource.getServerUrl();
115-
AbstractBitbucketEndpoint endpoint = (AbstractBitbucketEndpoint) BitbucketEndpointProvider
116-
.lookupEndpoint(serverURL)
115+
BitbucketEndpoint endpoint = BitbucketEndpointProvider.lookupEndpoint(serverURL)
117116
.orElse(new BitbucketServerEndpoint(null, serverURL, false, null, false, null));
118117

119-
String repositoryURL = endpoint.getRepositoryUrl(scmSource.getRepoOwner(), scmSource.getRepository());
118+
String repositoryURL = endpoint.getRepositoryURL(scmSource.getRepoOwner(), scmSource.getRepository());
120119
if (BitbucketApiUtils.isCloud(endpoint.getServerURL())) {
121120
withBrowser(new BitbucketWeb(repositoryURL));
122121
} else {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketTeam;
3232
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
3333
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
34-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
35-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
36-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
3734
import com.cloudbees.jenkins.plugins.bitbucket.impl.avatars.BitbucketTeamAvatarMetadataAction;
35+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
36+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
3837
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
3938
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketCredentials;
4039
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.MirrorListSupplier;
@@ -232,7 +231,7 @@ public void setServerUrl(@CheckForNull String serverUrl) {
232231
@Deprecated(since = "936.4.0", forRemoval = true)
233232
@NonNull
234233
public String getEndpointJenkinsRootUrl() {
235-
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
234+
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(serverUrl);
236235
}
237236

238237
@NonNull

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
import com.cloudbees.jenkins.plugins.bitbucket.api.PullRequestBranchType;
4141
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
4242
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.UserRoleInRepository;
43-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.AbstractBitbucketEndpoint;
44-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
4543
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
46-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
4744
import com.cloudbees.jenkins.plugins.bitbucket.hooks.HasPullRequests;
4845
import com.cloudbees.jenkins.plugins.bitbucket.impl.avatars.BitbucketRepoAvatarMetadataAction;
46+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
47+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
4948
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.BitbucketEnvVarExtension;
5049
import com.cloudbees.jenkins.plugins.bitbucket.impl.extension.GitClientAuthenticatorExtension;
5150
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
@@ -295,9 +294,10 @@ public void setServerUrl(@CheckForNull String serverUrl) {
295294
}
296295
}
297296

297+
@Deprecated(since = "936.4.0", forRemoval = true)
298298
@NonNull
299299
public String getEndpointJenkinsRootURL() {
300-
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
300+
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(serverUrl);
301301
}
302302

303303
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
package com.cloudbees.jenkins.plugins.bitbucket.api;
2525

26-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
26+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
2727
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
2828
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
2929
import hudson.plugins.git.GitSCM;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public interface BitbucketEndpoint extends Describable<BitbucketEndpoint> {
103103
*
104104
* @return the verbatim setting provided by endpoint configuration
105105
*/
106-
@CheckForNull
106+
@NonNull
107107
String getEndpointJenkinsRootURL();
108108

109109
boolean isEnableHookSignature();

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

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

26-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
2726
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
28-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
27+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
28+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
2929
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
3030
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.URLUtils;
3131
import edu.umd.cs.findbugs.annotations.CheckForNull;
3232
import edu.umd.cs.findbugs.annotations.NonNull;
3333
import edu.umd.cs.findbugs.annotations.Nullable;
34+
import hudson.Util;
3435
import hudson.util.ListBoxModel;
3536
import java.util.Collection;
3637
import java.util.List;
3738
import java.util.Objects;
3839
import java.util.Optional;
3940
import java.util.function.UnaryOperator;
4041
import org.apache.commons.lang3.StringUtils;
42+
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
4143

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

99+
/**
100+
* Jenkins Server Root URL to be used by the Bitbucket endpoint that matches
101+
* the given serverURL. The global setting from Jenkins.get().getRootUrl()
102+
* will be used if this field is null or equals an empty string.
103+
*
104+
* @param serverURL the server url to check.
105+
* @return the verbatim setting provided by endpoint configuration
106+
*/
107+
@NonNull
108+
public static String lookupEndpointJenkinsRootURL(@CheckForNull String serverURL) {
109+
return lookupEndpoint(serverURL)
110+
.map(BitbucketEndpoint::getEndpointJenkinsRootURL)
111+
.orElse(Util.ensureEndsWith(URLUtils.normalizeURL(Util.fixEmptyAndTrim(DisplayURLProvider.get().getRoot())), "/"));
112+
}
113+
97114
/**
98115
* Checks to see if the supplied server URL is defined in the global
99116
* configuration.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
2828
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
2929
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
30-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
30+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
3131
import edu.umd.cs.findbugs.annotations.CheckForNull;
3232
import edu.umd.cs.findbugs.annotations.NonNull;
3333
import edu.umd.cs.findbugs.annotations.Nullable;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/AbstractBitbucketEndpointDescriptor.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketEndpointConfiguration.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
28+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
29+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
2830
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
2931
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.URLUtils;
3032
import edu.umd.cs.findbugs.annotations.CheckForNull;
3133
import edu.umd.cs.findbugs.annotations.NonNull;
3234
import hudson.Extension;
3335
import hudson.ExtensionList;
3436
import hudson.Util;
37+
import hudson.XmlFile;
3538
import hudson.security.ACL;
3639
import hudson.security.Permission;
3740
import hudson.util.ListBoxModel;
41+
import hudson.util.XStream2;
42+
import java.io.File;
3843
import java.util.ArrayList;
3944
import java.util.Collections;
4045
import java.util.HashSet;
@@ -73,6 +78,17 @@ public BitbucketEndpointConfiguration() {
7378
load();
7479
}
7580

81+
// TODO remove within a year
82+
@Restricted(NoExternalUse.class)
83+
@Override
84+
public XmlFile getConfigFile() {
85+
File cfgFile = new File(Jenkins.get().getRootDir(), getId() + ".xml");
86+
XStream2 xs = new XStream2(XStream2.getDefaultDriver());
87+
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint", BitbucketCloudEndpoint.class);
88+
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint", BitbucketServerEndpoint.class);
89+
return new XmlFile(xs, cfgFile);
90+
}
91+
7692
/**
7793
* Gets the {@link BitbucketEndpointConfiguration} singleton.
7894
*
@@ -156,9 +172,9 @@ public boolean configure(StaplerRequest2 req, JSONObject json) throws FormExcept
156172
* @return the list of endpoints
157173
*/
158174
@NonNull
159-
public List<AbstractBitbucketEndpoint /*BitbucketEndpoint*/> getEndpoints() {
175+
public List<BitbucketEndpoint /*BitbucketEndpoint*/> getEndpoints() {
160176
// make a local copy so if changes in meanwhile you do not get NPE
161-
List/*<BitbucketEndpoint>*/ localEndpoints = this.endpoints;
177+
List<BitbucketEndpoint> localEndpoints = this.endpoints;
162178
return CollectionUtils.isEmpty(localEndpoints)
163179
? List.of(new BitbucketCloudEndpoint())
164180
: Collections.unmodifiableList(localEndpoints);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
3232
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
3333
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit;
34-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
34+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
3535
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
3636
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.DateUtils;
3737
import com.cloudbees.jenkins.plugins.bitbucket.server.BitbucketServerVersion;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
28-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
28+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
2929
import edu.umd.cs.findbugs.annotations.CheckForNull;
3030
import edu.umd.cs.findbugs.annotations.NonNull;
3131
import edu.umd.cs.findbugs.annotations.Nullable;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import hudson.util.DaemonThreadFactory;
4141
import hudson.util.NamingThreadFactory;
4242
import java.io.IOException;
43-
import java.util.ArrayList;
4443
import java.util.List;
4544
import java.util.concurrent.ExecutorService;
4645
import java.util.concurrent.Executors;
@@ -133,7 +132,7 @@ private synchronized void registerHooks(SCMSourceOwner owner) throws IOException
133132
return;
134133
}
135134
for (BitbucketSCMSource source : sources) {
136-
String rootUrl = source.getEndpointJenkinsRootURL();
135+
String rootUrl = BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(source.getServerUrl());
137136
if (!rootUrl.startsWith("http://localhost") && !rootUrl.startsWith("http://unconfigured-jenkins-location")) {
138137
registerHook(source);
139138
} else {
@@ -161,13 +160,13 @@ private synchronized void registerHooks(SCMSourceOwner owner) throws IOException
161160
}
162161

163162
private void registerHook(BitbucketSCMSource source) throws IOException {
164-
BitbucketApi bitbucket = bitbucketApiFor(source);
163+
BitbucketApi bitbucket = getClientBySource(source);
165164
if (bitbucket == null) {
166165
return;
167166
}
168167

169168
BitbucketWebHook existingHook;
170-
String hookReceiverURL = source.getEndpointJenkinsRootURL() + BitbucketSCMSourcePushHookReceiver.FULL_PATH;
169+
String hookReceiverURL = getHookReceiverURL(source.getServerUrl());
171170
// Check for all hooks pointing to us
172171
existingHook = bitbucket.getWebHooks().stream()
173172
.filter(hook -> hook.getUrl() != null)
@@ -187,16 +186,20 @@ private void registerHook(BitbucketSCMSource source) throws IOException {
187186
}
188187
}
189188

189+
private String getHookReceiverURL(String endpointURL) {
190+
return BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(endpointURL) + BitbucketSCMSourcePushHookReceiver.FULL_PATH;
191+
}
192+
190193
private void removeHooks(SCMSourceOwner owner) throws IOException {
191194
List<BitbucketSCMSource> sources = getBitbucketSCMSources(owner);
192195
for (BitbucketSCMSource source : sources) {
193-
BitbucketApi bitbucket = bitbucketApiFor(source);
196+
BitbucketApi bitbucket = getClientBySource(source);
194197
if (bitbucket != null) {
195198
List<? extends BitbucketWebHook> existent = bitbucket.getWebHooks();
196199
BitbucketWebHook hook = null;
197200
for (BitbucketWebHook h : existent) {
198201
// Check if there is a hook pointing to us
199-
if (h.getUrl().startsWith(source.getEndpointJenkinsRootURL() + BitbucketSCMSourcePushHookReceiver.FULL_PATH)) {
202+
if (h.getUrl().startsWith(getHookReceiverURL(source.getServerUrl()))) {
200203
hook = h;
201204
break;
202205
}
@@ -214,7 +217,7 @@ private void removeHooks(SCMSourceOwner owner) throws IOException {
214217
}
215218

216219
@CheckForNull
217-
private BitbucketApi bitbucketApiFor(@NonNull BitbucketSCMSource source) {
220+
private BitbucketApi getClientBySource(@NonNull BitbucketSCMSource source) {
218221
switch (new BitbucketSCMSourceContext(null, SCMHeadObserver.none())
219222
.withTraits(source.getTraits())
220223
.webhookRegistration()) {
@@ -257,13 +260,10 @@ private boolean isUsedSomewhereElse(SCMSourceOwner owner, String repoOwner, Stri
257260
}
258261

259262
private List<BitbucketSCMSource> getBitbucketSCMSources(SCMSourceOwner owner) {
260-
List<BitbucketSCMSource> sources = new ArrayList<>();
261-
for (SCMSource source : owner.getSCMSources()) {
262-
if (source instanceof BitbucketSCMSource) {
263-
sources.add((BitbucketSCMSource) source);
264-
}
265-
}
266-
return sources;
263+
return owner.getSCMSources().stream()
264+
.filter(BitbucketSCMSource.class::isInstance)
265+
.map(BitbucketSCMSource.class::cast)
266+
.toList();
267267
}
268268

269269
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
2929
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
3030
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketRepositoryHook;
31-
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint;
31+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
3232
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
3333
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerWebhook;
3434
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.NativeBitbucketServerWebhook;
@@ -147,7 +147,7 @@ boolean updateHook(BitbucketWebHook hook, BitbucketSCMSource owner) {
147147
}
148148
} else if (hook instanceof NativeBitbucketServerWebhook serverHook) {
149149
String serverURL = owner.getServerUrl();
150-
String url = getNativeServerWebhookUrl(serverURL, owner.getEndpointJenkinsRootURL());
150+
String url = getNativeServerWebhookUrl(serverURL, BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(owner.getServerUrl()));
151151

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

177177
public BitbucketWebHook getHook(BitbucketSCMSource owner) {
178178
final String serverUrl = owner.getServerUrl();
179-
final String rootUrl = owner.getEndpointJenkinsRootURL();
179+
final String rootUrl = BitbucketEndpointProvider.lookupEndpointJenkinsRootURL(owner.getServerUrl());
180180
final String signatureSecret = getSecret(owner.getServerUrl());
181181

182182
if (BitbucketApiUtils.isCloud(serverUrl)) {

0 commit comments

Comments
 (0)