mirror of
https://github.com/jlengrand/jreleaser.git
synced 2026-03-10 08:31:24 +00:00
[chore] refactor timeout validation
This commit is contained in:
@@ -32,7 +32,7 @@ import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
* @author Andres Almiray
|
||||
* @since 0.6.0
|
||||
*/
|
||||
public class Sdkman extends AbstractTool {
|
||||
public class Sdkman extends AbstractTool implements TimeoutAware {
|
||||
public static final String SDKMAN_CONSUMER_KEY = "SDKMAN_CONSUMER_KEY";
|
||||
public static final String SDKMAN_CONSUMER_TOKEN = "SDKMAN_CONSUMER_TOKEN";
|
||||
public static final String NAME = "sdkman";
|
||||
@@ -115,18 +115,22 @@ public class Sdkman extends AbstractTool {
|
||||
this.consumerToken = consumerToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
@@ -94,11 +94,6 @@ public abstract class ArtifactoryValidator extends Validator {
|
||||
break;
|
||||
}
|
||||
|
||||
if (artifactory.getConnectTimeout() <= 0 || artifactory.getConnectTimeout() > 300) {
|
||||
artifactory.setConnectTimeout(20);
|
||||
}
|
||||
if (artifactory.getReadTimeout() <= 0 || artifactory.getReadTimeout() > 300) {
|
||||
artifactory.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(artifactory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,6 @@ public abstract class DiscordValidator extends Validator {
|
||||
errors.configuration("discord.messageTemplate does not exist. " + discord.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (discord.getConnectTimeout() <= 0 || discord.getConnectTimeout() > 300) {
|
||||
discord.setConnectTimeout(20);
|
||||
}
|
||||
if (discord.getReadTimeout() <= 0 || discord.getReadTimeout() > 300) {
|
||||
discord.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(discord);
|
||||
}
|
||||
}
|
||||
@@ -73,11 +73,6 @@ public abstract class DiscussionsValidator extends Validator {
|
||||
errors.configuration("discussions.messageTemplate does not exist. " + discussions.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (discussions.getConnectTimeout() <= 0 || discussions.getConnectTimeout() > 300) {
|
||||
discussions.setConnectTimeout(context.getModel().getRelease().getGitService().getConnectTimeout());
|
||||
}
|
||||
if (discussions.getReadTimeout() <= 0 || discussions.getReadTimeout() > 300) {
|
||||
discussions.setReadTimeout(context.getModel().getRelease().getGitService().getReadTimeout());
|
||||
}
|
||||
validateTimeout(discussions);
|
||||
}
|
||||
}
|
||||
@@ -152,12 +152,7 @@ public abstract class GitServiceValidator extends Validator {
|
||||
service.getCommitAuthor().setEmail("jreleaser@kordamp.org");
|
||||
}
|
||||
|
||||
if (service.getConnectTimeout() <= 0 || service.getConnectTimeout() > 300) {
|
||||
service.setConnectTimeout(20);
|
||||
}
|
||||
if (service.getReadTimeout() <= 0 || service.getReadTimeout() > 300) {
|
||||
service.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(service);
|
||||
|
||||
if (service.isReleaseSupported()) {
|
||||
// milestone
|
||||
|
||||
@@ -59,11 +59,6 @@ public abstract class GitterValidator extends Validator {
|
||||
errors.configuration("gitter.messageTemplate does not exist. " + gitter.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (gitter.getConnectTimeout() <= 0 || gitter.getConnectTimeout() > 300) {
|
||||
gitter.setConnectTimeout(20);
|
||||
}
|
||||
if (gitter.getReadTimeout() <= 0 || gitter.getReadTimeout() > 300) {
|
||||
gitter.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(gitter);
|
||||
}
|
||||
}
|
||||
@@ -59,11 +59,6 @@ public abstract class GoogleChatValidator extends Validator {
|
||||
errors.configuration("googleChat.messageTemplate does not exist. " + googleChat.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (googleChat.getConnectTimeout() <= 0 || googleChat.getConnectTimeout() > 300) {
|
||||
googleChat.setConnectTimeout(20);
|
||||
}
|
||||
if (googleChat.getReadTimeout() <= 0 || googleChat.getReadTimeout() > 300) {
|
||||
googleChat.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(googleChat);
|
||||
}
|
||||
}
|
||||
@@ -101,11 +101,6 @@ public abstract class HttpUploaderValidator extends Validator {
|
||||
break;
|
||||
}
|
||||
|
||||
if (http.getConnectTimeout() <= 0 || http.getConnectTimeout() > 300) {
|
||||
http.setConnectTimeout(20);
|
||||
}
|
||||
if (http.getReadTimeout() <= 0 || http.getReadTimeout() > 300) {
|
||||
http.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(http);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,6 @@ public abstract class MastodonValidator extends Validator {
|
||||
mastodon.setStatus("\uD83D\uDE80 {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}");
|
||||
}
|
||||
|
||||
if (mastodon.getConnectTimeout() <= 0 || mastodon.getConnectTimeout() > 300) {
|
||||
mastodon.setConnectTimeout(20);
|
||||
}
|
||||
if (mastodon.getReadTimeout() <= 0 || mastodon.getReadTimeout() > 300) {
|
||||
mastodon.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(mastodon);
|
||||
}
|
||||
}
|
||||
@@ -59,11 +59,6 @@ public abstract class MattermostValidator extends Validator {
|
||||
errors.configuration("mattermost.messageTemplate does not exist. " + mattermost.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (mattermost.getConnectTimeout() <= 0 || mattermost.getConnectTimeout() > 300) {
|
||||
mattermost.setConnectTimeout(20);
|
||||
}
|
||||
if (mattermost.getReadTimeout() <= 0 || mattermost.getReadTimeout() > 300) {
|
||||
mattermost.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(mattermost);
|
||||
}
|
||||
}
|
||||
@@ -113,12 +113,7 @@ public abstract class PackagersValidator extends Validator {
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (tool.getConnectTimeout() <= 0 || tool.getConnectTimeout() > 300) {
|
||||
tool.setConnectTimeout(20);
|
||||
}
|
||||
if (tool.getReadTimeout() <= 0 || tool.getReadTimeout() > 300) {
|
||||
tool.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(tool);
|
||||
}
|
||||
|
||||
private static void validatePackager(JReleaserContext context,
|
||||
|
||||
@@ -64,12 +64,7 @@ public abstract class SdkmanAnnouncerValidator extends Validator {
|
||||
sdkman.disable();
|
||||
}
|
||||
|
||||
if (sdkman.getConnectTimeout() <= 0 || sdkman.getConnectTimeout() > 300) {
|
||||
sdkman.setConnectTimeout(20);
|
||||
}
|
||||
if (sdkman.getReadTimeout() <= 0 || sdkman.getReadTimeout() > 300) {
|
||||
sdkman.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(sdkman);
|
||||
|
||||
context.getModel().getActiveDistributions().stream()
|
||||
.filter(d -> d.getSdkman().isEnabled())
|
||||
|
||||
@@ -47,9 +47,6 @@ public abstract class SdkmanValidator extends Validator {
|
||||
if (!tool.isActiveSet() && parentTool.isActiveSet()) {
|
||||
tool.setActive(parentTool.getActive());
|
||||
}
|
||||
if(model.getProject().isSnapshot()) {
|
||||
tool.disable();
|
||||
}
|
||||
if (!tool.resolveEnabled(context.getModel().getProject(), distribution)) return;
|
||||
GitService service = model.getRelease().getGitService();
|
||||
if (!service.isReleaseSupported()) {
|
||||
@@ -99,12 +96,7 @@ public abstract class SdkmanValidator extends Validator {
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
if (tool.getConnectTimeout() <= 0 || tool.getConnectTimeout() > 300) {
|
||||
tool.setConnectTimeout(20);
|
||||
}
|
||||
if (tool.getReadTimeout() <= 0 || tool.getReadTimeout() > 300) {
|
||||
tool.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(tool);
|
||||
|
||||
validateArtifactPlatforms(context, distribution, tool, errors);
|
||||
}
|
||||
|
||||
@@ -81,11 +81,6 @@ public abstract class SlackValidator extends Validator {
|
||||
errors.configuration("slack.messageTemplate does not exist. " + slack.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (slack.getConnectTimeout() <= 0 || slack.getConnectTimeout() > 300) {
|
||||
slack.setConnectTimeout(20);
|
||||
}
|
||||
if (slack.getReadTimeout() <= 0 || slack.getReadTimeout() > 300) {
|
||||
slack.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(slack);
|
||||
}
|
||||
}
|
||||
@@ -55,11 +55,6 @@ public abstract class TeamsValidator extends Validator {
|
||||
errors.configuration("teams.messageTemplate does not exist. " + teams.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (teams.getConnectTimeout() <= 0 || teams.getConnectTimeout() > 300) {
|
||||
teams.setConnectTimeout(20);
|
||||
}
|
||||
if (teams.getReadTimeout() <= 0 || teams.getReadTimeout() > 300) {
|
||||
teams.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(teams);
|
||||
}
|
||||
}
|
||||
@@ -72,11 +72,6 @@ public abstract class TwitterValidator extends Validator {
|
||||
twitter.setStatus("\uD83D\uDE80 {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}");
|
||||
}
|
||||
|
||||
if (twitter.getConnectTimeout() <= 0 || twitter.getConnectTimeout() > 300) {
|
||||
twitter.setConnectTimeout(20);
|
||||
}
|
||||
if (twitter.getReadTimeout() <= 0 || twitter.getReadTimeout() > 300) {
|
||||
twitter.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(twitter);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.jreleaser.model.CommitAuthorAware;
|
||||
import org.jreleaser.model.Environment;
|
||||
import org.jreleaser.model.JReleaserContext;
|
||||
import org.jreleaser.model.OwnerAware;
|
||||
import org.jreleaser.model.TimeoutAware;
|
||||
import org.jreleaser.model.Tool;
|
||||
import org.jreleaser.util.Env;
|
||||
import org.jreleaser.util.Errors;
|
||||
@@ -98,4 +99,13 @@ class Validator {
|
||||
if (isBlank(author.getEmail())) author.setEmail(other.getCommitAuthor().getEmail());
|
||||
self.setCommitAuthor(author);
|
||||
}
|
||||
|
||||
static void validateTimeout(TimeoutAware self) {
|
||||
if (self.getConnectTimeout() <= 0 || self.getConnectTimeout() > 300) {
|
||||
self.setConnectTimeout(20);
|
||||
}
|
||||
if (self.getReadTimeout() <= 0 || self.getReadTimeout() > 300) {
|
||||
self.setReadTimeout(60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,13 +90,7 @@ public abstract class WebhooksValidator extends Validator {
|
||||
errors.configuration("webhook." + webhook.getName() + ".messageTemplate does not exist. " + webhook.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (webhook.getConnectTimeout() <= 0 || webhook.getConnectTimeout() > 300) {
|
||||
webhook.setConnectTimeout(20);
|
||||
}
|
||||
|
||||
if (webhook.getReadTimeout() <= 0 || webhook.getReadTimeout() > 300) {
|
||||
webhook.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(webhook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -73,11 +73,6 @@ public abstract class ZulipValidator extends Validator {
|
||||
errors.configuration("zulip.messageTemplate does not exist. " + zulip.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (zulip.getConnectTimeout() <= 0 || zulip.getConnectTimeout() > 300) {
|
||||
zulip.setConnectTimeout(20);
|
||||
}
|
||||
if (zulip.getReadTimeout() <= 0 || zulip.getReadTimeout() > 300) {
|
||||
zulip.setReadTimeout(60);
|
||||
}
|
||||
validateTimeout(zulip);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user