def execute(self): basedir = os.path.join(self.get_options().pants_distdir, self._output_folder) runtime_classpath = self.context.products.get_data('runtime_classpath') targets = self.context.targets() if self.get_options().manifest_jar_only: classpath = ClasspathUtil.classpath(targets, runtime_classpath) # Safely create e.g. dist/export-classpath/manifest.jar safe_classpath(classpath, basedir, "manifest.jar") else: ClasspathProducts.create_canonical_classpath( runtime_classpath, targets, basedir, save_classpath_file=True)
def execute(self): basedir = os.path.join(self.get_options().pants_distdir, self._output_folder) runtime_classpath = self.context.products.get_data('runtime_classpath') targets = self.context.targets() if self.get_options().manifest_jar_only: classpath = ClasspathUtil.classpath(targets, runtime_classpath) # Safely create e.g. dist/export-classpath/manifest.jar safe_classpath(classpath, basedir, "manifest.jar") else: ClasspathProducts.create_canonical_classpath(runtime_classpath, targets, basedir, save_classpath_file=True)
def _test_canonical_classpath_helper(self, classpath_products, targets, libs_dir, expected_canonical_classpath, expected_classspath_files, excludes=None): """ Helper method to call `create_canonical_classpath` and verify generated canonical classpath. :param ClasspathProducts classpath_products: Classpath products. :param list targets: List of targets to generate canonical classpath from. :param string libs_dir: Directory where canonical classpath are to be generated. :param list expected_canonical_classpath: List of canonical classpath relative to a base directory. :param dict expected_classspath_files: A dict of classpath.txt path to its expected content. """ canonical_classpath = ClasspathProducts.create_canonical_classpath( classpath_products, targets, libs_dir, save_classpath_file=True, internal_classpath_only=False, excludes=excludes) # check canonical path returned self.assertEquals(expected_canonical_classpath, relativize_paths(canonical_classpath, libs_dir)) # check canonical path created contain the exact set of files, no more, no less self.assertTrue(contains_exact_files(libs_dir, expected_canonical_classpath + expected_classspath_files.keys())) # check the content of classpath.txt for classpath_file in expected_classspath_files: self.assertTrue(check_file_content(os.path.join(libs_dir, classpath_file), expected_classspath_files[classpath_file]))
def _test_canonical_classpath_helper(self, classpath_products, targets, libs_dir, expected_canonical_classpath, expected_classspath_files, excludes=None): """ Helper method to call `create_canonical_classpath` and verify generated canonical classpath. :param ClasspathProducts classpath_products: Classpath products. :param list targets: List of targets to generate canonical classpath from. :param string libs_dir: Directory where canonical classpath are to be generated. :param list expected_canonical_classpath: List of canonical classpath relative to a base directory. :param dict expected_classspath_files: A dict of classpath.txt path to its expected content. """ canonical_classpath = ClasspathProducts.create_canonical_classpath( classpath_products, targets, libs_dir, save_classpath_file=True, internal_classpath_only=False, excludes=excludes) # check canonical path returned self.assertEquals(expected_canonical_classpath, relativize_paths(canonical_classpath, libs_dir)) # check canonical path created contain the exact set of files, no more, no less self.assertTrue(contains_exact_files(libs_dir, expected_canonical_classpath + expected_classspath_files.keys())) # check the content of classpath.txt for classpath_file in expected_classspath_files: self.assertTrue(check_file_content(os.path.join(libs_dir, classpath_file), expected_classspath_files[classpath_file]))
def bundle(self, app, results_dir): """Create a self-contained application bundle. The bundle will contain the target classes, dependencies and resources. """ assert (isinstance(app, BundleCreate.App)) bundle_dir = self._get_bundle_dir(app, results_dir) self.context.log.debug('creating {}'.format( os.path.relpath(bundle_dir, get_buildroot()))) safe_mkdir(bundle_dir, clean=True) classpath = OrderedSet() # Create symlinks for both internal and external dependencies under `lib_dir`. This is # only needed when not creating a deployjar lib_dir = os.path.join(bundle_dir, self.LIBS_DIR) if not app.deployjar: os.mkdir(lib_dir) consolidated_classpath = self.context.products.get_data( 'consolidated_classpath') classpath.update( ClasspathProducts.create_canonical_classpath( consolidated_classpath, app.target.closure(bfs=True, **self._target_closure_kwargs), lib_dir, internal_classpath_only=False, excludes=app.binary.deploy_excludes, )) bundle_jar = os.path.join(bundle_dir, '{}.jar'.format(app.binary.basename)) with self.monolithic_jar(app.binary, bundle_jar, manifest_classpath=classpath) as jar: self.add_main_manifest_entry(jar, app.binary) # Make classpath complete by adding the monolithic jar. classpath.update([jar.path]) if app.binary.shading_rules: for jar_path in classpath: # In case `jar_path` is a symlink, this is still safe, shaded jar will overwrite jar_path, # original file `jar_path` linked to remains untouched. # TODO run in parallel to speed up self.shade_jar(shading_rules=app.binary.shading_rules, jar_path=jar_path) self._symlink_bundles(app, bundle_dir) return bundle_dir
def bundle(self, app, results_dir): """Create a self-contained application bundle. The bundle will contain the target classes, dependencies and resources. """ assert(isinstance(app, BundleCreate.App)) bundle_dir = self._get_bundle_dir(app, results_dir) self.context.log.debug('creating {}'.format(os.path.relpath(bundle_dir, get_buildroot()))) safe_mkdir(bundle_dir, clean=True) classpath = OrderedSet() # Create symlinks for both internal and external dependencies under `lib_dir`. This is # only needed when not creating a deployjar lib_dir = os.path.join(bundle_dir, self.LIBS_DIR) if not app.deployjar: os.mkdir(lib_dir) consolidated_classpath = self.context.products.get_data('consolidated_classpath') classpath.update(ClasspathProducts.create_canonical_classpath( consolidated_classpath, app.target.closure(bfs=True, **self._target_closure_kwargs), lib_dir, internal_classpath_only=False, excludes=app.binary.deploy_excludes, )) bundle_jar = os.path.join(bundle_dir, '{}.jar'.format(app.binary.basename)) with self.monolithic_jar(app.binary, bundle_jar, manifest_classpath=classpath) as jar: self.add_main_manifest_entry(jar, app.binary) # Make classpath complete by adding the monolithic jar. classpath.update([jar.path]) if app.binary.shading_rules: for jar_path in classpath: # In case `jar_path` is a symlink, this is still safe, shaded jar will overwrite jar_path, # original file `jar_path` linked to remains untouched. # TODO run in parallel to speed up self.shade_jar(shading_rules=app.binary.shading_rules, jar_path=jar_path) self._symlink_bundles(app, bundle_dir) return bundle_dir