Skip to content

Commit

Permalink
Merge pull request salesforce#102 from dylanShark/allow_prefix_suffix
Browse files Browse the repository at this point in the history
Allow prefix/suffix for generated version properties
dylanShark authored Mar 30, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 01714c1 + d448bf5 commit 7c6e838
Showing 13 changed files with 125 additions and 69 deletions.
22 changes: 21 additions & 1 deletion config/config.py
Original file line number Diff line number Diff line change
@@ -80,6 +80,8 @@ 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",)),
@@ -110,15 +112,19 @@ 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=(),
excluded_src_file_extensions=(),
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))
@@ -142,6 +148,20 @@ 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
9 changes: 6 additions & 3 deletions crawl/pom.py
Original file line number Diff line number Diff line change
@@ -258,6 +258,9 @@ 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
@@ -447,7 +450,7 @@ def _get_crawled_dependencies_properties(self, pomcontenttype, pom_template_pars

properties = {}
if substitute_version_properties:
updated_group_version_dict = pomproperties.get_group_version_dict(self.dependencies_library_transitive_closure, group_version_dict=group_version_dict)
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(
@@ -458,7 +461,7 @@ def _get_crawled_dependencies_properties(self, pomcontenttype, pom_template_pars
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, group_version_dict=updated_group_version_dict)
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 = {}
content = self._build_template_only_deps_property_content(\
@@ -681,7 +684,7 @@ def gen(self, pomcontenttype):
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)
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)
10 changes: 8 additions & 2 deletions crawl/pomproperties.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

_INDENT = common.INDENT

def get_group_version_dict(deps, group_version_dict={}):
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
@@ -24,14 +24,20 @@ def get_group_version_dict(deps, group_version_dict={}):
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
result_group_version_dict[group_id] = pomparser.ParsedProperty("%s.version" % group_id, version)
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 = ""):
4 changes: 3 additions & 1 deletion crawl/workspace.py
Original file line number Diff line number Diff line change
@@ -22,13 +22,15 @@ class Workspace:
"""

def __init__(self, repo_root_path, excluded_dependency_paths,
source_exclusions,
source_exclusions,
property_prefix_suffix,
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()
1 change: 1 addition & 0 deletions misc/extdeps_pomgen.py
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ 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
1 change: 1 addition & 0 deletions pomgen.py
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ 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)
1 change: 1 addition & 0 deletions query.py
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@ 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)
2 changes: 1 addition & 1 deletion tests/crawlertest.py
Original file line number Diff line number Diff line change
@@ -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="")
8 changes: 4 additions & 4 deletions tests/crawlertest_misc.py
Original file line number Diff line number Diff line change
@@ -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="")
2 changes: 1 addition & 1 deletion tests/crawlerunittest.py
Original file line number Diff line number Diff line change
@@ -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=[],
source_exclusions=[], property_prefix_suffix=("", ""),
maven_install_info=maveninstallinfo.NOOP,
pom_content="",)

53 changes: 37 additions & 16 deletions tests/pompropertiestest.py
Original file line number Diff line number Diff line change
@@ -9,50 +9,71 @@ 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.version", "1"),
"com.google.android":pomparser.ParsedProperty("com.google.android.version", "4"),
"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])))
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.version", "1") }
self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, guava_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.version", "1") }
self.assertTrue(self._compare_group_version_dict(expected_dict, pomproperties.get_group_version_dict([guava_failureaccess, guava_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)))
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.version", "1")
"com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1")
}
expected_pom = " <com.google.guava.version>1</com.google.guava.version>\n"
expected_pom = " <com.google.guava.managed_version>1</com.google.guava.managed_version>\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.version", "1"),
"com.google.android":pomparser.ParsedProperty("com.google.android.version", "4"),
"com.google.guava":pomparser.ParsedProperty("com.google.guava.managed_version", "1"),
"com.google.android":pomparser.ParsedProperty("com.google.android.managed_version", "4"),
}
expected_pom = """ <com.google.android.version>4</com.google.android.version>
<com.google.guava.version>1</com.google.guava.version>
expected_pom = """ <com.google.android.managed_version>4</com.google.android.managed_version>
<com.google.guava.managed_version>1</com.google.guava.managed_version>
"""
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.version", "4"),
"com.google.android":pomparser.ParsedProperty("com.google.android.managed_version", "4"),
}
original_pom = """
<project>
@@ -61,7 +82,7 @@ def test_gen_version_properties__existing_property(self):
</properties>
</project>
"""
expected_pom = " <com.google.android.version>4</com.google.android.version>\n"
expected_pom = " <com.google.android.managed_version>4</com.google.android.managed_version>\n"
self.assertEqual(expected_pom, pomproperties.gen_version_properties(group_version_dict, original_pom))

def _compare_group_version_dict(self, expected_dict, actual_dict):
58 changes: 29 additions & 29 deletions tests/pomtest.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,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 +137,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 = """<project>
#{description}
@@ -163,7 +163,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 = """<project>
#{description}
@@ -194,7 +194,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 +219,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 +241,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 +283,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,7 +306,7 @@ 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)
@@ -327,7 +327,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 +348,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)
@@ -399,7 +399,7 @@ def test_template__deps_config_setion_is_removed(self):
</project>
"""
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,7 +458,7 @@ def test_template__unencountered_deps(self):
</project>
"""
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)
@@ -486,28 +486,28 @@ def test_template__library_transitives(self):
expected_pom = """
<project>
<properties>
<cg.version>0.0.1</cg.version>
<com.grail.srpc.version>5.6.7</com.grail.srpc.version>
<cg.managed_version>0.0.1</cg.managed_version>
<com.grail.srpc.managed_version>5.6.7</com.grail.srpc.managed_version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.grail.srpc</groupId>
<artifactId>srpc-api</artifactId>
<version>${com.grail.srpc.version}</version>
<version>${com.grail.srpc.managed_version}</version>
</dependency>
<dependency>
<groupId>cg</groupId>
<artifactId>ca</artifactId>
<version>${cg.version}</version>
<version>${cg.managed_version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
"""
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)
@@ -561,15 +561,15 @@ def test_template__crawled_external_deps__configured_exclusions(self):
expected_pom = """
<project>
<properties>
<cg.version>0.0.1</cg.version>
<cg.managed_version>0.0.1</cg.managed_version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cg</groupId>
<artifactId>ca</artifactId>
<version>${cg.version}</version>
<version>${cg.managed_version}</version>
<classifier>c1</classifier>
<exclusions>
<exclusion>
@@ -587,7 +587,7 @@ def test_template__crawled_external_deps__configured_exclusions(self):
</project>
"""
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)
@@ -628,15 +628,15 @@ def test_template__crawled_external_deps__configured_attributes(self):
expected_pom = """
<project>
<properties>
<cg.version>0.0.1</cg.version>
<cg.managed_version>0.0.1</cg.managed_version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cg</groupId>
<artifactId>ca</artifactId>
<version>${cg.version}</version>
<version>${cg.managed_version}</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
@@ -645,7 +645,7 @@ def test_template__crawled_external_deps__configured_attributes(self):
</project>
"""
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)
@@ -680,7 +680,7 @@ def test_template__reuse_version_properties(self):
<project>
<properties>
<existing.srpc.version>5.6.7</existing.srpc.version>
<cg.version>0.0.1</cg.version>
<cg.managed_version>0.0.1</cg.managed_version>
</properties>
<dependencyManagement>
<dependencies>
@@ -692,14 +692,14 @@ def test_template__reuse_version_properties(self):
<dependency>
<groupId>cg</groupId>
<artifactId>ca</artifactId>
<version>${cg.version}</version>
<version>${cg.managed_version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
"""
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)
@@ -721,7 +721,7 @@ def test_template_unknown_variable(self):
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 +740,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)
23 changes: 12 additions & 11 deletions tests/workspacetest.py
Original file line number Diff line number Diff line change
@@ -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,6 +112,7 @@ 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)

@@ -129,7 +130,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)

@@ -153,7 +154,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])
@@ -178,7 +179,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])
@@ -207,7 +208,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:
@@ -222,7 +223,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:
@@ -253,7 +254,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])
@@ -288,7 +289,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])

0 comments on commit 7c6e838

Please sign in to comment.