Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scop/958364ff5bb7b725cc06 to your computer and use it in GitHub Desktop.
Save scop/958364ff5bb7b725cc06 to your computer and use it in GitHub Desktop.
From dea7efd630376d0d227841d20a2dfda2c1315675 Mon Sep 17 00:00:00 2001
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
Date: Fri, 19 Nov 2010 18:46:52 +0100
Subject: [PATCH] Add checking for correct pom file naming
---
FilesCheck.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/FilesCheck.py b/FilesCheck.py
index e8d6810..9860978 100644
--- a/FilesCheck.py
+++ b/FilesCheck.py
@@ -220,6 +220,8 @@ skipdocs_regex = re.compile(Config.getOption('SkipDocsRegexp', '\.(?:rtf|x?html?
meta_package_regex = re.compile(Config.getOption('MetaPackageRegexp', '^(bundle|task)-'))
filesys_packages = ['filesystem'] # TODO: make configurable?
quotes_regex = re.compile('[\'"]+')
+groupid_regex = re.compile(r'<groupId>(.*)</groupId>')
+artifactid_regex = re.compile(r'<artifactId>(.*)</artifactId>')
for idx in range(0, len(dangling_exceptions)):
dangling_exceptions[idx][0] = re.compile(dangling_exceptions[idx][0])
@@ -347,6 +349,33 @@ def python_bytecode_to_script(path):
return None
+def get_artifact_depmaps(fragments_file):
+ """Given path to maven depmap file if will return list of
+ tuples containing group and artifact IDs that should be
+ present in java/pom directory"""
+
+ groupIds = []
+ artifactIds = []
+ with open(fragments_file, 'r') as f:
+ for line in f:
+ gid = groupid_regex.search(line)
+ if gid:
+ groupIds.append(gid.group(1))
+ aid = artifactid_regex.search(line)
+ if aid:
+ artifactIds.append(aid.group(1))
+
+ if len(groupIds) != len(artifactIds) or len(groupIds) % 2 != 0:
+ return None
+
+ ret = []
+ # we expect Ids to always contain first maven then custom Id
+ # therefore add only even ids
+ for i in range(len(groupIds)):
+ if i % 2 == 1: # only add custom depmaps
+ ret.append((groupIds[i], artifactIds[i]))
+ return ret
+
class FilesCheck(AbstractCheck.AbstractCheck):
def __init__(self):
@@ -406,6 +435,12 @@ class FilesCheck(AbstractCheck.AbstractCheck):
# All man page "base" names (without section etc extensions)
man_basenames = set()
+ # List of all existing pom files
+ pom_files = []
+
+ # Pom files we expect to find
+ expected_poms = []
+
for f, pkgfile in files.items():
mode = pkgfile.mode
user = pkgfile.user
@@ -796,6 +831,15 @@ class FilesCheck(AbstractCheck.AbstractCheck):
if use_utf8 and not is_utf8(pkgfile.path):
printWarning(pkg, 'file-not-utf8', f)
+ if f.startswith('/etc/maven/fragments/'):
+ depmaps = get_artifact_depmaps(pkgfile.path)
+ for groupid, artifactid in depmaps:
+ groupid = groupid.replace('/','.')
+ pom_name = "%s-%s.pom" % (groupid, artifactid)
+ expected_poms.append(pom_name)
+ elif f.endswith('.pom'):
+ pom_files.append(os.path.basename(f))
+
# normal dir check
elif stat.S_ISDIR(mode):
if mode & 01002 == 2: # world writable without sticky bit
@@ -916,6 +960,10 @@ class FilesCheck(AbstractCheck.AbstractCheck):
if stat.S_IWGRP & mode or stat.S_IWOTH & mode:
printError(pkg, 'non-owner-writeable-only-crontab-file', f)
+ for pom in expected_poms:
+ if pom not in pom_files:
+ printWarning(pkg, 'pom-not-found', pom)
+
if log_file and not logrotate_file:
printWarning(pkg, 'log-files-without-logrotate', log_file)
@@ -1295,6 +1343,9 @@ It can cause problems when dirs in $PATH are reordered.''',
'manual-page-warning',
'''This man page may contain problems that can cause it not to be formatted
as intended.''',
+
+'pom-not-found',
+'''Expected pom file not found.''',
)
# FilesCheck.py ends here
--
1.7.3.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment