View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model-v3.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.settings;
6   
7   import java.io.Serializable;
8   import java.util.AbstractList;
9   import java.util.ArrayList;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Objects;
15  import java.util.Properties;
16  import java.util.stream.Collectors;
17  import java.util.stream.Stream;
18  import org.apache.maven.api.annotations.Generated;
19  import org.apache.maven.api.annotations.Nonnull;
20  
21  @Generated
22  public class Profile
23      extends IdentifiableBase
24      implements Serializable, Cloneable
25  {
26  
27      public Profile() {
28          this(org.apache.maven.api.settings.Profile.newInstance());
29      }
30  
31      public Profile(org.apache.maven.api.settings.Profile delegate) {
32          this(delegate, null);
33      }
34  
35      public Profile(org.apache.maven.api.settings.Profile delegate, BaseObject parent) {
36          super(delegate, parent);
37      }
38  
39      public Profile clone(){
40          return new Profile(getDelegate());
41      }
42  
43      @Override
44      public org.apache.maven.api.settings.Profile getDelegate() {
45          return (org.apache.maven.api.settings.Profile) super.getDelegate();
46      }
47  
48      @Override
49      public boolean equals(Object o) {
50          if (this == o) {
51              return true;
52          }
53          if (o == null || !(o instanceof Profile)) {
54              return false;
55          }
56          Profile that = (Profile) o;
57          return Objects.equals(this.delegate, that.delegate);
58      }
59  
60      @Override
61      public int hashCode() {
62          return getDelegate().hashCode();
63      }
64  
65      public Activation getActivation() {
66          return getDelegate().getActivation() != null ? new Activation(getDelegate().getActivation(), this) : null;
67      }
68  
69      public void setActivation(Activation activation) {
70          if (!Objects.equals(activation, getActivation())){
71              if (activation != null) {
72                  update(getDelegate().withActivation(activation.getDelegate()));
73                  activation.childrenTracking = this::replace;
74              } else {
75                  update(getDelegate().withActivation(null));
76              }
77          }
78      }
79  
80      @Nonnull
81      public Properties getProperties() {
82          return new WrapperProperties(() -> getDelegate().getProperties(), this::setProperties);
83      }
84  
85      public void setProperties(Properties properties) {
86          Map<String, String> map = properties.entrySet().stream()
87                  .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
88          if (!Objects.equals(map, getDelegate().getProperties())) {
89              update(getDelegate().withProperties(map));
90          }
91      }
92  
93      public void addProperty(String key, String value) {
94          getProperties().put(key, value);
95      }
96  
97      @Nonnull
98      public List<Repository> getRepositories() {
99          return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
100                     () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
101                     d -> new Repository(d, this), Repository::getDelegate);
102     }
103 
104     public void setRepositories(List<Repository> repositories) {
105         if (repositories == null) {
106             repositories = Collections.emptyList();
107         }
108         if (!Objects.equals(repositories, getRepositories())) {
109             update(getDelegate().withRepositories(
110                 repositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
111             repositories.forEach(e -> e.childrenTracking = this::replace);
112         }
113     }
114 
115     public void addRepository(Repository repository) {
116         update(getDelegate().withRepositories(
117                Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
118                         .collect(Collectors.toList())));
119         repository.childrenTracking = this::replace;
120     }
121 
122     public void removeRepository(Repository repository) {
123         update(getDelegate().withRepositories(
124                getDelegate().getRepositories().stream()
125                         .filter(e -> !Objects.equals(e, repository))
126                         .collect(Collectors.toList())));
127         repository.childrenTracking = null;
128     }
129 
130     @Nonnull
131     public List<Repository> getPluginRepositories() {
132         return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
133                     () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
134                     d -> new Repository(d, this), Repository::getDelegate);
135     }
136 
137     public void setPluginRepositories(List<Repository> pluginRepositories) {
138         if (pluginRepositories == null) {
139             pluginRepositories = Collections.emptyList();
140         }
141         if (!Objects.equals(pluginRepositories, getPluginRepositories())) {
142             update(getDelegate().withPluginRepositories(
143                 pluginRepositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
144             pluginRepositories.forEach(e -> e.childrenTracking = this::replace);
145         }
146     }
147 
148     public void addPluginRepository(Repository pluginRepository) {
149         update(getDelegate().withPluginRepositories(
150                Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
151                         .collect(Collectors.toList())));
152         pluginRepository.childrenTracking = this::replace;
153     }
154 
155     public void removePluginRepository(Repository pluginRepository) {
156         update(getDelegate().withPluginRepositories(
157                getDelegate().getPluginRepositories().stream()
158                         .filter(e -> !Objects.equals(e, pluginRepository))
159                         .collect(Collectors.toList())));
160         pluginRepository.childrenTracking = null;
161     }
162 
163     protected boolean replace(Object oldDelegate, Object newDelegate) {
164         if (super.replace(oldDelegate, newDelegate)) {
165             return true;
166         }
167         if (oldDelegate == getDelegate().getActivation()) {
168             update(getDelegate().withActivation((org.apache.maven.api.settings.Activation) newDelegate));
169             return true;
170         }
171         if (getDelegate().getRepositories().contains(oldDelegate)) {
172             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getRepositories());
173             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
174             update(getDelegate().withRepositories(list));
175             return true;
176         }
177         if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
178             List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getPluginRepositories());
179             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
180             update(getDelegate().withPluginRepositories(list));
181             return true;
182         }
183         return false;
184     }
185 
186     public static List<org.apache.maven.api.settings.Profile> profileToApiV4(List<Profile> list) {
187         return list != null ? new WrapperList<>(list, Profile::getDelegate, Profile::new) : null;
188     }
189 
190     public static List<Profile> profileToApiV3(List<org.apache.maven.api.settings.Profile> list) {
191         return list != null ? new WrapperList<>(list, Profile::new, Profile::getDelegate) : null;
192     }
193 
194 }