summaryrefslogtreecommitdiff
path: root/plugins_to_xml.py
blob: 0173e811a0361a27dd9f461e40f22b00cc858e70 (plain)
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
52
53
54
55
56
#!/usr/bin/env python

import json
import sys
# pip install --user semantic_version
from semantic_version import Version
import collections

data = json.load(sys.stdin)

docs = data["response"]["docs"]

#print json.dumps(docs, indent=2)
def info(msg):
  print >> sys.stderr, msg

info('Found ' + str(len(docs)) + ' artifacts')

# Some magic hacks to get semantic_version to like the versions more
def v(doc):
  return doc["v"]. \
    replace("alpha1", "0.alpha-1"). \
    replace("alpha2", "0.alpha-2")

found = {}
for doc in docs:
  key = doc["g"] + ":" + doc["a"]
  prev = found.get(key)
  if prev == None:
    found[key] = doc
#    print "First version of " + key + " => " + str(Version.coerce(doc["v"]))
    continue

  oldV = Version.coerce(v(prev))
#  print "oldV=" + str(oldV)
  newV = Version.coerce(v(doc))
#  print "newV=" + str(newV)

  if newV > oldV:
#    print "newer version of " + key + " => " + str(newV)
    found[key] = doc
#  else:
#    print "old   version of " + key + " => " + str(newV)

found = collections.OrderedDict(sorted(found.items()))

print "<pluginManagement>"
print "<plugins>"
for key, p in found.iteritems():
  print """    <plugin>
      <groupId>%(g)s</groupId>
      <artifactId>%(a)s</artifactId>
      <version>%(v)s</version>
    </plugin>""" % p
print "  </plugins>"
print "</pluginManagement>"