示例#1
0
    def test_merge5(self):
        a = Artifact.from_mvn_str("g1:a1:war::")
        b = Artifact.from_mvn_str("g1:a1:v1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "war")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")
示例#2
0
    def test_merge3(self):
        # different artifacts won't be merged
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g2:a2:e2::")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")
示例#3
0
 def test_from_mvn_str_gac(self):
     a = Artifact.from_mvn_str("g:a::c:")
     self.assertEqual(a.groupId, "g")
     self.assertEqual(a.artifactId, "a")
     self.assertEqual(a.extension, "jar")
     self.assertEqual(a.classifier, "c")
     self.assertEqual(a.version, "")
示例#4
0
 def test_from_mvn_str_full(self):
     a = Artifact.from_mvn_str("g:a:e:c:v")
     self.assertEqual(a.groupId, "g")
     self.assertEqual(a.artifactId, "a")
     self.assertEqual(a.extension, "e")
     self.assertEqual(a.classifier, "c")
     self.assertEqual(a.version, "v")
示例#5
0
    def from_mvn_str(cls, mvn_str):
        a = Artifact.from_mvn_str(mvn_str)

        return cls(a.groupId,
                   a.artifactId,
                   extension=a.extension,
                   classifier=a.classifier)
示例#6
0
 def test_from_xml_whitespace(self, doc):
     a = Artifact.from_xml_element(doc)
     self.assertEqual(a.groupId, "g")
     self.assertEqual(a.artifactId, "a")
     self.assertEqual(a.extension, "e")
     self.assertEqual(a.classifier, "c")
     self.assertEqual(a.version, "v")
示例#7
0
 def test_from_xml_gav(self, doc):
     a = Artifact.from_xml_element(doc)
     self.assertEqual(a.groupId, "g")
     self.assertEqual(a.artifactId, "a")
     self.assertEqual(a.extension, "jar")
     self.assertEqual(a.classifier, "")
     self.assertEqual(a.version, "v")
示例#8
0
def install_maven_artifact(artifact_spec):
    artifact = Artifact.from_mvn_str(artifact_spec)
    try:
        install_artifact(artifact.get_rpm_str(compat_ver=artifact.version))
    except InstallationException:
        if not artifact.version:
            raise
        install_artifact(artifact.get_rpm_str())
示例#9
0
 def setUp(self):
     # intentional whitespaces
     self.gaArtifact = Artifact(' g', ' a')
     self.gavArtifact = Artifact(' g', ' a', ' ', ' ', ' v')
     self.gaeArtifact = Artifact(' g', ' a', 'e')
     self.gacArtifact = Artifact(' g', ' a', ' ', ' c')
     self.gaevArtifact = Artifact(' g', 'a', ' e', ' ', ' v')
     self.gacvArtifact = Artifact(' g', 'a', ' ', 'c', ' v')
     self.fullArtifact = Artifact(' g', ' a', ' e', ' c', ' v')
示例#10
0
    def test_interpolation2(self):
        a = Artifact.from_mvn_str("${gid}:a1:${v.major}.${v.minor}")
        props = {"gid": "g1", "v.major": "4", "v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 0)
        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "4.11")
示例#11
0
    def test_interpolation3(self):
        a = Artifact.from_mvn_str("${gid}:a1")
        props = {"v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 1)
        self.assertEqual(res[0], "gid")
        self.assertEqual(a.groupId, "${gid}")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")
示例#12
0
文件: maven.py 项目: timhughes/rpg
 def compiled(self, project_dir, spec, sack):
     if(project_dir / ".xmvn-builddep").is_file():
         try:
             et = etree.parse(str(project_dir / ".xmvn-builddep")).getroot()
             deps = et.findall('./dependency')
             for dep in deps:
                 art = Artifact.from_xml_element(dep)
                 spec.BuildRequires.add(art.get_rpm_str(art.version))
         except (ArtifactValidationException,
                 ArtifactFormatException) as e:
             logging.warning("Exception during maven dependency generation"
                             "{e}: Provided artifact strings were invalid."
                             .format(e=e))
             return
示例#13
0
 def compiled(self, project_dir, spec, sack):
     """ After generation of dependencies (build) parses builddep file
         and creates Maven project build dependencies """
     if (project_dir / ".xmvn-builddep").is_file():
         try:
             et = etree.parse(str(project_dir / ".xmvn-builddep")).getroot()
             deps = et.findall('./dependency')
             for dep in deps:
                 art = Artifact.from_xml_element(dep)
                 if sack.query().filter(
                         provides=art.get_rpm_str(art.version)):
                     spec.BuildRequires.add(art.get_rpm_str(art.version))
         except (ArtifactValidationException, ArtifactFormatException) as e:
             logging.warning(
                 "Exception during maven dependency generation"
                 "{e}: Provided artifact strings were invalid.".format(e=e))
             return
示例#14
0
    def from_mvn_str(cls, mvn_str):
        a = Artifact.from_mvn_str(mvn_str)

        return cls(a.groupId, a.artifactId, extension=a.extension,
                   classifier=a.classifier, requestedVersion=a.version)
示例#15
0
commons-lang:commons-lang:1.2
commons-lang:commons-lang:war:
commons-lang:commons-lang:war:test-jar:
commons-lang:commons-lang:war:test-jar:3.1
*:commons-lang (equivalent to ':commons-lang')
"""

if __name__ == "__main__":
    parser = SaneParser(usage=usage,
                        epilog=epilog)
    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.error("At least one argument required")
    elif len(args) > 2:
        parser.error("At most 2 arguments are expected")
    elif len(args) == 1:
        args.append("__default")

    try:
        orig = Artifact.from_mvn_str(args[0])
        XMvnConfig().add_package_mapping(orig, args[1])
    except (ArtifactValidationException, ArtifactFormatException) as e:
        parser.error("{e}: Provided artifact strings were invalid. "
                     "Please see help  and check your arguments".format(e=e))
        sys.exit(1)
    except JavaPackagesToolsException as e:
        sys.exit(e)
示例#16
0
class TestArtifact(unittest.TestCase):
    def setUp(self):
        # intentional whitespaces
        self.gaArtifact = Artifact(' g', ' a')
        self.gavArtifact = Artifact(' g', ' a', ' ', ' ', ' v')
        self.gaeArtifact = Artifact(' g', ' a', 'e')
        self.gacArtifact = Artifact(' g', ' a', ' ', ' c')
        self.gaevArtifact = Artifact(' g', 'a', ' e', ' ', ' v')
        self.gacvArtifact = Artifact(' g', 'a', ' ', 'c', ' v')
        self.fullArtifact = Artifact(' g', ' a', ' e', ' c', ' v')

    def test_artifact_init(self):
        a = self.gaArtifact
        self.assertEqual(a.groupId, 'g')
        self.assertEqual(a.artifactId, 'a')
        self.assertEqual(a.classifier, '')
        self.assertEqual(a.extension, 'jar')
        self.assertEqual(a.version, '')

        a = self.fullArtifact
        self.assertEqual(a.groupId, 'g')
        self.assertEqual(a.artifactId, 'a')
        self.assertEqual(a.classifier, 'c')
        self.assertEqual(a.extension, 'e')
        self.assertEqual(a.version, 'v')

    def test_str(self):
        self.assertEqual(str(self.gaArtifact), "g:a")
        self.assertEqual(str(self.gavArtifact), "g:a:v")
        self.assertEqual(str(self.gacArtifact), "g:a::c:")
        self.assertEqual(str(self.gacvArtifact), "g:a::c:v")
        self.assertEqual(str(self.fullArtifact), "g:a:e:c:v")

    def test_rpm_str(self):
        self.assertEqual(self.gaArtifact.get_rpm_str(), "mvn(g:a)")
        self.assertEqual(self.gavArtifact.get_rpm_str(), "mvn(g:a)")
        self.assertEqual(self.gacArtifact.get_rpm_str(), "mvn(g:a::c:)")
        self.assertEqual(self.gacvArtifact.get_rpm_str(), "mvn(g:a::c:)")
        self.assertEqual(self.gaeArtifact.get_rpm_str(), "mvn(g:a:e:)")
        self.assertEqual(self.gaevArtifact.get_rpm_str(), "mvn(g:a:e:)")
        self.assertEqual(self.fullArtifact.get_rpm_str(), "mvn(g:a:e:c:)")

    def test_xml_str_ga(self):
        doc = fromstring(self.gaArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertEqual(item, None)
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 2)

    def test_xml_str_gae(self):
        doc = fromstring(self.gaeArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 3)

    def test_xml_str_gac(self):
        doc = fromstring(self.gacArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 4)

    def test_xml_str_gav(self):
        doc = fromstring(self.gavArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 4)

    def test_xml_str_gaev(self):
        doc = fromstring(self.gaevArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 4)

    def test_xml_str_gacv(self):
        doc = fromstring(self.gacvArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 5)

    def test_xml_str_full(self):
        doc = fromstring(self.fullArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 5)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-empty.xml")
    def test_from_xml_empty(self, doc):
        Artifact.from_xml_element(doc)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-nog.xml")
    def test_from_xml_nog(self, doc):
        Artifact.from_xml_element(doc)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-noa.xml")
    def test_from_xml_noa(self, doc):
        Artifact.from_xml_element(doc)

    @artifactfile("artifactga.xml")
    def test_from_xml_ga(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    @artifactfile("artifactgav.xml")
    def test_from_xml_gav(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    @artifactfile("artifactfull.xml")
    def test_from_xml_full(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    @artifactfile("artifact-whitespace.xml")
    def test_from_xml_whitespace(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_ga(self):
        a = Artifact.from_mvn_str("g:a")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gav(self):
        a = Artifact.from_mvn_str("g:a:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gae(self):
        a = Artifact.from_mvn_str("g:a:e:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gaev(self):
        a = Artifact.from_mvn_str("g:a:e:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gac(self):
        a = Artifact.from_mvn_str("g:a::c:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gacv(self):
        a = Artifact.from_mvn_str("g:a::c:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gaec(self):
        a = Artifact.from_mvn_str("g:a:e:c:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_full(self):
        a = Artifact.from_mvn_str("g:a:e:c:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_merge1(self):
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g1:a1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge2(self):
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g1:a1:v2")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge3(self):
        # different artifacts won't be merged
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g2:a2:e2::")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge4(self):
        a = Artifact.from_mvn_str("g1:a1")
        b = Artifact.from_mvn_str("g1:a1:v1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge5(self):
        a = Artifact.from_mvn_str("g1:a1:war::")
        b = Artifact.from_mvn_str("g1:a1:v1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "war")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_interpolation1(self):
        a = Artifact.from_mvn_str("${gid}:a1")
        props = {"gid": "g1"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 0)
        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_interpolation2(self):
        a = Artifact.from_mvn_str("${gid}:a1:${v.major}.${v.minor}")
        props = {"gid": "g1", "v.major": "4", "v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 0)
        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "4.11")

    def test_interpolation3(self):
        a = Artifact.from_mvn_str("${gid}:a1")
        props = {"v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 1)
        self.assertEqual(res[0], "gid")
        self.assertEqual(a.groupId, "${gid}")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")
示例#17
0
            pass
        elif options.xmvn_javadoc:
            mvn_args.append("org.fedoraproject.xmvn:xmvn-mojo:javadoc")
        else:
            mvn_args.append("org.apache.maven.plugins:maven-javadoc-plugin:aggregate")

    if not options.gradle:
        # Build dependency generation for Gradle is not yet implemented in XMvn
        mvn_args.append("org.fedoraproject.xmvn:xmvn-mojo:builddep")

    if options.goal_after:
        mvn_args.extend(options.goal_after)

    if options.singleton:
        # make sure we don't install artifacts with non-empty classifiers
        xc.add_package_mapping(Artifact.from_mvn_str(":::*?:"), "__noinstall",
                               optional=True)
        xc.add_package_mapping(Artifact.from_mvn_str(":{*}"), "@1")

    print("Executing:", " ".join(mvn_args), file=sys.stderr)
    print(mvn_args, file=sys.stderr)
    sys.stderr.flush()
    p = subprocess.Popen(" ".join(mvn_args), shell=True, env=os.environ)
    p.wait()

    subprocess.Popen("""
        if [ -f .xmvn-builddep ]; then
            echo -----BEGIN MAVEN BUILD DEPENDENCIES-----
            gzip -9nc <.xmvn-builddep | base64
            echo -----END MAVEN BUILD DEPENDENCIES-----
        fi
示例#18
0
 def test_from_xml_noa(self, doc):
     Artifact.from_xml_element(doc)
示例#19
0
class SaneParser(optparse.OptionParser):
    def format_epilog(self, formatter):
        return self.epilog

usage = "usage: %prog [options] <builddep file>"
epilog = """
%prog generates RPM requires from builddep file generated by XMvn during package build
"""

if __name__ == "__main__":
    parser = SaneParser(usage=usage,
                        epilog=epilog)
    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("Exactly 1 argument is required")

    try:
        et = etree.parse(args[0]).getroot()
        deps = et.findall('./dependency')
        for dep in deps:
            art = Artifact.from_xml_element(dep)
            print(art.get_rpm_str(compat_ver=art.version))
    except (ArtifactValidationException, ArtifactFormatException) as e:
        parser.error("{e}: Provided artifact strings were invalid. "
                     "Please see help  and check your arguments".format(e=e))
        sys.exit(1)
    except JavaPackagesToolsException as e:
        sys.exit(e)
示例#20
0
def _main():
    OptionParser.format_epilog = lambda self, formatter: self.epilog
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option(
        "--skip-dependencies",
        action="store_true",
        default=False,
        help="skip dependencies section in resulting metadata",
    )
    parser.add_option("-D", action="append", type="str", help="add artifact property", metavar="property=value")

    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()
    if len(args) < 1:
        parser.error("At least 1 argument is required")

    try:
        uart = Artifact.from_mvn_str(args[0])
        uart.validate(allow_backref=False)
        if len(args) == 1:
            parser.error("When using artifact specification artifact path must be " "provided")
        if not (uart.groupId and uart.artifactId and uart.version):
            parser.error("Defined artifact has to include at least groupId, " "artifactId and version")
    except (ArtifactFormatException):
        if is_it_ivy_file(args[0]):
            uart = IvyFile(args[0])
        else:
            # it should be good old POM file
            uart = POM(args[0])
        pom_path = args[0]
    else:
        pom_path = None

    art = MetadataArtifact(uart.groupId, uart.artifactId, version=uart.version)
    if hasattr(uart, "extension") and uart.extension:
        art.extension = uart.extension
    if hasattr(uart, "classifier") and uart.classifier:
        art.classifier = uart.classifier

    jar_path = None
    if len(args) > 1:
        jar_path = args[1]
        extension = (os.path.splitext(jar_path)[1])[1:]
        if hasattr(art, "extension") and art.extension and art.extension != extension and not pom_path:
            raise ExtensionsDontMatch("Extensions don't match: '%s' != '%s'" % (art.extension, extension))
        else:
            art.extension = extension
    else:
        art.extension = "pom"

    if os.path.exists(config):
        metadata = Metadata.create_from_file(config)
    else:
        metadata = Metadata()

    if not options.skip_dependencies and pom_path and not is_it_ivy_file(pom_path):
        deps = []
        mvn_deps = gather_dependencies(pom_path)
        for d in mvn_deps:
            deps.append(MetadataDependency.from_mvn_dependency(d))
        if deps:
            art.dependencies = set(deps)
    else:
        art.properties["xmvn.resolver.disableEffectivePom"] = "true"

    if options.D:
        for d_opt in options.D:
            key, value = d_opt.split("=")
            art.properties[key] = value

    add_artifact_elements(metadata, art, pom_path, jar_path)

    metadata.write_to_file(config)
示例#21
0
class TestArtifact(unittest.TestCase):

    def setUp(self):
        # intentional whitespaces
        self.gaArtifact = Artifact(' g', ' a')
        self.gavArtifact = Artifact(' g', ' a', ' ', ' ', ' v')
        self.gaeArtifact = Artifact(' g', ' a', 'e')
        self.gacArtifact = Artifact(' g', ' a', ' ', ' c')
        self.gaevArtifact = Artifact(' g', 'a', ' e', ' ', ' v')
        self.gacvArtifact = Artifact(' g', 'a', ' ', 'c', ' v')
        self.fullArtifact = Artifact(' g', ' a', ' e', ' c', ' v')

    def test_artifact_init(self):
        a = self.gaArtifact
        self.assertEqual(a.groupId, 'g')
        self.assertEqual(a.artifactId, 'a')
        self.assertEqual(a.classifier, '')
        self.assertEqual(a.extension, 'jar')
        self.assertEqual(a.version, '')

        a = self.fullArtifact
        self.assertEqual(a.groupId, 'g')
        self.assertEqual(a.artifactId, 'a')
        self.assertEqual(a.classifier, 'c')
        self.assertEqual(a.extension, 'e')
        self.assertEqual(a.version, 'v')

    def test_str(self):
        self.assertEqual(str(self.gaArtifact), "g:a")
        self.assertEqual(str(self.gavArtifact), "g:a:v")
        self.assertEqual(str(self.gacArtifact), "g:a::c:")
        self.assertEqual(str(self.gacvArtifact), "g:a::c:v")
        self.assertEqual(str(self.fullArtifact), "g:a:e:c:v")

    def test_rpm_str(self):
        self.assertEqual(self.gaArtifact.get_rpm_str(), "mvn(g:a)")
        self.assertEqual(self.gavArtifact.get_rpm_str(), "mvn(g:a)")
        self.assertEqual(self.gacArtifact.get_rpm_str(), "mvn(g:a::c:)")
        self.assertEqual(self.gacvArtifact.get_rpm_str(), "mvn(g:a::c:)")
        self.assertEqual(self.gaeArtifact.get_rpm_str(), "mvn(g:a:e:)")
        self.assertEqual(self.gaevArtifact.get_rpm_str(), "mvn(g:a:e:)")
        self.assertEqual(self.fullArtifact.get_rpm_str(), "mvn(g:a:e:c:)")

    def test_xml_str_ga(self):
        doc = fromstring(self.gaArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertEqual(item, None)
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 2)

    def test_xml_str_gae(self):
        doc = fromstring(self.gaeArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 3)

    def test_xml_str_gac(self):
        doc = fromstring(self.gacArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertEqual(item, None)
        self.assertEqual(len(doc), 4)

    def test_xml_str_gav(self):
        doc = fromstring(self.gavArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 4)

    def test_xml_str_gaev(self):
        doc = fromstring(self.gaevArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertEqual(item, None)
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 4)

    def test_xml_str_gacv(self):
        doc = fromstring(self.gacvArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'jar')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 5)

    def test_xml_str_full(self):
        doc = fromstring(self.fullArtifact.get_xml_str())
        self.assertNotEqual(doc, None)
        item = doc.find('./groupId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'g')
        item = doc.find('./artifactId')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'a')
        item = doc.find('./extension')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'e')
        item = doc.find('./classifier')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'c')
        item = doc.find('./version')
        self.assertNotEqual(item, None)
        self.assertEqual(item.text, 'v')
        self.assertEqual(len(doc), 5)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-empty.xml")
    def test_from_xml_empty(self, doc):
        Artifact.from_xml_element(doc)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-nog.xml")
    def test_from_xml_nog(self, doc):
        Artifact.from_xml_element(doc)

    @exception_expected(ArtifactFormatException)
    @artifactfile("artifact-noa.xml")
    def test_from_xml_noa(self, doc):
        Artifact.from_xml_element(doc)

    @artifactfile("artifactga.xml")
    def test_from_xml_ga(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    @artifactfile("artifactgav.xml")
    def test_from_xml_gav(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    @artifactfile("artifactfull.xml")
    def test_from_xml_full(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    @artifactfile("artifact-whitespace.xml")
    def test_from_xml_whitespace(self, doc):
        a = Artifact.from_xml_element(doc)
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_ga(self):
        a = Artifact.from_mvn_str("g:a")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gav(self):
        a = Artifact.from_mvn_str("g:a:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gae(self):
        a = Artifact.from_mvn_str("g:a:e:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gaev(self):
        a = Artifact.from_mvn_str("g:a:e:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gac(self):
        a = Artifact.from_mvn_str("g:a::c:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_gacv(self):
        a = Artifact.from_mvn_str("g:a::c:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_from_mvn_str_gaec(self):
        a = Artifact.from_mvn_str("g:a:e:c:")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "")

    def test_from_mvn_str_full(self):
        a = Artifact.from_mvn_str("g:a:e:c:v")
        self.assertEqual(a.groupId, "g")
        self.assertEqual(a.artifactId, "a")
        self.assertEqual(a.extension, "e")
        self.assertEqual(a.classifier, "c")
        self.assertEqual(a.version, "v")

    def test_merge1(self):
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g1:a1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge2(self):
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g1:a1:v2")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge3(self):
        # different artifacts won't be merged
        a = Artifact.from_mvn_str("g1:a1:v1")
        b = Artifact.from_mvn_str("g2:a2:e2::")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge4(self):
        a = Artifact.from_mvn_str("g1:a1")
        b = Artifact.from_mvn_str("g1:a1:v1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "v1")

    def test_merge5(self):
        a = Artifact.from_mvn_str("g1:a1:war::")
        b = Artifact.from_mvn_str("g1:a1:v1")
        a.merge_with(b)

        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "war")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_interpolation1(self):
        a = Artifact.from_mvn_str("${gid}:a1")
        props = {"gid": "g1"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 0)
        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")

    def test_interpolation2(self):
        a = Artifact.from_mvn_str("${gid}:a1:${v.major}.${v.minor}")
        props = {"gid": "g1", "v.major": "4", "v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 0)
        self.assertEqual(a.groupId, "g1")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "4.11")

    def test_interpolation3(self):
        a = Artifact.from_mvn_str("${gid}:a1")
        props = {"v.minor": "11"}
        res = a.interpolate(props)

        self.assertEqual(len(res), 1)
        self.assertEqual(res[0], "gid")
        self.assertEqual(a.groupId, "${gid}")
        self.assertEqual(a.artifactId, "a1")
        self.assertEqual(a.extension, "jar")
        self.assertEqual(a.classifier, "")
        self.assertEqual(a.version, "")
示例#22
0
 def test_from_xml_noa(self, doc):
     Artifact.from_xml_element(doc)
示例#23
0
commons-lang:commons-lang:1.2
commons-lang:commons-lang:war:
commons-lang:commons-lang:war:test-jar:
commons-lang:commons-lang:war:test-jar:3.1
*:commons-lang (equivalent to ':commons-lang')
"""

if __name__ == "__main__":
    parser = SaneParser(usage=usage,
                        epilog=epilog)

    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()
    if len(args) < 2:
        parser.error("At least 2 arguments are required")

    try:
        orig = Artifact.from_mvn_str(args[0])
        aliases = []
        for alias in args[1:]:
            aliases.append(Artifact.from_mvn_str(alias))

        XMvnConfig().add_aliases(orig, aliases)
    except (ArtifactValidationException, ArtifactFormatException) as e:
        parser.error("{e}: Provided artifact strings were invalid. "
                     "Please see help  and check your arguments".format(e=e))
        sys.exit(1)
    except JavaPackagesToolsException as e:
        sys.exit(e)