<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pants . backend . jvm . targets . jar_dependency import JarDependency <EOL> from pants . backend . jvm . targets . jar_library import JarLibrary <EOL> from pants . backend . jvm . targets . java_library import JavaLibrary <EOL> from pants . backend . jvm . targets . jvm_app import JvmApp <EOL> from pants . backend . jvm . targets . jvm_binary import JvmBinary <EOL> from pants . backend . jvm . tasks . bundle_create import BundleCreate <EOL> from pants . backend . jvm . tasks . classpath_util import MissingClasspathEntryError <EOL> from pants . util . contextutil import open_zip <EOL> from pants . util . dirutil import safe_file_dump <EOL> from pants_test . backend . jvm . tasks . jvm_binary_task_test_base import JvmBinaryTaskTestBase <EOL> from pants_test . testutils . file_test_util import check_zip_file_content <EOL> class TestBundleCreate ( JvmBinaryTaskTestBase ) : <EOL> FOO_JAR = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return BundleCreate <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestBundleCreate , self ) . setUp ( ) <EOL> self . jar_artifact = self . create_artifact ( org = '<STR_LIT>' , name = '<STR_LIT:foo>' , rev = '<STR_LIT>' ) <EOL> self . zip_artifact = self . create_artifact ( org = '<STR_LIT>' , name = '<STR_LIT:bar>' , rev = '<STR_LIT>' , <EOL> ext = '<STR_LIT>' ) <EOL> self . bundle_artifact = self . create_artifact ( org = '<STR_LIT>' , name = '<STR_LIT>' , rev = '<STR_LIT>' , <EOL> classifier = '<STR_LIT>' ) <EOL> self . tar_gz_artifact = self . create_artifact ( org = '<STR_LIT>' , name = '<STR_LIT>' , rev = '<STR_LIT>' , <EOL> ext = '<STR_LIT>' ) <EOL> self . jar_lib = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JarLibrary , <EOL> jars = [ JarDependency ( org = '<STR_LIT>' , name = '<STR_LIT:foo>' , rev = '<STR_LIT>' ) , <EOL> JarDependency ( org = '<STR_LIT>' , name = '<STR_LIT:bar>' , rev = '<STR_LIT>' , <EOL> ext = '<STR_LIT>' ) , <EOL> JarDependency ( org = '<STR_LIT>' , name = '<STR_LIT>' , rev = '<STR_LIT>' , <EOL> classifier = '<STR_LIT>' ) , <EOL> JarDependency ( org = '<STR_LIT>' , name = '<STR_LIT>' , rev = '<STR_LIT>' , <EOL> ext = '<STR_LIT>' ) ] ) <EOL> safe_file_dump ( os . path . join ( self . build_root , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . java_lib_target = self . make_target ( '<STR_LIT>' , JavaLibrary , sources = [ '<STR_LIT>' ] ) <EOL> self . binary_target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JvmBinary , <EOL> dependencies = [ self . java_lib_target , self . jar_lib ] ) <EOL> self . app_target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JvmApp , <EOL> basename = '<STR_LIT>' , <EOL> dependencies = [ self . binary_target ] ) <EOL> self . task_context = self . context ( target_roots = [ self . app_target ] ) <EOL> self . _setup_classpath ( self . task_context ) <EOL> self . dist_root = os . path . join ( self . build_root , '<STR_LIT>' ) <EOL> def _setup_classpath ( self , task_context ) : <EOL> """<STR_LIT>""" <EOL> classpath_products = self . ensure_classpath_products ( task_context ) <EOL> classpath_products . add_jars_for_targets ( targets = [ self . jar_lib ] , <EOL> conf = '<STR_LIT:default>' , <EOL> resolved_jars = [ self . jar_artifact , <EOL> self . zip_artifact , <EOL> self . bundle_artifact , <EOL> self . tar_gz_artifact ] ) <EOL> self . add_to_runtime_classpath ( task_context , self . binary_target , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_jvm_bundle_products ( self ) : <EOL> """<STR_LIT>""" <EOL> self . execute ( self . task_context ) <EOL> self . _check_bundle_products ( '<STR_LIT>' ) <EOL> def test_jvm_bundle_use_basename_prefix ( self ) : <EOL> """<STR_LIT>""" <EOL> self . set_options ( use_basename_prefix = True ) <EOL> self . task_context = self . context ( target_roots = [ self . app_target ] ) <EOL> self . _setup_classpath ( self . task_context ) <EOL> self . execute ( self . task_context ) <EOL> self . _check_bundle_products ( '<STR_LIT>' ) <EOL> def test_bundle_non_app_target ( self ) : <EOL> """<STR_LIT>""" <EOL> self . task_context = self . context ( target_roots = [ self . java_lib_target ] ) <EOL> self . _setup_classpath ( self . task_context ) <EOL> self . execute ( self . task_context ) <EOL> self . assertIsNone ( self . task_context . products . get ( '<STR_LIT>' ) . get ( self . java_lib_target ) ) <EOL> self . assertFalse ( os . path . exists ( self . dist_root ) ) <EOL> def test_jvm_bundle_missing_product ( self ) : <EOL> """<STR_LIT>""" <EOL> missing_jar_artifact = self . create_artifact ( org = '<STR_LIT>' , name = '<STR_LIT:foo>' , rev = '<STR_LIT>' , <EOL> materialize = False ) <EOL> classpath_products = self . ensure_classpath_products ( self . task_context ) <EOL> classpath_products . add_jars_for_targets ( targets = [ self . binary_target ] , <EOL> conf = '<STR_LIT:default>' , <EOL> resolved_jars = [ missing_jar_artifact ] ) <EOL> with self . assertRaises ( MissingClasspathEntryError ) : <EOL> self . execute ( self . task_context ) <EOL> def test_conflicting_basename ( self ) : <EOL> """<STR_LIT>""" <EOL> conflict_app_target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JvmApp , <EOL> basename = '<STR_LIT>' , <EOL> dependencies = [ self . binary_target ] ) <EOL> self . set_options ( use_basename_prefix = True ) <EOL> self . task_context = self . context ( target_roots = [ self . app_target , conflict_app_target ] ) <EOL> self . _setup_classpath ( self . task_context ) <EOL> with self . assertRaises ( BundleCreate . BasenameConflictError ) : <EOL> self . execute ( self . task_context ) <EOL> def _check_bundle_products ( self , bundle_basename ) : <EOL> products = self . task_context . products . get ( '<STR_LIT>' ) <EOL> self . assertIsNotNone ( products ) <EOL> product_data = products . get ( self . app_target ) <EOL> self . assertEquals ( { self . dist_root : [ '<STR_LIT>' . format ( basename = bundle_basename ) ] } , <EOL> product_data ) <EOL> self . assertTrue ( os . path . exists ( self . dist_root ) ) <EOL> bundle_root = os . path . join ( self . dist_root , <EOL> '<STR_LIT>' . format ( basename = bundle_basename ) ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) , <EOL> sorted ( self . iter_files ( bundle_root ) ) ) <EOL> check_zip_file_content ( os . path . join ( bundle_root , '<STR_LIT>' ) , <EOL> self . FOO_JAR ) <EOL> with open_zip ( os . path . join ( bundle_root , '<STR_LIT>' ) ) as jar : <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> sorted ( jar . namelist ( ) ) ) </s>
