2525from __future__ import absolute_import , print_function
2626
2727from functools import partial
28+ from itertools import izip_longest
2829import logging
2930import os .path
3031from os .path import dirname
5051Attempts to resolve some Maven properties when possible.
5152"""
5253
53- # FIXME: use Maven Java code directly or pymaven instead.
54+ # FIXME: use Maven Java code directly or pymaven instead. The parsing done here is rather weird.
55+ # the only part that is somewheta interesting short of using the original Maven parser is the properties resolution
5456
55- # FIXME: Maven 1 is an oddity and the code should cleaned to deal separately
56- # with eachy version
57+ # FIXME: Maven 1 is an oddity and the code should cleaned to deal separately with each version
58+ # or Maven1 support dropped entirely
5759
5860
5961# Maven1 field name -> xpath
8890 ('license' , '/project/licenses/license/name' ),
8991 ('license_comments' , '/project/licenses/license/comments' ),
9092 ('license_distribution' , '/project/licenses/license/distribution' ),
91- ('license_name' , '/project/licenses/license/name' ),
9293 ('license_url' , '/project/licenses/license/url' ),
9394
9495 ('organization_name' , '/project/organization/name' ),
@@ -364,7 +365,7 @@ def resolve_properties(value, properties):
364365 logger .debug (' resolve_properties: KeyError' )
365366
366367 msg = ('Failed to resolve property %(val)r. error:\n %(e)r' % locals ())
367- logger .debug (' resolve_properties: ' + msg )
368+ logger .debug (' resolve_properties: ' + msg )
368369 # always accumulate the raw value if we failed to resolve
369370 original = u'${%(val)s}' % locals ()
370371 logger .debug (' resolve_properties: IndexError: resolved_props.append(%(original)r)' % locals ())
@@ -484,6 +485,7 @@ def extract_pom_data(xdoc, fields=MAVEN_FIELDS):
484485
485486 if resolved :
486487 logger .debug (' extract_pom_data: found: {resolved}' .format (** locals ()))
488+ # FIXME: this is grossly incorrect!
487489 pom_data [name ] = resolved or []
488490
489491 # logger.debug(' found: {pom_data}'.format(**locals()))
@@ -510,44 +512,60 @@ def inherit_from_parent(pom_data):
510512 return pom_data
511513
512514
513- def transposed (lists ):
514- """
515- Transpose a list of lists.
516-
517- Equivalent to these examples:
518- >>> a=[[1,2,3],[4,5,6]]
519- >>> transposed(a)
520- [[1, 4], [2, 5], [3, 6]]
521- >>> zip(*a)
522- [(1, 4), (2, 5), (3, 6)]
523- >>> map(None,a)
524- [[1, 2, 3], [4, 5, 6]]
525- >>> map(None,*a)
526- [(1, 4), (2, 5), (3, 6)]
527- """
528- if not lists :
529- return []
530- return map (lambda * row : list (row ), * lists )
531-
532515
533516def parse (location ):
534517 """
535518 Parse a pom file at location and return a Package or None.
536519 """
537520 if not location .endswith ('pom.xml' ) or location .endswith ('.pom' ):
538521 return
522+
539523 pom = parse_pom (location )
540- logger .debug ('POM: \n ' + repr (pom ))
541- asserted_license = models .AssertedLicense (license = pom ['maven_license' ], url = pom ['maven_license_url' ])
542- package = models .MavenPackage (
543- version = '' .join (pom ['maven_component_version' ]),
544- id = '' .join (pom ['maven_component_group_id' ]),
545- authors = '\n ' .join (pom ['maven_developer_name' ]),
546- homepage_url = '' .join (pom ['maven_project_url' ]),
547- description = '' .join (pom ['maven_project_description' ]),
548- name = '' .join (pom ['maven_component_artifact_id' ]),
549- asserted_licenses = [asserted_license ],
550- location = location
524+
525+ def get_val (key ):
526+ val = pom .get (key )
527+ if not val :
528+ return
529+ if isinstance (val , list ) and len (val ) == 1 :
530+ return val [0 ]
531+ else :
532+ return u'\n ' .join (val )
533+
534+ group_artifact = ':' .join ([get_val ('maven_component_group_id' ), get_val ('maven_component_artifact_id' )])
535+
536+ # FIXME: the way we collect nested tags is entirely WRONG, especially for licenses
537+ # attempt to align licenses for now
538+ licenses = izip_longest (
539+ pom ['maven_license' ],
540+ pom ['maven_license_url' ],
541+ pom ['maven_license_comments' ],
542+ )
543+ licenses = [models .AssertedLicense (license = lic , url = url , notice = comments )
544+ for lic , url , comments in licenses ]
545+
546+ authors = izip_longest (
547+ pom ['maven_developer_name' ],
548+ pom ['maven_developer_email' ],
549+ )
550+ authors = [models .Party (type = models .party_person , name = name , email = email ) for name , email in authors ]
551+
552+ orgs = izip_longest (
553+ pom ['maven_organization_name' ],
554+ pom ['maven_organization_url' ],
555+ )
556+ orgs = [models .Party (type = models .party_org , name = name , url = url ) for name , url in orgs ]
557+
558+ package = models .MavenJar (
559+ location = location ,
560+ name = group_artifact ,
561+ # FIXME: this is not right: name and identifier should be storable
562+ summary = get_val ('maven_project_name' ),
563+ version = get_val ('maven_component_version' ),
564+ homepage_url = get_val ('maven_project_url' ),
565+ description = get_val ('maven_project_description' ),
566+ asserted_licenses = licenses ,
567+ authors = authors ,
568+ owners = orgs ,
551569 )
552570 return package
553571
@@ -556,6 +574,8 @@ class MavenRecognizer(object):
556574 """
557575 A package recognizer for Maven-based packages.
558576 """
577+ def __init__ (self ):
578+ return NotImplementedError ()
559579
560580 def recon (self , location ):
561581 for f in os .listdir (location ):
0 commit comments