Skip to content

Commit fc3df6e

Browse files
committed
Combine maven and status modules
The status module was Maven-side only, not GitHub or other sources. So let's just put the processing logic into the same module. KISS.
1 parent 1ce587a commit fc3df6e

File tree

2 files changed

+84
-89
lines changed

2 files changed

+84
-89
lines changed

maven.py

100644100755
Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@
88
# ------------------------------------------------------------------------
99
# Supporting library for harvesting metadata about Maven components.
1010
# Requires direct access to the backing storage of the repositories.
11+
#
12+
# When run from the command line, generates a data structure with information
13+
# about the components and repositories of the SciJava component collection.
1114

12-
import datetime, logging, os, pathlib, re
15+
import datetime, json, logging, os, pathlib, re, sys
1316
import xml.etree.ElementTree as ET
1417

18+
# -- Constants --
19+
1520
storage = "/opt/sonatype-work/nexus/storage"
1621
release_repos = ["releases", "thirdparty", "sonatype", "central", "ome-releases"]
1722
snapshot_repos = ["snapshots", "sonatype-snapshots", "ome-snapshots"]
1823

1924
ts_allowance = 10 # maximum seconds difference in SNAPSHOT timestamp
2025

26+
# -- Classes --
27+
2128
class XML:
2229

2330
def __init__(self, source):
@@ -191,3 +198,79 @@ def _pom(repos, g, a, v, ts=None):
191198
if os.path.exists(path):
192199
return MavenPOM(path)
193200
return None
201+
202+
# -- Functions --
203+
204+
def resource_path(source):
205+
return None if source is None else source[len(storage):]
206+
207+
def status(c):
208+
"""
209+
Gathers information from Maven about the given groupId:artifactId.
210+
"""
211+
record = {
212+
"groupId": c.groupId,
213+
"artifactId": c.artifactId
214+
}
215+
record["release"] = None if c.release is None else {
216+
"source": resource_path(c.release.source),
217+
"groupId": c.release.groupId,
218+
"artifactId": c.release.artifactId,
219+
"lastUpdated": c.release.lastUpdated,
220+
"latest": c.release.latest,
221+
"lastVersion": c.release.lastVersion,
222+
"release": c.release.release,
223+
}
224+
record["snapshot"] = None if c.snapshot is None else {
225+
"source": resource_path(c.snapshot.source),
226+
"groupId": c.snapshot.groupId,
227+
"artifactId": c.snapshot.artifactId,
228+
"lastUpdated": c.snapshot.lastUpdated,
229+
"latest": c.snapshot.latest,
230+
"lastVersion": c.snapshot.lastVersion,
231+
"release": c.snapshot.release,
232+
}
233+
record["pom"] = None if c.pom is None else {
234+
"source": resource_path(c.pom.source),
235+
"groupId": c.pom.groupId,
236+
"artifactId": c.pom.artifactId,
237+
"version": c.pom.version,
238+
"scm": c.pom.scmURL,
239+
"issues": c.pom.issuesURL,
240+
"ci": c.pom.ciURL,
241+
"developers": c.pom.developers,
242+
}
243+
return record
244+
245+
def matches(g, a, patterns):
246+
return not patterns or any(re.match(pat, f"{g}:{a}") for pat in patterns)
247+
248+
def process(patterns=[]):
249+
g = "org.scijava"
250+
a = "pom-scijava"
251+
psj = MavenComponent(g, a)
252+
253+
if not psj.release and not psj.snapshot and not psj.pom:
254+
return None
255+
256+
records = []
257+
258+
if matches(g, a, patterns):
259+
records.append(status(psj))
260+
261+
for dep in psj.pom.elements("dependencyManagement/dependencies/dependency"):
262+
g = dep.find("groupId").text
263+
a = dep.find("artifactId").text
264+
265+
if matches(g, a, patterns):
266+
c = MavenComponent(g, a)
267+
records.append(status(c))
268+
269+
return records
270+
271+
if __name__ == '__main__':
272+
result = process(sys.argv[1:])
273+
if result:
274+
print(json.dumps(result, sort_keys=True, indent=4))
275+
else:
276+
print("This script must be run from the SciJava Maven server.")

status.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)