def test_java_compile_reads_resource_mapping(self): # Ensure that if an annotation processor produces a resource-mapping, # the artifact contains that resource mapping. with temporary_dir() as cache_dir: artifact_dir = os.path.join(cache_dir, 'JavaCompile', 'testprojects.src.java.com.pants.testproject.annotation.main.main') config = {'compile.java': {'write_artifact_caches': [cache_dir]}} pants_run = self.run_pants(['compile', 'testprojects/src/java/com/pants/testproject/annotation/main'], config) self.assert_success(pants_run) self.assertTrue(os.path.exists(artifact_dir)) artifacts = os.listdir(artifact_dir) self.assertEqual(len(artifacts), 1) with temporary_dir() as extract_dir: TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir) all_files = set() for dirpath, dirs, files in safe_walk(extract_dir): for name in files: path = os.path.join(dirpath, name) all_files.add(path) report_file_name = os.path.join(extract_dir, 'compile/jvm/java/classes/deprecation_report.txt') self.assertIn(report_file_name, all_files) annotated_classes = [line.rstrip() for line in file(report_file_name).read().splitlines()] self.assertEquals( {'com.pants.testproject.annotation.main.Main', 'com.pants.testproject.annotation.main.Main$TestInnerClass'}, set(annotated_classes))
def test_java_compile_reads_resource_mapping(self): # Ensure that if an annotation processor produces a resource-mapping, # the artifact contains that resource mapping. with temporary_dir() as cache_dir: artifact_dir = os.path.join( cache_dir, 'JavaCompile', 'testprojects.src.java.com.pants.testproject.annotation.main.main' ) config = {'java-compile': {'write_artifact_caches': [cache_dir]}} pants_run = self.run_pants([ 'goal', 'compile', 'testprojects/src/java/com/pants/testproject/annotation/main' ], config) self.assert_success(pants_run) self.assertTrue(os.path.exists(artifact_dir)) artifacts = os.listdir(artifact_dir) self.assertEqual(len(artifacts), 1) with temporary_dir() as extract_dir: TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir) all_files = set() for dirpath, dirs, files in safe_walk(extract_dir): for name in files: path = os.path.join(dirpath, name) all_files.add(path) self.assertIn( os.path.join( extract_dir, "compile/jvm/java/classes/deprecation_report.txt"), all_files)
def test_java_compile_reads_resource_mapping(self): # Ensure that if an annotation processor produces a resource-mapping, # the artifact contains that resource mapping. with temporary_dir() as cache_dir: config = {'cache.compile.zinc': {'write_to': [cache_dir]}} self.assert_success( self.run_pants([ 'compile', 'testprojects/src/java/org/pantsbuild/testproject/annotation/main', ], config=config)) base_artifact_dir = self.get_cache_subdir(cache_dir) artifact_dir = os.path.join( base_artifact_dir, 'testprojects.src.java.org.pantsbuild.testproject.annotation.main.main', ) self.assertTrue(os.path.exists(artifact_dir)) artifacts = os.listdir(artifact_dir) self.assertEqual(len(artifacts), 1) with temporary_dir() as extract_dir: TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir) all_files = set() for dirpath, dirs, files in safe_walk(extract_dir): for name in files: path = os.path.join(dirpath, name) all_files.add(path) # Locate the report file on the classpath. report_file_name = 'deprecation_report.txt' reports = [ f for f in all_files if f.endswith(report_file_name) ] self.assertEquals( 1, len(reports), 'Expected exactly one {} file; got: {}'.format( report_file_name, all_files)) with open(reports[0]) as fp: annotated_classes = [ line.rstrip() for line in fp.read().splitlines() ] self.assertEquals( { 'org.pantsbuild.testproject.annotation.main.Main', 'org.pantsbuild.testproject.annotation.main.Main$TestInnerClass' }, set(annotated_classes))
def test_java_compile_reads_resource_mapping(self, strategy): # Ensure that if an annotation processor produces a resource-mapping, # the artifact contains that resource mapping. with temporary_dir() as cache_dir: artifact_dir = os.path.join( cache_dir, "JavaCompile", "testprojects.src.java.org.pantsbuild.testproject.annotation.main.main" ) config = {"compile.java": {"write_artifact_caches": [cache_dir]}} pants_run = self.run_pants( [ "compile.java", "--strategy={}".format(strategy), "compile.apt", "--strategy={}".format(strategy), "testprojects/src/java/org/pantsbuild/testproject/annotation/main", ], config, ) self.assert_success(pants_run) self.assertTrue(os.path.exists(artifact_dir)) artifacts = os.listdir(artifact_dir) self.assertEqual(len(artifacts), 1) with temporary_dir() as extract_dir: TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir) all_files = set() for dirpath, dirs, files in safe_walk(extract_dir): for name in files: path = os.path.join(dirpath, name) all_files.add(path) # Locate the report file on the classpath. report_file_name = "deprecation_report.txt" reports = [f for f in all_files if f.endswith(report_file_name)] self.assertEquals( 1, len(reports), "Expected exactly one {} file; got: {}".format(report_file_name, all_files) ) with open(reports[0]) as fp: annotated_classes = [line.rstrip() for line in fp.read().splitlines()] self.assertEquals( { "org.pantsbuild.testproject.annotation.main.Main", "org.pantsbuild.testproject.annotation.main.Main$TestInnerClass", }, set(annotated_classes), )
def execute(self): targets = [ t for t in self.context.targets() if isinstance(t, WebPack.Resources) ] for target in targets: concrete_target = target.concrete_derived_from bundle_dir = os.path.join(self.get_options().pants_distdir, 'webpack-bundles', concrete_target.id) safe_mkdir(bundle_dir, clean=True) archiver = TarArchiver(mode='w:gz', extension='tgz') archiver.create( basedir=target.target_base, outdir=bundle_dir, name=concrete_target.id, )
def test_java_compile_reads_resource_mapping(self): # Ensure that if an annotation processor produces a resource-mapping, # the artifact contains that resource mapping. with temporary_dir() as cache_dir: config = {'cache.compile.zinc': {'write_to': [cache_dir]}} self.assert_success(self.run_pants([ 'compile', 'testprojects/src/java/org/pantsbuild/testproject/annotation/main', ], config=config)) base_artifact_dir = self.get_cache_subdir(cache_dir) artifact_dir = os.path.join( base_artifact_dir, 'testprojects.src.java.org.pantsbuild.testproject.annotation.main.main', ) self.assertTrue(os.path.exists(artifact_dir)) artifacts = os.listdir(artifact_dir) self.assertEqual(len(artifacts), 1) with temporary_dir() as extract_dir: TarArchiver.extract(os.path.join(artifact_dir, artifacts[0]), extract_dir) all_files = set() for dirpath, dirs, files in safe_walk(extract_dir): for name in files: path = os.path.join(dirpath, name) all_files.add(path) # Locate the report file on the classpath. report_file_name = 'deprecation_report.txt' reports = [f for f in all_files if f.endswith(report_file_name)] self.assertEquals(1, len(reports), 'Expected exactly one {} file; got: {}'.format(report_file_name, all_files)) with open(reports[0]) as fp: annotated_classes = [line.rstrip() for line in fp.read().splitlines()] self.assertEquals( {'org.pantsbuild.testproject.annotation.main.Main', 'org.pantsbuild.testproject.annotation.main.Main$TestInnerClass'}, set(annotated_classes))