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