org.jreleaser.model.internal.deploy.maven.Maven 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.deploy.maven;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.jreleaser.model.Active;
import org.jreleaser.model.internal.common.AbstractActivatable;
import org.jreleaser.model.internal.common.AbstractModelObject;
import org.jreleaser.model.internal.common.Activatable;
import org.jreleaser.model.internal.common.Domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
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;
/**
* @author Andres Almiray
* @since 1.3.0
*/
public final class Maven extends AbstractActivatable implements Domain, Activatable {
private static final long serialVersionUID = 1126431134090848347L;
private final Map artifactory = new LinkedHashMap<>();
private final Map azure = new LinkedHashMap<>();
private final Map gitea = new LinkedHashMap<>();
private final Map github = new LinkedHashMap<>();
private final Map gitlab = new LinkedHashMap<>();
private final Map nexus2 = new LinkedHashMap<>();
private final Map mavenCentral = new LinkedHashMap<>();
private final Pomchecker pomchecker = new Pomchecker();
@JsonIgnore
private final org.jreleaser.model.api.deploy.maven.Maven immutable = new org.jreleaser.model.api.deploy.maven.Maven() {
private static final long serialVersionUID = 6345180810995769120L;
private Map artifactory;
private Map azure;
private Map gitea;
private Map github;
private Map gitlab;
private Map nexus2;
private Map mavenCentral;
@Override
public Map getArtifactory() {
if (null == artifactory) {
artifactory = Maven.this.artifactory.values().stream()
.map(ArtifactoryMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return artifactory;
}
@Override
public Map getAzure() {
if (null == azure) {
azure = Maven.this.azure.values().stream()
.map(AzureMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return azure;
}
@Override
public Map getGitea() {
if (null == gitea) {
gitea = Maven.this.gitea.values().stream()
.map(GiteaMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return gitea;
}
@Override
public Map getGithub() {
if (null == github) {
github = Maven.this.github.values().stream()
.map(GithubMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return github;
}
@Override
public Map getGitlab() {
if (null == gitlab) {
gitlab = Maven.this.gitlab.values().stream()
.map(GitlabMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return gitlab;
}
@Override
public Map getNexus2() {
if (null == nexus2) {
nexus2 = Maven.this.nexus2.values().stream()
.map(Nexus2MavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return nexus2;
}
@Override
public Map getMavenCentral() {
if (null == mavenCentral) {
mavenCentral = Maven.this.mavenCentral.values().stream()
.map(MavenCentralMavenDeployer::asImmutable)
.collect(toMap(org.jreleaser.model.api.deploy.maven.MavenDeployer::getName, identity()));
}
return mavenCentral;
}
@Override
public Pomchecker getPomchecker() {
return pomchecker.asImmutable();
}
@Override
public Active getActive() {
return Maven.this.getActive();
}
@Override
public boolean isEnabled() {
return Maven.this.isEnabled();
}
@Override
public Map asMap(boolean full) {
return unmodifiableMap(Maven.this.asMap(full));
}
};
public Maven() {
enabledSet(true);
}
public org.jreleaser.model.api.deploy.maven.Maven asImmutable() {
return immutable;
}
@Override
public void merge(Maven source) {
super.merge(source);
setArtifactory(mergeModel(this.artifactory, source.artifactory));
setAzure(mergeModel(this.azure, source.azure));
setGitea(mergeModel(this.gitea, source.gitea));
setGithub(mergeModel(this.github, source.github));
setGitlab(mergeModel(this.gitlab, source.gitlab));
setNexus2(mergeModel(this.nexus2, source.nexus2));
setMavenCentral(mergeModel(this.mavenCentral, source.mavenCentral));
setPomchecker(source.pomchecker);
}
@Override
public boolean isSet() {
return super.isSet() ||
!artifactory.isEmpty() ||
!azure.isEmpty() ||
!gitea.isEmpty() ||
!github.isEmpty() ||
!gitlab.isEmpty() ||
!nexus2.isEmpty() ||
!mavenCentral.isEmpty();
}
public Optional getActiveArtifactory(String name) {
return artifactory.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveAzure(String name) {
return azure.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveGitea(String name) {
return gitea.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveGithub(String name) {
return github.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveGitlab(String name) {
return gitlab.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveNexus2(String name) {
return nexus2.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public Optional getActiveMavenCentral(String name) {
return mavenCentral.values().stream()
.filter(MavenDeployer::isEnabled)
.filter(a -> name.equals(a.getName()))
.findFirst();
}
public List getActiveArtifactories() {
return artifactory.values().stream()
.filter(ArtifactoryMavenDeployer::isEnabled)
.collect(toList());
}
public List getActiveAzures() {
return azure.values().stream()
.filter(AzureMavenDeployer::isEnabled)
.collect(toList());
}
public List extends MavenDeployer> getActiveDeployers() {
List list = new ArrayList<>();
list.addAll(getActiveArtifactories());
list.addAll(getActiveAzures());
list.addAll(getActiveGiteas());
list.addAll(getActiveGithubs());
list.addAll(getActiveGitlabs());
list.addAll(getActiveNexus2s());
list.addAll(getActiveMavenCentrals());
return list;
}
public Map getArtifactory() {
return artifactory;
}
public void setArtifactory(Map artifactory) {
this.artifactory.clear();
this.artifactory.putAll(artifactory);
}
public void addArtifactory(ArtifactoryMavenDeployer artifactory) {
this.artifactory.put(artifactory.getName(), artifactory);
}
public Map getAzure() {
return azure;
}
public void setAzure(Map azure) {
this.azure.clear();
this.azure.putAll(azure);
}
public void addAzure(AzureMavenDeployer azure) {
this.azure.put(azure.getName(), azure);
}
public List getActiveGiteas() {
return gitea.values().stream()
.filter(GiteaMavenDeployer::isEnabled)
.collect(toList());
}
public Map getGitea() {
return gitea;
}
public void setGitea(Map gitea) {
this.gitea.clear();
this.gitea.putAll(gitea);
}
public void addGitea(GiteaMavenDeployer gitea) {
this.gitea.put(gitea.getName(), gitea);
}
public List getActiveGithubs() {
return github.values().stream()
.filter(GithubMavenDeployer::isEnabled)
.collect(toList());
}
public Map getGithub() {
return github;
}
public void setGithub(Map github) {
this.github.clear();
this.github.putAll(github);
}
public void addGithub(GithubMavenDeployer github) {
this.github.put(github.getName(), github);
}
public List getActiveGitlabs() {
return gitlab.values().stream()
.filter(GitlabMavenDeployer::isEnabled)
.collect(toList());
}
public Map getGitlab() {
return gitlab;
}
public void setGitlab(Map gitlab) {
this.gitlab.clear();
this.gitlab.putAll(gitlab);
}
public void addGitlab(GitlabMavenDeployer gitlab) {
this.gitlab.put(gitlab.getName(), gitlab);
}
public List getActiveNexus2s() {
return nexus2.values().stream()
.filter(Nexus2MavenDeployer::isEnabled)
.collect(toList());
}
public Map getNexus2() {
return nexus2;
}
public void setNexus2(Map nexus2) {
this.nexus2.clear();
this.nexus2.putAll(nexus2);
}
public void addNexus2(Nexus2MavenDeployer nexus2) {
this.nexus2.put(nexus2.getName(), nexus2);
}
public List getActiveMavenCentrals() {
return mavenCentral.values().stream()
.filter(MavenCentralMavenDeployer::isEnabled)
.collect(toList());
}
public Map getMavenCentral() {
return mavenCentral;
}
public void setMavenCentral(Map mavenCentral) {
this.mavenCentral.clear();
this.mavenCentral.putAll(mavenCentral);
}
public void addMavenCentral(MavenCentralMavenDeployer mavenCentral) {
this.mavenCentral.put(mavenCentral.getName(), mavenCentral);
}
public Pomchecker getPomchecker() {
return pomchecker;
}
public void setPomchecker(Pomchecker pomchecker) {
this.pomchecker.merge(pomchecker);
}
@Override
public Map asMap(boolean full) {
Map map = new LinkedHashMap<>();
map.put("enabled", isEnabled());
map.put("active", getActive());
map.put("pomchecker", pomchecker.asMap(full));
List