Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exception with internal and external dep #185

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions crawl/pom.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,8 @@ def _check_for_dep_conflict(self, dep1, dep2):
elif dep1.bazel_package is not None and dep2.bazel_package is not None:
# both deps are internal, it doesn't make sense to get here
raise Exception("All internal dependencies must always be on the same versions! [%s] vs [%s]" % (dep1, dep2))
else:
if dep1.bazel_package is None and dep2.bazel_package is not None:
external_dep = dep1
internal_dep = dep2
else:
external_dep = dep2
internal_dep = dep1

raise Exception("The internal dependency at [%s] has the same artifactId and groupId as the external dependency [%s:%s] - this is unsupported" % (internal_dep.bazel_package, external_dep.group_id, external_dep.artifact_id))
return False

def _build_template_only_deps_property_content(self, deps,
pom_template_parsed_deps,
Expand Down
47 changes: 36 additions & 11 deletions tests/pomtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ def test_template_var_sub__ext_deps_with_diff_versions__no_unqual(self):
self.assertIn("has unresolvable references", str(ctx.exception))
self.assertIn("['org.apache.maven:mult-versions:version']", str(ctx.exception))

def test_template_var_sub__conflicting_gav__ext_and_BUILDpom(self):
def test_template_var_sub__conflicting_gav__ext_and_BUILDpom_internal_dep(self):
"""
Verifies error handling when gavs are conflicting between external deps
and what is set in BUILD.pom files.
Verifies handling when gavs are conflicting between external deps
and what is set in BUILD.pom files when a Bazel Dep is in the transitive closure.
"""
depmd = dependencym.DependencyMetadata(None)
ws = workspace.Workspace("some/path",
Expand All @@ -535,19 +535,44 @@ def test_template_var_sub__conflicting_gav__ext_and_BUILDpom(self):
label_to_overridden_fq_label={})
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 = "srpc #{g:a:version}"
artifact_def.custom_pom_template_content = "srpc #{com.google.guava:guava:version}"
pomgen = pom.TemplatePomGen(ws, artifact_def, dep)
# this guava dep is conflicting with an external dep
art = buildpom.MavenArtifactDef("com.google.guava","guava","26.0", bazel_package="a/b/c")

# this guava dep is conflicting with an external dep -- internal package called a/b/c
art = buildpom.MavenArtifactDef("com.google.guava","guava","29.0", bazel_package="a/b/c")
d = dependency.MonorepoDependency(art, bazel_target=None)
pomgen.register_dependencies_transitive_closure__library(set([d]))

with self.assertRaises(Exception) as ctx:
pomgen.gen(pom.PomContentType.RELEASE)
generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

#The Bazel_package guava version should be picked
self.assertIn("29.0", generated_pom)

def test_template_var_sub__conflicting_gav__ext_and_BUILDpom_no_internal_dep(self):
"""
Verifies handling when gavs are conflicting between external deps
and what is set in BUILD.pom files when no Bazel Dep is in the transitive closure.
"""
depmd = dependencym.DependencyMetadata(None)
ws = workspace.Workspace("some/path",
self._get_config(),
self._mocked_mvn_install_info("maven"),
pomcontent.NOOP,
depmd,
label_to_overridden_fq_label={})
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 = "srpc #{com.google.guava:guava:version}"
pomgen = pom.TemplatePomGen(ws, artifact_def, dep)

# this guava dep is conflicting with an external dep -- internal package called a/b/c
art = buildpom.MavenArtifactDef("com.google.guava","guava","29.0", bazel_package="a/b/c")
d = dependency.MonorepoDependency(art, bazel_target=None)

generated_pom = pomgen.gen(pom.PomContentType.RELEASE)

self.assertIn("The internal dependency at [a/b/c]", str(ctx.exception))
self.assertIn("the same artifactId and groupId", str(ctx.exception))
self.assertIn("[com.google.guava:guava]", str(ctx.exception))
#The maven_install guava version should be picked
self.assertIn("23.0", generated_pom)

def test_template_genmode__goldfile(self):
"""
Expand Down
Loading