1
2
3
4
5 package org.apache.maven.artifact.repository.metadata;
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.stream.Collectors;
16 import java.util.stream.Stream;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Nonnull;
19
20 @Generated
21 public class Versioning
22 extends BaseObject
23 {
24
25 public Versioning() {
26 this(org.apache.maven.artifact.repository.metadata.v4.Versioning.newInstance());
27 }
28
29 public Versioning(org.apache.maven.artifact.repository.metadata.v4.Versioning delegate) {
30 this(delegate, null);
31 }
32
33 public Versioning(org.apache.maven.artifact.repository.metadata.v4.Versioning delegate, BaseObject parent) {
34 super(delegate, parent);
35 }
36
37 public Versioning clone(){
38 return new Versioning(getDelegate());
39 }
40
41 public org.apache.maven.artifact.repository.metadata.v4.Versioning getDelegate() {
42 return (org.apache.maven.artifact.repository.metadata.v4.Versioning) super.getDelegate();
43 }
44
45 @Override
46 public boolean equals(Object o) {
47 if (this == o) {
48 return true;
49 }
50 if (o == null || !(o instanceof Versioning)) {
51 return false;
52 }
53 Versioning that = (Versioning) o;
54 return Objects.equals(this.delegate, that.delegate);
55 }
56
57 @Override
58 public int hashCode() {
59 return getDelegate().hashCode();
60 }
61
62 public String getLatest() {
63 return getDelegate().getLatest();
64 }
65
66 public void setLatest(String latest) {
67 if (!Objects.equals(latest, getLatest())) {
68 update(getDelegate().withLatest(latest));
69 }
70 }
71
72 public String getRelease() {
73 return getDelegate().getRelease();
74 }
75
76 public void setRelease(String release) {
77 if (!Objects.equals(release, getRelease())) {
78 update(getDelegate().withRelease(release));
79 }
80 }
81
82 @Nonnull
83 public List<String> getVersions() {
84 return new WrapperList<String, String>(() -> getDelegate().getVersions(), this::setVersions, s -> s, s -> s);
85 }
86
87 public void setVersions(List<String> versions) {
88 if (!Objects.equals(versions, getVersions())) {
89 update(getDelegate().withVersions(versions));
90 }
91 }
92
93 public void addVersion(String version) {
94 update(getDelegate().withVersions(
95 Stream.concat(getDelegate().getVersions().stream(), Stream.of(version))
96 .collect(Collectors.toList())));
97 }
98
99 public void removeVersion(String version) {
100 update(getDelegate().withVersions(
101 getDelegate().getVersions().stream()
102 .filter(e -> !Objects.equals(e, version))
103 .collect(Collectors.toList())));
104 }
105
106 public String getLastUpdated() {
107 return getDelegate().getLastUpdated();
108 }
109
110 public void setLastUpdated(String lastUpdated) {
111 if (!Objects.equals(lastUpdated, getLastUpdated())) {
112 update(getDelegate().withLastUpdated(lastUpdated));
113 }
114 }
115
116 public Snapshot getSnapshot() {
117 return getDelegate().getSnapshot() != null ? new Snapshot(getDelegate().getSnapshot(), this) : null;
118 }
119
120 public void setSnapshot(Snapshot snapshot) {
121 if (!Objects.equals(snapshot, getSnapshot())){
122 if (snapshot != null) {
123 update(getDelegate().withSnapshot(snapshot.getDelegate()));
124 snapshot.childrenTracking = this::replace;
125 } else {
126 update(getDelegate().withSnapshot(null));
127 }
128 }
129 }
130
131 @Nonnull
132 public List<SnapshotVersion> getSnapshotVersions() {
133 return new WrapperList<SnapshotVersion, org.apache.maven.artifact.repository.metadata.v4.SnapshotVersion>(
134 () -> getDelegate().getSnapshotVersions(), l -> update(getDelegate().withSnapshotVersions(l)),
135 d -> new SnapshotVersion(d, this), SnapshotVersion::getDelegate);
136 }
137
138 public void setSnapshotVersions(List<SnapshotVersion> snapshotVersions) {
139 if (snapshotVersions == null) {
140 snapshotVersions = Collections.emptyList();
141 }
142 if (!Objects.equals(snapshotVersions, getSnapshotVersions())) {
143 update(getDelegate().withSnapshotVersions(
144 snapshotVersions.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
145 snapshotVersions.forEach(e -> e.childrenTracking = this::replace);
146 }
147 }
148
149 public void addSnapshotVersion(SnapshotVersion snapshotVersion) {
150 update(getDelegate().withSnapshotVersions(
151 Stream.concat(getDelegate().getSnapshotVersions().stream(), Stream.of(snapshotVersion.getDelegate()))
152 .collect(Collectors.toList())));
153 snapshotVersion.childrenTracking = this::replace;
154 }
155
156 public void removeSnapshotVersion(SnapshotVersion snapshotVersion) {
157 update(getDelegate().withSnapshotVersions(
158 getDelegate().getSnapshotVersions().stream()
159 .filter(e -> !Objects.equals(e, snapshotVersion))
160 .collect(Collectors.toList())));
161 snapshotVersion.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().getSnapshot()) {
169 update(getDelegate().withSnapshot((org.apache.maven.artifact.repository.metadata.v4.Snapshot) newDelegate));
170 return true;
171 }
172 if (getDelegate().getSnapshotVersions().contains(oldDelegate)) {
173 List<org.apache.maven.artifact.repository.metadata.v4.SnapshotVersion> list = new ArrayList<>(getDelegate().getSnapshotVersions());
174 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.artifact.repository.metadata.v4.SnapshotVersion) newDelegate : d);
175 update(getDelegate().withSnapshotVersions(list));
176 return true;
177 }
178 return false;
179 }
180
181 public static List<org.apache.maven.artifact.repository.metadata.v4.Versioning> versioningToApiV4(List<Versioning> list) {
182 return list != null ? new WrapperList<>(list, Versioning::getDelegate, Versioning::new) : null;
183 }
184
185 public static List<Versioning> versioningToApiV3(List<org.apache.maven.artifact.repository.metadata.v4.Versioning> list) {
186 return list != null ? new WrapperList<>(list, Versioning::new, Versioning::getDelegate) : null;
187 }
188
189
190 public void updateTimestamp()
191 {
192 setLastUpdatedTimestamp( new java.util.Date() );
193 }
194
195 public void setLastUpdatedTimestamp( java.util.Date date )
196 {
197 java.util.TimeZone timezone = java.util.TimeZone.getTimeZone( "UTC" );
198 java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" );
199 fmt.setTimeZone( timezone );
200 setLastUpdated( fmt.format( date ) );
201 }
202
203 }