All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jreleaser.model.internal.packagers.GofishPackager Maven / Gradle / Ivy

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.JAVA_BINARY;
import static org.jreleaser.model.Distribution.DistributionType.JLINK;
import static org.jreleaser.model.api.packagers.GofishPackager.SKIP_GOFISH;
import static org.jreleaser.model.api.packagers.GofishPackager.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 0.10.0
 */
public final class GofishPackager extends AbstractRepositoryPackager {
    private static final Map> SUPPORTED = new LinkedHashMap<>();
    private static final long serialVersionUID = -4053286282850852250L;

    static {
        Set extensions = setOf(
            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);
    }

    private final GofishRepository repository = new GofishRepository();

    @JsonIgnore
    private final org.jreleaser.model.api.packagers.GofishPackager immutable = new org.jreleaser.model.api.packagers.GofishPackager() {
        private static final long serialVersionUID = 7575986906210858224L;

        @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 GofishPackager.this.getCommitAuthor().asImmutable();
        }

        @Override
        public String getTemplateDirectory() {
            return GofishPackager.this.getTemplateDirectory();
        }

        @Override
        public List getSkipTemplates() {
            return unmodifiableList(GofishPackager.this.getSkipTemplates());
        }

        @Override
        public String getType() {
            return GofishPackager.this.getType();
        }

        @Override
        public String getDownloadUrl() {
            return GofishPackager.this.getDownloadUrl();
        }

        @Override
        public boolean supportsPlatform(String platform) {
            return GofishPackager.this.supportsPlatform(platform);
        }

        @Override
        public boolean supportsDistribution(Distribution.DistributionType distributionType) {
            return GofishPackager.this.supportsDistribution(distributionType);
        }

        @Override
        public Set getSupportedFileExtensions(Distribution.DistributionType distributionType) {
            return GofishPackager.this.getSupportedFileExtensions(distributionType);
        }

        @Override
        public Set getSupportedStereotypes() {
            return GofishPackager.this.getSupportedStereotypes();
        }

        @Override
        public boolean isSnapshotSupported() {
            return GofishPackager.this.isSnapshotSupported();
        }

        @Override
        public boolean isContinueOnError() {
            return GofishPackager.this.isContinueOnError();
        }

        @Override
        public Active getActive() {
            return GofishPackager.this.getActive();
        }

        @Override
        public boolean isEnabled() {
            return GofishPackager.this.isEnabled();
        }

        @Override
        public Map asMap(boolean full) {
            return unmodifiableMap(GofishPackager.this.asMap(full));
        }

        @Override
        public String getPrefix() {
            return GofishPackager.this.prefix();
        }

        @Override
        public Map getExtraProperties() {
            return unmodifiableMap(GofishPackager.this.getExtraProperties());
        }
    };

    public GofishPackager() {
        super(TYPE);
    }

    @Override
    public org.jreleaser.model.api.packagers.GofishPackager asImmutable() {
        return immutable;
    }

    @Override
    public void merge(GofishPackager source) {
        super.merge(source);
        setRepository(source.repository);
    }

    public GofishRepository getRepository() {
        return repository;
    }

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

    @Override
    protected void asMap(boolean full, Map props) {
        super.asMap(full, props);
        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.isWindows(platform) ||
            PlatformUtils.isLinux(platform) && !PlatformUtils.isAlpineLinux(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_GOFISH));
    }

    public static final class GofishRepository extends PackagerRepository {
        private static final long serialVersionUID = 2534363121328369670L;

        public GofishRepository() {
            super("gofish", "fish-food");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy