[javapackages] Check if manifest was successfully opened
by Michal Srb
commit 7786cdc9d70742a3a06cd0a68879607982e9d70e
Author: Michal Srb <msrb(a)redhat.com>
Date: Wed Jul 2 15:48:25 2014 +0200
Check if manifest was successfully opened
depgenerators/osgi.prov | 2 ++
depgenerators/osgi.req | 4 ++++
2 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/depgenerators/osgi.prov b/depgenerators/osgi.prov
index 4c7762d..aa16a77 100755
--- a/depgenerators/osgi.prov
+++ b/depgenerators/osgi.prov
@@ -42,6 +42,8 @@ class TagBuilder(object):
for path in paths:
if not os.path.islink(path):
manifest = osgi.open_manifest(path)
+ if not manifest:
+ continue
pinfo = osgi.OsgiProvideInfo.from_manifest(manifest)
pinfo.printProvide()
diff --git a/depgenerators/osgi.req b/depgenerators/osgi.req
index c4f07b0..3715f96 100755
--- a/depgenerators/osgi.req
+++ b/depgenerators/osgi.req
@@ -52,12 +52,16 @@ class TagBuilder(object):
fpath = os.path.abspath(os.path.join(dirpath, filename))
if _check_path(fpath):
manifest = osgi.open_manifest(fpath)
+ if not manifest:
+ continue
provided.append(osgi.OsgiProvideInfo.from_manifest(manifest))
# print requires
for path in paths:
if not os.path.islink(path):
manifest = osgi.open_manifest(path)
+ if not manifest:
+ continue
reqs = osgi.get_requires_from_manifest(manifest)
for bundle in reqs:
pinfo = osgi.OsgiProvideInfo(symbolicName=bundle)
9 years, 10 months
[javapackages] [osgi.req] Generate versioned requires on subpackages
by Michal Srb
commit 95b0d183f15c6343ca6409a60bd881324e848a0b
Author: Michal Srb <msrb(a)redhat.com>
Date: Wed Jul 2 15:45:31 2014 +0200
[osgi.req] Generate versioned requires on subpackages
depgenerators/osgi.req | 44 +++++++++++++++++++++++++++++------
python/javapackages/common/osgi.py | 11 ++++++++-
2 files changed, 46 insertions(+), 9 deletions(-)
---
diff --git a/depgenerators/osgi.req b/depgenerators/osgi.req
index ebbc916..c4f07b0 100755
--- a/depgenerators/osgi.req
+++ b/depgenerators/osgi.req
@@ -40,17 +40,45 @@ class TagBuilder(object):
if filelist == None:
filelist = sys.stdin
paths = [x.rstrip() for x in filelist.readlines()]
+ try:
+ buildroot = os.environ['RPM_BUILD_ROOT']
+ except KeyError:
+ raise Exception("RPM_BUILD_ROOT environment is not set")
+
+ # get all provided bundles
+ provided = []
+ for dirpath, _, filenames in os.walk(buildroot):
+ for filename in filenames:
+ fpath = os.path.abspath(os.path.join(dirpath, filename))
+ if _check_path(fpath):
+ manifest = osgi.open_manifest(fpath)
+ provided.append(osgi.OsgiProvideInfo.from_manifest(manifest))
+
+ # print requires
for path in paths:
if not os.path.islink(path):
manifest = osgi.open_manifest(path)
- print_requires(manifest)
-
-def print_requires(manifest):
- headers = osgi.parse_manifest(manifest)
- if headers.get("Require-Bundle"):
- for bundle in osgi.split_bundle_name(headers.get("Require-Bundle")):
- if bundle != "system.bundle":
- print "osgi(%s)" % (bundle)
+ reqs = osgi.get_requires_from_manifest(manifest)
+ for bundle in reqs:
+ pinfo = osgi.OsgiProvideInfo(symbolicName=bundle)
+ if pinfo in provided:
+ index = provided.index(pinfo)
+ print("osgi(%s) = %s" % (bundle, provided[index].version))
+ else:
+ print("osgi(%s)" % (bundle))
+
+
+def _check_path(path):
+ if path.endswith(".jar"):
+ return True
+ if path.endswith("/MANIFEST.MF"):
+ # who knows where the manifest can be in buildroot
+ # TODO: improve this check somehow(?)
+ # this is an attempt to identify only MANIFEST.MF files
+ # which are in %{_datadir} or %{_libdir}
+ if "/usr/share/" in path or "/usr/lib" in path:
+ return True
+ return False
if __name__ == "__main__":
diff --git a/python/javapackages/common/osgi.py b/python/javapackages/common/osgi.py
index 140dd28..ebe0833 100644
--- a/python/javapackages/common/osgi.py
+++ b/python/javapackages/common/osgi.py
@@ -31,7 +31,6 @@
#
# Authors: Alexander Kurtakov <akurtako(a)redhat.com>
-import os.path
import zipfile
from zipfile import ZipFile
@@ -125,3 +124,13 @@ def open_manifest(path):
except IOError:
pass
return None
+
+
+def get_requires_from_manifest(manifest):
+ reqs = []
+ headers = parse_manifest(manifest)
+ if headers.get("Require-Bundle"):
+ for bundle in split_bundle_name(headers.get("Require-Bundle")):
+ if bundle != "system.bundle":
+ reqs.append(bundle)
+ return reqs
9 years, 10 months
[javapackages] Move code shared between OSGi depgenerators to separate module
by Michal Srb
commit ac31a5c8e653e3ed5c81f54bb9ec4f2e4f423c0b
Author: Michal Srb <msrb(a)redhat.com>
Date: Wed Jul 2 10:07:07 2014 +0200
Move code shared between OSGi depgenerators to separate module
depgenerators/osgi.prov | 70 +++-----------------
depgenerators/osgi.req | 86 +++++--------------------
python/javapackages/common/osgi.py | 127 ++++++++++++++++++++++++++++++++++++
3 files changed, 153 insertions(+), 130 deletions(-)
---
diff --git a/depgenerators/osgi.prov b/depgenerators/osgi.prov
index 53b2cb4..4c7762d 100755
--- a/depgenerators/osgi.prov
+++ b/depgenerators/osgi.prov
@@ -30,71 +30,21 @@
#
# Authors: Alexander Kurtakov <akurtako(a)redhat.com>
+import javapackages.common.osgi as osgi
import sys
-import os.path
-import zipfile
-from zipfile import ZipFile
+import os
-class OsgiProvideInfo:
-
- symbolicName = None
- version = None
-
- def setSymbolicName(self, content):
- self.symbolicName = content.split(";")[0].strip()
-
- def setVersion(self, content):
- versions = content.split('.')[0:3]
- self.version = ".".join(versions)
-
- def printProvide(self):
- if self.version and self.symbolicName:
- print "osgi(%s) = %s" %(self.symbolicName, self.version)
-
-class TagBuilder:
-
- def __init__ (self, filelist=None):
+class TagBuilder(object):
+ def __init__(self, filelist=None):
if filelist == None:
filelist = sys.stdin
- paths = map (lambda x: x.rstrip (), filelist.readlines ())
+ paths = [x.rstrip() for x in filelist.readlines()]
for path in paths:
- self.get_osgi_provide (path)
-
- def normalize_manifest(self, manifest):
- lines = []
- for line in manifest.readlines():
- if line.startswith(' '):
- lines[-1] += line.strip()
- else:
- lines.append(line.strip())
- return lines
-
- def handle_manifest(self, manifest):
- provideInfo = OsgiProvideInfo()
- for line in self.normalize_manifest(manifest):
- if line.startswith("Bundle-SymbolicName:"):
- provideInfo.setSymbolicName(line.split(':')[1].strip())
- if line.startswith("Bundle-Version:"):
- provideInfo.setVersion(line.split(':')[1].strip())
-
- provideInfo.printProvide()
-
- def get_osgi_provide (self, path):
- if not os.path.islink(path):
- if path.endswith("META-INF/MANIFEST.MF"):
- manifest = open(path)
- self.handle_manifest(manifest)
- if zipfile.is_zipfile(path):
- # looks like "zipfile.is_zipfile()" is not reliable
- # see rhbz#889131 for more details
- try:
- jarfile = ZipFile(path)
- if "META-INF/MANIFEST.MF" in jarfile.namelist():
- manifest = jarfile.open("META-INF/MANIFEST.MF")
- self.handle_manifest(manifest)
- except IOError:
- pass
+ if not os.path.islink(path):
+ manifest = osgi.open_manifest(path)
+ pinfo = osgi.OsgiProvideInfo.from_manifest(manifest)
+ pinfo.printProvide()
if __name__ == "__main__":
- builder = TagBuilder ()
+ builder = TagBuilder()
diff --git a/depgenerators/osgi.req b/depgenerators/osgi.req
index 8d657db..ebbc916 100755
--- a/depgenerators/osgi.req
+++ b/depgenerators/osgi.req
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright (c) 2011, Red Hat, Inc
+# Copyright (c) 2014, Red Hat, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -30,82 +30,28 @@
#
# Authors: Alexander Kurtakov <akurtako(a)redhat.com>
+import javapackages.common.osgi as osgi
import sys
-import os.path
-import zipfile
-from zipfile import ZipFile
+import os
-class TagBuilder:
+class TagBuilder(object):
- def __init__ (self, filelist=None):
+ def __init__(self, filelist=None):
if filelist == None:
filelist = sys.stdin
- paths = map (lambda x: x.rstrip (), filelist.readlines ())
+ paths = [x.rstrip() for x in filelist.readlines()]
for path in paths:
- self.get_osgi_require (path)
+ if not os.path.islink(path):
+ manifest = osgi.open_manifest(path)
+ print_requires(manifest)
- def normalize_manifest(self, manifest):
- lines = []
- for line in manifest.readlines():
- if line.startswith(' '):
- lines[-1] += line.strip()
- else:
- lines.append(line.strip())
- return lines
+def print_requires(manifest):
+ headers = osgi.parse_manifest(manifest)
+ if headers.get("Require-Bundle"):
+ for bundle in osgi.split_bundle_name(headers.get("Require-Bundle")):
+ if bundle != "system.bundle":
+ print "osgi(%s)" % (bundle)
- def parse_manifest (self, manifest):
- headers = {}
- DELIM = ": "
- for line in self.normalize_manifest(manifest):
- split = line.split(DELIM)
- if len(split) > 1:
- name = split[0].strip()
- headers[name]= split[1].strip()
- return headers
-
- def split_bundle_name (self, bundles):
- bundlenames = []
- bundleline = ""
- for bundle in bundles.split(','):
- if not bundle:
- continue
- if "(" in bundle or "[" in bundle:
- bundleline = bundle
- continue
- if bundleline:
- bundle = bundleline + bundle
- if ":=optional" in bundle:
- bundleline = ""
- continue
- if ";" in bundle:
- bundlenames.append(bundle.split(";")[0].strip())
- else:
- bundlenames.append(bundle.strip())
- bundleline = ""
- return bundlenames
-
- def print_requires (self, manifest):
- headers = self.parse_manifest(manifest)
- if headers.get("Require-Bundle"):
- for bundle in self.split_bundle_name(headers.get("Require-Bundle")):
- if bundle != "system.bundle":
- print "osgi(%s)" %(bundle)
-
- def get_osgi_require (self, path):
- if not os.path.islink(path):
- if path.endswith("META-INF/MANIFEST.MF"):
- manifest = open(path)
- self.print_requires(manifest)
- if zipfile.is_zipfile(path):
- # looks like "zipfile.is_zipfile()" is not reliable
- # see rhbz#889131 for more details
- try:
- jarfile = ZipFile(path)
- if "META-INF/MANIFEST.MF" in jarfile.namelist():
- manifest = jarfile.open("META-INF/MANIFEST.MF")
- self.print_requires(manifest)
- except IOError:
- pass
if __name__ == "__main__":
- builder = TagBuilder ()
+ builder = TagBuilder()
diff --git a/python/javapackages/common/osgi.py b/python/javapackages/common/osgi.py
new file mode 100644
index 0000000..140dd28
--- /dev/null
+++ b/python/javapackages/common/osgi.py
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+# Copyright (c) 2014, Red Hat, Inc.
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name of the Red Hat nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Alexander Kurtakov <akurtako(a)redhat.com>
+
+import os.path
+import zipfile
+from zipfile import ZipFile
+
+
+class OsgiProvideInfo:
+ def __init__(self, symbolicName=None, version=None):
+ self.symbolicName = symbolicName
+ self.version = version
+
+ def printProvide(self):
+ if self.version and self.symbolicName:
+ print("osgi(%s) = %s" % (self.symbolicName, self.version))
+
+ def __cmp__(self, other):
+ if isinstance(other, OsgiProvideInfo):
+ if self.symbolicName == other.symbolicName:
+ return 0
+ return -1
+
+ def __str__(self):
+ return "osgi(%s) = %s" % (self.symbolicName, self.version)
+
+ @classmethod
+ def from_manifest(cls, manifest):
+ symbolicName = None
+ version = None
+ for line in normalize_manifest(manifest):
+ if line.startswith("Bundle-SymbolicName:"):
+ symbolicName = line.split(':')[1].strip()
+ symbolicName = symbolicName.split(";")[0].strip()
+ if line.startswith("Bundle-Version:"):
+ versions = line.split(':')[1].strip()
+ versions = versions.split('.')[0:3]
+ version = ".".join(versions)
+ return cls(symbolicName=symbolicName, version=version)
+
+
+def normalize_manifest(manifest):
+ lines = []
+ for line in manifest.readlines():
+ if line.startswith(' '):
+ lines[-1] += line.strip()
+ else:
+ lines.append(line.strip())
+ return lines
+
+
+def parse_manifest(manifest):
+ headers = {}
+ DELIM = ": "
+ for line in normalize_manifest(manifest):
+ split = line.split(DELIM)
+ if len(split) > 1:
+ name = split[0].strip()
+ headers[name] = split[1].strip()
+ return headers
+
+
+def split_bundle_name(bundles):
+ bundlenames = []
+ bundleline = ""
+ for bundle in bundles.split(','):
+ if not bundle:
+ continue
+ if "(" in bundle or "[" in bundle:
+ bundleline = bundle
+ continue
+ if bundleline:
+ bundle = bundleline + bundle
+ if ":=optional" in bundle:
+ bundleline = ""
+ continue
+ if ";" in bundle:
+ bundlenames.append(bundle.split(";")[0].strip())
+ else:
+ bundlenames.append(bundle.strip())
+ bundleline = ""
+ return bundlenames
+
+
+def open_manifest(path):
+ if path.endswith("META-INF/MANIFEST.MF"):
+ return open(path)
+ if zipfile.is_zipfile(path):
+ # looks like "zipfile.is_zipfile()" is not reliable
+ # see rhbz#889131 for more details
+ try:
+ jarfile = ZipFile(path)
+ if "META-INF/MANIFEST.MF" in jarfile.namelist():
+ return jarfile.open("META-INF/MANIFEST.MF")
+ except IOError:
+ pass
+ return None
9 years, 10 months
[javapackages: 5/5] Merge branch 'pom_xpath_disable'
by Michael Šimáček
commit 42536b99f19153d305b86da16a81d33d3c62b734
Merge: f5f02e4 a92512c
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Tue Jul 1 16:56:25 2014 +0200
Merge branch 'pom_xpath_disable'
java-utils/pom_editor.py | 54 ++++++++++++++++++++++++++++-----------
macros.d/macros.fjava | 2 +
test/pom_editor_modules_test.py | 17 ++++++++++++
test/pom_editor_paths_test.py | 2 +-
4 files changed, 59 insertions(+), 16 deletions(-)
---
9 years, 10 months
[javapackages] (5 commits) ...Merge branch 'pom_xpath_disable'
by Michael Šimáček
Summary of changes:
bca5719... Generalize submodule traversal (*)
c3d8f72... Implement pom_xpath_disable macro (*)
144a7bd... Basic test for pom_xpath_disable (*)
a92512c... Finish the pom_xpath_disable macro implementation (*)
42536b9... Merge branch 'pom_xpath_disable'
(*) This commit already existed in another branch; no separate mail sent
9 years, 10 months