From 311dc718e4796b0b03de65a318e264df9a44bbde Mon Sep 17 00:00:00 2001 From: Di Sang Date: Thu, 1 Apr 2021 01:07:40 -0400 Subject: [PATCH] Revert to 720e64f615934197876a70124e0a65cb282f0753 --- BUILD | 15 --- common/common.py | 14 --- config/config.py | 22 +--- config/pom_template.xml | 1 - crawl/pom.py | 223 +++++++++++++----------------------- crawl/pomparser.py | 40 +------ crawl/pomproperties.py | 60 ---------- crawl/workspace.py | 4 +- misc/extdeps_pomgen.py | 1 - pomgen.py | 1 - query.py | 1 - tests/buildpomupdatetest.py | 1 + tests/crawlertest.py | 2 +- tests/crawlertest_misc.py | 8 +- tests/crawlerunittest.py | 2 +- tests/pomgentest.py | 1 + tests/pompropertiestest.py | 99 ---------------- tests/pomtest.py | 124 ++++---------------- tests/workspacetest.py | 23 ++-- 19 files changed, 129 insertions(+), 513 deletions(-) delete mode 100644 crawl/pomproperties.py delete mode 100644 tests/pompropertiestest.py diff --git a/BUILD b/BUILD index 384947f..4b9ccd9 100644 --- a/BUILD +++ b/BUILD @@ -87,7 +87,6 @@ py_test( py_test( name = "buildpomtest", srcs = ["common/code.py", - "common/common.py", "common/mdfiles.py", "common/pomgenmode.py", "common/version.py", @@ -209,7 +208,6 @@ py_test( py_test( name = "pomparsertest", srcs = ["common/logger.py", - "common/common.py", "crawl/dependency.py", "crawl/pomparser.py", "tests/pomparsertest.py"], @@ -218,19 +216,6 @@ py_test( python_version = python_version, ) -py_test( - name = "pompropertiestest", - srcs = ["common/common.py", - "common/logger.py", - "crawl/dependency.py", - "crawl/pomparser.py", - "crawl/pomproperties.py", - "tests/pompropertiestest.py"], - imports = ["."], - size = "small", - python_version = python_version, -) - py_test( name = "workspacetest", srcs = [":pomgen_files", diff --git a/common/common.py b/common/common.py index 9b9a523..a0c2ff6 100644 --- a/common/common.py +++ b/common/common.py @@ -10,8 +10,6 @@ import os -INDENT = 4 # spaces - def get_repo_root(repo_root=None): if repo_root is None: repo_root = os.getcwd() @@ -29,15 +27,3 @@ def get_repo_root(repo_root=None): def _has_workspace_file(repo_root): return os.path.exists(os.path.join(repo_root, "WORKSPACE")) -def xml(content, element, indent, value=None, close_element=False): - """ - Helper method used to generated xml. - """ - if value is None: - if close_element: - return "%s%s%s" % (content, ' '*(indent - INDENT), element, os.linesep), indent - INDENT - else: - return "%s%s<%s>%s" % (content, ' '*indent, element, os.linesep), indent + INDENT - else: - return "%s%s<%s>%s%s" % (content, ' '*indent, element, value, element, os.linesep), indent - diff --git a/config/config.py b/config/config.py index 4ff0d0d..a03198b 100644 --- a/config/config.py +++ b/config/config.py @@ -80,8 +80,6 @@ def artifact(option, dflt, valid_values=None): cfg = Config( pom_template_path_and_content=_read_files(repo_root, pom_template_p)[0], maven_install_paths=gen("maven_install_paths", ("maven_install.json",)), - version_property_prefix=gen("version_property_prefix", ""), - version_property_suffix=gen("version_property_suffix", ""), excluded_dependency_paths=crawl("excluded_dependency_paths", ()), excluded_src_relpaths=artifact("excluded_relative_paths", ("src/test",)), excluded_src_file_names=artifact("excluded_filenames", (".gitignore",)), @@ -112,8 +110,6 @@ class Config: def __init__(self, pom_template_path_and_content=("",""), maven_install_paths=(), - version_property_prefix="", - version_property_suffix="", excluded_dependency_paths=(), excluded_src_relpaths=(), excluded_src_file_names=(), @@ -121,10 +117,8 @@ def __init__(self, transitives_versioning_mode="semver"): # general - self.pom_template_path_and_content = pom_template_path_and_content + self.pom_template_path_and_content=pom_template_path_and_content self.maven_install_paths = _to_tuple(maven_install_paths) - self._version_property_prefix = version_property_prefix - self._version_property_suffix = version_property_suffix # crawler self.excluded_dependency_paths = _add_pathsep(_to_tuple(excluded_dependency_paths)) @@ -148,20 +142,6 @@ def all_src_exclusions(self): self.excluded_src_file_names, self.excluded_src_file_extensions) - @property - def version_property_prefix(self): - """ - Convenience method that returns the prefix to use for generated version properties. - """ - return self._version_property_prefix - - @property - def version_property_suffix(self): - """ - Convenience method that returns the suffix to use for generated version properties. - """ - return self._version_property_suffix - def __str__(self): return """[general] pom_template_path=%s diff --git a/config/pom_template.xml b/config/pom_template.xml index e008ad1..daa8c43 100644 --- a/config/pom_template.xml +++ b/config/pom_template.xml @@ -17,7 +17,6 @@ UTF-8 1.8 1.8 -#{dependency_management_version_properties} #{dependencies} diff --git a/crawl/pom.py b/crawl/pom.py index 6e9f52a..c847882 100644 --- a/crawl/pom.py +++ b/crawl/pom.py @@ -8,13 +8,10 @@ """ from common import pomgenmode -from common import logger -from common import common import copy from crawl import bazel from crawl import pomparser from crawl import workspace -from crawl import pomproperties import os import re @@ -193,7 +190,21 @@ def _dep_version(self, pomcontenttype, dep): """ return PomContentType.MASKED_VERSION if pomcontenttype is PomContentType.GOLDFILE and dep.bazel_package is not None else dep.version - def _gen_dependency_element(self, pomcontenttype, dep, content, indent, close_element, group_version_dict={}): + def _xml(self, content, element, indent, value=None, close_element=False): + """ + Helper method used to generated xml. + + This method is only intended to be called by subclasses. + """ + if value is None: + if close_element: + return "%s%s%s" % (content, ' '*(indent - _INDENT), element, os.linesep), indent - _INDENT + else: + return "%s%s<%s>%s" % (content, ' '*indent, element, os.linesep), indent + _INDENT + else: + return "%s%s<%s>%s%s" % (content, ' '*indent, element, value, element, os.linesep), indent + + def _gen_dependency_element(self, pomcontenttype, dep, content, indent, close_element): """ Generates a pomx.xml element. @@ -202,33 +213,29 @@ def _gen_dependency_element(self, pomcontenttype, dep, content, indent, close_el This method is only intended to be called by subclasses. """ - content, indent = common.xml(content, "dependency", indent) - content, indent = common.xml(content, "groupId", indent, dep.group_id) - content, indent = common.xml(content, "artifactId", indent, dep.artifact_id) - version_from_dep = self._dep_version(pomcontenttype, dep) - if dep.group_id in group_version_dict and version_from_dep == group_version_dict[dep.group_id].get_property_value(): - content, indent = common.xml(content, "version", indent, "${%s}" % group_version_dict[dep.group_id].get_property_name()) - else: - content, indent = common.xml(content, "version", indent, version_from_dep) + content, indent = self._xml(content, "dependency", indent) + content, indent = self._xml(content, "groupId", indent, dep.group_id) + content, indent = self._xml(content, "artifactId", indent, dep.artifact_id) + content, indent = self._xml(content, "version", indent, self._dep_version(pomcontenttype, dep)) if dep.classifier is not None: - content, indent = common.xml(content, "classifier", indent, dep.classifier) + content, indent = self._xml(content, "classifier", indent, dep.classifier) if dep.scope is not None: - content, indent = common.xml(content, "scope", indent, dep.scope) + content, indent = self._xml(content, "scope", indent, dep.scope) if close_element: - content, indent = common.xml(content, "dependency", indent, close_element=True) + content, indent = self._xml(content, "dependency", indent, close_element=True) return content, indent def _gen_exclusions(self, content, indent, group_and_artifact_ids): """ This method is only intended to be called by subclasses. """ - content, indent = common.xml(content, "exclusions", indent) + content, indent = self._xml(content, "exclusions", indent) for ga in group_and_artifact_ids: - content, indent = common.xml(content, "exclusion", indent) - content, indent = common.xml(content, "groupId", indent, ga[0]) - content, indent = common.xml(content, "artifactId", indent, ga[1]) - content, indent = common.xml(content, "exclusion", indent, close_element=True) - content, indent = common.xml(content, "exclusions", indent, close_element=True) + content, indent = self._xml(content, "exclusion", indent) + content, indent = self._xml(content, "groupId", indent, ga[0]) + content, indent = self._xml(content, "artifactId", indent, ga[1]) + content, indent = self._xml(content, "exclusion", indent, close_element=True) + content, indent = self._xml(content, "exclusions", indent, close_element=True) return content, indent def _remove_token(self, content, token_name): @@ -247,9 +254,9 @@ def _remove_token(self, content, token_name): def _gen_description(self, description): content = "" - content, indent = common.xml(content, "description", indent=_INDENT) + content, indent = self._xml(content, "description", indent=_INDENT) content = "%s%s%s%s" % (content, ' '*indent, description, os.linesep) - content, indent = common.xml(content, "description", indent=indent, close_element=True) + content, indent = self._xml(content, "description", indent=indent, close_element=True) return content def _handle_description(self, content, description): @@ -258,9 +265,6 @@ def _handle_description(self, content, description): else: return content.replace("#{description}", self._gen_description(description)) - def _get_property_prefix_suffix(self): - return self._workspace.property_prefix_suffix - class NoopPomGen(AbstractPomGen): """ A placeholder pom generator that doesn't generator anything, but still @@ -280,9 +284,6 @@ class TemplatePomGen(AbstractPomGen): UNUSED_CONFIGURED_DEPS_PROP_NAME = "pomgen.unencountered_dependencies" DEPS_CONFIG_SECTION_START = "__pomgen.start_dependency_customization__" DEPS_CONFIG_SECTION_END = "__pomgen.end_dependency_customization__" - PROPERTIES_SECTION_START = "" - PROPERTIES_SECTION_END = "" - VERSION_PROPERTY_SUBSTITUTION = "pomgen.template_generated_properties" # these properties need to be replaced first in pom templates # because their values may reference other properties @@ -296,26 +297,24 @@ def __init__(self, workspace, artifact_def, dependency): super(TemplatePomGen, self).__init__(workspace, artifact_def, dependency) def gen(self, pomcontenttype): pom_content = self.artifact_def.custom_pom_template_content - parsed_properties = self._process_properties_content(pom_content) - pom_content, parsed_dependencies = self._process_deps_customization_content(pom_content) - all_version_properties, template_version_properties, group_version_dict = self._get_version_properties(pomcontenttype, parsed_properties) - substitute_version_properties = ("#{%s}" % TemplatePomGen.VERSION_PROPERTY_SUBSTITUTION in pom_content or pom_content.find(TemplatePomGen.PROPERTIES_SECTION_START) != -1) - initial_properties, updated_group_version_dict = self._get_crawled_dependencies_properties(pomcontenttype, parsed_dependencies, group_version_dict, substitute_version_properties) + pom_content, parsed_dependencies = self._process_pom_template_content(pom_content) + + properties = self._get_properties(pomcontenttype, parsed_dependencies) + for k in TemplatePomGen.INITAL_PROPERTY_SUBSTITUTIONS: - if k in initial_properties: - pom_content = pom_content.replace("#{%s}" % k, initial_properties[k]) - del initial_properties[k] - if substitute_version_properties: - pom_content = self._add_generated_version_properties(updated_group_version_dict, pom_content) - for k in all_version_properties.keys(): - pom_content = pom_content.replace("#{%s}" % k, all_version_properties[k]) - bad_refs = [match.group(1) for match in re.finditer(r"""\#\{(.*?)\}""", pom_content) if len(match.groups()) == 1] + if k in properties: + pom_content = pom_content.replace("#{%s}" % k, properties[k]) + del properties[k] + + for k in properties.keys(): + pom_content = pom_content.replace("#{%s}" % k, properties[k]) + bad_refs = [match.group(1) for match in re.finditer(r"""\#\{(.*?)\}""", pom_content) if len(match.groups()) == 1] if len(bad_refs) > 0: raise Exception("pom template for [%s] has unresolvable references: %s" % (self._artifact_def, bad_refs)) return pom_content - def _process_deps_customization_content(self, pom_template_content): + def _process_pom_template_content(self, pom_template_content): """ Handles the special "dependency config markers" that may be present in the pom template file. @@ -325,10 +324,8 @@ def _process_deps_customization_content(self, pom_template_content): """ start_section_index = pom_template_content.find(TemplatePomGen.DEPS_CONFIG_SECTION_START) if start_section_index == -1: - return (pom_template_content, pomparser.ParsedDependencies()) + return pom_template_content, pomparser.ParsedDependencies() else: - if TemplatePomGen.TRANSITIVE_DEPS_PROP_NAME not in pom_template_content and TemplatePomGen.UNUSED_CONFIGURED_DEPS_PROP_NAME not in pom_template_content: - logger.error("Dependency customization section found but neither %s nor %s substitution is used. Dependency customization will be ignored." % TemplatePomGen.INITAL_PROPERTY_SUBSTITUTIONS) end_section_index = pom_template_content.index(TemplatePomGen.DEPS_CONFIG_SECTION_END) dynamic_deps_content = pom_template_content[start_section_index + len(TemplatePomGen.DEPS_CONFIG_SECTION_START):end_section_index] # make this a well formed pom @@ -339,21 +336,12 @@ def _process_deps_customization_content(self, pom_template_content): pom_template_content = pom_template_content[:start_section_index] + pom_template_content[end_section_index + len(TemplatePomGen.DEPS_CONFIG_SECTION_END)+1:] return (pom_template_content, parsed_dependencies) - def _process_properties_content(self, pom_template_content): - """ - Processes the section in pom template if exists. - - Returns a list of pomparser.ParsedProperty instances - """ - parsed_properties = [] - start_section_index = pom_template_content.find(TemplatePomGen.PROPERTIES_SECTION_START) - if start_section_index != -1: - end_section_index = pom_template_content.index(TemplatePomGen.PROPERTIES_SECTION_END) - properties_content = pom_template_content[start_section_index:end_section_index + len(TemplatePomGen.PROPERTIES_SECTION_END)] - parsed_properties = pomparser.parse_version_properties(properties_content) - return parsed_properties + def _get_properties(self, pomcontenttype, pom_template_parsed_deps): + properties = self._get_version_properties(pomcontenttype) + properties.update(self._get_crawled_dependencies_properties(pomcontenttype, pom_template_parsed_deps)) + return properties - def _get_version_properties(self, pomcontenttype, pom_template_parsed_properties): + def _get_version_properties(self, pomcontenttype): # the version of all dependencies can be referenced in a pom template # using the syntax: #{::[:]version}. # @@ -414,91 +402,64 @@ def _get_version_properties(self, pomcontenttype, pom_template_parsed_properties # of which maven install rule they are managed by # if the versions differ, then the fully qualified label name # has to be used - key = "%s.version" % dep.unqualified_bazel_label_name - key_to_version[key] = dep.version - key_to_dep[key] = dep - - updated_properties = [] - group_version_dict = {} - for parsed_property in pom_template_parsed_properties: - property_name = parsed_property.get_property_name() - property_value = parsed_property.get_property_value() - templated = re.match('#{(.+)}', property_value) - if templated: - key = templated.group(1) - if key in ["artifact_id", "group_id", "version"]: - continue - version_property = pomparser.ParsedProperty(property_name, key_to_version[key]) - updated_properties.append(version_property) - group_id = key_to_dep[key].group_id - group_version_dict[group_id] = version_property - else: - updated_properties.append(parsed_property) + key_to_version["%s.version" % dep.unqualified_bazel_label_name] = dep.version # the maven coordinates of this artifact can be referenced directly: key_to_version["artifact_id"] = self._artifact_def.artifact_id key_to_version["group_id"] = self._artifact_def.group_id key_to_version["version"] = self._artifact_def_version(pomcontenttype) - return key_to_version, updated_properties, group_version_dict + return key_to_version - def _get_crawled_dependencies_properties(self, pomcontenttype, pom_template_parsed_deps, group_version_dict, substitute_version_properties): + def _get_crawled_dependencies_properties(self, pomcontenttype, pom_template_parsed_deps): # this is somewhat lame: an educated guess on where the properties # being build here will be referenced (within - # project/dependencyManagement/dependencies) + # project/depedencyManagement/dependencies) indent = _INDENT*3 properties = {} - if substitute_version_properties: - updated_group_version_dict = pomproperties.get_group_version_dict(self.dependencies_library_transitive_closure, self._get_property_prefix_suffix(), group_version_dict=group_version_dict) - else: - updated_group_version_dict = {} + content = self._build_deps_property_content( self.dependencies_library_transitive_closure, pom_template_parsed_deps, - pomcontenttype, indent, updated_group_version_dict) + pomcontenttype, indent) properties[TemplatePomGen.TRANSITIVE_DEPS_PROP_NAME] = content - pom_template_only_deps = pom_template_parsed_deps.get_parsed_deps_set_missing_from(self.dependencies_library_transitive_closure) - if substitute_version_properties: - updated_group_version_dict = pomproperties.get_group_version_dict(pom_template_only_deps, self._get_property_prefix_suffix(), group_version_dict=updated_group_version_dict) - else: - updated_group_version_dict = {} + pom_template_only_deps = pom_template_parsed_deps.get_parsed_deps_set_missing_from(self.dependencies_library_transitive_closure) content = self._build_template_only_deps_property_content(\ _sort(pom_template_only_deps), pom_template_parsed_deps, - indent, updated_group_version_dict) + indent) properties[TemplatePomGen.UNUSED_CONFIGURED_DEPS_PROP_NAME] = content - return properties, updated_group_version_dict + + return properties def _build_template_only_deps_property_content(self, deps, pom_template_parsed_deps, - indent, group_version_dict): + indent): content = "" for dep in deps: raw_xml = pom_template_parsed_deps.get_parsed_xml_str_for(dep) - if dep.group_id in group_version_dict and dep.version == group_version_dict[dep.group_id].get_property_value(): - replace_version = group_version_dict[dep.group_id].get_property_name() - raw_xml = raw_xml.replace(dep.version, "${%s}" % replace_version) content += pomparser.indent_xml(raw_xml, indent) content = content.rstrip() return content def _build_deps_property_content(self, deps, pom_template_parsed_deps, - pomcontenttype, indent, group_version_dict): + pomcontenttype, indent): + content = "" deps = _sort(deps) for dep in deps: dep = self._copy_attributes_from_parsed_dep(dep, pom_template_parsed_deps) pom_template_exclusions = pom_template_parsed_deps.get_parsed_exclusions_for(dep) dep_has_exclusions = len(pom_template_exclusions) > 0 - content, indent = self._gen_dependency_element(pomcontenttype, dep, content, indent, close_element=not dep_has_exclusions, group_version_dict=group_version_dict) + content, indent = self._gen_dependency_element(pomcontenttype, dep, content, indent, close_element=not dep_has_exclusions) if dep_has_exclusions: exclusions = list(pom_template_exclusions) exclusions.sort() group_and_artifact_ids = [(d.group_id, d.artifact_id) for d in exclusions] content, indent = self._gen_exclusions(content, indent, group_and_artifact_ids) - content, indent = common.xml(content, "dependency", indent, close_element=True) + content, indent = self._xml(content, "dependency", indent, close_element=True) content = content.rstrip() return content @@ -517,28 +478,13 @@ def _copy_attributes_from_parsed_dep(self, dep, pom_template_parsed_deps): dep.classifier = parsed_dep.classifier return dep - def _add_generated_version_properties(self, group_version_dict, pom_content): - version_properties_content = pomproperties.gen_version_properties(group_version_dict, pom_content) - if "#{%s}" % TemplatePomGen.VERSION_PROPERTY_SUBSTITUTION in pom_content: - content = "" - if version_properties_content: - content, indent = common.xml(content, "properties", indent=_INDENT) - content += version_properties_content - content, indent = common.xml(content, "properties", indent, close_element=True) - pom_content = pom_content.replace("#{%s}" % TemplatePomGen.VERSION_PROPERTY_SUBSTITUTION, content) - else: - properties_section_start_index = pom_content.find(TemplatePomGen.PROPERTIES_SECTION_START) - properties_section_end_index = pom_content.index(TemplatePomGen.PROPERTIES_SECTION_END) - inject_index = pom_content[:properties_section_end_index].rfind(os.linesep) + 1 - pom_content = pom_content[:inject_index] + version_properties_content + pom_content[inject_index:] - return pom_content class DynamicPomGen(AbstractPomGen): """ A non-generic, non-reusable, specialized pom.xml generator, targeted for the "monorepo pom generation" use-case. - Generates a pom.xml file based on the specified singleton (shared) template. + Generates a pom.xm file based on the specified singleton (shared) template. The following placesholders must exist in the specified template: #{dependencies} - will be replaced with the section @@ -560,7 +506,6 @@ def gen(self, pomcontenttype): version = self._artifact_def_version(pomcontenttype) content = content.replace("#{version}", version) content = self._handle_description(content, self.pom_content.description) - content = self._remove_token(content, "#{%s}" % DependencyManagementPomGen.VERSION_PROPERTY_SUBSTITUTION) if len(self.dependencies) == 0: content = self._remove_token(content, "#{dependencies}") else: @@ -583,7 +528,7 @@ def _gen_dependencies(self, pomcontenttype): deps.sort() content = "" - content, indent = common.xml(content, "dependencies", indent=_INDENT) + content, indent = self._xml(content, "dependencies", indent=_INDENT) for dep in deps: content, indent = self._gen_dependency_element(pomcontenttype, dep, content, indent, close_element=False) # handle @@ -592,8 +537,8 @@ def _gen_dependencies(self, pomcontenttype): if len(excluded_group_and_artifact_ids) > 0: content, indent = self._gen_exclusions(content, indent, excluded_group_and_artifact_ids) - content, indent = common.xml(content, "dependency", indent, close_element=True) - content, indent = common.xml(content, "dependencies", indent, close_element=True) + content, indent = self._xml(content, "dependency", indent, close_element=True) + content, indent = self._xml(content, "dependencies", indent, close_element=True) return content def _gen_dep_management(self, pomcontenttype): @@ -619,13 +564,13 @@ def _gen_dep_management(self, pomcontenttype): sorted_transitives = sorted(transitives) content = "" - content, indent = common.xml(content, "dependencyManagement", indent=_INDENT) - content, indent = common.xml(content, "dependencies", indent, close_element=False) + content, indent = self._xml(content, "dependencyManagement", indent=_INDENT) + content, indent = self._xml(content, "dependencies", indent, close_element=False) for dep in sorted_transitives: content, indent = self._gen_dependency_element(pomcontenttype, dep, content, indent, close_element=False) - content, indent = common.xml(content, "dependency", indent, close_element=True) - content, indent = common.xml(content, "dependencies", indent, close_element=True) - content, indent = common.xml(content, "dependencyManagement", indent, close_element=True) + content, indent = self._xml(content, "dependency", indent, close_element=True) + content, indent = self._xml(content, "dependencies", indent, close_element=True) + content, indent = self._xml(content, "dependencyManagement", indent, close_element=True) return content @@ -646,9 +591,6 @@ def _get_hardcoded_exclusions_for_dep(self, dep): class DependencyManagementPomGen(AbstractPomGen): - - VERSION_PROPERTY_SUBSTITUTION = "dependency_management_version_properties" - """ Generates a dependency management" only pom, containing a section with the transitive closure of all @@ -664,7 +606,6 @@ class DependencyManagementPomGen(AbstractPomGen): #{group_id} #{version} """ - def __init__(self, workspace, artifact_def, dependency, pom_template): super(DependencyManagementPomGen, self).__init__(workspace, artifact_def, dependency) self.pom_template = pom_template @@ -682,12 +623,8 @@ def gen(self, pomcontenttype): content = self._handle_description(content, self.pom_content.description) if len(self.dependencies_artifact_transitive_closure) == 0: content = self._remove_token(content, "#{dependencies}") - content = self._remove_token(content, "#{%s}" % DependencyManagementPomGen.VERSION_PROPERTY_SUBSTITUTION) else: - group_version_dict = pomproperties.get_group_version_dict(self.dependencies_artifact_transitive_closure, self._get_property_prefix_suffix()) - version_properties_content = pomproperties.gen_version_properties(group_version_dict) - content = content.replace("#{%s}" % DependencyManagementPomGen.VERSION_PROPERTY_SUBSTITUTION, version_properties_content) - dep_man_content = self._gen_dependency_management(self.dependencies_artifact_transitive_closure, group_version_dict) + dep_man_content = self._gen_dependency_management(self.dependencies_artifact_transitive_closure) content = content.replace("#{dependencies}", dep_man_content) # we assume the template specified jar @@ -699,14 +636,14 @@ def gen(self, pomcontenttype): return content - def _gen_dependency_management(self, deps, group_version_dict): + def _gen_dependency_management(self, deps): content = "" - content, indent = common.xml(content, "dependencyManagement", indent=_INDENT) - content, indent = common.xml(content, "dependencies", indent) + content, indent = self._xml(content, "dependencyManagement", indent=_INDENT) + content, indent = self._xml(content, "dependencies", indent) for dep in deps: - content, indent = self._gen_dependency_element(PomContentType.RELEASE, dep, content, indent, close_element=True, group_version_dict=group_version_dict) - content, indent = common.xml(content, "dependencies", indent, close_element=True) - content, indent = common.xml(content, "dependencyManagement", indent, close_element=True) + content, indent = self._gen_dependency_element(PomContentType.RELEASE, dep, content, indent, close_element=True) + content, indent = self._xml(content, "dependencies", indent, close_element=True) + content, indent = self._xml(content, "dependencyManagement", indent, close_element=True) return content @@ -742,7 +679,7 @@ def _load_additional_dependencies_hook(self): return self.pomgen._load_additional_dependencies_hook() -_INDENT = common.INDENT +_INDENT = pomparser.INDENT def _sort(s): diff --git a/crawl/pomparser.py b/crawl/pomparser.py index e720379..728e79f 100644 --- a/crawl/pomparser.py +++ b/crawl/pomparser.py @@ -11,7 +11,6 @@ from collections import defaultdict from crawl import dependency import os -from common import common try: from lxml import etree except ImportError as ex: @@ -24,7 +23,7 @@ # this is the indentation used when writing out pom content, including content # for pom templates -_INDENT = common.INDENT # spaces +INDENT = 4 # spaces def format_for_comparison(pom_content): """ @@ -36,7 +35,6 @@ def format_for_comparison(pom_content): parser = etree.XMLParser(remove_blank_text=True) tree = etree.XML(pom_content.encode().strip(), parser=parser) - # remove , if it exists description_el = tree.find(XML_NS + "description") if description_el is not None: @@ -58,46 +56,14 @@ def indent_xml(xml_content, indent): line = line.strip() handled_indent = False if line.startswith(" section in the specified pom_content. - - Returns a list of ParsedProperty instances. - """ - - parser = etree.XMLParser(remove_blank_text=True) - tree = etree.XML(pom_content.encode().strip(), parser=parser) - all_props = tree.xpath('/properties/*') - - version_properties = [] - for el in all_props: - property_name = el.tag - if (property_name.endswith(".version")): - property_value = el.text - version_properties.append(ParsedProperty(property_name, property_value)) - - return version_properties - class ParsedDependencies: def __init__(self, dependencies=set(), dependency_to_exclusions=defaultdict(list), dependency_to_str_repr={}): diff --git a/crawl/pomproperties.py b/crawl/pomproperties.py deleted file mode 100644 index 0c7b9d7..0000000 --- a/crawl/pomproperties.py +++ /dev/null @@ -1,60 +0,0 @@ -""" -Copyright (c) 2018, salesforce.com, inc. -All rights reserved. -SPDX-License-Identifier: BSD-3-Clause -For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause - - -This is a helper module for pom property generation - it contains methods that create version properties -content based on groupId. -""" -from common import common -from crawl import pomparser -import re - -_INDENT = common.INDENT - -def get_group_version_dict(deps, property_prefix_suffix, group_version_dict={}): - """ - Processes a list of Dependency instances, and optionally a mapping from groupId to ParsedProperty instance. - If multiple artifacts with same groupId have different versions, this will create a version property for - the first artifact parsed. If a version property for a groupId already exists in the group_version_dict - from input, then it won't create a new property for that groupId. - - Returns a mapping from groupId to ParsedProperty instance. - """ - content = "" - prefix, suffix = property_prefix_suffix - result_group_version_dict = dict(group_version_dict) - for dep in deps: - group_id = dep.group_id - version = dep.version - if group_id not in result_group_version_dict: - if re.match('#{(.+)}', version) or re.match('\${(.+)}', version): - continue - property_name = group_id - if prefix: - property_name = "%s.%s" % (prefix, property_name) - if suffix: - property_name = "%s.%s" % (property_name, suffix) - result_group_version_dict[group_id] = pomparser.ParsedProperty("%s.managed_version" % property_name, version) - return result_group_version_dict - -def gen_version_properties(group_version_dict, pom_content = ""): - """ - Processes a mapping from groupId to ParsedProperty instance, and optionally a pom content. - This method generate version property pom content for the ParsedProperty instances in group_version_dict, - if it does not already exist in pom_content. - - Returns a string with the pom content containing multiple version properties. - """ - group_version_properties = list(group_version_dict.values()) - sorted_group_version_properties = sorted(group_version_properties, key=lambda x: x.get_property_name()) - content = "" - indent = _INDENT*2 - for version_property in sorted_group_version_properties: - property_name = version_property.get_property_name() - property_value = version_property.get_property_value() - if "<%s>" % property_name not in pom_content: - content, indent = common.xml(content, property_name, indent, property_value) - return content diff --git a/crawl/workspace.py b/crawl/workspace.py index 261e524..e3c1926 100644 --- a/crawl/workspace.py +++ b/crawl/workspace.py @@ -22,15 +22,13 @@ class Workspace: """ def __init__(self, repo_root_path, excluded_dependency_paths, - source_exclusions, - property_prefix_suffix, + source_exclusions, maven_install_info, pom_content, verbose=False): self.repo_root_path = repo_root_path self.excluded_dependency_paths = excluded_dependency_paths self.source_exclusions = source_exclusions - self.property_prefix_suffix = property_prefix_suffix self.pom_content = pom_content self.verbose = verbose self.dependency_metadata = dependencymd.DependencyMetadata() diff --git a/misc/extdeps_pomgen.py b/misc/extdeps_pomgen.py index 9233ac2..09e18d9 100755 --- a/misc/extdeps_pomgen.py +++ b/misc/extdeps_pomgen.py @@ -67,7 +67,6 @@ def main(args): ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths, cfg.all_src_exclusions, - (cfg.version_property_prefix, cfg.version_property_suffix), mvn_install_info, pomcontent.NOOP) group_id = "all_ext_deps_group" if args.group_id is None else args.group_id diff --git a/pomgen.py b/pomgen.py index fb7e005..684ed3a 100755 --- a/pomgen.py +++ b/pomgen.py @@ -78,7 +78,6 @@ def main(args): ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths, cfg.all_src_exclusions, - (cfg.version_property_prefix, cfg.version_property_suffix), mvn_install_info, pom_content) packages = argsupport.get_all_packages(repo_root, args.package) diff --git a/query.py b/query.py index 183f8d5..7151c85 100755 --- a/query.py +++ b/query.py @@ -93,7 +93,6 @@ def _matches_filter(maven_artifact, all_filters): ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths, cfg.all_src_exclusions, - (cfg.version_property_prefix, cfg.version_property_suffix), mvn_install_info, pomcontent.NOOP, args.verbose) diff --git a/tests/buildpomupdatetest.py b/tests/buildpomupdatetest.py index bcb56a9..5053d50 100644 --- a/tests/buildpomupdatetest.py +++ b/tests/buildpomupdatetest.py @@ -508,6 +508,7 @@ def test_add_pom_generation_mode_to_BUILD_pom(self): with open(os.path.join(pack1_path, "MVN-INF", "BUILD.pom"), "r") as f: content = f.read() + print(content) self.assertIn('maven_artifact(', content) self.assertIn(' group_id = "p1g"', content) self.assertIn(' artifact_id = "p1a"', content) diff --git a/tests/crawlertest.py b/tests/crawlertest.py index f928638..a4f4658 100644 --- a/tests/crawlertest.py +++ b/tests/crawlertest.py @@ -57,7 +57,7 @@ def setUp(self): self.cwd = os.getcwd() os.chdir(self.repo_root_path) ws = workspace.Workspace(self.repo_root_path, - [], exclusions.src_exclusions(), ("",""), + [], exclusions.src_exclusions(), maven_install_info=maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) self.crawler = crawler.Crawler(ws, pom_template="") diff --git a/tests/crawlertest_misc.py b/tests/crawlertest_misc.py index df0e31c..85532ec 100644 --- a/tests/crawlertest_misc.py +++ b/tests/crawlertest_misc.py @@ -41,7 +41,7 @@ def test_default_package_ref(self): self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1"]) ws = workspace.Workspace(repo_root_path, [], - exclusions.src_exclusions(), ("", ""), + exclusions.src_exclusions(), maveninstallinfo.NOOP, pomcontent.NOOP) crawler = crawlerm.Crawler(ws, pom_template="") @@ -63,7 +63,7 @@ def test_default_package_ref_explicit(self): self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:a1"]) ws = workspace.Workspace(repo_root_path, [], - exclusions.src_exclusions(), ("", ""), + exclusions.src_exclusions(), maveninstallinfo.NOOP, pomcontent.NOOP) crawler = crawlerm.Crawler(ws, pom_template="") @@ -86,7 +86,7 @@ def test_non_default_package_ref__not_allowed(self): self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:foo"]) ws = workspace.Workspace(repo_root_path, [], - exclusions.src_exclusions(), ("", ""), + exclusions.src_exclusions(), maveninstallinfo.NOOP, pomcontent.NOOP) crawler = crawlerm.Crawler(ws, pom_template="") @@ -108,7 +108,7 @@ def test_non_default_package_ref__allowed_for_skip_pom_gen_mode(self): self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:foo"]) ws = workspace.Workspace(repo_root_path, [], - exclusions.src_exclusions(), ("", ""), + exclusions.src_exclusions(), maveninstallinfo.NOOP, pomcontent.NOOP) crawler = crawlerm.Crawler(ws, pom_template="") diff --git a/tests/crawlerunittest.py b/tests/crawlerunittest.py index 8c33fd5..d0cbaa6 100644 --- a/tests/crawlerunittest.py +++ b/tests/crawlerunittest.py @@ -481,7 +481,7 @@ def _get_3rdparty_dep(self, artifact_str, name): def _get_workspace(self): return workspace.Workspace(repo_root_path="a/b/c", excluded_dependency_paths=[], - source_exclusions=[], property_prefix_suffix=("", ""), + source_exclusions=[], maven_install_info=maveninstallinfo.NOOP, pom_content="",) diff --git a/tests/pomgentest.py b/tests/pomgentest.py index 4ef1da9..e6098f2 100644 --- a/tests/pomgentest.py +++ b/tests/pomgentest.py @@ -114,6 +114,7 @@ def _add_LIBRARY_root(self, package_rel_path): self._write_file(package_rel_path, "MVN-INF", "LIBRARY.root", "") def _write_file(self, package_rel_path, rel_path, filename, content): + print(content) path = os.path.join(self.repo_root_path, package_rel_path, rel_path, filename) parent_dir = os.path.dirname(path) diff --git a/tests/pompropertiestest.py b/tests/pompropertiestest.py deleted file mode 100644 index 098ef76..0000000 --- a/tests/pompropertiestest.py +++ /dev/null @@ -1,99 +0,0 @@ -from crawl import dependency -from crawl import pomproperties -from crawl import pomparser -import unittest - -class PomPropertiesTest(unittest.TestCase): - - def test_get_group_version_dict__basic(self): - guava_failureaccess = dependency.new_dep_from_maven_art_str("com.google.guava:failureaccess:1", "failureaccess") - android_annotations = dependency.new_dep_from_maven_art_str("com.google.android:annotations:4", "annotations") - expected_dict = { - "com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1"), - "com.google.android":pomparser.ParsedProperty("com.google.android.managed_version", "4"), - } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, android_annotations], ("","")))) - - def test_get_group_version_dict__same_group_same_version(self): - guava_failureaccess = dependency.new_dep_from_maven_art_str("com.google.guava:failureaccess:1", "failureaccess") - guava_guava = dependency.new_dep_from_maven_art_str("com.google.guava:guava:1", "guava") - expected_dict = { "com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1") } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, guava_guava], ("",""),))) - - def test_get_group_version_dict__same_group_same_version(self): - guava_failureaccess = dependency.new_dep_from_maven_art_str("com.google.guava:failureaccess:1", "failureaccess") - guava_guava = dependency.new_dep_from_maven_art_str("com.google.guava:guava:20", "guava") - expected_dict = { "com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1") } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, guava_guava], ("","")))) - - def test_get_group_version_dict__existing_dict(self): - existing_dict = { "com.google.guava":pomparser.ParsedProperty("existing.guava.version", "20") } - guava_failureaccess = dependency.new_dep_from_maven_art_str("com.google.guava:failureaccess:1", "failureaccess") - expected_dict = { "com.google.guava":pomparser.ParsedProperty("existing.guava.version", "20") } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess], ("",""), existing_dict))) - - def test_get_group_version_dict__with_prefix_suffix(self): - guava_failureaccess = dependency.new_dep_from_maven_art_str("com.google.guava:failureaccess:1", "failureaccess") - android_annotations = dependency.new_dep_from_maven_art_str("com.google.android:annotations:4", "annotations") - expected_dict = { - "com.google.guava":pomparser.ParsedProperty("testprefix.com.google.guava.managed_version", "1"), - "com.google.android":pomparser.ParsedProperty("testprefix.com.google.android.managed_version", "4"), - } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, android_annotations], ("testprefix","")))) - - expected_dict = { - "com.google.guava":pomparser.ParsedProperty("com.google.guava.testsuffix.managed_version", "1"), - "com.google.android":pomparser.ParsedProperty("com.google.android.testsuffix.managed_version", "4"), - } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, android_annotations], ("","testsuffix")))) - - expected_dict = { - "com.google.guava":pomparser.ParsedProperty("testprefix.com.google.guava.testsuffix.managed_version", "1"), - "com.google.android":pomparser.ParsedProperty("testprefix.com.google.android.testsuffix.managed_version", "4"), - } - self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, android_annotations], ("testprefix","testsuffix")))) - - def test_gen_version_properties__basic(self): - group_version_dict = { - "com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1") - } - expected_pom = " 1\n" - self.assertEqual(expected_pom, pomproperties.gen_version_properties(group_version_dict)) - - def test_gen_version_properties__sorted(self): - group_version_dict = { - "com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1"), - "com.google.android":pomparser.ParsedProperty("com.google.android.managed_version", "4"), - } - expected_pom = """ 4 - 1 -""" - self.assertEqual(expected_pom, pomproperties.gen_version_properties(group_version_dict)) - - def test_gen_version_properties__existing_property(self): - group_version_dict = { - "com.google.guava":pomparser.ParsedProperty("com.google.guava.version", "1"), - "com.google.android":pomparser.ParsedProperty("com.google.android.managed_version", "4"), - } - original_pom = """ - - - 1 - - -""" - expected_pom = " 4\n" - self.assertEqual(expected_pom, pomproperties.gen_version_properties(group_version_dict, original_pom)) - - def _compare_group_version_dict(self, expected_dict, actual_dict): - for group_id in expected_dict: - if group_id not in actual_dict: - return False - else: - if expected_dict[group_id].get_property_name() != actual_dict[group_id].get_property_name() or expected_dict[group_id].get_property_value() != actual_dict[group_id].get_property_value(): - return False - return True - -if __name__ == '__main__': - unittest.main() - diff --git a/tests/pomtest.py b/tests/pomtest.py index ac06837..731e309 100644 --- a/tests/pomtest.py +++ b/tests/pomtest.py @@ -31,8 +31,6 @@ class PomTest(unittest.TestCase): - maxDiff = None - def setUp(self): f = dependency.new_dep_from_maven_art_str all_excluded_dep = f("*:*:-1", "maven") @@ -57,7 +55,7 @@ def test_dynamic_pom__sanity(self): Ensures that dynamic pom generation isn't totally broken. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3") artifact_def = buildpom._augment_art_def_values(artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC) @@ -137,9 +135,9 @@ def test_dynamic_pom__gen_description(self): """ pc = pomcontent.PomContent() pc.description = "this is a cool description" - ws = workspace.Workspace("some/path", [], + ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pc) pom_template = """ #{description} @@ -163,7 +161,7 @@ def test_dynamic_pom__remove_description_token_if_no_value(self): # pc.description IS NOT set here - that's the point of this test ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pc) pom_template = """ #{description} @@ -194,7 +192,7 @@ def test_dyamic_pom__no_dep_management(self): artifact_def = buildpom._augment_art_def_values(artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC) dep = dependency.new_dep_from_maven_artifact_def(artifact_def) ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) pomgen = pom.DynamicPomGen(ws, artifact_def, dep, TEST_POM_TEMPLATE) org_function = bazel.query_java_library_deps_attributes @@ -219,7 +217,7 @@ def test_dynamic_pom__do_not_include_deps(self): Tests the seldomly used "include_deps = False" BUILD.pom attribute. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", include_deps=False) @@ -241,7 +239,7 @@ def test_dynamic_pom_genmode__goldfile(self): Test goldfile mode with dynamic pom gen. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) artifact_def = buildpom.maven_artifact("g1", "a2", "1.2.3") artifact_def = buildpom._augment_art_def_values(artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC) @@ -283,7 +281,7 @@ def test_template_var_sub(self): Verifies variable substitution in a pom template. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.4.4") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -306,11 +304,11 @@ def test_template_var_sub__monorepo_deps(self): Verifies references to monorepo versions in a pom template. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) - artifact_def.custom_pom_template_content = "#{pomgen.template_generated_properties} srpc #{com.grail.srpc:srpc-api:version}" + artifact_def.custom_pom_template_content = "srpc #{com.grail.srpc:srpc-api:version}" srpc_artifact_def = buildpom.MavenArtifactDef( "com.grail.srpc", "srpc-api", "5.6.7", bazel_package="a/b/c") srpc_dep = dependency.MonorepoDependency(srpc_artifact_def, bazel_target=None) @@ -327,7 +325,7 @@ def test_template_var_sub__conflicting_gav__ext_and_BUILDpom(self): and what is set in BUILD.pom files. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -348,7 +346,7 @@ def test_template_genmode__goldfile(self): Verifies version omissions when genmode is GOLDFILE. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), self._mocked_mvn_install_info("maven"), + self._mocked_mvn_install_info("maven"), pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -357,7 +355,6 @@ def test_template_genmode__goldfile(self): srpc_artifact_def = buildpom._augment_art_def_values(srpc_artifact_def, None, "pack1", None, None, pomgenmode.DYNAMIC) srpc_dep = dependency.MonorepoDependency(srpc_artifact_def, bazel_target=None) artifact_def.custom_pom_template_content = """ -#{pomgen.template_generated_properties} this artifact version #{version} logback coord #{ch.qos.logback:logback-classic:version} logback qualified #{@maven//:ch_qos_logback_logback_classic.version} @@ -399,7 +396,7 @@ def test_template__deps_config_setion_is_removed(self): """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -458,13 +455,15 @@ def test_template__unencountered_deps(self): """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = pom_template pomgen = pom.TemplatePomGen(ws, artifact_def, dep) + generated_pom = pomgen.gen(pom.PomContentType.RELEASE) + self.assertEqual(expected_pom, generated_pom) def test_template__library_transitives(self): @@ -474,7 +473,6 @@ def test_template__library_transitives(self): """ pom_template = """ -#{pomgen.template_generated_properties} #{pomgen.transitive_closure_of_library_dependencies} @@ -485,29 +483,24 @@ def test_template__library_transitives(self): expected_pom = """ - - 0.0.1 - 5.6.7 - - com.grail.srpc srpc-api - ${com.grail.srpc.managed_version} + 5.6.7 cg ca - ${cg.managed_version} + 0.0.1 """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -531,7 +524,6 @@ def test_template__crawled_external_deps__configured_exclusions(self): """ pom_template = """ -#{pomgen.template_generated_properties} __pomgen.start_dependency_customization__ @@ -560,16 +552,12 @@ def test_template__crawled_external_deps__configured_exclusions(self): expected_pom = """ - - 0.0.1 - - cg ca - ${cg.managed_version} + 0.0.1 c1 @@ -587,7 +575,7 @@ def test_template__crawled_external_deps__configured_exclusions(self): """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -607,7 +595,6 @@ def test_template__crawled_external_deps__configured_attributes(self): """ pom_template = """ -#{pomgen.template_generated_properties} __pomgen.start_dependency_customization__ @@ -627,16 +614,12 @@ def test_template__crawled_external_deps__configured_attributes(self): expected_pom = """ - - 0.0.1 - - cg ca - ${cg.managed_version} + 0.0.1 sources test @@ -645,7 +628,7 @@ def test_template__crawled_external_deps__configured_attributes(self): """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) @@ -658,70 +641,13 @@ def test_template__crawled_external_deps__configured_attributes(self): self.assertEqual(expected_pom, generated_pom) - def test_template__reuse_version_properties(self): - """ - Verifies that transitive dependencies can be referenced using the - property pomgen.transitive_closure_of_library_dependencies. - """ - pom_template = """ - - - #{com.grail.srpc:srpc-api:version} - - - -#{pomgen.transitive_closure_of_library_dependencies} - - - -""" - - expected_pom = """ - - - 5.6.7 - 0.0.1 - - - - - com.grail.srpc - srpc-api - ${existing.srpc.version} - - - cg - ca - ${cg.managed_version} - - - - -""" - ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, - pomcontent.NOOP) - artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") - dep = dependency.new_dep_from_maven_artifact_def(artifact_def) - artifact_def.custom_pom_template_content = pom_template - pomgen = pom.TemplatePomGen(ws, artifact_def, dep) - srpc_artifact_def = buildpom.MavenArtifactDef( - "com.grail.srpc", "srpc-api", "5.6.7", bazel_package="a/b/c") - internal_dep = dependency.MonorepoDependency(srpc_artifact_def, bazel_target=None) - - external_dep = dependency.ThirdPartyDependency("name", "cg", "ca", "0.0.1") - pomgen.register_dependencies_transitive_closure__library(set([external_dep, internal_dep])) - - generated_pom = pomgen.gen(pom.PomContentType.RELEASE) - self.assertEqual(expected_pom, generated_pom) - def test_template_unknown_variable(self): """ Verifies that an unknown variable in a pom template is handled and results in an error during template processing. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.maven_artifact("groupId", "artifactId", "1.2.3") @@ -740,7 +666,7 @@ def test_depman_pom__sanity(self): Ensures that dependency management pom generation isn't totally broken. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("", ""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pomcontent.NOOP) artifact_def = buildpom.MavenArtifactDef( "g1", "a2", "1.2.3", gen_dependency_management_pom=True) diff --git a/tests/workspacetest.py b/tests/workspacetest.py index 3f35245..8e33820 100644 --- a/tests/workspacetest.py +++ b/tests/workspacetest.py @@ -37,7 +37,7 @@ def tearDown(self): def test_normalize_deps__default_removes_refs_to_same_package(self): ws = workspace.Workspace("so/path", [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) package = "a/b/c" art1 = buildpom.MavenArtifactDef("g1", "a1", "1", bazel_package=package, @@ -56,7 +56,7 @@ def test_normalize_deps__default_removes_refs_to_same_package(self): def test_normalize_deps__skip_pomgen_mode_allows_refs_to_same_package(self): ws = workspace.Workspace("so/path", [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) package = "a/b/c" art1 = buildpom.MavenArtifactDef("g1", "a1", "1", bazel_package=package, @@ -78,7 +78,7 @@ def test_parse_ext_dep(self): Verifies that an external dependency label is correctly parsed into a Dependency instance. """ - ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), ("",""), + ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), maven_install_info=self._mocked_mvn_install_info("maven"), pom_content=pomcontent.NOOP) @@ -95,7 +95,7 @@ def test_parse_ext_dep__unknown_dep(self): """ Verifies the error that is thrown when an unknown dep is encountered. """ - ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), ("",""), + ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), maven_install_info=self._mocked_mvn_install_info("maven"), pom_content=pomcontent.NOOP) @@ -112,7 +112,6 @@ def test_excluded_dependency_paths(self): ws = workspace.Workspace("some/path", excluded_dependency_paths=["projects/protos/",], source_exclusions=exclusions.src_exclusions(), - property_prefix_suffix=("",""), maven_install_info=self._mocked_mvn_install_info("maven"), pom_content=pomcontent.NOOP) @@ -130,7 +129,7 @@ def test_parse_ext_dep_with_reserved_words(self): Dependency instance when the strings being parsed contain reserved words such as "artifact". """ - ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), ("",""), + ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), maven_install_info=self._mocked_mvn_install_info("maven"), pom_content=pomcontent.NOOP) @@ -154,7 +153,7 @@ def test_parse_src_dep(self): self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root") self._write_build_pom(repo_root, package_name, artifact_id, group_id, artifact_version) ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) deps = ws.parse_dep_labels(["//%s" % package_name]) @@ -179,7 +178,7 @@ def test_parse_src_dep_with_target(self): self._touch_file_at_path(repo_root, "", "MVN-INF", "LIBRARY.root") self._write_build_pom(repo_root, package_name, artifact_id, group_id, artifact_version) ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) deps = ws.parse_dep_labels(["//%s:my_cool_target" % package_name]) @@ -208,7 +207,7 @@ def test_src_dep_without_build_pom(self): os.mkdir(os.path.join(repo_root, bad_package_name)) # no BUILD.pom ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) with self.assertRaises(Exception) as ctx: @@ -223,7 +222,7 @@ def test_parse_invalid_dep(self): Verifies that parsing of an invalid label behaves as expected. """ ws = workspace.Workspace("some/path", [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) with self.assertRaises(Exception) as ctx: @@ -254,7 +253,7 @@ def test_parse_src_dep_without_changes_since_last_release(self): package_hash = git.get_dir_hash(repo_root, package_name, exclusions.src_exclusions()) self._write_build_pom_released(repo_root, package_name, released_version, package_hash) ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) deps = ws.parse_dep_labels(["//%s" % package_name]) @@ -289,7 +288,7 @@ def test_parse_src_dep_with_changes_since_last_release(self): self._touch_file_at_path(repo_root, package_name, "", "myfile") self._commit(repo_root) ws = workspace.Workspace(repo_root, [], exclusions.src_exclusions(), - ("",""), maveninstallinfo.NOOP, + maveninstallinfo.NOOP, pom_content=pomcontent.NOOP) deps = ws.parse_dep_labels(["//%s" % package_name])