[java-sig-commits] [javapackages] Add maven and osgi provides generators.

Alexander Kurtakov akurtakov at fedoraproject.org
Mon Jun 6 05:59:52 UTC 2011


commit 2ba711f1b339136bcf42c3dd3a628ab00642dfe3
Author: Alexander Kurtakov <akurtako at redhat.com>
Date:   Mon Jun 6 08:58:46 2011 +0300

    Add maven and osgi provides generators.

 depgenerators/fileattrs/maven.attr |    3 +
 depgenerators/fileattrs/osgi.attr  |    3 +
 depgenerators/maven.prov           |   63 +++++++++++++++++++++++++++++
 depgenerators/osgi.prov            |   77 ++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+), 0 deletions(-)
---
diff --git a/depgenerators/fileattrs/maven.attr b/depgenerators/fileattrs/maven.attr
new file mode 100644
index 0000000..9964c69
--- /dev/null
+++ b/depgenerators/fileattrs/maven.attr
@@ -0,0 +1,3 @@
+%__maven_provides	%{_rpmconfigdir}/maven.prov
+%__maven_path	^%{_datadir}/maven2/.*\.pom
+
diff --git a/depgenerators/fileattrs/osgi.attr b/depgenerators/fileattrs/osgi.attr
new file mode 100644
index 0000000..78ae38b
--- /dev/null
+++ b/depgenerators/fileattrs/osgi.attr
@@ -0,0 +1,3 @@
+%__osgi_provides	%{_rpmconfigdir}/osgi.prov
+%__osgi_path	^.*\.jar
+
diff --git a/depgenerators/maven.prov b/depgenerators/maven.prov
new file mode 100644
index 0000000..d9ea469
--- /dev/null
+++ b/depgenerators/maven.prov
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+# Copyright (c) 2011, 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:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# * 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.
+# * Neither the name of the <ORGANIZATION> 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 REGENTS 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 REGENTS 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 at redhat.com>
+
+import sys
+import xml.etree.ElementTree as ET
+
+class TagBuilder:
+    mavenns = "{http://maven.apache.org/POM/4.0.0}"
+    
+    def __init__ (self, filelist=None):
+        if filelist == None:
+            filelist = sys.stdin
+        paths = map (lambda x: x.rstrip (), filelist.readlines ())
+        for path in paths:
+	        self.get_mvn_provide (path)
+	  
+    def get_mvn_provide (self, path):
+        doc = ET.parse(path)
+        artifactId = doc.getroot().findtext("%sartifactId"%(self.mavenns))
+        if artifactId is None:
+            artifactId = doc.getroot().findtext("artifactId")
+        if artifactId is None:
+            return
+        groupId = doc.getroot().findtext("%sgroupId"%(self.mavenns))
+        if groupId is None:
+            groupId = doc.getroot().findtext("groupId")
+        if groupId is None:
+            groupId = doc.getroot().findtext("%sparent/%sgroupId"%(self.mavenns, self.mavenns))
+        if groupId is None:
+            groupId = doc.getroot().findtext("parent/groupId")
+        if groupId is not None:
+            print "mvn(%s:%s)" %(groupId, artifactId)
+
+if __name__ == "__main__":
+    builder = TagBuilder ()
diff --git a/depgenerators/osgi.prov b/depgenerators/osgi.prov
new file mode 100644
index 0000000..9bb70de
--- /dev/null
+++ b/depgenerators/osgi.prov
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+
+# Copyright (c) 2011, 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:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# * 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.
+# * Neither the name of the <ORGANIZATION> 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 REGENTS 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 REGENTS 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 at redhat.com>
+
+import sys
+import os.path
+import zipfile
+from zipfile import ZipFile
+
+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):
+        if filelist == None:
+            filelist = sys.stdin
+        paths = map (lambda x: x.rstrip (), filelist.readlines ())
+        for path in paths:
+	        self.get_osgi_provide (path)
+	  
+    def get_osgi_provide (self, path):
+        if not os.path.islink(path):
+            if zipfile.is_zipfile(path):
+                jarfile = ZipFile(path)
+                manifest = jarfile.open("META-INF/MANIFEST.MF")
+                provideInfo = OsgiProvideInfo()
+                for line in manifest.readlines():
+                    if line.startswith("Bundle-SymbolicName:"):
+                        provideInfo.setSymbolicName(line.split(':')[1].strip())
+                    if line.startswith("Bundle-Version:"):
+                        provideInfo.setVersion(line.split(':')[1].strip())
+                provideInfo.printProvide()
+                    
+
+if __name__ == "__main__":
+    builder = TagBuilder ()


More information about the java-sig-commits mailing list