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

org.apache.maven.model.Model Maven / Gradle / Ivy

The newest version!
// =================== DO NOT EDIT THIS FILE ====================
//  Generated by Modello Velocity from model-v3.vm
//  template, any modifications will be overwritten.
// ==============================================================
package org.apache.maven.model;

import java.io.Serializable;
import java.nio.file.Path;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.annotations.Generated;
import org.apache.maven.api.annotations.Nonnull;
import org.codehaus.plexus.util.xml.Xpp3Dom;

@Generated
public class Model
    extends ModelBase
    implements Serializable, Cloneable
{

    public Model() {
        this(org.apache.maven.api.model.Model.newInstance());
    }

    public Model(org.apache.maven.api.model.Model delegate) {
        this(delegate, null);
    }

    public Model(org.apache.maven.api.model.Model delegate, BaseObject parent) {
        super(delegate, parent);
    }

    public Model clone(){
        return new Model(getDelegate());
    }

    @Override
    public org.apache.maven.api.model.Model getDelegate() {
        return (org.apache.maven.api.model.Model) super.getDelegate();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || !(o instanceof Model)) {
            return false;
        }
        Model that = (Model) o;
        return Objects.equals(this.delegate, that.delegate);
    }

    @Override
    public int hashCode() {
        return getDelegate().hashCode();
    }

    public String getModelEncoding() {
        return getDelegate().getModelEncoding();
    }

    public String getModelVersion() {
        return getDelegate().getModelVersion();
    }

    public void setModelVersion(String modelVersion) {
        if (!Objects.equals(modelVersion, getModelVersion())) {
            update(getDelegate().withModelVersion(modelVersion));
        }
    }

    public Parent getParent() {
        return getDelegate().getParent() != null ? new Parent(getDelegate().getParent(), this) : null;
    }

    public void setParent(Parent parent) {
        if (!Objects.equals(parent, getParent())){
            if (parent != null) {
                update(getDelegate().withParent(parent.getDelegate()));
                parent.childrenTracking = this::replace;
            } else {
                update(getDelegate().withParent(null));
            }
        }
    }

    public String getGroupId() {
        return getDelegate().getGroupId();
    }

    public void setGroupId(String groupId) {
        if (!Objects.equals(groupId, getGroupId())) {
            update(getDelegate().withGroupId(groupId));
        }
    }

    public String getArtifactId() {
        return getDelegate().getArtifactId();
    }

    public void setArtifactId(String artifactId) {
        if (!Objects.equals(artifactId, getArtifactId())) {
            update(getDelegate().withArtifactId(artifactId));
        }
    }

    public String getVersion() {
        return getDelegate().getVersion();
    }

    public void setVersion(String version) {
        if (!Objects.equals(version, getVersion())) {
            update(getDelegate().withVersion(version));
        }
    }

    public String getPackaging() {
        return getDelegate().getPackaging();
    }

    public void setPackaging(String packaging) {
        if (!Objects.equals(packaging, getPackaging())) {
            update(getDelegate().withPackaging(packaging));
        }
    }

    public String getName() {
        return getDelegate().getName();
    }

    public void setName(String name) {
        if (!Objects.equals(name, getName())) {
            update(getDelegate().withName(name));
        }
    }

    public String getDescription() {
        return getDelegate().getDescription();
    }

    public void setDescription(String description) {
        if (!Objects.equals(description, getDescription())) {
            update(getDelegate().withDescription(description));
        }
    }

    public String getUrl() {
        return getDelegate().getUrl();
    }

    public void setUrl(String url) {
        if (!Objects.equals(url, getUrl())) {
            update(getDelegate().withUrl(url));
        }
    }

    public String getChildProjectUrlInheritAppendPath() {
        return getDelegate().getChildProjectUrlInheritAppendPath();
    }

    public void setChildProjectUrlInheritAppendPath(String childProjectUrlInheritAppendPath) {
        if (!Objects.equals(childProjectUrlInheritAppendPath, getChildProjectUrlInheritAppendPath())) {
            update(getDelegate().withChildProjectUrlInheritAppendPath(childProjectUrlInheritAppendPath));
        }
    }

    public String getInceptionYear() {
        return getDelegate().getInceptionYear();
    }

    public void setInceptionYear(String inceptionYear) {
        if (!Objects.equals(inceptionYear, getInceptionYear())) {
            update(getDelegate().withInceptionYear(inceptionYear));
        }
    }

    public Organization getOrganization() {
        return getDelegate().getOrganization() != null ? new Organization(getDelegate().getOrganization(), this) : null;
    }

    public void setOrganization(Organization organization) {
        if (!Objects.equals(organization, getOrganization())){
            if (organization != null) {
                update(getDelegate().withOrganization(organization.getDelegate()));
                organization.childrenTracking = this::replace;
            } else {
                update(getDelegate().withOrganization(null));
            }
        }
    }

    @Nonnull
    public List getLicenses() {
        return new WrapperList(
                    () -> getDelegate().getLicenses(), l -> update(getDelegate().withLicenses(l)),
                    d -> new License(d, this), License::getDelegate);
    }

    public void setLicenses(List licenses) {
        if (licenses == null) {
            licenses = Collections.emptyList();
        }
        if (!Objects.equals(licenses, getLicenses())) {
            update(getDelegate().withLicenses(
                licenses.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            licenses.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addLicense(License license) {
        update(getDelegate().withLicenses(
               Stream.concat(getDelegate().getLicenses().stream(), Stream.of(license.getDelegate()))
                        .collect(Collectors.toList())));
        license.childrenTracking = this::replace;
    }

    public void removeLicense(License license) {
        update(getDelegate().withLicenses(
               getDelegate().getLicenses().stream()
                        .filter(e -> !Objects.equals(e, license))
                        .collect(Collectors.toList())));
        license.childrenTracking = null;
    }

    @Nonnull
    public List getDevelopers() {
        return new WrapperList(
                    () -> getDelegate().getDevelopers(), l -> update(getDelegate().withDevelopers(l)),
                    d -> new Developer(d, this), Developer::getDelegate);
    }

    public void setDevelopers(List developers) {
        if (developers == null) {
            developers = Collections.emptyList();
        }
        if (!Objects.equals(developers, getDevelopers())) {
            update(getDelegate().withDevelopers(
                developers.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            developers.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addDeveloper(Developer developer) {
        update(getDelegate().withDevelopers(
               Stream.concat(getDelegate().getDevelopers().stream(), Stream.of(developer.getDelegate()))
                        .collect(Collectors.toList())));
        developer.childrenTracking = this::replace;
    }

    public void removeDeveloper(Developer developer) {
        update(getDelegate().withDevelopers(
               getDelegate().getDevelopers().stream()
                        .filter(e -> !Objects.equals(e, developer))
                        .collect(Collectors.toList())));
        developer.childrenTracking = null;
    }

    @Nonnull
    public List getContributors() {
        return new WrapperList(
                    () -> getDelegate().getContributors(), l -> update(getDelegate().withContributors(l)),
                    d -> new Contributor(d, this), Contributor::getDelegate);
    }

    public void setContributors(List contributors) {
        if (contributors == null) {
            contributors = Collections.emptyList();
        }
        if (!Objects.equals(contributors, getContributors())) {
            update(getDelegate().withContributors(
                contributors.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            contributors.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addContributor(Contributor contributor) {
        update(getDelegate().withContributors(
               Stream.concat(getDelegate().getContributors().stream(), Stream.of(contributor.getDelegate()))
                        .collect(Collectors.toList())));
        contributor.childrenTracking = this::replace;
    }

    public void removeContributor(Contributor contributor) {
        update(getDelegate().withContributors(
               getDelegate().getContributors().stream()
                        .filter(e -> !Objects.equals(e, contributor))
                        .collect(Collectors.toList())));
        contributor.childrenTracking = null;
    }

    @Nonnull
    public List getMailingLists() {
        return new WrapperList(
                    () -> getDelegate().getMailingLists(), l -> update(getDelegate().withMailingLists(l)),
                    d -> new MailingList(d, this), MailingList::getDelegate);
    }

    public void setMailingLists(List mailingLists) {
        if (mailingLists == null) {
            mailingLists = Collections.emptyList();
        }
        if (!Objects.equals(mailingLists, getMailingLists())) {
            update(getDelegate().withMailingLists(
                mailingLists.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            mailingLists.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addMailingList(MailingList mailingList) {
        update(getDelegate().withMailingLists(
               Stream.concat(getDelegate().getMailingLists().stream(), Stream.of(mailingList.getDelegate()))
                        .collect(Collectors.toList())));
        mailingList.childrenTracking = this::replace;
    }

    public void removeMailingList(MailingList mailingList) {
        update(getDelegate().withMailingLists(
               getDelegate().getMailingLists().stream()
                        .filter(e -> !Objects.equals(e, mailingList))
                        .collect(Collectors.toList())));
        mailingList.childrenTracking = null;
    }

    public Prerequisites getPrerequisites() {
        return getDelegate().getPrerequisites() != null ? new Prerequisites(getDelegate().getPrerequisites(), this) : null;
    }

    public void setPrerequisites(Prerequisites prerequisites) {
        if (!Objects.equals(prerequisites, getPrerequisites())){
            if (prerequisites != null) {
                update(getDelegate().withPrerequisites(prerequisites.getDelegate()));
                prerequisites.childrenTracking = this::replace;
            } else {
                update(getDelegate().withPrerequisites(null));
            }
        }
    }

    public Scm getScm() {
        return getDelegate().getScm() != null ? new Scm(getDelegate().getScm(), this) : null;
    }

    public void setScm(Scm scm) {
        if (!Objects.equals(scm, getScm())){
            if (scm != null) {
                update(getDelegate().withScm(scm.getDelegate()));
                scm.childrenTracking = this::replace;
            } else {
                update(getDelegate().withScm(null));
            }
        }
    }

    public IssueManagement getIssueManagement() {
        return getDelegate().getIssueManagement() != null ? new IssueManagement(getDelegate().getIssueManagement(), this) : null;
    }

    public void setIssueManagement(IssueManagement issueManagement) {
        if (!Objects.equals(issueManagement, getIssueManagement())){
            if (issueManagement != null) {
                update(getDelegate().withIssueManagement(issueManagement.getDelegate()));
                issueManagement.childrenTracking = this::replace;
            } else {
                update(getDelegate().withIssueManagement(null));
            }
        }
    }

    public CiManagement getCiManagement() {
        return getDelegate().getCiManagement() != null ? new CiManagement(getDelegate().getCiManagement(), this) : null;
    }

    public void setCiManagement(CiManagement ciManagement) {
        if (!Objects.equals(ciManagement, getCiManagement())){
            if (ciManagement != null) {
                update(getDelegate().withCiManagement(ciManagement.getDelegate()));
                ciManagement.childrenTracking = this::replace;
            } else {
                update(getDelegate().withCiManagement(null));
            }
        }
    }

    public Build getBuild() {
        return getDelegate().getBuild() != null ? new Build(getDelegate().getBuild(), this) : null;
    }

    public void setBuild(Build build) {
        if (!Objects.equals(build, getBuild())){
            if (build != null) {
                update(getDelegate().withBuild(build.getDelegate()));
                build.childrenTracking = this::replace;
            } else {
                update(getDelegate().withBuild(null));
            }
        }
    }

    @Nonnull
    public List getProfiles() {
        return new WrapperList(
                    () -> getDelegate().getProfiles(), l -> update(getDelegate().withProfiles(l)),
                    d -> new Profile(d, this), Profile::getDelegate);
    }

    public void setProfiles(List profiles) {
        if (profiles == null) {
            profiles = Collections.emptyList();
        }
        if (!Objects.equals(profiles, getProfiles())) {
            update(getDelegate().withProfiles(
                profiles.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            profiles.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addProfile(Profile profile) {
        update(getDelegate().withProfiles(
               Stream.concat(getDelegate().getProfiles().stream(), Stream.of(profile.getDelegate()))
                        .collect(Collectors.toList())));
        profile.childrenTracking = this::replace;
    }

    public void removeProfile(Profile profile) {
        update(getDelegate().withProfiles(
               getDelegate().getProfiles().stream()
                        .filter(e -> !Objects.equals(e, profile))
                        .collect(Collectors.toList())));
        profile.childrenTracking = null;
    }

    public InputLocation getLocation(Object key) {
        org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
        return loc != null ? new InputLocation(loc) : null;
    }

    public void setLocation(Object key, InputLocation location) {
        update(org.apache.maven.api.model.Model.newBuilder(getDelegate(), true)
                        .location(key, location.toApiLocation()).build());
    }

    public InputLocation getImportedFrom() {
        org.apache.maven.api.model.InputLocation loc = getDelegate().getImportedFrom();
        return loc != null ? new InputLocation(loc) : null;
    }

    public void setImportedFrom(InputLocation location) {
        update(org.apache.maven.api.model.Model.newBuilder(getDelegate(), true)
                        .importedFrom(location.toApiLocation()).build());
    }

    public Set getLocationKeys() {
        return getDelegate().getLocationKeys();
    }

    protected boolean replace(Object oldDelegate, Object newDelegate) {
        if (super.replace(oldDelegate, newDelegate)) {
            return true;
        }
        if (oldDelegate == getDelegate().getParent()) {
            update(getDelegate().withParent((org.apache.maven.api.model.Parent) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getOrganization()) {
            update(getDelegate().withOrganization((org.apache.maven.api.model.Organization) newDelegate));
            return true;
        }
        if (getDelegate().getLicenses().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getLicenses());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.License) newDelegate : d);
            update(getDelegate().withLicenses(list));
            return true;
        }
        if (getDelegate().getDevelopers().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getDevelopers());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Developer) newDelegate : d);
            update(getDelegate().withDevelopers(list));
            return true;
        }
        if (getDelegate().getContributors().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getContributors());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Contributor) newDelegate : d);
            update(getDelegate().withContributors(list));
            return true;
        }
        if (getDelegate().getMailingLists().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getMailingLists());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.MailingList) newDelegate : d);
            update(getDelegate().withMailingLists(list));
            return true;
        }
        if (oldDelegate == getDelegate().getPrerequisites()) {
            update(getDelegate().withPrerequisites((org.apache.maven.api.model.Prerequisites) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getScm()) {
            update(getDelegate().withScm((org.apache.maven.api.model.Scm) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getIssueManagement()) {
            update(getDelegate().withIssueManagement((org.apache.maven.api.model.IssueManagement) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getCiManagement()) {
            update(getDelegate().withCiManagement((org.apache.maven.api.model.CiManagement) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getBuild()) {
            update(getDelegate().withBuild((org.apache.maven.api.model.Build) newDelegate));
            return true;
        }
        if (getDelegate().getProfiles().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getProfiles());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Profile) newDelegate : d);
            update(getDelegate().withProfiles(list));
            return true;
        }
        return false;
    }

    public static List modelToApiV4(List list) {
        return list != null ? new WrapperList<>(list, Model::getDelegate, Model::new) : null;
    }

    public static List modelToApiV3(List list) {
        return list != null ? new WrapperList<>(list, Model::new, Model::getDelegate) : null;
    }


            
    /**
     * Gets the POM file for the corresponding project (if any).
     *
     * @return The POM file from which this model originated or {@code null} if this model does not belong to a local
     *         project (e.g. describes the metadata of some artifact from the repository).
     */
    @Deprecated
    public java.io.File getPomFile() {
        return (getDelegate().getPomFile() != null) ? getDelegate().getPomFile().toFile() : null;
    }

    @Deprecated
    public void setPomFile(java.io.File pomFile) {
        update( getDelegate().withPomFile(pomFile != null ? pomFile.toPath() : null));
    }

    /**
     * Gets the POM file for the corresponding project (if any).
     *
     * @return The POM file from which this model originated or {@code null} if this model does not belong to a local
     *         project (e.g. describes the metadata of some artifact from the repository).
     */
    public java.nio.file.Path getPomPath() {
        return (getDelegate().getPomFile() != null) ? getDelegate().getPomFile() : null;
    }

    public void setPomPath(java.nio.file.Path pomPath) {
        update( getDelegate().withPomFile(pomPath));
    }

    public void setModelEncoding(String modelEncoding) {
        update(getDelegate().with().modelEncoding(modelEncoding).build());
    }

    /**
     * Gets the base directory for the corresponding project (if any).
     *
     * @return The base directory for the corresponding project or {@code null} if this model does not belong to a local
     *         project (e.g. describes the metadata of some artifact from the repository).
     */
    @Deprecated
    public java.io.File getProjectDirectory() {
        return (getDelegate().getProjectDirectory() != null) ? getDelegate().getProjectDirectory().toFile() : null;
    }

    /**
     * Gets the base directory for the corresponding project (if any).
     *
     * @return The base directory for the corresponding project or {@code null} if this model does not belong to a local
     *         project (e.g. describes the metadata of some artifact from the repository).
     */
    public java.nio.file.Path getProjectDirectoryPath() {
        return getDelegate().getProjectDirectory();
    }

    /**
     * @return the model id as {@code groupId:artifactId:packaging:version}
     */
    public String getId() {
        StringBuilder id = new StringBuilder( 64 );

        id.append( ( getGroupId() == null ) ? "[inherited]" : getGroupId() );
        id.append( ":" );
        id.append( getArtifactId() );
        id.append( ":" );
        id.append( getPackaging() );
        id.append( ":" );
        id.append( ( getVersion() == null ) ? "[inherited]" : getVersion() );

        return id.toString();
    }

    @Override
    public String toString() {
        return getId();
    }

    public boolean isChildProjectUrlInheritAppendPath() {
        return getDelegate().isChildProjectUrlInheritAppendPath();
    }

    public void setChildProjectUrlInheritAppendPath(boolean childProjectUrlInheritAppendPath) {
        delegate = getDelegate().withChildProjectUrlInheritAppendPath(String.valueOf(childProjectUrlInheritAppendPath));
    }

            
          
}