Skip to content

Commit

Permalink
feat(core): Support asdf-vm as packager. Resolves #825
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 26, 2022
1 parent 5ad20a5 commit 1d37aa4
Show file tree
Hide file tree
Showing 41 changed files with 1,500 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ tmp/
.DS_Store
.tmp
# Eclipse
bin
*/bin
!core/jreleaser-templates/src/main/resources/META-INF/jreleaser/templates/**/bin
.classpath
.project
.settings
137 changes: 137 additions & 0 deletions core/jreleaser-model/src/main/java/org/jreleaser/model/Asdf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 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;

import org.jreleaser.util.PlatformUtils;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import static org.jreleaser.model.Distribution.DistributionType.BINARY;
import static org.jreleaser.model.Distribution.DistributionType.JAVA_BINARY;
import static org.jreleaser.model.Distribution.DistributionType.JLINK;
import static org.jreleaser.model.Distribution.DistributionType.NATIVE_IMAGE;
import static org.jreleaser.util.CollectionUtils.newSet;
import static org.jreleaser.util.FileType.TAR;
import static org.jreleaser.util.FileType.TAR_GZ;
import static org.jreleaser.util.FileType.TAR_XZ;
import static org.jreleaser.util.FileType.TGZ;
import static org.jreleaser.util.FileType.TXZ;
import static org.jreleaser.util.FileType.ZIP;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isFalse;

/**
* @author Andres Almiray
* @since 1.2.0
*/
public class Asdf extends AbstractRepositoryPackager<Asdf> {
public static final String TYPE = "asdf";
public static final String SKIP_ASDF = "skipAsdf";

private static final Map<Distribution.DistributionType, Set<String>> SUPPORTED = new LinkedHashMap<>();

static {
Set<String> extensions = newSet(
TAR_GZ.extension(),
TAR_XZ.extension(),
TGZ.extension(),
TXZ.extension(),
TAR.extension(),
ZIP.extension());

SUPPORTED.put(BINARY, extensions);
SUPPORTED.put(JAVA_BINARY, extensions);
SUPPORTED.put(JLINK, extensions);
SUPPORTED.put(NATIVE_IMAGE, extensions);
}

private final AsdfRepository repository = new AsdfRepository();

private String toolCheck;

public Asdf() {
super(TYPE);
}

@Override
public void merge(Asdf source) {
freezeCheck();
super.merge(source);
this.toolCheck = merge(this.toolCheck, source.toolCheck);
setRepository(source.repository);
}

public String getToolCheck() {
return toolCheck;
}

public void setToolCheck(String toolCheck) {
this.toolCheck = toolCheck;
}

public AsdfRepository getRepository() {
return repository;
}

public void setRepository(AsdfRepository repository) {
this.repository.merge(repository);
}

@Override
protected void asMap(boolean full, Map<String, Object> props) {
super.asMap(full, props);
props.put("toolcheck", toolCheck);
props.put("repository", repository.asMap(full));
}

@Override
public RepositoryTap getRepositoryTap() {
return repository;
}

@Override
public boolean supportsPlatform(String platform) {
return isBlank(platform) ||
PlatformUtils.isMac(platform) ||
PlatformUtils.isLinux(platform);
}

@Override
public boolean supportsDistribution(Distribution distribution) {
return SUPPORTED.containsKey(distribution.getType());
}

@Override
public Set<String> getSupportedExtensions(Distribution distribution) {
return Collections.unmodifiableSet(SUPPORTED.getOrDefault(distribution.getType(), Collections.emptySet()));
}

@Override
protected boolean isNotSkipped(Artifact artifact) {
return isFalse(artifact.getExtraProperties().get(SKIP_ASDF));
}

public static class AsdfRepository extends AbstractRepositoryTap<AsdfRepository> {
public AsdfRepository() {
super("asdf", "asdf");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ public <T extends Packager> T getPackager(String name) {

private <T extends Packager> T resolvePackager(String name) {
switch (name.toLowerCase().trim()) {
case Asdf.TYPE:
return (T) getAsdf();
case Brew.TYPE:
return (T) getBrew();
case Chocolatey.TYPE:
Expand Down Expand Up @@ -377,6 +379,7 @@ public Map<String, Object> asMap(boolean full) {

public static Set<String> supportedPackagers() {
Set<String> set = new LinkedHashSet<>();
set.add(Asdf.TYPE);
set.add(Brew.TYPE);
set.add(Chocolatey.TYPE);
set.add(Docker.TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 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;

import static java.util.Objects.requireNonNull;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.requireNonBlank;

/**
* @author Andres Almiray
* @since 1.1.0
*/
public class ExecutionEvent {
private final Type type;
private final String name;

private ExecutionEvent(Type type, String name) {
this.type = requireNonNull(type, "'type' must not be null");
this.name = requireNonBlank(name, "'name' must not be blank");
}

public Type getType() {
return type;
}

public String getName() {
return name;
}

public static ExecutionEvent before(String name) {
return new ExecutionEvent(Type.BEFORE, name);
}

public static ExecutionEvent after(String name) {
return new ExecutionEvent(Type.AFTER, name);
}

public enum Type {
BEFORE,
AFTER;

@Override
public String toString() {
return name().toLowerCase();
}

public static Type of(String str) {
if (isBlank(str)) return null;
return Type.valueOf(str.replaceAll(" ", "_")
.replaceAll("-", "_")
.toUpperCase().trim());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 0.1.0
*/
public class Packagers<S extends Packagers<S>> extends AbstractModelObject<S> implements Domain {
protected final Asdf asdf = new Asdf();
protected final Brew brew = new Brew();
protected final Chocolatey chocolatey = new Chocolatey();
protected final Docker docker = new Docker();
Expand All @@ -37,7 +38,8 @@ public class Packagers<S extends Packagers<S>> extends AbstractModelObject<S> im
protected final Spec spec = new Spec();

public boolean hasEnabledPackagers() {
return brew.isEnabled() ||
return asdf.isEnabled() ||
brew.isEnabled() ||
chocolatey.isEnabled() ||
docker.isEnabled() ||
gofish.isEnabled() ||
Expand All @@ -52,6 +54,7 @@ public boolean hasEnabledPackagers() {
@Override
public void freeze() {
super.freeze();
asdf.freeze();
brew.freeze();
chocolatey.freeze();
docker.freeze();
Expand All @@ -67,6 +70,7 @@ public void freeze() {
@Override
public void merge(S packagers) {
freezeCheck();
setAsdf(packagers.asdf);
setBrew(packagers.brew);
setChocolatey(packagers.chocolatey);
setDocker(packagers.docker);
Expand All @@ -79,6 +83,14 @@ public void merge(S packagers) {
setSpec(packagers.spec);
}

public Asdf getAsdf() {
return asdf;
}

public void setAsdf(Asdf asdf) {
this.asdf.merge(asdf);
}

public Brew getBrew() {
return brew;
}
Expand Down Expand Up @@ -162,6 +174,7 @@ public void setSpec(Spec spec) {
@Override
public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
map.putAll(asdf.asMap(full));
map.putAll(brew.asMap(full));
map.putAll(chocolatey.asMap(full));
map.putAll(docker.asMap(full));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 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.validation;

import org.jreleaser.bundle.RB;
import org.jreleaser.model.Active;
import org.jreleaser.model.Artifact;
import org.jreleaser.model.Asdf;
import org.jreleaser.model.Distribution;
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.util.Errors;

import java.util.List;

import static org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms;
import static org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties;
import static org.jreleaser.model.validation.TemplateValidator.validateTemplate;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isNotBlank;

/**
* @author Andres Almiray
* @since 1.2.0
*/
public abstract class AsdfValidator extends Validator {
public static void validateAsdf(JReleaserContext context, Distribution distribution, Asdf packager, Errors errors) {
JReleaserModel model = context.getModel();
Asdf parentPackager = model.getPackagers().getAsdf();

if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
packager.setActive(parentPackager.getActive());
}
if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) {
packager.disable();
return;
}
GitService service = model.getRelease().getGitService();
if (!service.isReleaseSupported()) {
packager.disable();
return;
}

List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
if (candidateArtifacts.size() == 0) {
packager.setActive(Active.NEVER);
packager.disable();
return;
} else if (candidateArtifacts.stream()
.filter(artifact -> isBlank(artifact.getPlatform()))
.count() > 1) {
errors.configuration(RB.$("validation_packager_multiple_artifacts", "distribution." + distribution.getName() + ".asdf"));
packager.disable();
return;
}

if (isBlank(packager.getToolCheck()) && isNotBlank(parentPackager.getToolCheck())) {
packager.setToolCheck(parentPackager.getToolCheck());
}
if (isBlank(packager.getToolCheck())) {
packager.setToolCheck("{{distributionExecutable}} --version");
}

if (isBlank(packager.getRepository().getName())) {
packager.getRepository().setName("asdf-" + distribution.getName());
}
packager.getRepository().setTapName("asdf-" + distribution.getName());

validateCommitAuthor(packager, parentPackager);
Asdf.AsdfRepository repository = packager.getRepository();
repository.resolveEnabled(model.getProject());
validateTap(context, distribution, repository, parentPackager.getRepository(), "asdf.repository");
validateTemplate(context, distribution, packager, parentPackager, errors);
mergeExtraProperties(packager, parentPackager);
validateContinueOnError(packager, parentPackager);
if (isBlank(packager.getDownloadUrl())) {
packager.setDownloadUrl(parentPackager.getDownloadUrl());
}
validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
}
}

0 comments on commit 1d37aa4

Please sign in to comment.