Skip to content

Commit

Permalink
Fix a bug in writing out the manifest entries when there is no 'sourc…
Browse files Browse the repository at this point in the history
…e' attribute present in the jvm_binary() target

Testing Done:
CI running at https://travis-ci.org/pantsbuild/pants/builds/62097771

Updated `testprojects/src/java/org/pantsbuild/testproject/manifest/BUILD` and integration test with the case that was failing.

Bugs closed: 1522

Reviewed at https://rbcommons.com/s/twitter/r/2199/
  • Loading branch information
ericzundel committed May 11, 2015
1 parent 5f54d41 commit ff9fdec
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/python/pants/backend/jvm/tasks/jar_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

from pants.backend.jvm.subsystems.jar_tool import JarTool
from pants.backend.jvm.targets.java_agent import JavaAgent
from pants.backend.jvm.targets.jvm_app import JvmApp
from pants.backend.jvm.targets.jvm_binary import Duplicate, JarRules, JvmBinary, Skip
from pants.backend.jvm.tasks.nailgun_task import NailgunTask
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.binary_util import safe_args
from pants.java.jar.manifest import Manifest
Expand Down Expand Up @@ -382,8 +382,8 @@ def add_products(target_products):
if isinstance(tgt, JavaAgent):
self._add_agent_manifest(tgt, self._manifest)

if isinstance(tgt, JvmBinary):
self._add_manifest_entries(tgt, self._manifest)
if isinstance(target, JvmBinary):
self._add_manifest_entries(target, self._manifest)

if recursive:
target.walk(add_to_jar)
Expand Down
27 changes: 25 additions & 2 deletions testprojects/src/java/org/pantsbuild/testproject/manifest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,32 @@

jvm_binary(
source = 'Manifest.java',
name = 'manifest',
name = 'manifest-with-source',
main = 'org.pantsbuild.testproject.manifest.Manifest',
manifest_entries = {
'Implementation-Version' : '1.2.3',
}
},
)

jvm_binary(
name = 'manifest-no-source',
main = 'org.pantsbuild.testproject.manifest.Manifest',
manifest_entries = {
'Implementation-Version' : '4.5.6',
},
dependencies = [
':manifest-lib',
],
)

java_library(
name = 'manifest-lib',
sources = ['Manifest.java'],
)

jvm_app(
name = 'manifest-app',
dependencies = [
':manifest-no-source',
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,48 @@ class JvmBinaryIntegrationTest(PantsRunIntegrationTest):

def test_manifest_entries(self):
self.assert_success(self.run_pants(['clean-all']))
args = ['binary', 'testprojects/src/java/org/pantsbuild/testproject/manifest']
args = ['binary', 'testprojects/src/java/org/pantsbuild/testproject/manifest:manifest-with-source']
pants_run = self.run_pants(args, {})
self.assert_success(pants_run)

out_path = os.path.join(get_buildroot(), 'dist')
java_run = subprocess.Popen(['java', '-cp', 'manifest.jar',
java_run = subprocess.Popen(['java', '-cp', 'manifest-with-source.jar',
'org.pantsbuild.testproject.manifest.Manifest'],
stdout=subprocess.PIPE,
cwd=out_path)
java_retcode = java_run.wait()
java_out = java_run.stdout.read()
self.assertEquals(java_retcode, 0)
self.assertIn('Hello World! Version: 1.2.3', java_out)

def test_manifest_entries_no_source(self):
self.assert_success(self.run_pants(['clean-all']))
args = ['binary', 'testprojects/src/java/org/pantsbuild/testproject/manifest:manifest-no-source']
pants_run = self.run_pants(args, {})
self.assert_success(pants_run)

out_path = os.path.join(get_buildroot(), 'dist')
java_run = subprocess.Popen(['java', '-cp', 'manifest-no-source.jar',
'org.pantsbuild.testproject.manifest.Manifest'],
stdout=subprocess.PIPE,
cwd=out_path)
java_retcode = java_run.wait()
java_out = java_run.stdout.read()
self.assertEquals(java_retcode, 0)
self.assertIn('Hello World! Version: 4.5.6', java_out)

def test_manifest_entries_bundle(self):
self.assert_success(self.run_pants(['clean-all']))
args = ['bundle', 'testprojects/src/java/org/pantsbuild/testproject/manifest:manifest-app']
pants_run = self.run_pants(args, {})
self.assert_success(pants_run)

out_path = os.path.join(get_buildroot(), 'dist', 'manifest-app-bundle')
java_run = subprocess.Popen(['java', '-cp', 'manifest-no-source.jar',
'org.pantsbuild.testproject.manifest.Manifest'],
stdout=subprocess.PIPE,
cwd=out_path)
java_retcode = java_run.wait()
java_out = java_run.stdout.read()
self.assertEquals(java_retcode, 0)
self.assertIn('Hello World! Version: 4.5.6', java_out)

0 comments on commit ff9fdec

Please sign in to comment.