Skip to content

Commit

Permalink
[model] allow partial execution bases on selected platform. Resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 21, 2021
1 parent 403d990 commit 6f67c10
Show file tree
Hide file tree
Showing 70 changed files with 532 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
Expand Down Expand Up @@ -129,7 +131,8 @@ protected JReleaserContext createContext() {
actualBasedir,
getOutputDirectory(),
dryrun(),
gitRootSearch);
gitRootSearch,
collectSelectedPlatforms());
}

protected Path getOutputDirectory() {
Expand All @@ -156,4 +159,8 @@ private Set<String> getSupportedConfigFormats() {
protected JReleaserContext.Mode getMode() {
return JReleaserContext.Mode.FULL;
}

protected List<String> collectSelectedPlatforms() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.cli;

import org.jreleaser.util.PlatformUtils;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Andres Almiray
* @since 0.6.0
*/
@CommandLine.Command
public abstract class AbstractPlatformAwareModelCommand extends AbstractModelCommand {
@CommandLine.Option(names = {"--select-current-platform"},
description = "Activates paths matching the current platform.")
boolean selectCurrentPlatform;

@CommandLine.Option(names = {"--select-platform"},
description = "Activates paths matching the given platform.")
String[] selectPlatforms;

@Override
protected List<String> collectSelectedPlatforms() {
if (selectCurrentPlatform) return Collections.singletonList(PlatformUtils.getCurrentFull());

List<String> list = new ArrayList<>();
if (selectPlatforms != null && selectPlatforms.length > 0) {
Collections.addAll(list, selectPlatforms);
}
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "announce",
mixinStandardHelpOptions = true,
description = "Announce a release.")
public class Announce extends AbstractModelCommand {
public class Announce extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "checksum",
mixinStandardHelpOptions = true,
description = "Calculate checksums.")
public class Checksum extends AbstractModelCommand {
public class Checksum extends AbstractPlatformAwareModelCommand {
@Override
protected void doExecute(JReleaserContext context) {
Workflows.checksum(context).execute();
Expand Down
2 changes: 1 addition & 1 deletion apps/jreleaser/src/main/java/org/jreleaser/cli/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "config",
mixinStandardHelpOptions = true,
description = "Display current configuration.")
public class Config extends AbstractModelCommand {
public class Config extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-f", "--full"},
description = "Display full configuration.")
boolean full;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "full-release",
mixinStandardHelpOptions = true,
description = "Perform a full release.")
public class FullRelease extends AbstractModelCommand {
public class FullRelease extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "package",
mixinStandardHelpOptions = true,
description = "Package all distributions.")
public class Package extends AbstractModelCommand {
public class Package extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "prepare",
mixinStandardHelpOptions = true,
description = "Prepare all distributions.")
public class Prepare extends AbstractModelCommand {
public class Prepare extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-dn", "--distribution-name"},
description = "The name of the distribution.")
String distributionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "publish",
mixinStandardHelpOptions = true,
description = "Publish all distributions.")
public class Publish extends AbstractModelCommand {
public class Publish extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down
3 changes: 2 additions & 1 deletion apps/jreleaser/src/main/java/org/jreleaser/cli/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@CommandLine.Command(name = "release",
mixinStandardHelpOptions = true,
description = "Create or update a release.")
public class Release extends AbstractModelCommand {
public class Release extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down Expand Up @@ -177,6 +177,7 @@ protected void execute() {
.armored(armored)
.files(collectFiles())
.globs(collectGlobs())
.selectedPlatforms(collectSelectedPlatforms())
.autoConfigure();

doExecute(context);
Expand Down
2 changes: 1 addition & 1 deletion apps/jreleaser/src/main/java/org/jreleaser/cli/Sign.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "sign",
mixinStandardHelpOptions = true,
description = "Sign release artifacts.")
public class Sign extends AbstractModelCommand {
public class Sign extends AbstractPlatformAwareModelCommand {
@Override
protected void doExecute(JReleaserContext context) {
Workflows.sign(context).execute();
Expand Down
2 changes: 1 addition & 1 deletion apps/jreleaser/src/main/java/org/jreleaser/cli/Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@CommandLine.Command(name = "upload",
mixinStandardHelpOptions = true,
description = "Upload all artifacts.")
public class Upload extends AbstractModelCommand {
public class Upload extends AbstractPlatformAwareModelCommand {
@CommandLine.Option(names = {"-y", "--dryrun"},
description = "Skip remote operations.")
boolean dryrun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void collectAndWriteChecksums(JReleaserContext context) throws JRe
Map<Algorithm, List<String>> checksums = new LinkedHashMap<>();

for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (!artifact.isActive()) continue;
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
readHash(context, algorithm, artifact);
List<String> list = checksums.computeIfAbsent(algorithm, k -> new ArrayList<>());
Expand All @@ -57,6 +58,7 @@ public static void collectAndWriteChecksums(JReleaserContext context) throws JRe

for (Distribution distribution : context.getModel().getActiveDistributions()) {
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
readHash(context, distribution, algorithm, artifact);
List<String> list = checksums.computeIfAbsent(algorithm, k -> new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jreleaser.util.Version;

import java.nio.file.Path;
import java.util.List;

/**
* @author Andres Almiray
Expand All @@ -40,14 +41,16 @@ public static JReleaserContext create(JReleaserLogger logger,
Path basedir,
Path outputDirectory,
boolean dryrun,
boolean gitRootSearch) {
boolean gitRootSearch,
List<String> selectedPlatforms) {
return create(logger,
mode,
resolveModel(logger, configFile),
basedir,
outputDirectory,
dryrun,
gitRootSearch);
gitRootSearch,
selectedPlatforms);
}

public static JReleaserContext create(JReleaserLogger logger,
Expand All @@ -56,15 +59,17 @@ public static JReleaserContext create(JReleaserLogger logger,
Path basedir,
Path outputDirectory,
boolean dryrun,
boolean gitRootSearch) {
boolean gitRootSearch,
List<String> selectedPlatforms) {
JReleaserContext context = new JReleaserContext(
logger,
mode,
model,
basedir,
outputDirectory,
dryrun,
gitRootSearch);
gitRootSearch,
selectedPlatforms);

ModelConfigurer.configure(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ModelAutoConfigurer {

private final List<String> files = new ArrayList<>();
private final List<String> globs = new ArrayList<>();
private final List<String> selectedPlatforms = new ArrayList<>();
private final Set<UpdateSection> updateSections = new LinkedHashSet<>();
private JReleaserLogger logger;
private Path basedir;
Expand Down Expand Up @@ -254,6 +255,21 @@ public ModelAutoConfigurer glob(String glob) {
return this;
}

public ModelAutoConfigurer selectedPlatforms(List<String> platforms) {
this.selectedPlatforms.clear();
if (null != platforms && !platforms.isEmpty()) {
platforms.forEach(this::selectedPlatform);
}
return this;
}

public ModelAutoConfigurer selectedPlatform(String platform) {
if (isNotBlank(platform)) {
this.selectedPlatforms.add(platform.trim());
}
return this;
}

public JReleaserContext autoConfigure() {
requireNonNull(logger, "Argument 'logger' ust not be null");
requireNonNull(basedir, "Argument 'basedir' ust not be null");
Expand All @@ -277,7 +293,8 @@ private JReleaserContext createAutoConfiguredContext() {
basedir,
outputDirectory,
dryrun,
gitRootSearch);
gitRootSearch,
selectedPlatforms);
}

private void dumpAutoConfig() {
Expand Down Expand Up @@ -312,6 +329,11 @@ private void dumpAutoConfig() {
logger.info("- glob: {}", glob);
}
}
if (!selectedPlatforms.isEmpty()) {
for (String platform : selectedPlatforms) {
logger.info("- platform: {}", platform);
}
}
}

private JReleaserModel autoConfiguredModel(Path basedir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ private static List<FilePair> collectArtifacts(JReleaserContext context, Keyring
String extension = context.getModel().getSigning().isArmored() ? ".asc" : ".sig";

for (Artifact artifact : Artifacts.resolveFiles(context)) {
if (!artifact.isActive()) continue;
Path input = artifact.getEffectivePath(context);
Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
FilePair pair = new FilePair(input, output);
Expand All @@ -256,6 +257,7 @@ private static List<FilePair> collectArtifacts(JReleaserContext context, Keyring

for (Distribution distribution : context.getModel().getActiveDistributions()) {
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
Path input = artifact.getEffectivePath(context, distribution);
Path output = signaturesDirectory.resolve(input.getFileName().toString().concat(extension));
FilePair pair = new FilePair(input, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,27 @@ public class Artifact implements Domain, ExtraProperties {
private String transform;
private Path resolvedPath;
private Path resolvedTransform;
private boolean active;

void setAll(Artifact artifact) {
this.path = artifact.path;
this.platform = artifact.platform;
this.transform = artifact.transform;
this.resolvedPath = artifact.resolvedPath;
this.resolvedTransform = artifact.resolvedTransform;
this.active = artifact.active;
setExtraProperties(artifact.extraProperties);
setHashes(artifact.hashes);
}

public boolean isActive() {
return active;
}

public void activate() {
this.active = true;
}

public Path getEffectivePath(JReleaserContext context) {
Path rp = getResolvedPath(context);
Path tp = getResolvedTransform(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Artifact getArtifact() {

public void setArtifact(Artifact artifact) {
this.artifact = artifact;
this.artifact.activate();
}

public String getName() {
Expand Down

0 comments on commit 6f67c10

Please sign in to comment.