[announce] fix sdkman announcer when run on dryrun mode. Fixes #329

This commit is contained in:
Andres Almiray
2021-08-02 19:26:01 +02:00
parent 3894b1a2ae
commit 0d34cf52bb
5 changed files with 128 additions and 6 deletions

View File

@@ -0,0 +1,99 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.model;
/**
* @author Andres Almiray
* @since 0.6.0
*/
public enum JReleaserCommand {
ASSEMBLE,
CHANGELOG,
CHECKSUM,
SIGN,
UPLOAD,
RELEASE,
PREPARE,
PACKAGE,
PUBLISH,
ANNOUNCE,
FULL_RELEASE;
public static boolean supportsAssemble(JReleaserCommand command) {
return ASSEMBLE == command;
}
public static boolean supportsChangelog(JReleaserCommand command) {
return CHANGELOG == command ||
RELEASE == command ||
ANNOUNCE == command ||
FULL_RELEASE == command;
}
public static boolean supportsChecksum(JReleaserCommand command) {
return CHECKSUM == command ||
SIGN == command ||
UPLOAD == command ||
RELEASE == command ||
PREPARE == command ||
PACKAGE == command ||
PUBLISH == command ||
FULL_RELEASE == command;
}
public static boolean supportsSign(JReleaserCommand command) {
return SIGN == command ||
UPLOAD == command ||
RELEASE == command ||
FULL_RELEASE == command;
}
public static boolean supportsUpload(JReleaserCommand command) {
return UPLOAD == command ||
RELEASE == command ||
FULL_RELEASE == command;
}
public static boolean supportsRelease(JReleaserCommand command) {
return RELEASE == command ||
FULL_RELEASE == command;
}
public static boolean supportsPrepare(JReleaserCommand command) {
return PREPARE == command ||
PACKAGE == command ||
PUBLISH == command ||
FULL_RELEASE == command;
}
public static boolean supportsPackage(JReleaserCommand command) {
return PACKAGE == command ||
PUBLISH == command ||
FULL_RELEASE == command;
}
public static boolean supportsPublish(JReleaserCommand command) {
return PUBLISH == command ||
FULL_RELEASE == command;
}
public static boolean supportsAnnounce(JReleaserCommand command) {
return ANNOUNCE == command ||
FULL_RELEASE == command;
}
}

View File

@@ -90,6 +90,7 @@ public class JReleaserContext {
private String assemblerName; private String assemblerName;
private String changelog; private String changelog;
private Releaser releaser; private Releaser releaser;
private JReleaserCommand command;
public JReleaserContext(JReleaserLogger logger, public JReleaserContext(JReleaserLogger logger,
Configurer configurer, Configurer configurer,
@@ -370,6 +371,14 @@ public class JReleaserContext {
this.assemblerName = assemblerName; this.assemblerName = assemblerName;
} }
public JReleaserCommand getCommand() {
return command;
}
public void setCommand(JReleaserCommand command) {
this.command = command;
}
public Map<String, Object> props() { public Map<String, Object> props() {
Map<String, Object> props = new LinkedHashMap<>(model.props()); Map<String, Object> props = new LinkedHashMap<>(model.props());
props.put(Constants.KEY_OUTPUT_DIRECTORY, getOutputDirectory()); props.put(Constants.KEY_OUTPUT_DIRECTORY, getOutputDirectory());

View File

@@ -19,7 +19,6 @@ package org.jreleaser.tools;
import org.jreleaser.model.Artifact; import org.jreleaser.model.Artifact;
import org.jreleaser.model.Distribution; import org.jreleaser.model.Distribution;
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext; import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.Sdkman; import org.jreleaser.model.Sdkman;
import org.jreleaser.model.tool.spi.ToolProcessingException; import org.jreleaser.model.tool.spi.ToolProcessingException;
@@ -130,8 +129,6 @@ public class SdkmanToolProcessor extends AbstractToolProcessor<Sdkman> {
@Override @Override
protected void fillToolProperties(Map<String, Object> props, Distribution distribution) throws ToolProcessingException { protected void fillToolProperties(Map<String, Object> props, Distribution distribution) throws ToolProcessingException {
GitService gitService = context.getModel().getRelease().getGitService();
props.put(Constants.KEY_SDKMAN_CANDIDATE, tool.getCandidate()); props.put(Constants.KEY_SDKMAN_CANDIDATE, tool.getCandidate());
props.put(Constants.KEY_SDKMAN_RELEASE_NOTES_URL, applyTemplate(tool.getReleaseNotesUrl(), props)); props.put(Constants.KEY_SDKMAN_RELEASE_NOTES_URL, applyTemplate(tool.getReleaseNotesUrl(), props));
} }

View File

@@ -17,6 +17,7 @@
*/ */
package org.jreleaser.workflow; package org.jreleaser.workflow;
import org.jreleaser.model.JReleaserCommand;
import org.jreleaser.model.JReleaserContext; import org.jreleaser.model.JReleaserContext;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
@@ -28,24 +29,28 @@ import static java.util.Collections.singletonList;
*/ */
public class Workflows { public class Workflows {
public static Workflow assemble(JReleaserContext context) { public static Workflow assemble(JReleaserContext context) {
context.setCommand(JReleaserCommand.ASSEMBLE);
return new WorkflowImpl(context, singletonList( return new WorkflowImpl(context, singletonList(
new AssembleWorkflowItem() new AssembleWorkflowItem()
)); ));
} }
public static Workflow changelog(JReleaserContext context) { public static Workflow changelog(JReleaserContext context) {
context.setCommand(JReleaserCommand.CHANGELOG);
return new WorkflowImpl(context, singletonList( return new WorkflowImpl(context, singletonList(
new ChangelogWorkflowItem() new ChangelogWorkflowItem()
)); ));
} }
public static Workflow checksum(JReleaserContext context) { public static Workflow checksum(JReleaserContext context) {
context.setCommand(JReleaserCommand.CHECKSUM);
return new WorkflowImpl(context, singletonList( return new WorkflowImpl(context, singletonList(
new ChecksumWorkflowItem() new ChecksumWorkflowItem()
)); ));
} }
public static Workflow sign(JReleaserContext context) { public static Workflow sign(JReleaserContext context) {
context.setCommand(JReleaserCommand.SIGN);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
new SignWorkflowItem() new SignWorkflowItem()
@@ -53,6 +58,7 @@ public class Workflows {
} }
public static Workflow upload(JReleaserContext context) { public static Workflow upload(JReleaserContext context) {
context.setCommand(JReleaserCommand.UPLOAD);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
new SignWorkflowItem(), new SignWorkflowItem(),
@@ -61,6 +67,7 @@ public class Workflows {
} }
public static Workflow release(JReleaserContext context) { public static Workflow release(JReleaserContext context) {
context.setCommand(JReleaserCommand.RELEASE);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChangelogWorkflowItem(), new ChangelogWorkflowItem(),
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
@@ -71,6 +78,7 @@ public class Workflows {
} }
public static Workflow prepare(JReleaserContext context) { public static Workflow prepare(JReleaserContext context) {
context.setCommand(JReleaserCommand.PREPARE);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
new PrepareWorkflowItem() new PrepareWorkflowItem()
@@ -78,6 +86,7 @@ public class Workflows {
} }
public static Workflow packageRelease(JReleaserContext context) { public static Workflow packageRelease(JReleaserContext context) {
context.setCommand(JReleaserCommand.PACKAGE);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
new PrepareWorkflowItem(), new PrepareWorkflowItem(),
@@ -86,6 +95,7 @@ public class Workflows {
} }
public static Workflow publish(JReleaserContext context) { public static Workflow publish(JReleaserContext context) {
context.setCommand(JReleaserCommand.PUBLISH);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),
new PrepareWorkflowItem(), new PrepareWorkflowItem(),
@@ -95,6 +105,7 @@ public class Workflows {
} }
public static Workflow announce(JReleaserContext context) { public static Workflow announce(JReleaserContext context) {
context.setCommand(JReleaserCommand.ANNOUNCE);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChangelogWorkflowItem(), new ChangelogWorkflowItem(),
new AnnounceWorkflowItem() new AnnounceWorkflowItem()
@@ -102,6 +113,7 @@ public class Workflows {
} }
public static Workflow fullRelease(JReleaserContext context) { public static Workflow fullRelease(JReleaserContext context) {
context.setCommand(JReleaserCommand.FULL_RELEASE);
return new WorkflowImpl(context, asList( return new WorkflowImpl(context, asList(
new ChangelogWorkflowItem(), new ChangelogWorkflowItem(),
new ChecksumWorkflowItem(), new ChecksumWorkflowItem(),

View File

@@ -19,6 +19,7 @@ package org.jreleaser.sdk.sdkman;
import org.jreleaser.model.Artifact; import org.jreleaser.model.Artifact;
import org.jreleaser.model.Distribution; import org.jreleaser.model.Distribution;
import org.jreleaser.model.JReleaserCommand;
import org.jreleaser.model.JReleaserContext; import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.Sdkman; import org.jreleaser.model.Sdkman;
import org.jreleaser.model.announcer.spi.AnnounceException; import org.jreleaser.model.announcer.spi.AnnounceException;
@@ -59,15 +60,19 @@ public class SdkmanAnnouncer implements Announcer {
public void announce() throws AnnounceException { public void announce() throws AnnounceException {
Map<String, Distribution> distributions = context.getModel().getActiveDistributions().stream() Map<String, Distribution> distributions = context.getModel().getActiveDistributions().stream()
.filter(d -> d.getSdkman().isEnabled()) .filter(d -> d.getSdkman().isEnabled())
.filter(d -> d.getSdkman().isPublished()) .filter(d -> !JReleaserCommand.supportsPublish(context.getCommand()) || d.getSdkman().isPublished())
.collect(Collectors.toMap(distribution -> { .collect(Collectors.toMap(distribution -> {
Sdkman sdkman = distribution.getSdkman(); Sdkman sdkman = distribution.getSdkman();
return isNotBlank(sdkman.getCandidate()) ? sdkman.getCandidate().trim() : context.getModel().getProject().getName(); return isNotBlank(sdkman.getCandidate()) ? sdkman.getCandidate().trim() : context.getModel().getProject().getName();
}, distribution -> distribution)); }, distribution -> distribution));
Boolean set = (Boolean) context.getModel().getAnnounce().getSdkman().getExtraProperties().remove(MAGIC_SET); Boolean set = (Boolean) context.getModel().getAnnounce().getSdkman().getExtraProperties().remove(MAGIC_SET);
if (distributions.isEmpty() && (set != null && !set)) { if (distributions.isEmpty()) {
announceProject(); if (set == null || !set) {
announceProject();
} else {
context.getLogger().debug("disabled. Skipping");
}
return; return;
} }