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