From f91896a1d6360abf4d46a8c67dc075c0d12500cd Mon Sep 17 00:00:00 2001 From: Simon Toens Date: Tue, 17 Dec 2024 09:20:50 +0900 Subject: [PATCH] Allow non-default targets (#187) --- README.md | 4 ++ crawl/buildpom.py | 24 ++++++-- crawl/crawler.py | 39 ++++--------- crawl/dependency.py | 5 +- crawl/pomparser.py | 2 +- crawl/workspace.py | 2 +- docs/mdfiles.md | 7 +++ examples/compile-only-dependencies/README.md | 1 - examples/dependency-management/README.md | 1 + examples/hello-world/README.md | 10 ++-- examples/hello-world/juicer/BUILD | 6 +- examples/hello-world/juicer/MVN-INF/BUILD.pom | 1 + examples/hello-world/wintervegetables/BUILD | 2 +- .../wintervegetables/MVN-INF/BUILD.pom | 1 + maven/maven_functions.sh | 27 +++++---- tests/buildpomtest.py | 47 +++++++++++----- tests/crawlertest_misc.py | 51 ++++++++++++----- tests/crawlerunittest.py | 3 +- tests/dependencymdtest.py | 4 +- tests/dependencytest.py | 32 +++++++---- tests/libaggregatortest.py | 3 +- tests/pomtest.py | 56 ++++++++++--------- 22 files changed, 203 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index c4c5f5e..5df47db 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ The set of scripts in this repository provides a solution for: - Generating pom.xml files for jars built by Bazel (typically ```java_library``` or ```java_binary``` rules) - Uploading the pom.xmls and jars to a Maven Artifact Repository such as Nexus (or installing them into the local Maven Repository at ~/.m2/repository) + - Handling the grouping of related jars into a "library", similar to a multi-module Maven project: all jars that are part of the same library are uploaded together + - Crawling library references and uploading those that have changed since they were last uploaded to Nexus pomgen does not run as part of the Bazel build - therefore Bazel BUILD files can remain free of pom.xml related metadata. @@ -54,6 +56,7 @@ See [this doc](docs/change_detection.md) for more information on change detectio Please see the [hello-world example](examples/hello-world/README.md) to see how pomgen works. + ## External Dependencies - Bazel, ideally through [bazelisk](https://github.com/bazelbuild/bazelisk) @@ -176,6 +179,7 @@ Please see [more information about transitives versioning](docs/ci.md#using-a-di See [this example](examples/dep-overrides). + ## CI setup [This document](docs/ci.md) goes over the CI setup. diff --git a/crawl/buildpom.py b/crawl/buildpom.py index 9c42237..f874d6d 100644 --- a/crawl/buildpom.py +++ b/crawl/buildpom.py @@ -21,6 +21,7 @@ class MavenArtifactDef(object): Represents an instance of a maven_artifact rule defined in BUILD.pom file. Information from the BUILD.pom.released file is added, if that file exists. + ==== Read out of the BUILD.pom file ==== group_id: the maven artifact groupId of the bazel package. @@ -64,6 +65,7 @@ class MavenArtifactDef(object): version_increment_strategy_name: specifies how this artifacts version should be incremented. + ==== Read out of the optional BUILD.pom.released file ==== released_version: the previously released version to Nexus @@ -72,19 +74,22 @@ class MavenArtifactDef(object): previously released to Nexus + ===== Internal attributes (never specified by the user) ==== deps: additional targets this package depends on; list of Bazel labels. For example: deps = ["//projects/libs/servicelibs/srpc/srpc-thrift-svc-runtime"] - Only used by tests. + The deps attribute is only used by tests. + + bazel_package: the bazel package the BUILD (and MVN-INF/) files live in - bazel_package: the bazel package the BUILD.pom file lives in + bazel_target: the bazel target that builds this artifact - library_path: the path to the root directory of the library this - monorepo package is part of + library_path: the path to the root directory of the library this artifact + is part of - requires_release: whether this monorepo package should be released (to Nexus + requires_release: whether this artifact should be released (to Nexus or local Maven repository) release_reason: the reason for releasing this artifact @@ -93,6 +98,7 @@ class MavenArtifactDef(object): BUILD.pom file, the content of the pom.xml.released file ===== + Implementation notes: - properties are kept read-only whenever possible - the constructor provides default values for easier instantiation @@ -115,6 +121,7 @@ def __init__(self, released_version=None, released_artifact_hash=None, bazel_package=None, + bazel_target=None, library_path=None, requires_release=None, released_pom_content=None): @@ -133,6 +140,7 @@ def __init__(self, self._released_version = released_version self._released_artifact_hash = released_artifact_hash self._bazel_package = bazel_package + self._bazel_target = bazel_target self._library_path = library_path self._requires_release = requires_release self._release_reason = None @@ -206,6 +214,10 @@ def released_artifact_hash(self, value): def bazel_package(self): return self._bazel_package + @property + def bazel_target(self): + return self._bazel_target + @property def library_path(self): return self._library_path @@ -279,6 +291,7 @@ def parse_maven_artifact_def(root_path, package): additional_change_detected_packages=ma_attrs.get("additional_change_detected_packages", []), gen_dependency_management_pom=ma_attrs.get("generate_dependency_management_pom", False), jar_path=ma_attrs.get("jar_path", None), + bazel_target=ma_attrs.get("target_name", None), deps=ma_attrs.get("deps", [])) template_path = ma_attrs.get("pom_template_file", None) @@ -348,6 +361,7 @@ def _augment_art_def_values(user_art_def, rel_art_def, bazel_package, gen_dependency_management_pom=False if user_art_def.gen_dependency_management_pom is None else user_art_def.gen_dependency_management_pom, jar_path=None if user_art_def.jar_path is None else os.path.normpath(os.path.join(bazel_package, mdfiles.MD_DIR_NAME, user_art_def.jar_path)), deps=user_art_def.deps, + bazel_target=user_art_def.bazel_target if user_art_def.bazel_target is not None else os.path.basename(bazel_package), released_version=rel_art_def.version if rel_art_def is not None else None, released_artifact_hash=rel_art_def.artifact_hash if rel_art_def is not None else None, bazel_package=bazel_package, diff --git a/crawl/crawler.py b/crawl/crawler.py index 6cd7ffc..a948249 100644 --- a/crawl/crawler.py +++ b/crawl/crawler.py @@ -220,12 +220,11 @@ def _get_deps_transitive_closure_for_library(self, library_path, # other, but these references are not guaranteed) artifacts = self.library_to_artifact[library_path] for art_def in artifacts: - all_deps.add(dependency.new_dep_from_maven_artifact_def(art_def, bazel_target=None)) - + all_deps.add(dependency.new_dep_from_maven_artifact_def(art_def)) return all_deps def _get_crawled_packages_as_deps(self): - deps = [dependency.new_dep_from_maven_artifact_def(art_def, bazel_target=None) for art_def in self.package_to_artifact.values()] + deps = [dependency.new_dep_from_maven_artifact_def(art_def) for art_def in self.package_to_artifact.values()] deps = set(self._filter_non_artifact_referencing_deps(deps)) return deps @@ -510,7 +509,10 @@ def _crawl(self, package, dep, parent_node, follow_references): Returns a Node instance for the crawled package. """ - target_key = self._get_target_key(package, dep) + artifact_def = self.workspace.parse_maven_artifact_def(package) + if artifact_def is None: + raise Exception("No artifact defined at package %s" % package) + target_key = self._get_target_key(package, dep, artifact_def) if target_key in self.target_to_node: # if we have already processed this target, we can re-use the # children we discovered previously @@ -532,13 +534,7 @@ def _crawl(self, package, dep, parent_node, follow_references): else: if self.verbose: logger.info("Processing [%s]" % target_key) - artifact_def = self.workspace.parse_maven_artifact_def(package) - - if artifact_def is None: - raise Exception("No artifact defined at package %s" % package) - self._validate_default_target_dep(parent_node, dep, artifact_def) - self.package_to_artifact[package] = artifact_def self.library_to_artifact[artifact_def.library_path].append(artifact_def) pomgen = self._get_pom_generator(artifact_def, dep) @@ -563,20 +559,6 @@ def _crawl(self, package, dep, parent_node, follow_references): self._store_if_leafnode(node) return node - def _validate_default_target_dep(self, parent_node, dep, artifact_def): - if dep is not None: - if artifact_def.pom_generation_mode.produces_artifact: - # if the current bazel target produces an artifact - # (pom/jar that goes to Nexus), validate that the BUILD - # file pointing at this target uses the default bazel - # package target - # this is a current pomgen requirement: - # 1 bazel package produces one artifact, named after the - # bazel package - dflt_package_name = os.path.basename(artifact_def.bazel_package) - if dep.bazel_target != dflt_package_name: - raise Exception("Non default-package references are only supported to non-artifact producing packages: [%s] can only reference [%s], [%s:%s] is not allowed" % (parent_node.artifact_def.bazel_package, artifact_def.bazel_package, artifact_def.bazel_package, dep.bazel_target)) - def _get_pom_generator(self, artifact_def, dep): if dep is None: # make a real dependency instance here so we can pass it along @@ -587,12 +569,15 @@ def _get_pom_generator(self, artifact_def, dep): dep) @classmethod - def _get_target_key(clazz, package, dep): + def _get_target_key(clazz, package, dep, artifact_def=None): if dep is None: - target = os.path.basename(package) + # initial bootstrap - we start a bazel package and we don't + # have a dep pointing here + assert artifact_def is not None + target = artifact_def.bazel_target else: target = dep.bazel_target - assert target is not None, "Target is None for dep %s" % dep + assert target is not None, "Target is None for package %s" % package return "%s:%s" % (package, target) def _store_if_leafnode(self, node): diff --git a/crawl/dependency.py b/crawl/dependency.py index 70c5037..c33f69a 100644 --- a/crawl/dependency.py +++ b/crawl/dependency.py @@ -314,8 +314,9 @@ def new_dep_from_maven_art_str(maven_artifact_str, name): def new_dep_from_maven_artifact_def(artifact_def, bazel_target=None): - if bazel_target is not None: - assert len(bazel_target) > 0, "bazel target must not be empty for artifact def %s" % artifact_def.bazel_package + if bazel_target is None: + bazel_target = artifact_def.bazel_target + assert bazel_target is not None return MonorepoDependency(artifact_def, bazel_target) diff --git a/crawl/pomparser.py b/crawl/pomparser.py index b74c60c..caf676f 100644 --- a/crawl/pomparser.py +++ b/crawl/pomparser.py @@ -213,5 +213,5 @@ def _import_lxml(): return etree except ImportError as ex: print("Module lxml is not installed, please execute the following in your environment:") - print("pip install --user lxml") + print("pip3 install --user lxml") return None diff --git a/crawl/workspace.py b/crawl/workspace.py index 4d2c907..5b33466 100644 --- a/crawl/workspace.py +++ b/crawl/workspace.py @@ -126,7 +126,7 @@ def _parse_dep_label(self, dep_label): raise Exception("Unknown external dependency - please make sure all maven install json files have been registered with pomgen (by setting maven_install_paths in the pomgen config file): [%s]" % dep_label) return self._label_to_ext_dep[dep_label] elif dep_label.startswith("//"): - # monorepo src ref: + # src ref: package_path = dep_label[2:] # remove leading "//" target_name = None i = package_path.rfind(":") diff --git a/docs/mdfiles.md b/docs/mdfiles.md index 1d33599..6629622 100644 --- a/docs/mdfiles.md +++ b/docs/mdfiles.md @@ -22,6 +22,7 @@ maven_artifact_update( ) ``` + #### Required Attributes ##### maven_artifact.group_id @@ -50,8 +51,13 @@ Given a current version of `1.2.3`, the `major`, `minor`, and `patch` incrementi Given a current version of `20230605.1`, the `calver` incrementing strategy would produce `.1` (or `.2` if the current version is already `.1`). + #### Optional Attributes +##### maven_artifact.target_name + +The name of the bazel target that builds the jar artifact pomgen will be processing. Defaults to the [default target](https://bazel.build/concepts/labels) of the bazel package (aka the target that has the same name as the directory the BUILD file, that defines the target, lives in). + ##### maven_artifact.change_detection Controls whether change detection should be enabled for this artifact. If set to `False`, this artifact will always be marked as needing to be released (and a new pom will always be generated). @@ -85,6 +91,7 @@ Default value: `None` See the `java_import` [example](../examples/java-import). + ### LIBRARY.root (required) The LIBRARY.root file is a marker file that is currently empty. It groups together multiple artifacts, defined by BUILD.pom files, into a single "library". All artifacts that belong to a single library are processed (installed/uploaded) together. Change detection also operates at the library level. If a single artifact in a library has changed, then all artifacts in the library are marked as needing to be released. diff --git a/examples/compile-only-dependencies/README.md b/examples/compile-only-dependencies/README.md index 32ab529..cbdea8c 100644 --- a/examples/compile-only-dependencies/README.md +++ b/examples/compile-only-dependencies/README.md @@ -1,6 +1,5 @@ # Compilation time only dependencies should not be evaluated by pomgen - There are some dependencies that are needed only at compilation time, for example Lombok. To ensure compile-time only dependencies are not included at runtime, Bazel has the `neverlink` attribute, which can be added to `java_library` rules. Typically compile-time only dependencies won't have a `BUILD.pom` file, so they have to be ignored by `pomgen`. diff --git a/examples/dependency-management/README.md b/examples/dependency-management/README.md index f2d79dd..b49f984 100644 --- a/examples/dependency-management/README.md +++ b/examples/dependency-management/README.md @@ -4,6 +4,7 @@ This examples shows how pomgen can optionally generate a dependencyManagement "c The dependency management pom contains a `` section with the transitive closure of all dependencies of the artifact it was generated for. It uses the `artifact_id` specified in the BUILD.pom file, suffixed with `.depmanagement`. + ### Try this example From the root of the repository: diff --git a/examples/hello-world/README.md b/examples/hello-world/README.md index 8902ebb..458225e 100644 --- a/examples/hello-world/README.md +++ b/examples/hello-world/README.md @@ -5,13 +5,15 @@ In the Maven world, a typical project setup consists of a top level pom.xml file with multiple modules in subdirectories. Each module produces a Maven Artifact (typically a jar or a pom.xml). -The pomgen terminology for a top level project with modules is a "library". Subdirectories of the library (the modules) are Bazel Packages that each produce a Maven Artifact (jar or pom). pomgen processes all modules that are part of a library together. +The pomgen terminology for a top level project with modules is a `library`. Subdirectories of the library (the modules) are Bazel Packages that each produce a Maven Artifact (jar or pom). pomgen processes all modules that are part of a library together. This example has 3 libraries. A library is defined by the presence of a [LIBRARY.root](healthyfoods/MVN-INF/LIBRARY.root) marker file. -A Bazel Package that produces a Maven Artifact must have a [BUILD.pom](healthyfoods/fruit-api/MVN-INF/BUILD.pom) file that defines Maven specific metadata. Note that the `java_library` target that builds the jar Maven Artifact must be the default target, ie it must have the same name as the directory its BUILD file lives in. +A Bazel Package that produces a Maven Artifact must have a [BUILD.pom](healthyfoods/fruit-api/MVN-INF/BUILD.pom) file that defines Maven specific metadata. -The libraries in this example are, and reference each other in this order: +The `java_library` target that builds the jar Maven Artifact is typically the default target, ie it the target that the same name as the directory its BUILD file lives in. If the target is not the default target, its name must be explicitly specified in the BUILD.pom file using the `maven_artifact.target_name` attribute. + +The libraries in this example reference each other in this order: - [juicer](juicer) - [wintervegetables](wintervegetables) - [healthyfoods](healthyfoods) @@ -67,7 +69,7 @@ The command above specifies: - The **library** to generate poms for: `examples/hello-world/juicer` -pomgen follows refernces between libraries; since `juicer` depends on 2 other libraries `healthyfoods` and `wintervegerables`, pomgen generated pom.xml files for all 3 libraries, ie for all modules that are part of those libraries. Usually this is the right behavior, but if there a lot of upstream libraries, it may be desirable in some cases to not follow library references. This can be accomplished by setting `-i` (ignore references) flag: +pomgen follows references between libraries; since `juicer` depends on 2 other libraries `healthyfoods` and `wintervegerables`, pomgen generated pom.xml files for all 3 libraries, ie for all modules that are part of those libraries. Usually this is the right behavior, but if there a lot of upstream libraries, it may be desirable in some cases to not follow library references. This can be accomplished by setting `-i` (ignore references) flag: ``` bazel run @pomgen//maven -- -a pomgen -l examples/hello-world/juicer -i diff --git a/examples/hello-world/juicer/BUILD b/examples/hello-world/juicer/BUILD index 6183904..09bbf84 100644 --- a/examples/hello-world/juicer/BUILD +++ b/examples/hello-world/juicer/BUILD @@ -1,15 +1,15 @@ java_library( - name = "juicer", + name = "juicer_lib", srcs = glob(["src/main/java/**/*.java"]), deps = ["//examples/hello-world/healthyfoods/fruit-api", "//examples/hello-world/healthyfoods/vegetable-api", - "//examples/hello-world/wintervegetables", + "//examples/hello-world/wintervegetables:wintervegetables_lib2", "@maven//:com_google_guava_guava", ] ) java_binary( name = "make-juice", - runtime_deps = [":juicer"], + runtime_deps = [":juicer_lib"], main_class = "com.pomgen.example.Main", ) diff --git a/examples/hello-world/juicer/MVN-INF/BUILD.pom b/examples/hello-world/juicer/MVN-INF/BUILD.pom index 6979cb1..7fd6410 100644 --- a/examples/hello-world/juicer/MVN-INF/BUILD.pom +++ b/examples/hello-world/juicer/MVN-INF/BUILD.pom @@ -3,6 +3,7 @@ maven_artifact( artifact_id = "juicer", version = "10.0.0-qual1-SNAPSHOT", pom_generation_mode = "dynamic", + target_name = "juicer_lib", ) maven_artifact_update( diff --git a/examples/hello-world/wintervegetables/BUILD b/examples/hello-world/wintervegetables/BUILD index 44bfbe6..9338429 100644 --- a/examples/hello-world/wintervegetables/BUILD +++ b/examples/hello-world/wintervegetables/BUILD @@ -1,5 +1,5 @@ java_library( - name = "wintervegetables", + name = "wintervegetables_lib2", srcs = glob(["src/main/java/**/*.java"]), deps = ["//examples/hello-world/healthyfoods/vegetable-api"], visibility = ["//examples/hello-world/juicer:__subpackages__"], diff --git a/examples/hello-world/wintervegetables/MVN-INF/BUILD.pom b/examples/hello-world/wintervegetables/MVN-INF/BUILD.pom index 754f71c..037f58f 100644 --- a/examples/hello-world/wintervegetables/MVN-INF/BUILD.pom +++ b/examples/hello-world/wintervegetables/MVN-INF/BUILD.pom @@ -3,6 +3,7 @@ maven_artifact( artifact_id = "wintervegetables", version = "20200416.1-SNAPSHOT", pom_generation_mode = "dynamic", + target_name = "wintervegetables_lib2", ) maven_artifact_update( diff --git a/maven/maven_functions.sh b/maven/maven_functions.sh index a8f3c42..b33ef1b 100644 --- a/maven/maven_functions.sh +++ b/maven/maven_functions.sh @@ -96,18 +96,24 @@ _for_each_pom() { process_jar_artifact=0 else echo "ERROR: Did not find jar at custom path [${jar_artifact_path}]." - echo "This is a bug" exit 1 fi else + local build_pom_path="$src_dir_package_path/MVN-INF/BUILD.pom" + # check if the BUILD.pom file specifies a custom target name + local target_name=$(grep target_name "$build_pom_path" | grep -v '^[[:space:]]*#' | tr -s ' ' | cut -d= -f2 | tr -d '", ' || echo -n "") + if [ -z "$target_name" ]; then + # default target + target_name="$package_name" + fi # the filename of the jar built by Bazel uses this pattern: - jar_artifact_path="$build_dir_package_path/lib${package_name}.jar" + jar_artifact_path="$build_dir_package_path/lib${target_name}.jar" # bazel's java_library rule has an implicit target that builds # a jar containing the sources, see # https://bazel.build/reference/be/java#java_library: # lib-src.jar: An archive containing the sources # note that this file only exists if that implicit target ran! - sources_jar_path="$build_dir_package_path/lib${package_name}-src.jar" + sources_jar_path="$build_dir_package_path/lib${target_name}-src.jar" if [ ! -f "${jar_artifact_path}" ]; then echo "WARN: lib${package_name}.jar not found, looking for alternatives" # we also support executable jars - this is an edge case but @@ -117,19 +123,20 @@ _for_each_pom() { # first we look for the special _deploy.jar # created by java_binary - jar_artifact_path="$build_dir_package_path/${package_name}_deploy.jar" + jar_artifact_path="$build_dir_package_path/${target_name}_deploy.jar" if [ -f "${jar_artifact_path}" ]; then - echo "INFO: Found ${package_name}_deploy.jar" + echo "INFO: Found ${jar_artifact_path}" else # last attempt: maybe a jar called .jar - # exists - jar_artifact_path="$build_dir_package_path/${package_name}.jar" + # exists - this is used by springboot packaging: + # https://github.com/salesforce/rules_spring + jar_artifact_path="$build_dir_package_path/${target_name}.jar" if [ -f "${jar_artifact_path}" ]; then - echo "INFO: Found ${package_name}.jar" + echo "INFO: Found ${jar_artifact_path}" fi fi - # we've seen jar break in weird ways when trying to unjar - # large "uber" jars: + # we've seen the jar cmd break in weird ways when trying + # to unjar large "uber" jars: # java.io.FileNotFoundException: META-INF/LICENSE (Is a directory) # so do not attempt to add the generated pom.xml to uber # jars, since the pom isn't required for uber jars anyway: diff --git a/tests/buildpomtest.py b/tests/buildpomtest.py index 27d453d..7cd2c26 100644 --- a/tests/buildpomtest.py +++ b/tests/buildpomtest.py @@ -19,7 +19,7 @@ def test_parse_BUILD_pom(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, @@ -38,6 +38,7 @@ def test_parse_BUILD_pom(self): self.assertFalse(art_def.include_deps) self.assertTrue(art_def.change_detection) self.assertEqual(package_rel_path, art_def.bazel_package) + self.assertEqual("package2", art_def.bazel_target) self.assertEqual(None, art_def.released_version) self.assertEqual(None, art_def.released_artifact_hash) self.assertEqual("major", art_def.version_increment_strategy_name) @@ -49,7 +50,7 @@ def test_parse_BUILD__pom__empty_deps(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, @@ -65,7 +66,7 @@ def test_parse_BUILD_pom_gen_dep_man_pom(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) @@ -86,7 +87,7 @@ def test_parse_BUILD_pom_with_change_detection(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) @@ -109,7 +110,7 @@ def test_parse_BUILD_pom_and_BUILD_pom_released(self): version = "1.2.3" released_version = "1.2.2" released_artifact_hash = "af5fe5cac7dfcfbc500283b111ea9e37083e5862" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, "dynamic") @@ -134,7 +135,7 @@ def test_parse_BUILD_pom__default_pomgen_mode(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, pom_gen_mode="dynamic") @@ -148,7 +149,7 @@ def test_parse_BUILD_pom__dynamic_pomgen_mode(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, pom_gen_mode="dynamic") @@ -163,7 +164,7 @@ def test_parse_BUILD_pom__template_pomgen_mode(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, pom_gen_mode="template") @@ -179,7 +180,7 @@ def test_parse_BUILD_pom__additional_change_detected_packages(self): artifact_id = "art1" version = "1.2.3" more_packages = ["//root/a/b/c", "root/d/e/f"] - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom( @@ -196,7 +197,7 @@ def test_parse_BUILD_pom__skip_pomgen_mode(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom_skip_generation_mode(repo_package) @@ -223,7 +224,7 @@ def test_parse_BUILD_pom__jar_path(self): artifact_id = "art1" version = "1.2.3" jar_path = "../a-jar.jar" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, @@ -234,12 +235,29 @@ def test_parse_BUILD_pom__jar_path(self): self.assertEqual("package1/package2/a-jar.jar", art_def.jar_path) + def test_parse_BUILD_pom__custom_target(self): + package_rel_path = "package1/package2" + group_id = "group1" + artifact_id = "art1" + version = "1.2.3" + target = "juicer_lib" + repo_root = tempfile.mkdtemp("reporoot") + repo_package = os.path.join(repo_root, package_rel_path) + os.makedirs(repo_package) + self._write_build_pom(repo_package, artifact_id, group_id, version, + pom_gen_mode="template", + bazel_target=target) + + art_def = buildpom.parse_maven_artifact_def(repo_root, package_rel_path) + + self.assertEqual(target, art_def.bazel_target) + def test_load_pom_xml_released(self): package_rel_path = "package1/package2" group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, "dynamic") @@ -255,7 +273,7 @@ def test_load_custom_pom_template(self): group_id = "group1" artifact_id = "art1" version = "1.2.3" - repo_root = tempfile.mkdtemp("monorepo") + repo_root = tempfile.mkdtemp("reporoot") repo_package = os.path.join(repo_root, package_rel_path) os.makedirs(repo_package) self._write_build_pom(repo_package, artifact_id, group_id, version, @@ -279,6 +297,7 @@ def _write_build_pom(self, deps=None, jar_path=None, pom_template_file=None, + bazel_target=None, generate_dependency_management_pom=None): build_pom = """ maven_artifact( @@ -293,6 +312,7 @@ def _write_build_pom(self, %s %s %s + %s ) maven_artifact_update( @@ -305,6 +325,7 @@ def _write_build_pom(self, "" if deps is None else "deps = %s," % deps, "" if jar_path is None else 'jar_path = "%s",' % jar_path, "" if pom_template_file is None else 'pom_template_file = "%s",' % pom_template_file, + "" if bazel_target is None else 'target_name = "%s",' % bazel_target, "" if generate_dependency_management_pom is None else 'generate_dependency_management_pom = %s,' % generate_dependency_management_pom) path = os.path.join(package_path, "MVN-INF") diff --git a/tests/crawlertest_misc.py b/tests/crawlertest_misc.py index 1e3d769..1d268ba 100644 --- a/tests/crawlertest_misc.py +++ b/tests/crawlertest_misc.py @@ -6,6 +6,7 @@ """ from common import maveninstallinfo +from common import pomgenmode from config import config from crawl import crawler as crawlerm from crawl import dependencymd as dependencym @@ -20,6 +21,7 @@ GROUP_ID = "group" POM_TEMPLATE_FILE = "foo.template" + class CrawlerTest(unittest.TestCase): """ Various one-off crawler related test cases that require file-system setup. @@ -81,16 +83,17 @@ def test_default_package_ref_explicit(self): self.assertEqual("lib/a2", result.nodes[0].artifact_def.bazel_package) self.assertEqual(1, len(result.nodes[0].children)) self.assertEqual("lib/a1", result.nodes[0].children[0].artifact_def.bazel_package) + self.assertEqual("a1", result.nodes[0].children[0].artifact_def.bazel_target) - def test_non_default_package_ref__not_allowed(self): + def test_non_default_package_ref(self): """ - lib/a2 cannot reference lib/a1:foo - only default package refs - are allowed. + lib/a2 can reference lib/a1:foo. """ depmd = dependencym.DependencyMetadata(None) repo_root_path = tempfile.mkdtemp("monorepo") self._write_library_root(repo_root_path, "lib") - self._add_artifact(repo_root_path, "lib/a1", "template", deps=[]) + self._add_artifact(repo_root_path, "lib/a1", "template", deps=[], + target_name="foo") self._add_artifact(repo_root_path, "lib/a2", "template", deps=["//lib/a1:foo"]) ws = workspace.Workspace(repo_root_path, @@ -101,15 +104,16 @@ def test_non_default_package_ref__not_allowed(self): label_to_overridden_fq_label={}) crawler = crawlerm.Crawler(ws, pom_template="") - with self.assertRaises(Exception) as ctx: - crawler.crawl(["lib/a2"]) + result = crawler.crawl(["lib/a2"]) - self.assertIn("[lib/a2] can only reference [lib/a1]", str(ctx.exception)) + self.assertEqual(1, len(result.nodes)) + self.assertEqual("lib/a2", result.nodes[0].artifact_def.bazel_package) + self.assertEqual("lib/a1", result.nodes[0].children[0].artifact_def.bazel_package) + self.assertEqual("foo", result.nodes[0].children[0].artifact_def.bazel_target) - def test_non_default_package_ref__allowed_for_skip_pom_gen_mode(self): + def test_non_default_package_ref__skip_pom_gen_mode(self): """ - lib/a2 is allowed to ref lib/a1:foo because lib/a1 has - pom_gen_mode = "skip" + lib/a2 -> lib/a1:foo, lib/a1 has pom_gen_mode = "skip" https://github.com/salesforce/pomgen/tree/master/examples/skip-artifact-generation """ repo_root_path = tempfile.mkdtemp("monorepo") @@ -126,21 +130,32 @@ def test_non_default_package_ref__allowed_for_skip_pom_gen_mode(self): label_to_overridden_fq_label={}) crawler = crawlerm.Crawler(ws, pom_template="") - crawler.crawl(["lib/a2"]) + result = crawler.crawl(["lib/a2"]) + + self.assertEqual(1, len(result.nodes)) + self.assertEqual("lib/a2", result.nodes[0].artifact_def.bazel_package) + self.assertEqual("lib/a1", result.nodes[0].children[0].artifact_def.bazel_package) + self.assertIs(pomgenmode.SKIP, result.nodes[0].children[0].artifact_def.pom_generation_mode) def _get_config(self): return config.Config() - def _add_artifact(self, repo_root_path, package_rel_path, - pom_generation_mode, deps=[]): + def _add_artifact(self, repo_root_path, package_rel_path, + pom_generation_mode, + target_name=None, deps=[]): self._write_build_pom(repo_root_path, package_rel_path, pom_generation_mode, artifact_id=os.path.basename(package_rel_path), group_id="g1", version="1.0.0-SNAPSHOT", + target_name=target_name, deps=deps) - def _write_build_pom(self, repo_root_path, package_rel_path, pom_generation_mode, artifact_id, group_id, version, deps=None): + def _write_build_pom(self, repo_root_path, package_rel_path, + pom_generation_mode, + artifact_id, group_id, version, + target_name=None, + deps=None): build_pom = """ maven_artifact( artifact_id = "%s", @@ -149,6 +164,7 @@ def _write_build_pom(self, repo_root_path, package_rel_path, pom_generation_mode pom_generation_mode = "%s", pom_template_file = "%s", $deps$ + $target_name$ ) maven_artifact_update( @@ -162,7 +178,11 @@ def _write_build_pom(self, repo_root_path, package_rel_path, pom_generation_mode if deps is None: content = content.replace("$deps$", "") else: - content = content.replace("$deps$", "deps=[%s]" % ",".join(['"%s"' % d for d in deps])) + content = content.replace("$deps$", "deps=[%s]," % ",".join(['"%s"' % d for d in deps])) + if target_name is None: + content = content.replace("$target_name$", "") + else: + content = content.replace("$target_name$", "target_name = \"%s\"" % target_name) with open(os.path.join(path, "BUILD.pom"), "w") as f: f.write(content) @@ -173,5 +193,6 @@ def _write_library_root(self, repo_root_path, package_rel_path): with open(os.path.join(path, "LIBRARY.root"), "w") as f: f.write("foo") + if __name__ == '__main__': unittest.main() diff --git a/tests/crawlerunittest.py b/tests/crawlerunittest.py index b2c3a06..bc0da17 100644 --- a/tests/crawlerunittest.py +++ b/tests/crawlerunittest.py @@ -512,7 +512,8 @@ def _build_node(self, artifact_id, bazel_package, "g1", artifact_id, "1.0.0", bazel_package=bazel_package, pom_generation_mode=pom_generation_mode, - library_path=library_path) + library_path=library_path, + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def) return crawlerm.Node(parent=parent_node, artifact_def=art_def, dependency=dep) diff --git a/tests/dependencymdtest.py b/tests/dependencymdtest.py index c872fa4..e198232 100644 --- a/tests/dependencymdtest.py +++ b/tests/dependencymdtest.py @@ -77,7 +77,7 @@ def test_get_classifier__none(self): dependencymd = dependencymdmod.DependencyMetadata(jar_artifact_classifier=None) ext_dep = dependency.new_dep_from_maven_art_str("g1:a1:pack:class:2.0,0", "m1") art_def = buildpom.MavenArtifactDef("g1", "a1", "1.0.0") - int_dep = dependency.new_dep_from_maven_artifact_def(art_def, None) + int_dep = dependency.new_dep_from_maven_artifact_def(art_def, "t1") self.assertEqual("class", dependencymd.get_classifier(ext_dep)) self.assertIsNone(dependencymd.get_classifier(int_dep)) @@ -86,7 +86,7 @@ def test_get_classifier__set_globally(self): dependencymd = dependencymdmod.DependencyMetadata(jar_artifact_classifier="foo22") ext_dep = dependency.new_dep_from_maven_art_str("g1:a1:2.0,0", "m1") art_def = buildpom.MavenArtifactDef("g1", "a1", "1.0.0") - int_dep = dependency.new_dep_from_maven_artifact_def(art_def, None) + int_dep = dependency.new_dep_from_maven_artifact_def(art_def, "t1") self.assertIsNone(dependencymd.get_classifier(ext_dep)) self.assertEqual("foo22", dependencymd.get_classifier(int_dep)) diff --git a/tests/dependencytest.py b/tests/dependencytest.py index 67a070a..76bfc87 100644 --- a/tests/dependencytest.py +++ b/tests/dependencytest.py @@ -184,7 +184,7 @@ def test_source_dependency__from_artifact_definition__name(self): artifact_id = "a1" version = "1.1.0" package = "pack1" - art_def = buildpom.MavenArtifactDef(group_id, artifact_id, version) + art_def = buildpom.MavenArtifactDef(group_id, artifact_id, version, bazel_package="p1") art_def = buildpom._augment_art_def_values(art_def, None, package, None, None, pomgenmode.DYNAMIC) dep = dependency.new_dep_from_maven_artifact_def(art_def, None) @@ -203,7 +203,7 @@ def test_source_dependency__from_artifact_definition__default(self): art_def = buildpom.MavenArtifactDef(group_id, artifact_id, version) art_def = buildpom._augment_art_def_values(art_def, None, package, None, None, pomgenmode.DYNAMIC) - dep = dependency.new_dep_from_maven_artifact_def(art_def, None) + dep = dependency.new_dep_from_maven_artifact_def(art_def) self.assertEqual(group_id, dep.group_id) self.assertEqual(artifact_id, dep.artifact_id) @@ -226,7 +226,8 @@ def test_source_dependency__from_artifact_definition__with_changes(self): bazel_package=package, requires_release=True, released_version="1.2.3", - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def, None) @@ -252,7 +253,8 @@ def test_source_dependency__from_artifact_definition__no_changes(self): bazel_package=package, requires_release=False, released_version=released_version, - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def, None) @@ -273,13 +275,15 @@ def test_source_dependency__bazel_target__defaulted(self): released_version = "1.2.3" package = "pack1/pack2" art_def = buildpom.MavenArtifactDef(group_id, artifact_id, version, - bazel_package=package, requires_release=False, released_version=released_version, released_artifact_hash="123456789") - dep = dependency.new_dep_from_maven_artifact_def(art_def, target) + art_def = buildpom._augment_art_def_values(art_def, None, package, None, None, pomgenmode.DYNAMIC) + + dep = dependency.new_dep_from_maven_artifact_def(art_def) + self.assertEqual("pack2", art_def.bazel_target) self.assertEqual("pack2", dep.bazel_target) def test_source_dependency__bazel_target__explicit(self): @@ -296,9 +300,10 @@ def test_source_dependency__bazel_target__explicit(self): bazel_package=package, requires_release=False, released_version=released_version, - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target=target) - dep = dependency.new_dep_from_maven_artifact_def(art_def, target) + dep = dependency.new_dep_from_maven_artifact_def(art_def) self.assertEqual(target, dep.bazel_target) @@ -313,7 +318,8 @@ def test_source_dependency__references_artifact__skip_pom_gen_mode(self): bazel_package=package, requires_release=False, released_version=released_version, - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def) @@ -330,7 +336,8 @@ def test_source_dependency__references_artifact__dynamic_pom_gen_mode(self): bazel_package=package, requires_release=False, released_version=released_version, - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def) @@ -347,7 +354,8 @@ def test_source_dependency__references_artifact__template_pom_gen_mode(self): bazel_package=package, requires_release=False, released_version=released_version, - released_artifact_hash="123456789") + released_artifact_hash="123456789", + bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(art_def) @@ -360,7 +368,7 @@ def test_sort_order(self): """ dep1 = dependency.new_dep_from_maven_art_str("com.google.guava:guava:20.0", "name") dep2 = dependency.new_dep_from_maven_art_str("com.google.guava:zoouava:20.0", "name") - art_def = buildpom.MavenArtifactDef("com.zoogle.guava", "art1", "1.0") + art_def = buildpom.MavenArtifactDef("com.zoogle.guava", "art1", "1.0", bazel_package="p1") art_def = buildpom._augment_art_def_values(art_def, None, "pack1", None, None, pomgenmode.DYNAMIC) dep3 = dependency.new_dep_from_maven_artifact_def(art_def, None) art_def = buildpom.MavenArtifactDef("com.google.guava", "art1", "1.0") diff --git a/tests/libaggregatortest.py b/tests/libaggregatortest.py index d376e07..7ee3f5e 100644 --- a/tests/libaggregatortest.py +++ b/tests/libaggregatortest.py @@ -164,7 +164,8 @@ def _create_library_artifact_node(self, group_id, artifact_id, version, artifact_def = MavenArtifactDef(group_id, artifact_id, dev_version, released_version=released_version, library_path=library_path, - requires_release=requires_release) + requires_release=requires_release, + bazel_target="t1") artifact_def.release_reason = release_reason dep = dependency.new_dep_from_maven_artifact_def(artifact_def) return Node(parent=None, artifact_def=artifact_def, dependency=dep) diff --git a/tests/pomtest.py b/tests/pomtest.py index 7de6cc3..c90fa53 100644 --- a/tests/pomtest.py +++ b/tests/pomtest.py @@ -76,8 +76,10 @@ def test_dynamic_pom__sanity(self): bazel.query_java_library_deps_attributes = lambda r, p, a, v: ("@maven//:com_google_guava_guava", "@maven//:aopalliance_aopalliance", "@maven//:ch_qos_logback_logback_classic", "@maven//:gt2_t2" ) _, _, deps = pomgen.process_dependencies() deps = list(deps) - # appending a dependency that is built in the shared-repo (should not have an exclusions block) - artifact_def = buildpom.MavenArtifactDef("shared-repo", "my-dep", "1.2.3") + # appending a dependency that is built from soure + # (should not have an exclusions block) + artifact_def = buildpom.MavenArtifactDef( + "repo", "my-dep", "1.2.3", bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) deps.append(dep) deps = tuple(deps) @@ -134,9 +136,10 @@ def test_dynamic_pom__sanity(self): """, generated_pom) - # this dependency shouldn't have the exclusions block due to it having "bazel_buildable=True" + # this dependency shouldn't have the exclusions block due to it + # having "bazel_buildable=True" self.assertIn(""" - shared-repo + repo my-dep 1.2.3 """, generated_pom) @@ -197,7 +200,7 @@ def test_dynamic_pom__gen_description(self): #{description} """ - artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) pomgen = pom.DynamicPomGen(ws, artifact_def, dep, pom_template) generated_pom = pomgen.gen(pom.PomContentType.RELEASE) @@ -224,7 +227,7 @@ def test_dynamic_pom__remove_description_token_if_no_value(self): #{description} """ - artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) pomgen = pom.DynamicPomGen(ws, artifact_def, dep, pom_template) @@ -245,7 +248,7 @@ def test_dyamic_pom__no_explicit_transitives(self): ] orig_bazel_parse_maven_install = bazel.parse_maven_install bazel.parse_maven_install = lambda names, overrides, verbose: query_result - artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", bazel_target="t2") 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) depmd = dependencym.DependencyMetadata(None) @@ -291,7 +294,7 @@ def test_dynamic_pom__classifier(self): root_dep = dependency.new_dep_from_maven_artifact_def(root_artifact_def) pomgen = pom.DynamicPomGen(ws, root_artifact_def, root_dep, TEST_POM_TEMPLATE) - dep_art_def = buildpom.MavenArtifactDef("class-group", "class-art", "1") + dep_art_def = buildpom.MavenArtifactDef("class-group", "class-art", "1", bazel_target="g1") dep = dependency.new_dep_from_maven_artifact_def(dep_art_def) dep_element, _ = pomgen._gen_dependency_element( @@ -315,8 +318,8 @@ def test_dynamic_pom__do_not_include_deps(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", - include_deps=False) + artifact_def = buildpom.MavenArtifactDef( + "g1", "a2", "1.2.3", bazel_target="t1", include_deps=False) dep = dependency.new_dep_from_maven_artifact_def(artifact_def) pomgen = pom.DynamicPomGen(ws, artifact_def, dep, "") @@ -341,7 +344,7 @@ def test_dynamic_pom_genmode__goldfile(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("g1", "a2", "1.2.3", bazel_target="t1") 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) @@ -387,7 +390,7 @@ def test_template_var_sub(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4", bazel_target="t1") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = """ unqualified #{ch_qos_logback_logback_classic.version} @@ -414,7 +417,7 @@ def test_template_var_sub__monorepo_deps(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="t") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = "srpc #{com.grail.srpc:srpc-api:version}" srpc_artifact_def = buildpom.MavenArtifactDef( @@ -440,7 +443,7 @@ def test_template_var_sub__ext_deps_with_same_versions(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4", bazel_target="c") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = """ 1 v1 #{@maven//:org_apache_maven_same_version.version} @@ -470,7 +473,7 @@ def test_template_var_sub__ext_deps_with_diff_versions(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4", bazel_target="t3") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = """ v1 #{@maven//:org_apache_maven_mult_versions.version} @@ -496,7 +499,7 @@ def test_template_var_sub__ext_deps_with_diff_versions__no_unqual(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.4.4", bazel_target="t2") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = """ #{org_apache_maven_mult_versions.version} @@ -533,7 +536,7 @@ def test_template_var_sub__conflicting_gav__ext_and_BUILDpom_internal_dep(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="t4") 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) @@ -560,7 +563,7 @@ def test_template_var_sub__conflicting_gav__ext_and_BUILDpom_no_internal_dep(sel pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="r") 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) @@ -585,7 +588,7 @@ def test_template_genmode__goldfile(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="foo") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) srpc_artifact_def = buildpom.MavenArtifactDef("com.grail.srpc", "srpc-api", "5.6.7") @@ -639,7 +642,7 @@ def test_template__deps_config_setion_is_removed(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="t1") 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) @@ -702,7 +705,7 @@ def test_template__unencountered_deps(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="d") 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) @@ -751,7 +754,7 @@ def test_template__library_transitives(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="f") 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) @@ -830,7 +833,7 @@ def test_template__crawled_external_deps__configured_exclusions(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="123") 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) @@ -887,7 +890,7 @@ def test_template__crawled_external_deps__configured_attributes(self): pomcontent.NOOP, depmd, label_to_overridden_fq_label={}) - artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3") + artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", "1.2.3", bazel_target="123") 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) @@ -911,7 +914,7 @@ def test_template_unknown_variable(self): depmd, label_to_overridden_fq_label={}) artifact_def = buildpom.MavenArtifactDef("groupId", "artifactId", - "1.2.3") + "1.2.3", bazel_target="t") dep = dependency.new_dep_from_maven_artifact_def(artifact_def) artifact_def.custom_pom_template_content = "my pom template with a bad ref #{bad1} and also #{bad2}" pomgen = pom.TemplatePomGen(ws, artifact_def, dep) @@ -934,7 +937,8 @@ def test_depman_pom__sanity(self): depmd, label_to_overridden_fq_label={}) artifact_def = buildpom.MavenArtifactDef( - "g1", "a2", "1.2.3", gen_dependency_management_pom=True) + "g1", "a2", "1.2.3", bazel_target="t1", + gen_dependency_management_pom=True) dep = dependency.new_dep_from_maven_artifact_def(artifact_def) pomgen = pom.DependencyManagementPomGen(ws, artifact_def, dep, TEST_POM_TEMPLATE) guava = dependency.new_dep_from_maven_art_str("google:guava:1", "guav")