From a5d2f9a4a5bb980b5bf18a2901b6188fc6292e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20H=C3=BCbner?= Date: Mon, 15 May 2023 18:28:03 +0200 Subject: [PATCH] read mvn meta --- maven/meta.go | 25 +++++++++++++++++++++++++ maven/meta_test.go | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 maven/meta.go create mode 100644 maven/meta_test.go diff --git a/maven/meta.go b/maven/meta.go new file mode 100644 index 0000000..9df9188 --- /dev/null +++ b/maven/meta.go @@ -0,0 +1,25 @@ +package maven + +import ( + http "github.com/nothub/mrpack-install/requester" +) + +type Metadata struct { + GroupId string `xml:"groupId"` + ArtifactId string `xml:"artifactId"` + Versioning struct { + Latest string `xml:"latest"` + Release string `xml:"release"` + Versions []string `xml:"versions>version"` + LastUpdated string `xml:"lastUpdated"` // TODO: use Time type + } `xml:"versioning"` +} + +func FetchMetadata(url string) (*Metadata, error) { + m := &Metadata{} + err := http.DefaultHttpClient.GetXml(url, m, nil) + if err != nil { + return nil, err + } + return m, nil +} diff --git a/maven/meta_test.go b/maven/meta_test.go new file mode 100644 index 0000000..94369f0 --- /dev/null +++ b/maven/meta_test.go @@ -0,0 +1,16 @@ +package maven + +import ( + "testing" +) + +func TestFetchMetadata(t *testing.T) { + m, err := FetchMetadata("https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-installer/maven-metadata.xml") + if err != nil { + t.Fatal(err.Error()) + } + if m.ArtifactId != "quilt-installer" { + t.Fatal("wrong artifact id") + } + t.Logf("%++v", m) +}