Skip to content

Commit

Permalink
Maven project mock test (fix #331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Slouka committed Feb 20, 2016
1 parent 263cc77 commit 1809e89
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
19 changes: 18 additions & 1 deletion rpg/plugins/project_builder/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def extracted(self, project_dir, spec, sack):
if (project_dir / "pom.xml").is_file():
et = etree.parse(str(project_dir / "pom.xml")).getroot()
for branch in et:
tag = re.sub(r'^{.*?}', '', branch.tag)
tag = re.sub(r'^{.*?}', '', str(branch.tag))
if tag == 'name':
spec.Name = str_to_pkgname(branch.text.strip())
elif tag == 'version':
Expand Down Expand Up @@ -61,3 +61,20 @@ def compiled(self, project_dir, spec, sack):
"{e}: Provided artifact strings were invalid."
.format(e=e))
return

MOCK_ERR_DEP = re.compile(r"Error: No Package found for (.*)")

def mock_recover(self, log, spec):
""" Removes dependencies that are not in Fedora
thus causing build failure """
change = False
for err in log:
dep = self.MOCK_ERR_DEP.search(err)
if dep:
change = True
dep = dep.group(1)
spec.BuildRequires.discard(dep)
logging.debug("Maven dependency not available: " + dep)
if change:
return True
return False
43 changes: 43 additions & 0 deletions tests/mock_build/test_maven_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from tests.support import RpgTestCase
from rpg import Base
import os


class MavenBuildTest(RpgTestCase):

def test_simple_project(self):
self.base = Base()
self.base.sack = self.base.load_dnf_sack()
self.base.load_plugins()
self.base.load_project_from_url(
r"https://github.com/apache/commons-compress/archive/rel/1.10.zip")
self.base.spec.Name = "commons-compress"
self.base.spec.Version = "1.10"
self.base.spec.Release = "1"
self.base.spec.License = "ASL 2.0"
self.base.spec.Summary = (
"Commons Compress is a Java library for working with various"
"compression and archiving formats.")
self.base.spec.description = (
"The Apache Commons Compress library defines an API for working "
"with ar, cpio, Unix dump, tar, zip, gzip, XZ, Pack200, bzip2, "
"7z, arj, lzma, snappy, DEFLATE and Z files.")
self.base.spec.URL = (
r"http://commons.apache.org/proper/commons-compress/")
self.base.target_arch = "x86_64"
self.base.target_distro = "fedora-22"
self.base.spec.BuildRequires.update(['maven-local'])
self.base.spec.Requires.update(['maven-local'])
self.base.fetch_repos(self.base.target_distro, self.base.target_arch)
self.base.run_extracted_source_analysis()
self.base.run_patched_source_analysis()
self.base.build_project()
self.base.run_compiled_source_analysis()
self.base.install_project()
self.base.run_installed_source_analysis()
self.base.build_srpm()
self.assertTrue(self.base.srpm_path.exists())
self.base.build_rpm_recover(
self.base.target_distro, self.base.target_arch)
os.remove(str(self.base.srpm_path))
os.remove(str(self.base.spec_path))

0 comments on commit 1809e89

Please sign in to comment.