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

org.jreleaser.model.internal.common.JvmOptions 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.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.jreleaser.model.internal.JReleaserContext;
import org.jreleaser.mustache.TemplateContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.lang.System.lineSeparator;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.stream.Collectors.toList;
import static org.jreleaser.mustache.Templates.resolveTemplate;

/**
 * @author Andres Almiray
 * @since 0.13.0
 */
public final class JvmOptions extends AbstractModelObject implements Domain {
    //private static final long serialVersionUID = 4713757280623221679L;

    private final List universal = new ArrayList<>();
    private final List unix = new ArrayList<>();
    private final List linux = new ArrayList<>();
    private final List osx = new ArrayList<>();
    private final List windows = new ArrayList<>();

    @JsonIgnore
    private final org.jreleaser.model.api.common.JvmOptions immutable = new org.jreleaser.model.api.common.JvmOptions() {
        private static final long serialVersionUID = -7553541254718019915L;

        @Override
        public List getUniversal() {
            return unmodifiableList(universal);
        }

        @Override
        public List getUnix() {
            return unmodifiableList(unix);
        }

        @Override
        public List getLinux() {
            return unmodifiableList(linux);
        }

        @Override
        public List getOsx() {
            return unmodifiableList(osx);
        }

        @Override
        public List getWindows() {
            return unmodifiableList(windows);
        }

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

    public org.jreleaser.model.api.common.JvmOptions asImmutable() {
        return immutable;
    }

    @Override
    public void merge(JvmOptions source) {
        setUniversal(merge(this.universal, source.universal));
        setUnix(merge(this.unix, source.unix));
        setLinux(merge(this.linux, source.linux));
        setOsx(merge(this.osx, source.osx));
        setWindows(merge(this.windows, source.windows));
    }

    public void merge(Set source) {
        this.universal.addAll(source);
    }

    public List getUniversal() {
        return universal;
    }

    public void setUniversal(List universal) {
        this.universal.clear();
        this.universal.addAll(universal);
    }

    public List getUnix() {
        return unix;
    }

    public void setUnix(List unix) {
        this.unix.clear();
        this.unix.addAll(unix);
    }

    public List getLinux() {
        return linux;
    }

    public void setLinux(List linux) {
        this.linux.clear();
        this.linux.addAll(linux);
    }

    public List getOsx() {
        return osx;
    }

    public void setOsx(List osx) {
        this.osx.clear();
        this.osx.addAll(osx);
    }

    public List getWindows() {
        return windows;
    }

    public void setWindows(List windows) {
        this.windows.clear();
        this.windows.addAll(windows);
    }

    public boolean isSet() {
        return
            !universal.isEmpty() ||
                !unix.isEmpty() ||
                !linux.isEmpty() ||
                !osx.isEmpty() ||
                !windows.isEmpty();
    }

    public List getResolvedUniversal(JReleaserContext context) {
        TemplateContext props = context.fullProps();

        return universal.stream()
            .map(option -> resolveTemplate(option, props))
            .map(option -> option.replace(lineSeparator(), ""))
            .collect(toList());
    }

    public List getResolvedUnix(JReleaserContext context) {
        TemplateContext props = context.fullProps();

        return unix.stream()
            .map(option -> resolveTemplate(option, props))
            .collect(toList());
    }

    public List getResolvedLinux(JReleaserContext context) {
        TemplateContext props = context.fullProps();

        return linux.stream()
            .map(option -> resolveTemplate(option, props))
            .collect(toList());
    }

    public List getResolvedOsx(JReleaserContext context) {
        TemplateContext props = context.fullProps();

        return osx.stream()
            .map(option -> resolveTemplate(option, props))
            .collect(toList());
    }

    public List getResolvedWindows(JReleaserContext context) {
        TemplateContext props = context.fullProps();

        return windows.stream()
            .map(option -> resolveTemplate(option, props))
            .collect(toList());
    }

    @Override
    public Map asMap(boolean full) {
        Map map = new LinkedHashMap<>();
        map.put("universal", universal);
        map.put("unix", unix);
        map.put("linux", linux);
        map.put("osx", osx);
        map.put("windows", windows);
        return map;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy