track pom files in the database
This commit is contained in:
parent
5d59b35ba9
commit
0ab3e4e541
4 changed files with 62 additions and 30 deletions
23
cli/koji
23
cli/koji
|
|
@ -1684,8 +1684,8 @@ def handle_import_archive(options, session, args):
|
|||
parser.add_option("--pom", help=_("POM file to use when auto-creating a Maven build"), metavar="FILE")
|
||||
(suboptions, args) = parser.parse_args(args)
|
||||
|
||||
if not len(args) > 1:
|
||||
parser.error(_("You must specify a build ID or N-V-R and the path to the archive to import"))
|
||||
if not len(args) > 0:
|
||||
parser.error(_("You must specify a build ID or N-V-R"))
|
||||
assert False
|
||||
|
||||
activate_session(session)
|
||||
|
|
@ -1698,21 +1698,22 @@ def handle_import_archive(options, session, args):
|
|||
|
||||
buildinfo = session.getBuild(arg_filter(args[0]))
|
||||
if not buildinfo:
|
||||
if not suboptions.create_build:
|
||||
if suboptions.create_build:
|
||||
needs_create = True
|
||||
else:
|
||||
print _("Could not find information for build: %s" % args[0])
|
||||
return 1
|
||||
else:
|
||||
needs_create = True
|
||||
|
||||
maveninfo = None
|
||||
if buildinfo:
|
||||
maveninfo = session.getMavenBuild(buildinfo)
|
||||
if suboptions.pom and not maveninfo:
|
||||
if not suboptions.create_build:
|
||||
print _("Could not find Maven information for build: %s" % args[0])
|
||||
return 1
|
||||
else:
|
||||
needs_create = True
|
||||
if not maveninfo:
|
||||
if suboptions.pom:
|
||||
if not suboptions.create_build:
|
||||
print _("Could not find Maven information for build: %s" % args[0])
|
||||
return 1
|
||||
else:
|
||||
needs_create = True
|
||||
|
||||
if needs_create:
|
||||
if not buildinfo:
|
||||
|
|
|
|||
|
|
@ -627,6 +627,7 @@ CREATE TABLE archivetypes (
|
|||
) WITHOUT OIDS;
|
||||
|
||||
insert into archivetypes (name, description, extensions) values ('zip', 'Zip archives, including jars', 'zip jar war rar ear');
|
||||
insert into archivetypes (name, description, extensions) values ('pom', 'Maven Project Object Management files', 'pom');
|
||||
|
||||
-- Do we want to enforce a constraint that a build can only generate one
|
||||
-- archive with a given name?
|
||||
|
|
|
|||
|
|
@ -3442,12 +3442,7 @@ def new_maven_build(build, pom_path):
|
|||
insert = """INSERT INTO maven_builds (build_id, group_id, artifact_id, version)
|
||||
VALUES (%(build_id)i, %(group_id)s, %(artifact_id)s, %(version)s)"""
|
||||
_dml(insert, locals())
|
||||
maveninfo = {'build_id': build_id,
|
||||
'group_id': group_id, 'artifact_id': artifact_id,
|
||||
'version': version}
|
||||
mavendir = koji.pathinfo.mavenbuild(build, maveninfo)
|
||||
_import_archive_file(pom, mavendir)
|
||||
_generate_maven_metadata(maveninfo, mavendir)
|
||||
import_archive(pom, build)
|
||||
|
||||
def import_archive(filepath, buildinfo, buildroot_id=None):
|
||||
"""
|
||||
|
|
@ -3498,11 +3493,25 @@ def import_archive(filepath, buildinfo, buildroot_id=None):
|
|||
koji.ensuredir(mavendir)
|
||||
if pom:
|
||||
pomname = '%(artifact_id)s-%(version)s.pom' % maveninfo
|
||||
pompath = '%s/%s' % (mavendir, pomname)
|
||||
if not os.path.exists(pompath):
|
||||
pomfile = file(pompath, 'w')
|
||||
pomfile.write(pom)
|
||||
pomfile.close()
|
||||
tmpdir = koji.pathinfo.tmpdir()
|
||||
koji.ensuredir(tmpdir)
|
||||
pompath = '%s/%s' % (tmpdir, pomname)
|
||||
pomfile = file(pompath, 'w')
|
||||
pomfile.write(pom)
|
||||
pomfile.close()
|
||||
# recursively call import_archive to import the .pom information
|
||||
import_archive(pompath, buildinfo, buildroot_id)
|
||||
_import_archive_file(filepath, mavendir)
|
||||
_generate_maven_metadata(maveninfo, mavendir)
|
||||
elif archivetype['name'] == 'pom':
|
||||
pomfile = file(filepath, 'r')
|
||||
pomdata = pomfile.read()
|
||||
pomfile.close()
|
||||
pom_info = _insert_maven_archive(archive_id, pomdata)
|
||||
maveninfo = {'group_id': pom_info['groupId'],
|
||||
'artifact_id': pom_info['artifactId'],
|
||||
'version': pom_info['version']}
|
||||
mavendir = koji.pathinfo.mavenbuild(buildinfo, maveninfo)
|
||||
_import_archive_file(filepath, mavendir)
|
||||
_generate_maven_metadata(maveninfo, mavendir)
|
||||
else:
|
||||
|
|
@ -3515,6 +3524,17 @@ def import_archive(filepath, buildinfo, buildroot_id=None):
|
|||
else:
|
||||
raise koji.GenericError, 'unsupported archive type: %s' % archivetype['name']
|
||||
|
||||
def _insert_maven_archive(archive_id, pomdata):
|
||||
"""Parse the pomdata and associate it with the given archive"""
|
||||
pom_info = koji.parse_pom(contents=pomdata)
|
||||
group_id = pom_info['groupId']
|
||||
artifact_id = pom_info['artifactId']
|
||||
version = pom_info['version']
|
||||
insert = """INSERT INTO maven_archives (archive_id, group_id, artifact_id, version)
|
||||
VALUES (%(archive_id)i, %(group_id)s, %(artifact_id)s, %(version)s)"""
|
||||
_dml(insert, locals())
|
||||
return pom_info
|
||||
|
||||
def import_maven_archive(archive_id, filepath, buildinfo, maveninfo):
|
||||
"""
|
||||
Import information about the file entries in the zip file.
|
||||
|
|
@ -3525,14 +3545,7 @@ def import_maven_archive(archive_id, filepath, buildinfo, maveninfo):
|
|||
pom_info = None
|
||||
if pom:
|
||||
# Some Maven-generated jars will not contain a pom.xml file (like -source and -javadoc jars)
|
||||
pom_info = koji.parse_pom(contents=pom)
|
||||
group_id = pom_info['groupId']
|
||||
artifact_id = pom_info['artifactId']
|
||||
version = pom_info['version']
|
||||
insert = """INSERT INTO maven_archives (archive_id, group_id, artifact_id, version)
|
||||
VALUES (%(archive_id)i, %(group_id)s, %(artifact_id)s, %(version)s)"""
|
||||
_dml(insert, locals())
|
||||
|
||||
pom_info = _insert_maven_archive(archive_id, pom)
|
||||
import_zip_archive(archive_id, filepath, buildinfo)
|
||||
|
||||
return pom, pom_info
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import md5
|
|||
import os
|
||||
import os.path
|
||||
import pwd
|
||||
import random
|
||||
import re
|
||||
import rpm
|
||||
import signal
|
||||
|
|
@ -802,6 +803,13 @@ def pom_to_nvr(pominfo):
|
|||
'epoch': None}
|
||||
return nvr
|
||||
|
||||
def mavenLabel(maveninfo):
|
||||
"""
|
||||
Return a user-friendly label for the given maveninfo. maveninfo is
|
||||
a dict as returned by kojihub:getMavenBuild().
|
||||
"""
|
||||
return '%(group_id)s-%(artifact_id)s-%(version)s' % maveninfo
|
||||
|
||||
def hex_string(s):
|
||||
"""Converts a string to a string of hex digits"""
|
||||
return ''.join([ '%02x' % ord(x) for x in s ])
|
||||
|
|
@ -1113,6 +1121,8 @@ def openRemoteFile(relpath, topurl=None, topdir=None):
|
|||
|
||||
|
||||
class PathInfo(object):
|
||||
# ASCII numbers and upper- and lower-case letter for use in tmpdir()
|
||||
ASCII_CHARS = [chr(i) for i in range(48, 58) + range(65, 91) + range(97, 123)]
|
||||
|
||||
def __init__(self,topdir=None):
|
||||
if topdir is None:
|
||||
|
|
@ -1163,6 +1173,13 @@ class PathInfo(object):
|
|||
"""Return the work dir"""
|
||||
return self.topdir + '/work'
|
||||
|
||||
def tmpdir(self):
|
||||
"""Return a path to a unique directory under work()/tmp/"""
|
||||
tmp = None
|
||||
while tmp is None or os.path.exists(tmp):
|
||||
tmp = self.work() + '/tmp/' + ''.join([random.choice(self.ASCII_CHARS) for dummy in '123456'])
|
||||
return tmp
|
||||
|
||||
def scratch(self):
|
||||
"""Return the main scratch dir"""
|
||||
return self.topdir + '/scratch'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue