Skip to content
Open
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
@@ -0,0 +1,61 @@
/*
* The MIT License
*
* Copyright (c) 2025, Allan Burdajewicz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.impl.webhook.plugin;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Logs a deprecation warning for the Bitbucket Addons support in the plugin.
* If the logger is configured to log FINE messages, the warning is logged at FINE level.
* Otherwise, the warning is logged at WARNING level at most once every 5 minutes to avoid log flooding in very active environment.
*/
public class PluginDeprecationLogger {

Check warning on line 34 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/plugin/PluginDeprecationLogger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 34 is not covered by tests

private static final long LOG_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
private static final java.util.concurrent.atomic.AtomicLong lastDeprecationLog =
new java.util.concurrent.atomic.AtomicLong(0);

/**
* Logs the deprecation warning if the last log was more than LOG_INTERVAL_MS ago.
*
* @param logger the logger to use
*/
public static void log(Logger logger) {
if(logger.isLoggable(Level.FINE)) {

Check warning on line 46 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/plugin/PluginDeprecationLogger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 46 is only partially covered, one branch is missing
logger.fine("Bitbucket Addons support are deprecated in favor of native integrations. Please migrate to Bitbucket Server native webhook.");

Check warning on line 47 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/plugin/PluginDeprecationLogger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 47 is not covered by tests
} else {
long now = System.currentTimeMillis();
long lastLog = lastDeprecationLog.get();
if (now - lastLog > LOG_INTERVAL_MS) {
if (lastDeprecationLog.compareAndSet(lastLog, now)) {

Check warning on line 52 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/plugin/PluginDeprecationLogger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 52 is only partially covered, one branch is missing
logger.log(
Level.WARNING,
() ->
"Bitbucket Addons support are deprecated in favor of native integrations. Please migrate to Bitbucket Server native webhook.");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import hudson.RestrictedSince;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.scm.api.SCMEvent;
import org.apache.commons.collections4.MultiValuedMap;
import org.kohsuke.accmod.Restricted;
Expand All @@ -45,6 +47,8 @@
@RestrictedSince("933.3.0")
public class PluginPullRequestWebhookProcessor extends AbstractWebhookProcessor {

private static final Logger logger = Logger.getLogger(PluginPullRequestWebhookProcessor.class.getName());

private static final List<String> supportedEvents = List.of(
HookEventType.PULL_REQUEST_CREATED.getKey(), // needed to create job
HookEventType.PULL_REQUEST_DECLINED.getKey(), // needed to remove job
Expand All @@ -61,6 +65,8 @@ public boolean canHandle(@NonNull Map<String, String> headers, @NonNull MultiVal

@Override
public void process(@NonNull String hookEventType, @NonNull String payload, @NonNull Map<String, Object> context, @NonNull BitbucketEndpoint endpoint) {
PluginDeprecationLogger.log(logger);
logger.log(Level.FINE, () -> "Processing hook: " + hookEventType + " payload: " + " from: " + endpoint.getServerURL());
HookEventType hookEvent = HookEventType.fromString(hookEventType);
BitbucketPullRequestEvent pull = BitbucketServerWebhookPayload.pullRequestEventFromPayload(payload);
if (pull != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public boolean canHandle(Map<String, String> headers, MultiValuedMap<String, Str

@Override
public void process(@NonNull String eventType, @NonNull String payload, @NonNull Map<String, Object> context, @NonNull BitbucketEndpoint endpoint) {
PluginDeprecationLogger.log(logger);
logger.log(Level.FINE, () -> "Processing hook: " + eventType + " payload: " + " from: " + endpoint.getServerURL());
BitbucketPushEvent push = BitbucketServerWebhookPayload.pushEventFromPayload(payload);
if (push != null) {
if (push.getChanges().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public void remove(@NonNull String webhookId, @NonNull BitbucketAuthenticatedCli

@Override
public void register(@NonNull BitbucketAuthenticatedClient client) throws IOException {
PluginDeprecationLogger.log(logger);
BitbucketPluginWebhook existingHook = (BitbucketPluginWebhook) read(client)
.stream()
.findFirst()
Expand Down
Loading