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.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 update(getDelegate().withActivation(activation.getDelegate()));
72 activation.childrenTracking = this::replace;
73 }
74 }
75
76 @Nonnull
77 public Properties getProperties() {
78 return new WrapperProperties(() -> getDelegate().getProperties(), this::setProperties);
79 }
80
81 public void setProperties(Properties properties) {
82 Map<String, String> map = properties.entrySet().stream()
83 .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
84 if (!Objects.equals(map, getDelegate().getProperties())) {
85 update(getDelegate().withProperties(map));
86 }
87 }
88
89 public void addProperty(String key, String value) {
90 getProperties().put(key, value);
91 }
92
93 @Nonnull
94 public List<Repository> getRepositories() {
95 return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
96 () -> getDelegate().getRepositories(), l -> update(getDelegate().withRepositories(l)),
97 d -> new Repository(d, this), Repository::getDelegate);
98 }
99
100 public void setRepositories(List<Repository> repositories) {
101 if (!Objects.equals(repositories, getRepositories())) {
102 update(getDelegate().withRepositories(
103 repositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
104 repositories.forEach(e -> e.childrenTracking = this::replace);
105 }
106 }
107
108 public void addRepository(Repository repository) {
109 update(getDelegate().withRepositories(
110 Stream.concat(getDelegate().getRepositories().stream(), Stream.of(repository.getDelegate()))
111 .collect(Collectors.toList())));
112 repository.childrenTracking = this::replace;
113 }
114
115 public void removeRepository(Repository repository) {
116 update(getDelegate().withRepositories(
117 getDelegate().getRepositories().stream()
118 .filter(e -> !Objects.equals(e, repository))
119 .collect(Collectors.toList())));
120 repository.childrenTracking = null;
121 }
122
123 @Nonnull
124 public List<Repository> getPluginRepositories() {
125 return new WrapperList<Repository, org.apache.maven.api.settings.Repository>(
126 () -> getDelegate().getPluginRepositories(), l -> update(getDelegate().withPluginRepositories(l)),
127 d -> new Repository(d, this), Repository::getDelegate);
128 }
129
130 public void setPluginRepositories(List<Repository> pluginRepositories) {
131 if (!Objects.equals(pluginRepositories, getPluginRepositories())) {
132 update(getDelegate().withPluginRepositories(
133 pluginRepositories.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
134 pluginRepositories.forEach(e -> e.childrenTracking = this::replace);
135 }
136 }
137
138 public void addPluginRepository(Repository pluginRepository) {
139 update(getDelegate().withPluginRepositories(
140 Stream.concat(getDelegate().getPluginRepositories().stream(), Stream.of(pluginRepository.getDelegate()))
141 .collect(Collectors.toList())));
142 pluginRepository.childrenTracking = this::replace;
143 }
144
145 public void removePluginRepository(Repository pluginRepository) {
146 update(getDelegate().withPluginRepositories(
147 getDelegate().getPluginRepositories().stream()
148 .filter(e -> !Objects.equals(e, pluginRepository))
149 .collect(Collectors.toList())));
150 pluginRepository.childrenTracking = null;
151 }
152
153 protected boolean replace(Object oldDelegate, Object newDelegate) {
154 if (super.replace(oldDelegate, newDelegate)) {
155 return true;
156 }
157 if (oldDelegate == getDelegate().getActivation()) {
158 update(getDelegate().withActivation((org.apache.maven.api.settings.Activation) newDelegate));
159 return true;
160 }
161 if (getDelegate().getRepositories().contains(oldDelegate)) {
162 List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getRepositories());
163 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
164 update(getDelegate().withRepositories(list));
165 return true;
166 }
167 if (getDelegate().getPluginRepositories().contains(oldDelegate)) {
168 List<org.apache.maven.api.settings.Repository> list = new ArrayList<>(getDelegate().getPluginRepositories());
169 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.settings.Repository) newDelegate : d);
170 update(getDelegate().withPluginRepositories(list));
171 return true;
172 }
173 return false;
174 }
175
176 public static List<org.apache.maven.api.settings.Profile> profileToApiV4(List<Profile> list) {
177 return list != null ? new WrapperList<>(list, Profile::getDelegate, Profile::new) : null;
178 }
179
180 public static List<Profile> profileToApiV3(List<org.apache.maven.api.settings.Profile> list) {
181 return list != null ? new WrapperList<>(list, Profile::new, Profile::getDelegate) : null;
182 }
183
184 }