def extract_target(java_targets, is_transitive, name = None): meta_target = bang.extract_target(java_targets, name) internal_deps, jar_deps = _extract_target(meta_target, is_transitive, lambda target: is_apt(target)) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(meta_target): return JavaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) elif is_scala(meta_target): return ScalaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def extract_target(java_targets, is_classpath): primary_target = InternalTarget.sort_targets(java_targets)[0] with ParseContext.temp(primary_target.target_base): internal_deps, jar_deps = _extract_target(java_targets, is_classpath) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(primary_target): return JavaLibrary('ide', sources, dependencies = all_deps, is_meta = True) elif is_scala(primary_target): return ScalaLibrary('ide', sources, dependencies = all_deps, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def stage_artifacts(target, jar, version, changelog, confs=None): def artifact_path(name=None, suffix='', extension='jar'): return os.path.join( self.outdir, jar.org, jar.name, '%s-%s%s.%s' % ((name or jar.name), version, suffix, extension)) with safe_open(artifact_path(suffix='-CHANGELOG', extension='txt'), 'w') as changelog_file: changelog_file.write(changelog) def get_pushdb(target): return get_db(target)[0] PomWriter(get_pushdb).write(target, artifact_path(extension='pom')) ivyxml = artifact_path(name='ivy', extension='xml') IvyWriter(get_pushdb).write(target, ivyxml, confs) def copy(typename, suffix=''): genmap = self.context.products.get(typename) for basedir, jars in genmap.get(target).items(): for artifact in jars: shutil.copy(os.path.join(basedir, artifact), artifact_path(suffix=suffix)) copy('jars') if is_java(target): copy('javadoc_jars', '-javadoc') copy('source_jars', '-sources') return ivyxml
def stage_artifacts(target, jar, version, changelog, confs=None): def artifact_path(name=None, suffix='', extension='jar'): return os.path.join(self.outdir, jar.org, jar.name, '%s-%s%s.%s' % ((name or jar.name), version, suffix, extension)) with safe_open(artifact_path(suffix='-CHANGELOG', extension='txt'), 'w') as changelog_file: changelog_file.write(changelog) def get_pushdb(target): return get_db(target)[0] PomWriter(get_pushdb).write(target, artifact_path(extension='pom')) ivyxml = artifact_path(name='ivy', extension='xml') IvyWriter(get_pushdb).write(target, ivyxml, confs) def copy(typename, suffix=''): genmap = self.context.products.get(typename) for basedir, jars in genmap.get(target).items(): for artifact in jars: shutil.copy(os.path.join(basedir, artifact), artifact_path(suffix=suffix)) copy('jars') if is_java(target): copy('javadoc_jars', '-javadoc') copy('source_jars', '-sources') return ivyxml
def extract_target(java_targets, is_transitive, is_classpath, name = None): meta_target = bang.extract_target(java_targets, name) internal_deps, jar_deps = _extract_target(meta_target, is_transitive, is_classpath) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(meta_target): return JavaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) elif is_scala(meta_target): return ScalaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def add_sources_under_test(tgt): if is_java(tgt) and not is_test(tgt) and not is_codegen(tgt): for source in tgt.sources: classes = classes_by_source.get(source) if classes: for base, classes in classes.items(): classes_under_test.update( JUnitRun.classfile_to_classname(cls) for cls in classes )
def add_sources_under_test(tgt): if is_java(tgt) and not is_test(tgt) and not is_codegen(tgt): for source in tgt.sources: classes = classes_by_source.get(source) if classes: for base, classes in classes.items(): classes_under_test.update( JUnitRun.classfile_to_classname(cls) for cls in classes)
def is_cp(target): return ( is_codegen(target) # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) or (self.intransitive and target not in self.context.target_roots))
def is_cp(target): return ( target.is_codegen # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) )
def stage_artifacts(target, jar, version, changelog, confs=None, synth_target=None): def artifact_path(name=None, suffix='', extension='jar', artifact_ext=''): return os.path.join(self.outdir, jar.org, jar.name + artifact_ext, '%s%s-%s%s.%s' % ( (name or jar.name), artifact_ext if name != 'ivy' else '', version, suffix, extension )) def get_pushdb(target): return get_db(target)[0] with safe_open(artifact_path(suffix='-CHANGELOG', extension='txt'), 'w') as changelog_file: changelog_file.write(changelog) ivyxml = artifact_path(name='ivy', extension='xml') IvyWriter(get_pushdb).write(target, ivyxml, confs) PomWriter(get_pushdb).write(target, artifact_path(extension='pom')) idl_ivyxml = None if synth_target: changelog_path = artifact_path(suffix='-CHANGELOG', extension='txt', artifact_ext='-only') with safe_open(changelog_path, 'w') as changelog_file: changelog_file.write(changelog) idl_ivyxml = artifact_path(name='ivy', extension='xml', artifact_ext='-only') # use idl publication spec in ivy for idl artifact IvyWriter(get_pushdb).write(synth_target, idl_ivyxml, ['idl'], synth=True) PomWriter(get_pushdb).write(synth_target, artifact_path(extension='pom', artifact_ext='-only'), synth=True) def copy(tgt, typename, suffix='', artifact_ext=''): genmap = self.context.products.get(typename) mapping = genmap.get(tgt) if not mapping: print('no mapping for %s' % tgt) else: for basedir, jars in mapping.items(): for artifact in jars: path = artifact_path(suffix=suffix, artifact_ext=artifact_ext) shutil.copy(os.path.join(basedir, artifact), path) copy(target, typename='jars') copy(target, typename='source_jars', suffix='-sources') if (synth_target): copy(synth_target, typename='idl_jars', suffix='-idl', artifact_ext='-only') if is_java(target): copy(target, typename='javadoc_jars', suffix='-javadoc') return ivyxml, idl_ivyxml
def is_cp(target): return ( is_codegen(target) # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) or (self.intransitive and target not in self.context.target_roots) )
def execute(self): target = Target.get(self.address) if is_java(target): if self.is_graph: self._print_digraph(target) else: self._print_dependency_tree(target) elif is_python(target): if self.is_internal_only or self.is_external_only or self.is_minimal or self.is_graph: print >> sys.stderr, 'Unsupported option for Python target' sys.exit(1) self._print_python_dependencies(target, 0)
def calculate_tests(self, targets): def is_test_file(test): # TODO(John Sirois): config for a list of include regexes and exclude regexes basename = os.path.basename(test) return (test.endswith('Test.java') or test.endswith('IT.java')) \ and not basename.startswith('Base') and not basename.startswith('Abstract') tests = set() for target in targets: if is_java(target) and is_test(target): tests.update(self.normalize(test, target.target_base) for test in target.sources if is_test_file(test)) return tests
def print_deps(printed, dep, indent = 0): dep_id, _ = self._dep_id(dep) if dep_id in printed: if not self.is_minimal: print_dep("*%s" % dep_id, indent) else: if not self.is_external_only: print_dep(dep_id, indent) printed.add(dep_id) indent += 1 for internal_dep in dep.internal_dependencies: print_deps(printed, internal_dep, indent) if not self.is_internal_only: if is_java(self): for jar_dep in dep.jar_dependencies: jar_dep_id, internal = self._dep_id(jar_dep) if not internal: if jar_dep_id not in printed or (not self.is_minimal and not self.is_external_only): print_dep(jar_dep_id, indent) printed.add(jar_dep_id)
def print_deps(printed, dep, indent=0): dep_id, _ = self._dep_id(dep) if dep_id in printed: if not self.is_minimal: print_dep("*%s" % dep_id, indent) else: if not self.is_external_only: print_dep(dep_id, indent) printed.add(dep_id) indent += 1 for internal_dep in dep.internal_dependencies: print_deps(printed, internal_dep, indent) if not self.is_internal_only: if is_java(self): for jar_dep in dep.jar_dependencies: jar_dep_id, internal = self._dep_id(jar_dep) if not internal: if jar_dep_id not in printed or ( not self.is_minimal and not self.is_external_only): print_dep(jar_dep_id, indent) printed.add(jar_dep_id)
def _is_checked(target): return is_java(target) and not is_synthetic(target)
def _is_java(target): return (is_java(target) or (isinstance(target, (JvmBinary, junit_tests, Benchmark)) and _has_sources(target, '.java')))
def source_target(target): return (self.transitive or target in self.targets) and has_sources(target) \ and (not is_codegen(target) and not (self.skip_java and is_java(target)) and not (self.skip_scala and is_scala(target)))
def calculate_tests(self, targets): for target in targets: if (is_java(target) or is_scala(target)) and is_test(target): for test in target.sources: for cls in self.normalize(test, target.target_base): yield cls
def is_coverage_target(self, tgt): return (is_java(tgt) or is_scala(tgt)) and not is_test(tgt) and not is_codegen(tgt)
def _is_checked(target): return is_java(target) and not target.is_codegen
def _is_checked(target): return is_java(target) and not is_codegen(target)
def source_target(target): return has_sources(target) \ and (not target.is_codegen and not (self.skip_java and is_java(target)) and not (self.skip_scala and is_scala(target)))
def is_cp(target): return target.is_codegen \ or is_apt(target) \ or (skip_java and is_java(target)) \ or (skip_scala and is_scala(target))