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 Mar 1, 2016
1 parent 986013d commit 0184950
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
before_script:
- docker run -i --privileged -d -v $HOME/build/$TRAVIS_REPO_SLUG:$HOME/build/$TRAVIS_REPO_SLUG --name test_fedora fedora:23 bash
- tito build --test --srpm && cp /tmp/tito/*.src.rpm .
- docker exec -i test_fedora bash -c "dnf install -y python-copr mock libsolv-devel make gcc gcc-c++ python3-dnf python-devel 'dnf-command(builddep)'; dnf builddep -y $HOME/build/$TRAVIS_REPO_SLUG/rpg.spec"
- docker exec -i test_fedora bash -c "dnf install -y python-copr mock libsolv-devel make maven-local xz-java gcc gcc-c++ python3-dnf python-devel 'dnf-command(builddep)'; dnf builddep -y $HOME/build/$TRAVIS_REPO_SLUG/rpg.spec"
- docker exec -i test_fedora bash -c "dnf builddep -y hawkey"
- docker exec -i test_fedora bash -c "dnf builddep -y libhif"
- docker exec -i test_fedora bash -c "dnf builddep -y libsolv"
Expand Down
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
41 changes: 41 additions & 0 deletions tests/mock_build/test_maven_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from tests.support import RpgTestCase
from rpg import Base
import os


class MavenBuildTest(RpgTestCase):

def test_maven_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 = "commonsCompress"
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.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 0184950

Please sign in to comment.