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

org.apache.maven.settings.Profile 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.settings;

import java.io.Serializable;
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;

@Generated
public class Profile
    extends IdentifiableBase
    implements Serializable, Cloneable
{

    public Profile() {
        this(org.apache.maven.api.settings.Profile.newInstance());
    }

    public Profile(org.apache.maven.api.settings.Profile delegate) {
        this(delegate, null);
    }

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

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

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

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

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

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

    public void setActivation(Activation activation) {
        if (!Objects.equals(activation, getActivation())){
            if (activation != null) {
                update(getDelegate().withActivation(activation.getDelegate()));
                activation.childrenTracking = this::replace;
            } else {
                update(getDelegate().withActivation(null));
            }
        }
    }

    @Nonnull
    public Properties getProperties() {
        return new WrapperProperties(() -> getDelegate().getProperties(), this::setProperties);
    }

    public void setProperties(Properties properties) {
        Map map = properties.entrySet().stream()
                .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
        if (!Objects.equals(map, getDelegate().getProperties())) {
            update(getDelegate().withProperties(map));
        }
    }

    public void addProperty(String key, String value) {
        getProperties().put(key, value);
    }

    @Nonnull
    public List getRepositories() {
        return new WrapperList(
                    () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
                    d -> new Repository(d, this), Repository::getDelegate);
    }

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

    public void addRepository(Repository repository) {
        update(getDelegate().withRepositories(
               Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
                        .collect(Collectors.toList())));
        repository.childrenTracking = this::replace;
    }

    public void removeRepository(Repository repository) {
        update(getDelegate().withRepositories(
               getDelegate().getRepositories().stream()
                        .filter(e -> !Objects.equals(e, repository))
                        .collect(Collectors.toList())));
        repository.childrenTracking = null;
    }

    @Nonnull
    public List getPluginRepositories() {
        return new WrapperList(
                    () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
                    d -> new Repository(d, this), Repository::getDelegate);
    }

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

    public void addPluginRepository(Repository pluginRepository) {
        update(getDelegate().withPluginRepositories(
               Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
                        .collect(Collectors.toList())));
        pluginRepository.childrenTracking = this::replace;
    }

    public void removePluginRepository(Repository pluginRepository) {
        update(getDelegate().withPluginRepositories(
               getDelegate().getPluginRepositories().stream()
                        .filter(e -> !Objects.equals(e, pluginRepository))
                        .collect(Collectors.toList())));
        pluginRepository.childrenTracking = null;
    }

    protected boolean replace(Object oldDelegate, Object newDelegate) {
        if (super.replace(oldDelegate, newDelegate)) {
            return true;
        }
        if (oldDelegate == getDelegate().getActivation()) {
            update(getDelegate().withActivation((org.apache.maven.api.settings.Activation) newDelegate));
            return true;
        }
        if (getDelegate().getRepositories().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getRepositories());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
            update(getDelegate().withRepositories(list));
            return true;
        }
        if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getPluginRepositories());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
            update(getDelegate().withPluginRepositories(list));
            return true;
        }
        return false;
    }

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

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

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy