org.jreleaser.model.internal.JReleaserModel 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;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.mustachejava.TemplateFunction;
import org.jreleaser.bundle.RB;
import org.jreleaser.model.Constants;
import org.jreleaser.model.JReleaserException;
import org.jreleaser.model.JReleaserVersion;
import org.jreleaser.model.internal.announce.Announce;
import org.jreleaser.model.internal.assemble.Assemble;
import org.jreleaser.model.internal.catalog.Catalog;
import org.jreleaser.model.internal.checksum.Checksum;
import org.jreleaser.model.internal.deploy.Deploy;
import org.jreleaser.model.internal.distributions.Distribution;
import org.jreleaser.model.internal.download.Download;
import org.jreleaser.model.internal.environment.Environment;
import org.jreleaser.model.internal.extensions.Extension;
import org.jreleaser.model.internal.files.Files;
import org.jreleaser.model.internal.hooks.Hooks;
import org.jreleaser.model.internal.packagers.Packagers;
import org.jreleaser.model.internal.platform.Platform;
import org.jreleaser.model.internal.project.Project;
import org.jreleaser.model.internal.release.BaseReleaser;
import org.jreleaser.model.internal.release.Release;
import org.jreleaser.model.internal.signing.Signing;
import org.jreleaser.model.internal.upload.Upload;
import org.jreleaser.mustache.MustacheUtils;
import org.jreleaser.mustache.TemplateContext;
import org.jreleaser.util.PlatformUtils;
import org.jreleaser.version.SemanticVersion;
import java.time.ZonedDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.jreleaser.mustache.MustacheUtils.applyTemplates;
import static org.jreleaser.util.StringUtils.getCapitalizedName;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isNotBlank;
import static org.jreleaser.util.TimeUtils.TIMESTAMP_FORMATTER;
/**
* @author Andres Almiray
* @since 0.1.0
*/
@org.jreleaser.infra.nativeimage.annotations.NativeImage
public class JReleaserModel {
private final Environment environment = new Environment();
private final Hooks hooks = new Hooks();
private final Project project = new Project();
private final Platform platform = new Platform();
private final Release release = new Release();
private final Packagers packagers = new Packagers();
private final Announce announce = new Announce();
private final Download download = new Download();
private final Assemble assemble = new Assemble();
private final Deploy deploy = new Deploy();
private final Upload upload = new Upload();
private final Checksum checksum = new Checksum();
private final Signing signing = new Signing();
private final Files files = new Files();
private final Catalog catalog = new Catalog();
private final Map distributions = new LinkedHashMap<>();
private final Map extensions = new LinkedHashMap<>();
@JsonIgnore
private final ZonedDateTime now;
@JsonIgnore
private final String timestamp;
@JsonIgnore
private org.jreleaser.model.api.JReleaserModel.Commit commit;
@JsonIgnore
private final org.jreleaser.model.api.JReleaserModel immutable = new org.jreleaser.model.api.JReleaserModel() {
private static final long serialVersionUID = -571955827712138358L;
private Map distributions;
private Map extensions;
@Override
public ZonedDateTime getNow() {
return now;
}
@Override
public String getTimestamp() {
return timestamp;
}
@Override
public Commit getCommit() {
return commit;
}
@Override
public org.jreleaser.model.api.environment.Environment getEnvironment() {
return environment.asImmutable();
}
@Override
public org.jreleaser.model.api.hooks.Hooks getHooks() {
return hooks.asImmutable();
}
@Override
public org.jreleaser.model.api.platform.Platform getPlatform() {
return platform.asImmutable();
}
@Override
public org.jreleaser.model.api.project.Project getProject() {
return project.asImmutable();
}
@Override
public org.jreleaser.model.api.release.Release getRelease() {
return release.asImmutable();
}
@Override
public org.jreleaser.model.api.packagers.Packagers getPackagers() {
return packagers.asImmutable();
}
@Override
public org.jreleaser.model.api.announce.Announce getAnnounce() {
return announce.asImmutable();
}
@Override
public org.jreleaser.model.api.assemble.Assemble getAssemble() {
return assemble.asImmutable();
}
@Override
public org.jreleaser.model.api.download.Download getDownload() {
return download.asImmutable();
}
@Override
public org.jreleaser.model.api.deploy.Deploy getDeploy() {
return deploy.asImmutable();
}
@Override
public org.jreleaser.model.api.upload.Upload getUpload() {
return upload.asImmutable();
}
@Override
public org.jreleaser.model.api.checksum.Checksum getChecksum() {
return checksum.asImmutable();
}
@Override
public org.jreleaser.model.api.signing.Signing getSigning() {
return signing.asImmutable();
}
@Override
public org.jreleaser.model.api.files.Files getFiles() {
return files.asImmutable();
}
@Override
public org.jreleaser.model.api.catalog.Catalog getCatalog() {
return catalog.asImmutable();
}
@Override
public Map getDistributions() {
if (null == distributions) {
distributions = JReleaserModel.this.distributions.values().stream()
.map(Distribution::asImmutable)
.collect(toMap(org.jreleaser.model.api.distributions.Distribution::getName, identity()));
}
return distributions;
}
@Override
public Map getExtensions() {
if (null == extensions) {
extensions = JReleaserModel.this.extensions.values().stream()
.map(Extension::asImmutable)
.collect(toMap(org.jreleaser.model.api.extensions.Extension::getName, identity()));
}
return extensions;
}
@Override
public Map asMap(boolean full) {
return unmodifiableMap(JReleaserModel.this.asMap(full));
}
};
public JReleaserModel() {
this.now = ZonedDateTime.now();
this.timestamp = now.format(TIMESTAMP_FORMATTER);
}
public org.jreleaser.model.api.JReleaserModel asImmutable() {
return immutable;
}
public ZonedDateTime getNow() {
return now;
}
public String getTimestamp() {
return timestamp;
}
public org.jreleaser.model.api.JReleaserModel.Commit getCommit() {
return commit;
}
public void setCommit(org.jreleaser.model.api.JReleaserModel.Commit commit) {
this.commit = commit;
}
public Environment getEnvironment() {
return environment;
}
public void setEnvironment(Environment environment) {
this.environment.merge(environment);
}
public Hooks getHooks() {
return hooks;
}
public void setHooks(Hooks hooks) {
this.hooks.merge(hooks);
}
public Platform getPlatform() {
return platform;
}
public void setPlatform(Platform platform) {
this.platform.merge(platform);
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project.merge(project);
}
public Release getRelease() {
return release;
}
public void setRelease(Release release) {
this.release.merge(release);
}
public Packagers getPackagers() {
return packagers;
}
public void setPackagers(Packagers packagers) {
this.packagers.merge(packagers);
}
public Announce getAnnounce() {
return announce;
}
public void setAnnounce(Announce announce) {
this.announce.merge(announce);
}
public Assemble getAssemble() {
return assemble;
}
public void setAssemble(Assemble assemble) {
this.assemble.merge(assemble);
}
public Download getDownload() {
return download;
}
public void setDownload(Download download) {
this.download.merge(download);
}
public Deploy getDeploy() {
return deploy;
}
public void setDeploy(Deploy deploy) {
this.deploy.merge(deploy);
}
public Upload getUpload() {
return upload;
}
public void setUpload(Upload upload) {
this.upload.merge(upload);
}
public Checksum getChecksum() {
return checksum;
}
public void setChecksum(Checksum checksum) {
this.checksum.merge(checksum);
}
public Signing getSigning() {
return signing;
}
public void setSigning(Signing signing) {
this.signing.merge(signing);
}
public Files getFiles() {
return files;
}
public void setFiles(Files files) {
this.files.merge(files);
}
public Catalog getCatalog() {
return catalog;
}
public void setCatalog(Catalog catalog) {
this.catalog.merge(catalog);
}
public List getActiveDistributions() {
return distributions.values().stream()
.filter(Distribution::isEnabled)
.collect(toList());
}
public Map getDistributions() {
return distributions;
}
public void setDistributions(Map distributions) {
this.distributions.clear();
this.distributions.putAll(distributions);
}
public void addDistribution(Distribution distribution) {
this.distributions.put(distribution.getName(), distribution);
}
public Distribution findDistribution(String name) {
if (isBlank(name)) {
throw new JReleaserException(RB.$("ERROR_distribution_name_is_blank"));
}
if (distributions.containsKey(name)) {
return distributions.get(name);
}
throw new JReleaserException(RB.$("ERROR_distribution_not_found", name));
}
public List getActiveExtensions() {
return extensions.values().stream()
.filter(Extension::isEnabled)
.collect(toList());
}
public Map getExtensions() {
return extensions;
}
public void setExtensions(Map extensions) {
this.extensions.clear();
this.extensions.putAll(extensions);
}
public void addExtension(Extension extension) {
this.extensions.put(extension.getName(), extension);
}
public ZonedDateTime resolveArchiveTimestamp() {
if (null != commit) return commit.getTimestamp();
return now;
}
public Map asMap(boolean full) {
Map map = new LinkedHashMap<>();
List