def compareArtifacts(localRepoPath, remoteUrl):
    tempDownloadDir = tempfile.mkdtemp()
    regexChecksum = re.compile("(\.sha1$)|(\.md5$)")
    regexMetadata = re.compile("(maven-metadata.xml)|(\.lastUpdated$)|(_maven.repositories)")
    for root, dirs, files in os.walk(localRepoPath, followlinks=True):
        for filename in files:
            if regexChecksum.search(filename):
                continue
            if regexMetadata.search(filename):
                continue
            filepath = os.path.join(root, filename)
            relRepoPath = os.path.relpath(filepath, localRepoPath)
            logging.debug("Checking artifact: %s", relRepoPath)

            # Attempt to download remote artifact
            tempDownloadFile = os.path.join(tempDownloadDir, relRepoPath)
            remoteFileUrl = remoteUrl + "/" + relRepoPath
            try:
                maven_repo_util.download(remoteFileUrl, tempDownloadFile, ChecksumMode.generate)
            except Exception:
                logging.error("An error occured while downloading %s", remoteFileUrl)

            # Compare the local and remote artifact checksums
            if os.path.exists(tempDownloadFile):
                localFileChecksum = maven_repo_util.getSha1Checksum(filepath)
                remoteFileChecksum = maven_repo_util.getSha1Checksum(tempDownloadFile)
                if localFileChecksum != remoteFileChecksum:
                    logging.error("Checksums do not match for artifact %s", relRepoPath)
            else:
                logging.debug("File does not exist in remote repo: %s", relRepoPath)
def compareArtifacts(localRepoPath, remoteUrl):
    tempDownloadDir = tempfile.mkdtemp()
    regexChecksum = re.compile('(\.sha1$)|(\.md5$)')
    regexMetadata = re.compile('(maven-metadata.xml)|(\.lastUpdated$)|(_maven.repositories)')
    for root, dirs, files in os.walk(localRepoPath, followlinks=True):
        for filename in files:
            if regexChecksum.search(filename):
                continue
            if regexMetadata.search(filename):
                continue
            filepath = os.path.join(root, filename)
            relRepoPath = os.path.relpath(filepath, localRepoPath)
            logging.debug('Checking artifact: %s', relRepoPath)

            # Attempt to download remote artifact
            tempDownloadFile = os.path.join(tempDownloadDir, relRepoPath)
            remoteFileUrl = remoteUrl + "/" + relRepoPath
            try:
                maven_repo_util.download(remoteFileUrl, tempDownloadFile, ChecksumMode.generate)
            except Exception:
                logging.error("An error occured while downloading %s", remoteFileUrl)

            # Compare the local and remote artifact checksums
            if os.path.exists(tempDownloadFile):
                localFileChecksum = maven_repo_util.getSha1Checksum(filepath)
                remoteFileChecksum = maven_repo_util.getSha1Checksum(tempDownloadFile)
                if (localFileChecksum != remoteFileChecksum):
                    logging.error('Checksums do not match for artifact %s', relRepoPath)
            else:
                logging.debug('File does not exist in remote repo: %s', relRepoPath)
示例#3
0
    def test_url_download(self):
        # make sure the shuffled sequence does not lose any elements
        url = "http://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.pom"
        tempDownloadDir = tempfile.mkdtemp()
        filepath = os.path.join(tempDownloadDir, "downloadfile.txt")
        self.assertFalse(os.path.exists(filepath), "Download file already exists: " + filepath)
        maven_repo_util.download(url, filepath, ChecksumMode.generate)
        self.assertTrue(os.path.exists(filepath), "File not downloaded")

        maven_repo_util.download(url, None, ChecksumMode.generate)
        localfilename = "jboss-parent-10.pom"
        self.assertTrue(os.path.exists(localfilename))
        if os.path.exists(localfilename):
            logging.debug('Removing temp local file: ' + localfilename)
            os.remove(localfilename)
示例#4
0
    def test_url_download(self):
        # make sure the shuffled sequence does not lose any elements
        url = "http://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.pom"
        tempDownloadDir = tempfile.mkdtemp()
        filepath = os.path.join(tempDownloadDir, "downloadfile.txt")
        self.assertFalse(os.path.exists(filepath),
                         "Download file already exists: " + filepath)
        maven_repo_util.download(url, filepath, ChecksumMode.generate)
        self.assertTrue(os.path.exists(filepath), "File not downloaded")

        maven_repo_util.download(url, None, ChecksumMode.generate)
        localfilename = "jboss-parent-10.pom"
        self.assertTrue(os.path.exists(localfilename))
        if os.path.exists(localfilename):
            logging.debug('Removing temp local file: ' + localfilename)
            os.remove(localfilename)
示例#5
0
    def test_bad_urls(self):
        url = "junk://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
        maven_repo_util.download(url, None, ChecksumMode.generate)

        url = "sadjfasfjsl"
        maven_repo_util.download(url, None, ChecksumMode.generate)

        url = "http://1234/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
        maven_repo_util.download(url, None, ChecksumMode.generate)
示例#6
0
    def test_bad_urls(self):
        url = "junk://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
        maven_repo_util.download(url, None, ChecksumMode.generate)

        url = "sadjfasfjsl"
        maven_repo_util.download(url, None, ChecksumMode.generate)

        url = "http://1234/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
        maven_repo_util.download(url, None, ChecksumMode.generate)
示例#7
0
 def test_http_404(self):
     url = "http://repo1.maven.org/maven2/somefilethatdoesnotexist"
     code = maven_repo_util.download(url, None, ChecksumMode.generate)
     self.assertEqual(code, 404)
示例#8
0
 def test_http_404(self):
     url = "http://repo1.maven.org/maven2/somefilethatdoesnotexist"
     code = maven_repo_util.download(url, None, ChecksumMode.generate)
     self.assertEqual(code, 404)