org.jreleaser.model.internal.packagers.AsdfPackager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jreleaser-model-impl Show documentation
Show all versions of jreleaser-model-impl Show documentation
JReleaser Model implementation
The newest version!
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2024 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.internal.packagers;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.jreleaser.model.Active;
import org.jreleaser.model.Distribution;
import org.jreleaser.model.Stereotype;
import org.jreleaser.model.internal.common.Artifact;
import org.jreleaser.util.PlatformUtils;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;
import static org.jreleaser.model.Distribution.DistributionType.BINARY;
import static org.jreleaser.model.Distribution.DistributionType.FLAT_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.model.api.packagers.AsdfPackager.SKIP_ASDF;
import static org.jreleaser.model.api.packagers.AsdfPackager.TYPE;
import static org.jreleaser.util.CollectionUtils.setOf;
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 final class AsdfPackager extends AbstractRepositoryPackager {
private static final Map> SUPPORTED = new LinkedHashMap<>();
private static final long serialVersionUID = 2289622050226719068L;
static {
Set extensions = setOf(
TAR_GZ.extension(),
TAR_XZ.extension(),
TGZ.extension(),
TXZ.extension(),
TAR.extension(),
ZIP.extension());
SUPPORTED.put(NATIVE_IMAGE, extensions);
SUPPORTED.put(BINARY, extensions);
SUPPORTED.put(JAVA_BINARY, extensions);
SUPPORTED.put(JLINK, extensions);
SUPPORTED.put(FLAT_BINARY, emptySet());
}
private final AsdfRepository repository = new AsdfRepository();
private String toolCheck;
@JsonIgnore
private final org.jreleaser.model.api.packagers.AsdfPackager immutable = new org.jreleaser.model.api.packagers.AsdfPackager() {
private static final long serialVersionUID = 2602907890530867272L;
@Override
public String getToolCheck() {
return toolCheck;
}
@Override
public org.jreleaser.model.api.packagers.PackagerRepository getRepository() {
return repository.asImmutable();
}
@Override
public org.jreleaser.model.api.packagers.PackagerRepository getPackagerRepository() {
return getRepository();
}
@Override
public org.jreleaser.model.api.common.CommitAuthor getCommitAuthor() {
return AsdfPackager.this.getCommitAuthor().asImmutable();
}
@Override
public String getTemplateDirectory() {
return AsdfPackager.this.getTemplateDirectory();
}
@Override
public List getSkipTemplates() {
return unmodifiableList(AsdfPackager.this.getSkipTemplates());
}
@Override
public String getType() {
return AsdfPackager.this.getType();
}
@Override
public String getDownloadUrl() {
return AsdfPackager.this.getDownloadUrl();
}
@Override
public boolean supportsPlatform(String platform) {
return AsdfPackager.this.supportsPlatform(platform);
}
@Override
public boolean supportsDistribution(Distribution.DistributionType distributionType) {
return AsdfPackager.this.supportsDistribution(distributionType);
}
@Override
public Set getSupportedFileExtensions(Distribution.DistributionType distributionType) {
return AsdfPackager.this.getSupportedFileExtensions(distributionType);
}
@Override
public Set getSupportedStereotypes() {
return AsdfPackager.this.getSupportedStereotypes();
}
@Override
public boolean isSnapshotSupported() {
return AsdfPackager.this.isSnapshotSupported();
}
@Override
public boolean isContinueOnError() {
return AsdfPackager.this.isContinueOnError();
}
@Override
public Active getActive() {
return AsdfPackager.this.getActive();
}
@Override
public boolean isEnabled() {
return AsdfPackager.this.isEnabled();
}
@Override
public Map asMap(boolean full) {
return unmodifiableMap(AsdfPackager.this.asMap(full));
}
@Override
public String getPrefix() {
return AsdfPackager.this.prefix();
}
@Override
public Map getExtraProperties() {
return unmodifiableMap(AsdfPackager.this.getExtraProperties());
}
};
public AsdfPackager() {
super(TYPE);
}
@Override
public org.jreleaser.model.api.packagers.AsdfPackager asImmutable() {
return immutable;
}
@Override
public void merge(AsdfPackager source) {
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 props) {
super.asMap(full, props);
props.put("toolcheck", toolCheck);
props.put("repository", repository.asMap(full));
}
@Override
public RepositoryTap getRepositoryTap() {
return getPackagerRepository();
}
public PackagerRepository getPackagerRepository() {
return getRepository();
}
@Override
public boolean supportsPlatform(String platform) {
return isBlank(platform) ||
PlatformUtils.isMac(platform) ||
PlatformUtils.isLinux(platform);
}
@Override
public boolean supportsDistribution(org.jreleaser.model.Distribution.DistributionType distributionType) {
return SUPPORTED.containsKey(distributionType);
}
@Override
public Set getSupportedFileExtensions(org.jreleaser.model.Distribution.DistributionType distributionType) {
return unmodifiableSet(SUPPORTED.getOrDefault(distributionType, emptySet()));
}
@Override
protected boolean isNotSkipped(Artifact artifact) {
return isFalse(artifact.getExtraProperties().get(SKIP_ASDF));
}
public static final class AsdfRepository extends PackagerRepository {
private static final long serialVersionUID = -3477982615763115685L;
public AsdfRepository() {
super("asdf", "asdf");
}
}
}