blob: e837eaf875e248a994fe64a2a861028e8aa4945f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package com.yahoo.vespa.hosted.controller.api.integration.maven;
import com.yahoo.component.Version;
import com.yahoo.text.XML;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Objects.requireNonNull;
/**
* Metadata about a released artifact.
*
* @author jonmv
*/
public class Metadata {
private final ArtifactId id;
private final List<Version> versions;
public Metadata(ArtifactId id, List<Version> versions) {
this.id = requireNonNull(id);
this.versions = versions.stream().sorted().collect(Collectors.toUnmodifiableList());
}
/** Creates a new Metadata object from the given XML document. */
public static Metadata fromXml(String xml) {
Element root = XML.getDocument(xml).getDocumentElement();
Element metadata = XML.getChild(root, "metadata");
ArtifactId id = new ArtifactId(XML.getValue(XML.getChild(metadata, "groupId")),
XML.getValue(XML.getChild(metadata, "artifactId")));
List<Version> versions = new ArrayList<>();
for (Element version : XML.getChildren(XML.getChild(metadata, "versioning"), "versions"))
versions.add(Version.fromString(XML.getValue(version)));
return new Metadata(id, versions);
}
/** Id of the metadata this concerns. */
public ArtifactId id() { return id; }
/** List of available versions of this, sorted by ascending version order. */
public List<Version> versions() { return versions; }
}
|