def test_no_dependencies(self, isdir_mock): isdir_mock.return_value = False pc = VersionCompile("/base/", "", "") cp = pc.get_dependency_classpath() assert_equals(cp, "")
def test_builds_classpath(self, listdir_mock, isdir_mock): isdir_mock.return_value = True listdir_mock.return_value = ["foo.jar", "bar.jar"] pc = VersionCompile("/base/", "", "") cp = pc.get_dependency_classpath() assert_equals(cp, "/base/dependencies/foo.jar:/base/dependencies/bar.jar")
def _get_detector_arguments(version_compile: VersionCompile): return { key_detector_mode: DetectAllFindingsTask.__DETECTOR_MODE, key_target_src_paths: version_compile.original_sources_paths, key_target_classes_paths: version_compile.original_classes_paths, key_dependency_classpath: version_compile.get_full_classpath() }
def _get_detector_arguments(version_compile: VersionCompile, misuse_compile: MisuseCompile): return { key_detector_mode: DetectProvidedCorrectUsagesTask.__DETECTOR_MODE, key_training_src_path: misuse_compile.correct_usage_sources_path, key_training_classes_path: misuse_compile.correct_usage_classes_path, key_target_src_paths: [misuse_compile.misuse_source_path], key_target_classes_paths: [misuse_compile.misuse_classes_path], key_dependency_classpath: version_compile.get_full_classpath() }
def run(self, misuse: Misuse, version_compile: VersionCompile): logger = logging.getLogger("task.compile_patterns") misuse_compile = misuse.get_misuse_compile(self.compile_base_path) if self.force_compile or version_compile.timestamp > misuse_compile.timestamp: misuse_compile.delete() if not exists(misuse_compile.misuse_source_path): logger.debug("Copying misuse sources...") for source_path in version_compile.original_sources_paths: CompileMisuseTask._copy_misuse_sources(source_path, misuse, misuse_compile.misuse_source_path) if not exists(misuse_compile.misuse_classes_path): logger.debug("Copying misuse classes...") for classes_path in version_compile.original_classes_paths: CompileMisuseTask._copy_misuse_classes(classes_path, misuse, misuse_compile.misuse_classes_path) try: if misuse_compile.needs_copy_sources() or misuse_compile.needs_compile(): logger.info("Compiling correct usage for %s...", misuse) if misuse_compile.needs_copy_sources(): logger.debug("Copying correct-usage sources...") copy_tree(misuse.correct_usage_path, misuse_compile.correct_usage_sources_path) if misuse_compile.needs_compile(): logger.debug("Compiling correct usages...") CompileMisuseTask._compile_correct_usages(misuse_compile.correct_usage_sources_path, misuse_compile.correct_usage_classes_path, version_compile.get_full_classpath()) misuse_compile.save(self.run_timestamp) elif misuse.correct_usages: logger.info("Correct usage already compiled.") except Exception: misuse_compile.delete() raise return misuse_compile
def test_saves_timestamp(self, _): test_timestamp = 1516183458 uut = VersionCompile(self.temp_dir, "", "") uut.save(test_timestamp) assert_equals(test_timestamp, uut.timestamp)
def test_uses_zero_time_if_never_saved(self, _): uut = VersionCompile(self.temp_dir, "", "") assert_equals(0, uut.timestamp)
def get_compile(self, base_path: str) -> VersionCompile: return VersionCompile( join(base_path, self.project_id, self.version_id), self.source_dirs, self.classes_dirs)