3dd908
From 6405dfa42ff8d12fb6f810041aa89243f6ae7433 Mon Sep 17 00:00:00 2001
3dd908
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
3dd908
Date: Wed, 4 Dec 2013 17:47:06 +0100
fcb490
Subject: [PATCH 1/3] Support absolute symlinks in SCLs in mvn_file
fcb490
 (rhbz#1038553)
3dd908
3dd908
---
3dd908
 java-utils/mvn_file.py                 | 11 +++++------
3dd908
 python/javapackages/xmvn_config.py     | 10 ++++++----
3dd908
 test/data/mvn_file/absolute1_00001.xml |  3 ++-
3dd908
 test/mvn_file_test.py                  | 27 +++++----------------------
3dd908
 4 files changed, 18 insertions(+), 33 deletions(-)
3dd908
3dd908
diff --git a/java-utils/mvn_file.py b/java-utils/mvn_file.py
3dd908
index e059129..c59ed6c 100644
3dd908
--- a/java-utils/mvn_file.py
3dd908
+++ b/java-utils/mvn_file.py
3dd908
@@ -35,7 +35,7 @@ import sys
3dd908
 
3dd908
 from javapackages.artifact import (Artifact, ArtifactFormatException,
3dd908
                                    ArtifactValidationException)
3dd908
-from javapackages.xmvn_config import XMvnConfig
3dd908
+from javapackages.xmvn_config import XMvnConfig, XMvnConfigException
3dd908
 
3dd908
 class SaneParser(optparse.OptionParser):
3dd908
     def format_epilog(self, formatter):
3dd908
@@ -61,10 +61,6 @@ commons-lang:commons-lang:war:test-jar:3.1
3dd908
 if __name__ == "__main__":
3dd908
     parser = SaneParser(usage=usage,
3dd908
                         epilog=epilog)
3dd908
-    parser.add_option("-p", "--prefix",
3dd908
-                      help="Set prefix for converting absolute paths to "+
3dd908
-                           "relative",
3dd908
-                      default="/usr/share/java")
3dd908
     for index, arg in enumerate(sys.argv):
3dd908
         sys.argv[index] = arg.decode(sys.getfilesystemencoding())
3dd908
 
3dd908
@@ -75,8 +71,11 @@ if __name__ == "__main__":
3dd908
     try:
3dd908
         orig = Artifact.from_mvn_str(args[0])
3dd908
         orig.validate(allow_backref=False)
3dd908
-        XMvnConfig().add_file_mapping(orig, args[1:], options.prefix)
3dd908
+        XMvnConfig().add_file_mapping(orig, args[1:])
3dd908
     except (ArtifactValidationException, ArtifactFormatException), e:
3dd908
         parser.error("{e}: Provided artifact strings were invalid. "
3dd908
                      "Please see help  and check your arguments".format(e=e))
3dd908
         sys.exit(1)
3dd908
+    except XMvnConfigException, e:
3dd908
+        parser.error("Incorrect configuration: {e}".format(e=e))
3dd908
+        sys.exit(1)
3dd908
diff --git a/python/javapackages/xmvn_config.py b/python/javapackages/xmvn_config.py
3dd908
index 838bde9..da22f0b 100644
3dd908
--- a/python/javapackages/xmvn_config.py
3dd908
+++ b/python/javapackages/xmvn_config.py
3dd908
@@ -43,6 +43,9 @@ from lxml.etree import ElementTree, Element, SubElement
3dd908
 
3dd908
 from javapackages.artifact import ArtifactValidationException
3dd908
 
3dd908
+class XMvnConfigException(Exception):
3dd908
+    pass
3dd908
+
3dd908
 class XMvnConfig(object):
3dd908
     """
3dd908
     Class for modifying XMvn configuration
3dd908
@@ -205,7 +208,7 @@ class XMvnConfig(object):
3dd908
         elems.append(velem)
3dd908
         self.__add_config("artifactManagement", "rule", content=elems)
3dd908
 
3dd908
-    def add_file_mapping(self, artifact, paths, prefix="/"):
3dd908
+    def add_file_mapping(self, artifact, paths):
3dd908
         """
3dd908
         Change where on filesystem given artifact is installed
3dd908
 
3dd908
@@ -217,6 +220,8 @@ class XMvnConfig(object):
3dd908
         main = artifact.get_xml_element(root="artifactGlob")
3dd908
         elems = [main]
3dd908
         felem = Element("files")
3dd908
+        if not [path for path in paths if not os.path.isabs(path)]:
3dd908
+            raise XMvnConfigException("At least one path must be relative")
3dd908
         for path in paths:
3dd908
             backrefs = self.__count_backreferences(path)
3dd908
             if backrefs > wild_groups:
3dd908
@@ -224,9 +229,6 @@ class XMvnConfig(object):
3dd908
                                                   "is higher than wildcard "
3dd908
                                                   "groups.")
3dd908
             pe = SubElement(felem, "file")
3dd908
-
3dd908
-            if os.path.isabs(path):
3dd908
-                path = os.path.relpath(path, prefix)
3dd908
             pe.text = path
3dd908
         elems.append(felem)
3dd908
         self.__add_config("artifactManagement", "rule", content=elems)
3dd908
diff --git a/test/data/mvn_file/absolute1_00001.xml b/test/data/mvn_file/absolute1_00001.xml
3dd908
index 82aeba1..2a56449 100644
3dd908
--- a/test/data/mvn_file/absolute1_00001.xml
3dd908
+++ b/test/data/mvn_file/absolute1_00001.xml
3dd908
@@ -11,7 +11,8 @@
3dd908
 	<groupId>a</groupId>
3dd908
       </artifactGlob>
3dd908
       <files>
3dd908
-	<file>sym</file>
3dd908
+        <file>file</file>
3dd908
+        <file>/usr/share/java/sym</file>
3dd908
       </files>
3dd908
     </rule>
3dd908
   </artifactManagement>
3dd908
diff --git a/test/mvn_file_test.py b/test/mvn_file_test.py
3dd908
index 09a2648..4792497 100644
3dd908
--- a/test/mvn_file_test.py
3dd908
+++ b/test/mvn_file_test.py
3dd908
@@ -234,7 +234,7 @@ class TestMvnFile(unittest.TestCase):
3dd908
                  ['artifactGlob'])
3dd908
             self.assertFalse(report, '\n' + report)
3dd908
 
3dd908
-    @xmvnconfig('mvn_file',['a:b', '/usr/share/java/sym', ])
3dd908
+    @xmvnconfig('mvn_file',['a:b', 'file', '/usr/share/java/sym'])
3dd908
     def test_absolute1(self, stdout, stderr, return_value):
3dd908
         self.assertEquals(return_value, 0)
3dd908
         filelist = get_config_file_list()
3dd908
@@ -245,27 +245,10 @@ class TestMvnFile(unittest.TestCase):
3dd908
                  ['artifactGlob'])
3dd908
             self.assertFalse(report, '\n' + report)
3dd908
 
3dd908
-    @xmvnconfig('mvn_file',['-p', '/usr/share/', 'a:b', '/usr/share/sym', ])
3dd908
-    def test_prefix1(self, stdout, stderr, return_value):
3dd908
-        self.assertEquals(return_value, 0)
3dd908
-        filelist = get_config_file_list()
3dd908
-        self.assertEquals(len(filelist), 1)
3dd908
-        for filename in filelist:
3dd908
-            report = compare_xml_files(get_actual_config(filename),
3dd908
-                 get_expected_config(filename, 'mvn_file', 'prefix1'),
3dd908
-                 ['artifactGlob'])
3dd908
-            self.assertFalse(report, '\n' + report)
3dd908
-
3dd908
-    @xmvnconfig('mvn_file',['-p', '/usr', 'a:b', '/usr/share/sym', ])
3dd908
-    def test_prefix2(self, stdout, stderr, return_value):
3dd908
-        self.assertEquals(return_value, 0)
3dd908
-        filelist = get_config_file_list()
3dd908
-        self.assertEquals(len(filelist), 1)
3dd908
-        for filename in filelist:
3dd908
-            report = compare_xml_files(get_actual_config(filename),
3dd908
-                 get_expected_config(filename, 'mvn_file', 'prefix2'),
3dd908
-                 ['artifactGlob'])
3dd908
-            self.assertFalse(report, '\n' + report)
3dd908
+    @xmvnconfig('mvn_file',['a:b', '/usr/share/java/sym', ])
3dd908
+    def test_absolute2(self, stdout, stderr, return_value):
3dd908
+        self.assertNotEqual(return_value, 0)
3dd908
+        self.assertTrue(stderr)
3dd908
 
3dd908
 if __name__ == '__main__':
3dd908
     unittest.main()
3dd908
-- 
fcb490
1.9.0
3dd908