From b59f5638e00d1e8be487c1c8dfde5621878f8bb7 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 23 Nov 2021 10:15:12 -0800 Subject: [PATCH 01/13] WIP # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../java/dependency_inference/rules.py | 2 ++ src/python/pants/backend/java/target_types.py | 10 +++++- .../dependency_inference/artifact_mapper.py | 35 +++++++++++++++++++ src/python/pants/jvm/target_types.py | 5 +++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/python/pants/backend/java/dependency_inference/rules.py b/src/python/pants/backend/java/dependency_inference/rules.py index c5dd5921d73..7a2a5878eaa 100644 --- a/src/python/pants/backend/java/dependency_inference/rules.py +++ b/src/python/pants/backend/java/dependency_inference/rules.py @@ -133,6 +133,8 @@ async def infer_java_dependencies_and_exports_via_source_analysis( third_party_matches: FrozenOrderedSet[Address] = FrozenOrderedSet() if java_infer_subsystem.third_party_imports: third_party_matches = find_artifact_mapping(typ, third_party_artifact_mapping) + if "AbstractMatcher" in str(request.source.address): + logger.warning("%s", f"TPM: {third_party_matches}") matches = first_party_matches.union(third_party_matches) if not matches: continue diff --git a/src/python/pants/backend/java/target_types.py b/src/python/pants/backend/java/target_types.py index 46811b19c3c..5ed1a5b4e33 100644 --- a/src/python/pants/backend/java/target_types.py +++ b/src/python/pants/backend/java/target_types.py @@ -22,7 +22,11 @@ generate_file_level_targets, ) from pants.engine.unions import UnionMembership, UnionRule -from pants.jvm.target_types import JvmCompatibleResolveNamesField, JvmResolveName +from pants.jvm.target_types import ( + JvmCompatibleResolveNamesField, + JvmProvidesTypesField, + JvmResolveName, +) class JavaSourceField(SingleSourceField): @@ -63,6 +67,7 @@ class JunitTestTarget(Target): JavaTestSourceField, Dependencies, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "A single Java test, run with JUnit." @@ -78,6 +83,7 @@ class JunitTestsGeneratorTarget(Target): JavaTestsGeneratorSourcesField, Dependencies, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "Generate a `junit_test` target for each file in the `sources` field." @@ -114,6 +120,7 @@ class JavaSourceTarget(Target): Dependencies, JavaSourceField, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "A single Java source file containing application or library code." @@ -129,6 +136,7 @@ class JavaSourcesGeneratorTarget(Target): Dependencies, JavaSourcesGeneratorSourcesField, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "Generate a `java_source` target for each file in the `sources` field." diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index 56b05fec3d6..6c976068ff3 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -16,6 +16,7 @@ JvmArtifactArtifactField, JvmArtifactGroupField, JvmArtifactPackagesField, + JvmProvidesTypesField, ) from pants.util.frozendict import FrozenDict from pants.util.logging import LogLevel @@ -38,6 +39,14 @@ def from_coord_str(cls, coord: str) -> UnversionedCoordinate: return UnversionedCoordinate(group=coordinate_parts[0], artifact=coordinate_parts[1]) +class FirstPartySourceProvided: + """Marks when a first-party source has declared that it provides a given JVM symbol. + + This resolves disambiguation cases in dependency inference when a first-party source provides + one type in a package that is otherwise fulfilled by third-party artifacts. + """ + + @dataclass(frozen=True) class AvailableThirdPartyArtifacts: """Maps JVM unversioned coordinates to target `Address`es and declared packages.""" @@ -56,6 +65,9 @@ def addresses_for_coordinates( class MutableTrieNode: + + __slots__ = ["children", "recursive", "addresses"] # don't use a `dict` to store attrs + def __init__(self): self.children: dict[str, MutableTrieNode] = {} self.recursive: bool = False @@ -71,6 +83,14 @@ def ensure_child(self, name: str) -> MutableTrieNode: @frozen_after_init class FrozenTrieNode: + + __slots__ = [ + "_is_frozen", + "_children", + "_recursive", + "_addresses", + ] # don't use a `dict` to store attrs + def __init__(self, node: MutableTrieNode) -> None: children = {} for key, child in node.children.items(): @@ -110,6 +130,10 @@ class AllJvmArtifactTargets(Targets): pass +class AllJvmTypeProvidingTargets(Targets): + pass + + @rule(desc="Find all jvm_artifact targets in project", level=LogLevel.DEBUG) def find_all_jvm_artifact_targets(targets: AllTargets) -> AllJvmArtifactTargets: return AllJvmArtifactTargets( @@ -117,6 +141,15 @@ def find_all_jvm_artifact_targets(targets: AllTargets) -> AllJvmArtifactTargets: ) +@rule(desc="Find all targets with experimental_provides fields in project", level=LogLevel.DEBUG) +def find_all_jvm_provides_fields(targets: AllTargets) -> AllJvmTypeProvidingTargets: + return AllJvmTypeProvidingTargets( + tgt + for tgt in targets + if tgt.has_fields((JvmProvidesTypesField,)) and tgt[JvmProvidesTypesField].value is not None + ) + + @dataclass(frozen=True) class ThirdPartyPackageToArtifactMapping: mapping_root: FrozenTrieNode @@ -126,6 +159,7 @@ class ThirdPartyPackageToArtifactMapping: async def find_available_third_party_artifacts( all_jvm_artifact_tgts: AllJvmArtifactTargets, ) -> AvailableThirdPartyArtifacts: + address_mapping: dict[UnversionedCoordinate, OrderedSet[Address]] = defaultdict(OrderedSet) package_mapping: dict[UnversionedCoordinate, OrderedSet[str]] = defaultdict(OrderedSet) for tgt in all_jvm_artifact_tgts: @@ -163,6 +197,7 @@ async def find_available_third_party_artifacts( async def compute_java_third_party_artifact_mapping( java_infer_subsystem: JavaInferSubsystem, available_artifacts: AvailableThirdPartyArtifacts, + all_jvm_type_providing_tgts: AllJvmTypeProvidingTargets, ) -> ThirdPartyPackageToArtifactMapping: """Implements the mapping logic from the `jvm_artifact` and `java-infer` help.""" diff --git a/src/python/pants/jvm/target_types.py b/src/python/pants/jvm/target_types.py index aed927ebf40..9fb0c53ca86 100644 --- a/src/python/pants/jvm/target_types.py +++ b/src/python/pants/jvm/target_types.py @@ -64,6 +64,11 @@ class JvmArtifactPackagesField(StringSequenceField): ) +class JvmProvidesTypesField(StringSequenceField): + alias = "experimental_provides_types" + help = "TODO: Add help for this." + + class JvmArtifactFieldSet(FieldSet): group: JvmArtifactGroupField From 2d5019fca9827c65bb8b99ee2faa7cc94309cdde Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 23 Nov 2021 12:02:55 -0800 Subject: [PATCH 02/13] WIP # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../dependency_inference/artifact_mapper.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index 6c976068ff3..6600e9d8d51 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -66,12 +66,18 @@ def addresses_for_coordinates( class MutableTrieNode: - __slots__ = ["children", "recursive", "addresses"] # don't use a `dict` to store attrs + __slots__ = [ + "children", + "recursive", + "addresses", + "first_party", + ] # don't use a `dict` to store attrs def __init__(self): self.children: dict[str, MutableTrieNode] = {} self.recursive: bool = False self.addresses: OrderedSet[Address] = OrderedSet() + self.first_party: bool = False def ensure_child(self, name: str) -> MutableTrieNode: if name in self.children: @@ -89,7 +95,8 @@ class FrozenTrieNode: "_children", "_recursive", "_addresses", - ] # don't use a `dict` to store attrs + "_first_party", + ] # don't use a `dict` to store attrs (speeds up attr access significantly) def __init__(self, node: MutableTrieNode) -> None: children = {} @@ -98,6 +105,7 @@ def __init__(self, node: MutableTrieNode) -> None: self._children: FrozenDict[str, FrozenTrieNode] = FrozenDict(children) self._recursive: bool = node.recursive self._addresses: FrozenOrderedSet[Address] = FrozenOrderedSet(node.addresses) + self._first_party: bool = node.first_party def find_child(self, name: str) -> FrozenTrieNode | None: return self._children.get(name) @@ -106,6 +114,10 @@ def find_child(self, name: str) -> FrozenTrieNode | None: def recursive(self) -> bool: return self._recursive + @property + def first_party(self) -> bool: + return self._first_party + @property def addresses(self) -> FrozenOrderedSet[Address]: return self._addresses @@ -266,6 +278,9 @@ def find_artifact_mapping( # If the length of the found nodes equals the number of parts of the package path, then there # is an exact match. if len(found_nodes) == len(imp_parts): + best_match = found_nodes[-1] + if best_match.first_party: + return FrozenOrderedSet() # The first-party symbol mapper should provide this dep return found_nodes[-1].addresses # Otherwise, check for the first found node (in reverse order) to match recursively, and use its coordinate. From 5004e0c583247d940d0ba6a70692f4712e1ab4e6 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 23 Nov 2021 13:04:50 -0800 Subject: [PATCH 03/13] Excludes `provide`d types from third-party deps list # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../jvm/dependency_inference/artifact_mapper.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index 6600e9d8d51..d953ec409a6 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -135,7 +135,7 @@ def __eq__(self, other: Any) -> bool: ) def __repr__(self): - return f"FrozenTrieNode(children={repr(self._children)}, recursive={self._recursive}, addresses={self._addresses})" + return f"FrozenTrieNode(children={repr(self._children)}, recursive={self._recursive}, addresses={self._addresses}, first_party={self._first_party})" class AllJvmArtifactTargets(Targets): @@ -214,7 +214,10 @@ async def compute_java_third_party_artifact_mapping( """Implements the mapping logic from the `jvm_artifact` and `java-infer` help.""" def insert( - mapping: MutableTrieNode, package_pattern: str, addresses: Iterable[Address] + mapping: MutableTrieNode, + package_pattern: str, + addresses: Iterable[Address], + first_party: bool, ) -> None: imp_parts = package_pattern.split(".") recursive = False @@ -228,6 +231,7 @@ def insert( current_node = child_node current_node.addresses.update(addresses) + current_node.first_party = first_party current_node.recursive = recursive # Build a default mapping from coord to package. @@ -252,7 +256,12 @@ def insert( # Default to exposing the `group` name as a package. packages = (f"{coord.group}.**",) for package in packages: - insert(mapping, package, addresses) + insert(mapping, package, addresses, False) + + # Mark types that have strong first-party declarations as first-party + for tgt in all_jvm_type_providing_tgts: + for provides_types in tgt[JvmProvidesTypesField].value or []: + insert(mapping, provides_types, [], True) return ThirdPartyPackageToArtifactMapping(FrozenTrieNode(mapping)) From a27e44e55a29e641da9d66393ad52ebb8ab9e184 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 23 Nov 2021 13:06:13 -0800 Subject: [PATCH 04/13] [DO NOT MERGE] demo of `provides` on testproject # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../src/jvm/org/pantsbuild/example/app/BUILD | 8 + .../pantsbuild/example/app/ExampleApp.scala | 4 +- .../example/app/coursier_resolve.lockfile | 408 +++++++++++++++++- .../src/jvm/org/pantsbuild/example/lib/BUILD | 5 +- .../example/lib/BadAndDangerous.java | 7 + 5 files changed, 429 insertions(+), 3 deletions(-) create mode 100644 testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD index 1132fb30b19..19eb93bd5bc 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD @@ -10,3 +10,11 @@ deploy_jar( scala_sources( compatible_resolves=["exampleapp"], ) + +jvm_artifact( + name = "com.google.truth_truth", + group = "com.google.truth", + artifact = "truth", + version = "0.45", + # scope = "test", +) diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala b/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala index fd60360b000..a5a7f737782 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala +++ b/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala @@ -1,9 +1,11 @@ package org.pantsbuild.example.app; import org.pantsbuild.example.lib.ExampleLib +import com.google.common.truth.BadAndDangerous class ExampleApp { def main(args: Array[String]): Unit = { - println(ExampleLib.hello()) + println(BadAndDangerous.hello()) + com.google.common.truth.Truth.assertThat(new Object()) } } diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile b/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile index 0637a088a01..a943688516c 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile +++ b/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile @@ -1 +1,407 @@ -[] \ No newline at end of file +[ + { + "coord": { + "group": "com.google.auto.value", + "artifact": "auto-value-annotations", + "version": "1.6.3", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.auto.value_auto-value-annotations_1.6.3.jar", + "file_digest": { + "fingerprint": "0e951fee8c31f60270bc46553a8586001b7b93dbb12aec06373aa99a150392c0", + "serialized_bytes_length": 5906 + } + }, + { + "coord": { + "group": "com.google.code.findbugs", + "artifact": "jsr305", + "version": "3.0.2", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.code.findbugs_jsr305_3.0.2.jar", + "file_digest": { + "fingerprint": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7", + "serialized_bytes_length": 19936 + } + }, + { + "coord": { + "group": "com.google.errorprone", + "artifact": "error_prone_annotations", + "version": "2.3.1", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.errorprone_error_prone_annotations_2.3.1.jar", + "file_digest": { + "fingerprint": "10a5949aa0f95c8de4fd47edfe20534d2acefd8c224f8afea1f607e112816120", + "serialized_bytes_length": 13162 + } + }, + { + "coord": { + "group": "com.google.guava", + "artifact": "failureaccess", + "version": "1.0.1", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.guava_failureaccess_1.0.1.jar", + "file_digest": { + "fingerprint": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", + "serialized_bytes_length": 4617 + } + }, + { + "coord": { + "group": "com.google.guava", + "artifact": "guava", + "version": "27.0.1-android", + "packaging": "jar" + }, + "directDependencies": [ + { + "group": "com.google.guava", + "artifact": "listenablefuture", + "version": "9999.0-empty-to-avoid-conflict-with-guava", + "packaging": "jar" + }, + { + "group": "com.google.code.findbugs", + "artifact": "jsr305", + "version": "3.0.2", + "packaging": "jar" + }, + { + "group": "com.google.errorprone", + "artifact": "error_prone_annotations", + "version": "2.3.1", + "packaging": "jar" + }, + { + "group": "org.codehaus.mojo", + "artifact": "animal-sniffer-annotations", + "version": "1.17", + "packaging": "jar" + }, + { + "group": "com.google.j2objc", + "artifact": "j2objc-annotations", + "version": "1.1", + "packaging": "jar" + }, + { + "group": "com.google.guava", + "artifact": "failureaccess", + "version": "1.0.1", + "packaging": "jar" + }, + { + "group": "org.checkerframework", + "artifact": "checker-compat-qual", + "version": "2.5.5", + "packaging": "jar" + } + ], + "dependencies": [ + { + "group": "com.google.guava", + "artifact": "listenablefuture", + "version": "9999.0-empty-to-avoid-conflict-with-guava", + "packaging": "jar" + }, + { + "group": "com.google.code.findbugs", + "artifact": "jsr305", + "version": "3.0.2", + "packaging": "jar" + }, + { + "group": "com.google.errorprone", + "artifact": "error_prone_annotations", + "version": "2.3.1", + "packaging": "jar" + }, + { + "group": "org.codehaus.mojo", + "artifact": "animal-sniffer-annotations", + "version": "1.17", + "packaging": "jar" + }, + { + "group": "com.google.j2objc", + "artifact": "j2objc-annotations", + "version": "1.1", + "packaging": "jar" + }, + { + "group": "com.google.guava", + "artifact": "failureaccess", + "version": "1.0.1", + "packaging": "jar" + }, + { + "group": "org.checkerframework", + "artifact": "checker-compat-qual", + "version": "2.5.5", + "packaging": "jar" + } + ], + "file_name": "com.google.guava_guava_27.0.1-android.jar", + "file_digest": { + "fingerprint": "caf0955aed29a1e6d149f85cfb625a89161b5cf88e0e246552b7ffa358204e28", + "serialized_bytes_length": 2603999 + } + }, + { + "coord": { + "group": "com.google.guava", + "artifact": "listenablefuture", + "version": "9999.0-empty-to-avoid-conflict-with-guava", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.guava_listenablefuture_9999.0-empty-to-avoid-conflict-with-guava.jar", + "file_digest": { + "fingerprint": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99", + "serialized_bytes_length": 2199 + } + }, + { + "coord": { + "group": "com.google.j2objc", + "artifact": "j2objc-annotations", + "version": "1.1", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.google.j2objc_j2objc-annotations_1.1.jar", + "file_digest": { + "fingerprint": "2994a7eb78f2710bd3d3bfb639b2c94e219cedac0d4d084d516e78c16dddecf6", + "serialized_bytes_length": 8782 + } + }, + { + "coord": { + "group": "com.google.truth", + "artifact": "truth", + "version": "0.45", + "packaging": "jar" + }, + "directDependencies": [ + { + "group": "com.google.guava", + "artifact": "guava", + "version": "27.0.1-android", + "packaging": "jar" + }, + { + "group": "junit", + "artifact": "junit", + "version": "4.12", + "packaging": "jar" + }, + { + "group": "com.google.errorprone", + "artifact": "error_prone_annotations", + "version": "2.3.1", + "packaging": "jar" + }, + { + "group": "com.googlecode.java-diff-utils", + "artifact": "diffutils", + "version": "1.3.0", + "packaging": "jar" + }, + { + "group": "com.google.auto.value", + "artifact": "auto-value-annotations", + "version": "1.6.3", + "packaging": "jar" + }, + { + "group": "org.checkerframework", + "artifact": "checker-compat-qual", + "version": "2.5.5", + "packaging": "jar" + } + ], + "dependencies": [ + { + "group": "com.google.guava", + "artifact": "listenablefuture", + "version": "9999.0-empty-to-avoid-conflict-with-guava", + "packaging": "jar" + }, + { + "group": "com.google.code.findbugs", + "artifact": "jsr305", + "version": "3.0.2", + "packaging": "jar" + }, + { + "group": "com.google.guava", + "artifact": "guava", + "version": "27.0.1-android", + "packaging": "jar" + }, + { + "group": "junit", + "artifact": "junit", + "version": "4.12", + "packaging": "jar" + }, + { + "group": "org.hamcrest", + "artifact": "hamcrest-core", + "version": "1.3", + "packaging": "jar" + }, + { + "group": "com.google.errorprone", + "artifact": "error_prone_annotations", + "version": "2.3.1", + "packaging": "jar" + }, + { + "group": "com.googlecode.java-diff-utils", + "artifact": "diffutils", + "version": "1.3.0", + "packaging": "jar" + }, + { + "group": "org.codehaus.mojo", + "artifact": "animal-sniffer-annotations", + "version": "1.17", + "packaging": "jar" + }, + { + "group": "com.google.j2objc", + "artifact": "j2objc-annotations", + "version": "1.1", + "packaging": "jar" + }, + { + "group": "com.google.guava", + "artifact": "failureaccess", + "version": "1.0.1", + "packaging": "jar" + }, + { + "group": "com.google.auto.value", + "artifact": "auto-value-annotations", + "version": "1.6.3", + "packaging": "jar" + }, + { + "group": "org.checkerframework", + "artifact": "checker-compat-qual", + "version": "2.5.5", + "packaging": "jar" + } + ], + "file_name": "com.google.truth_truth_0.45.jar", + "file_digest": { + "fingerprint": "0f7dced2a16e55a77e44fc3ff9c5be98d4bf4bb30abc18d78ffd735df950a69f", + "serialized_bytes_length": 257064 + } + }, + { + "coord": { + "group": "com.googlecode.java-diff-utils", + "artifact": "diffutils", + "version": "1.3.0", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "com.googlecode.java-diff-utils_diffutils_1.3.0.jar", + "file_digest": { + "fingerprint": "61ba4dc49adca95243beaa0569adc2a23aedb5292ae78aa01186fa782ebdc5c2", + "serialized_bytes_length": 34130 + } + }, + { + "coord": { + "group": "junit", + "artifact": "junit", + "version": "4.12", + "packaging": "jar" + }, + "directDependencies": [ + { + "group": "org.hamcrest", + "artifact": "hamcrest-core", + "version": "1.3", + "packaging": "jar" + } + ], + "dependencies": [ + { + "group": "org.hamcrest", + "artifact": "hamcrest-core", + "version": "1.3", + "packaging": "jar" + } + ], + "file_name": "junit_junit_4.12.jar", + "file_digest": { + "fingerprint": "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a", + "serialized_bytes_length": 314932 + } + }, + { + "coord": { + "group": "org.checkerframework", + "artifact": "checker-compat-qual", + "version": "2.5.5", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "org.checkerframework_checker-compat-qual_2.5.5.jar", + "file_digest": { + "fingerprint": "11d134b245e9cacc474514d2d66b5b8618f8039a1465cdc55bbc0b34e0008b7a", + "serialized_bytes_length": 5852 + } + }, + { + "coord": { + "group": "org.codehaus.mojo", + "artifact": "animal-sniffer-annotations", + "version": "1.17", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "org.codehaus.mojo_animal-sniffer-annotations_1.17.jar", + "file_digest": { + "fingerprint": "92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53", + "serialized_bytes_length": 3448 + } + }, + { + "coord": { + "group": "org.hamcrest", + "artifact": "hamcrest-core", + "version": "1.3", + "packaging": "jar" + }, + "directDependencies": [], + "dependencies": [], + "file_name": "org.hamcrest_hamcrest-core_1.3.jar", + "file_digest": { + "fingerprint": "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9", + "serialized_bytes_length": 45024 + } + } +] \ No newline at end of file diff --git a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD index 2563c023e16..8e8e7834b47 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD @@ -1,4 +1,7 @@ # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -java_sources(compatible_resolves=["exampleapp"]) +java_sources( + compatible_resolves=["exampleapp"], + experimental_provides_types=["com.google.common.truth.BadAndDangerous",] +) diff --git a/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java b/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java new file mode 100644 index 00000000000..646709b2af7 --- /dev/null +++ b/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java @@ -0,0 +1,7 @@ +package com.google.common.truth; + +public class BadAndDangerous { + public static String hello() { + return "Hello, World!"; + } +} From f50e0506c45c2ec5616e34623ff8b81b0eb071ff Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 23 Nov 2021 15:08:25 -0800 Subject: [PATCH 05/13] format build files # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- testprojects/src/jvm/org/pantsbuild/example/app/BUILD | 10 +++++----- testprojects/src/jvm/org/pantsbuild/example/lib/BUILD | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD index 19eb93bd5bc..6d044c04286 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD @@ -12,9 +12,9 @@ scala_sources( ) jvm_artifact( - name = "com.google.truth_truth", - group = "com.google.truth", - artifact = "truth", - version = "0.45", - # scope = "test", + name="com.google.truth_truth", + group="com.google.truth", + artifact="truth", + version="0.45", + # scope = "test", ) diff --git a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD index 8e8e7834b47..9e041058a3d 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD @@ -3,5 +3,7 @@ java_sources( compatible_resolves=["exampleapp"], - experimental_provides_types=["com.google.common.truth.BadAndDangerous",] + experimental_provides_types=[ + "com.google.common.truth.BadAndDangerous", + ], ) From e2d2a887e92ded35115cc9df8bb9aa2e166520d9 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 07:46:10 -0800 Subject: [PATCH 06/13] remove extraneous logging # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/backend/java/dependency_inference/rules.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python/pants/backend/java/dependency_inference/rules.py b/src/python/pants/backend/java/dependency_inference/rules.py index 7a2a5878eaa..c5dd5921d73 100644 --- a/src/python/pants/backend/java/dependency_inference/rules.py +++ b/src/python/pants/backend/java/dependency_inference/rules.py @@ -133,8 +133,6 @@ async def infer_java_dependencies_and_exports_via_source_analysis( third_party_matches: FrozenOrderedSet[Address] = FrozenOrderedSet() if java_infer_subsystem.third_party_imports: third_party_matches = find_artifact_mapping(typ, third_party_artifact_mapping) - if "AbstractMatcher" in str(request.source.address): - logger.warning("%s", f"TPM: {third_party_matches}") matches = first_party_matches.union(third_party_matches) if not matches: continue From da26a6f694d4003bd515d3a2e3efaa6f1b602cac Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 07:50:28 -0800 Subject: [PATCH 07/13] style remarks from code review # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/jvm/dependency_inference/artifact_mapper.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index d953ec409a6..ba99adc8a3d 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -65,7 +65,6 @@ def addresses_for_coordinates( class MutableTrieNode: - __slots__ = [ "children", "recursive", @@ -89,7 +88,6 @@ def ensure_child(self, name: str) -> MutableTrieNode: @frozen_after_init class FrozenTrieNode: - __slots__ = [ "_is_frozen", "_children", From cedef05a784ab3ed9188c6ae5cf7259e95cae947 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 07:53:00 -0800 Subject: [PATCH 08/13] Delete unused types # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../pants/jvm/dependency_inference/artifact_mapper.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index ba99adc8a3d..735f157d438 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -39,14 +39,6 @@ def from_coord_str(cls, coord: str) -> UnversionedCoordinate: return UnversionedCoordinate(group=coordinate_parts[0], artifact=coordinate_parts[1]) -class FirstPartySourceProvided: - """Marks when a first-party source has declared that it provides a given JVM symbol. - - This resolves disambiguation cases in dependency inference when a first-party source provides - one type in a package that is otherwise fulfilled by third-party artifacts. - """ - - @dataclass(frozen=True) class AvailableThirdPartyArtifacts: """Maps JVM unversioned coordinates to target `Address`es and declared packages.""" From 8ce67b2c9c641af4c9237cd0068969d742ec443a Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 08:37:01 -0800 Subject: [PATCH 09/13] Adds config verification for `provides` # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../jvm/dependency_inference/symbol_mapper.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/python/pants/jvm/dependency_inference/symbol_mapper.py b/src/python/pants/jvm/dependency_inference/symbol_mapper.py index 73372ce7923..bf862742171 100644 --- a/src/python/pants/jvm/dependency_inference/symbol_mapper.py +++ b/src/python/pants/jvm/dependency_inference/symbol_mapper.py @@ -10,6 +10,8 @@ from pants.build_graph.address import Address from pants.engine.rules import Get, MultiGet, collect_rules, rule from pants.engine.unions import UnionMembership, union +from pants.jvm.dependency_inference.artifact_mapper import AllJvmTypeProvidingTargets +from pants.jvm.target_types import JvmProvidesTypesField from pants.util.logging import LogLevel logger = logging.getLogger(__name__) @@ -78,6 +80,7 @@ class FirstPartySymbolMapping: @rule(level=LogLevel.DEBUG) async def merge_first_party_module_mappings( union_membership: UnionMembership, + targets_that_provide_types: AllJvmTypeProvidingTargets, ) -> FirstPartySymbolMapping: all_mappings = await MultiGet( Get( @@ -92,6 +95,25 @@ async def merge_first_party_module_mappings( for dep_map in all_mappings: merged_dep_map.merge(dep_map) + # `experimental_provides_types` ("`provides`") can be declared on a `java_sources` target, + # so each generated `java_source` target will have that `provides` annotation. All that matters + # here is that _one_ of the souce files amongst the set of sources actually provides that type. + + # Collect each address associated with a `provides` annotation and index by the provided type. + provided_types: dict[str, set[Address]] = defaultdict(set) + for tgt in targets_that_provide_types: + for provided_type in tgt[JvmProvidesTypesField].value or []: + provided_types[provided_type].add(tgt.address) + + # Check that at least one address declared by each `provides` value actually provides the type: + for provided_type, provided_addresses in provided_types.items(): + symbol_addresses = merged_dep_map.addresses_for_symbol(provided_type) + if not provided_addresses.intersection(symbol_addresses): + raise Exception( + f"The target {next(iter(provided_addresses))} declares that it provides the JVM type " + f"`{provided_type}`, however, it does not appear to actually provide that type." + ) + return FirstPartySymbolMapping(merged_dep_map) From d5021f65a1d224430924a6a8f47ee7c597551af2 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 08:47:01 -0800 Subject: [PATCH 10/13] `scala_source`(`s`) now declares `experimental_provides_types` # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/backend/scala/target_types.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/python/pants/backend/scala/target_types.py b/src/python/pants/backend/scala/target_types.py index 38905be010a..34508e59fb9 100644 --- a/src/python/pants/backend/scala/target_types.py +++ b/src/python/pants/backend/scala/target_types.py @@ -20,7 +20,7 @@ generate_file_level_targets, ) from pants.engine.unions import UnionMembership, UnionRule -from pants.jvm.target_types import JvmCompatibleResolveNamesField +from pants.jvm.target_types import JvmCompatibleResolveNamesField, JvmProvidesTypesField class ScalaSourceField(SingleSourceField): @@ -61,6 +61,7 @@ class ScalaJunitTestTarget(Target): Dependencies, ScalaTestSourceField, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "A single Scala test, run with JUnit." @@ -81,6 +82,7 @@ class ScalaJunitTestsGeneratorTarget(Target): ScalaTestsGeneratorSourcesField, Dependencies, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = ( "Generate a `junit_test` target for each file in the `sources` field (defaults to " @@ -121,6 +123,7 @@ class ScalaSourceTarget(Target): Dependencies, ScalaSourceField, JvmCompatibleResolveNamesField, + JvmProvidesTypesField, ) help = "A single Scala source file containing application or library code." @@ -141,7 +144,8 @@ class ScalaSourcesGeneratorTarget(Target): Dependencies, ScalaSourcesGeneratorSourcesField, JvmCompatibleResolveNamesField, - ) + JvmProvidesTypesField, + ) help = ( "Generate a `scala_source` target for each file in the `sources` field (defaults to " "all files named in the directory whose names end in `.scala` except for those which " From 4a4f4809d6889d696a84bdbfbcc5fd0a9f0d8186 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 09:15:38 -0800 Subject: [PATCH 11/13] Adds tests for `provides` # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../pants/backend/scala/target_types.py | 2 +- .../artifact_mapper_test.py | 125 +++++++++++++++++- .../jvm/dependency_inference/symbol_mapper.py | 6 +- 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/src/python/pants/backend/scala/target_types.py b/src/python/pants/backend/scala/target_types.py index 34508e59fb9..b8a416035ca 100644 --- a/src/python/pants/backend/scala/target_types.py +++ b/src/python/pants/backend/scala/target_types.py @@ -145,7 +145,7 @@ class ScalaSourcesGeneratorTarget(Target): ScalaSourcesGeneratorSourcesField, JvmCompatibleResolveNamesField, JvmProvidesTypesField, - ) + ) help = ( "Generate a `scala_source` target for each file in the `sources` field (defaults to " "all files named in the directory whose names end in `.scala` except for those which " diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper_test.py b/src/python/pants/jvm/dependency_inference/artifact_mapper_test.py index 4275f28cbc3..39165f1cdae 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper_test.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper_test.py @@ -17,13 +17,20 @@ FrozenTrieNode, ThirdPartyPackageToArtifactMapping, ) +from pants.jvm.dependency_inference.symbol_mapper import JvmFirstPartyPackageMappingException from pants.jvm.jdk_rules import rules as java_util_rules from pants.jvm.resolve.coursier_fetch import rules as coursier_fetch_rules from pants.jvm.resolve.coursier_setup import rules as coursier_setup_rules from pants.jvm.target_types import JvmArtifact from pants.jvm.testutil import maybe_skip_jdk_test from pants.jvm.util_rules import rules as util_rules -from pants.testutil.rule_runner import PYTHON_BOOTSTRAP_ENV, QueryRule, RuleRunner, logging +from pants.testutil.rule_runner import ( + PYTHON_BOOTSTRAP_ENV, + QueryRule, + RuleRunner, + engine_error, + logging, +) NAMED_RESOLVE_OPTIONS = '--jvm-resolves={"test": "coursier_resolve.lockfile"}' DEFAULT_RESOLVE_OPTION = "--jvm-default-resolve=test" @@ -300,3 +307,119 @@ def test_third_party_dep_inference_nonrecursive(rule_runner: RuleRunner) -> None assert rule_runner.request(Addresses, [DependenciesRequest(lib2[Dependencies])]) == Addresses( [Address("", target_name="joda-time_joda-time")] ) + + +@maybe_skip_jdk_test +def test_third_party_dep_inference_with_provides(rule_runner: RuleRunner) -> None: + rule_runner.set_options( + [ + "--java-infer-third-party-import-mapping={'org.joda.time.**':'joda-time:joda-time', 'org.joda.time.DateTime':'joda-time:joda-time-2'}" + ], + env_inherit=PYTHON_BOOTSTRAP_ENV, + ) + rule_runner.write_files( + { + "BUILD": dedent( + """\ + jvm_artifact( + name = "joda-time_joda-time", + group = "joda-time", + artifact = "joda-time", + version = "2.10.10", + ) + + java_sources( + name = 'lib', + experimental_provides_types = ['org.joda.time.MefripulousDateTime', ], + ) + """ + ), + "PrintDate.java": dedent( + """\ + package org.pantsbuild.example; + + import org.joda.time.DateTime; + import org.joda.time.MefripulousDateTime; + + public class PrintDate { + public static void main(String[] args) { + DateTime dt = new DateTime(); + System.out.println(dt.toString()); + new MefripulousDateTime().mefripulate(); + } + } + """ + ), + "MefripulousDateTime.java": dedent( + """\ + package org.joda.time; + + public class MefripulousDateTime { + public void mefripulate() { + DateTime dt = new LocalDateTime(); + System.out.println(dt.toString()); + } + } + """ + ), + } + ) + + lib1 = rule_runner.get_target( + Address("", target_name="lib", relative_file_path="PrintDate.java") + ) + assert rule_runner.request(Addresses, [DependenciesRequest(lib1[Dependencies])]) == Addresses( + [ + Address("", target_name="joda-time_joda-time"), + Address("", target_name="lib", relative_file_path="MefripulousDateTime.java"), + ] + ) + + +@maybe_skip_jdk_test +def test_third_party_dep_inference_with_incorrect_provides(rule_runner: RuleRunner) -> None: + rule_runner.set_options( + [ + "--java-infer-third-party-import-mapping={'org.joda.time.**':'joda-time:joda-time', 'org.joda.time.DateTime':'joda-time:joda-time-2'}" + ], + env_inherit=PYTHON_BOOTSTRAP_ENV, + ) + rule_runner.write_files( + { + "BUILD": dedent( + """\ + jvm_artifact( + name = "joda-time_joda-time", + group = "joda-time", + artifact = "joda-time", + version = "2.10.10", + ) + + java_sources( + name = 'lib', + experimental_provides_types = ['org.joda.time.DateTime', ], + ) + """ + ), + "PrintDate.java": dedent( + """\ + package org.pantsbuild.example; + + import org.joda.time.DateTime; + + public class PrintDate { + public static void main(String[] args) { + DateTime dt = new DateTime(); + System.out.println(dt.toString()); + } + } + """ + ), + } + ) + + lib1 = rule_runner.get_target( + Address("", target_name="lib", relative_file_path="PrintDate.java") + ) + with engine_error(JvmFirstPartyPackageMappingException): + rule_runner.request(Addresses, [DependenciesRequest(lib1[Dependencies])]) diff --git a/src/python/pants/jvm/dependency_inference/symbol_mapper.py b/src/python/pants/jvm/dependency_inference/symbol_mapper.py index bf862742171..31bea853f04 100644 --- a/src/python/pants/jvm/dependency_inference/symbol_mapper.py +++ b/src/python/pants/jvm/dependency_inference/symbol_mapper.py @@ -22,6 +22,10 @@ # ----------------------------------------------------------------------------------------------- +class JvmFirstPartyPackageMappingException(Exception): + pass + + class SymbolMap: """A mapping of JVM package names to owning addresses.""" @@ -109,7 +113,7 @@ async def merge_first_party_module_mappings( for provided_type, provided_addresses in provided_types.items(): symbol_addresses = merged_dep_map.addresses_for_symbol(provided_type) if not provided_addresses.intersection(symbol_addresses): - raise Exception( + raise JvmFirstPartyPackageMappingException( f"The target {next(iter(provided_addresses))} declares that it provides the JVM type " f"`{provided_type}`, however, it does not appear to actually provide that type." ) From cf8e08fa38af54ae0665b4ea8dd50d2f73b18d78 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 11:46:09 -0800 Subject: [PATCH 12/13] Code review comments # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- .../pants/jvm/dependency_inference/artifact_mapper.py | 6 +++--- src/python/pants/jvm/target_types.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/python/pants/jvm/dependency_inference/artifact_mapper.py b/src/python/pants/jvm/dependency_inference/artifact_mapper.py index 735f157d438..6c5af7a791f 100644 --- a/src/python/pants/jvm/dependency_inference/artifact_mapper.py +++ b/src/python/pants/jvm/dependency_inference/artifact_mapper.py @@ -148,7 +148,7 @@ def find_all_jvm_provides_fields(targets: AllTargets) -> AllJvmTypeProvidingTarg return AllJvmTypeProvidingTargets( tgt for tgt in targets - if tgt.has_fields((JvmProvidesTypesField,)) and tgt[JvmProvidesTypesField].value is not None + if tgt.has_field(JvmProvidesTypesField) and tgt[JvmProvidesTypesField].value is not None ) @@ -250,8 +250,8 @@ def insert( # Mark types that have strong first-party declarations as first-party for tgt in all_jvm_type_providing_tgts: - for provides_types in tgt[JvmProvidesTypesField].value or []: - insert(mapping, provides_types, [], True) + for provides_type in tgt[JvmProvidesTypesField].value or []: + insert(mapping, provides_type, [], True) return ThirdPartyPackageToArtifactMapping(FrozenTrieNode(mapping)) diff --git a/src/python/pants/jvm/target_types.py b/src/python/pants/jvm/target_types.py index 9fb0c53ca86..2948e7d44a2 100644 --- a/src/python/pants/jvm/target_types.py +++ b/src/python/pants/jvm/target_types.py @@ -66,7 +66,13 @@ class JvmArtifactPackagesField(StringSequenceField): class JvmProvidesTypesField(StringSequenceField): alias = "experimental_provides_types" - help = "TODO: Add help for this." + help = ( + "Signals that the specified types should be fulfilled by these source files during " + "dependency inference. This allows for specific types within packages that are otherwise " + "inferred as belonging to `jvm_artifact` targets to be unambiguously inferred as belonging " + "to this first-party source. If a given type is defined, at least one source file captured " + "by this target must actually provide that symbol." + ) class JvmArtifactFieldSet(FieldSet): From 6b1d2c9101c05d5b4df50544a4b8ed6b54a9e1e2 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 24 Nov 2021 12:04:12 -0800 Subject: [PATCH 13/13] Revert "[DO NOT MERGE] demo of `provides` on testproject" This reverts commit a27e44e55a29e641da9d66393ad52ebb8ab9e184. [ci skip-rust] [ci skip-build-wheels] --- .../src/jvm/org/pantsbuild/example/app/BUILD | 8 - .../pantsbuild/example/app/ExampleApp.scala | 4 +- .../example/app/coursier_resolve.lockfile | 408 +----------------- .../src/jvm/org/pantsbuild/example/lib/BUILD | 7 +- .../example/lib/BadAndDangerous.java | 7 - 5 files changed, 3 insertions(+), 431 deletions(-) delete mode 100644 testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD index 6d044c04286..1132fb30b19 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/app/BUILD @@ -10,11 +10,3 @@ deploy_jar( scala_sources( compatible_resolves=["exampleapp"], ) - -jvm_artifact( - name="com.google.truth_truth", - group="com.google.truth", - artifact="truth", - version="0.45", - # scope = "test", -) diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala b/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala index a5a7f737782..fd60360b000 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala +++ b/testprojects/src/jvm/org/pantsbuild/example/app/ExampleApp.scala @@ -1,11 +1,9 @@ package org.pantsbuild.example.app; import org.pantsbuild.example.lib.ExampleLib -import com.google.common.truth.BadAndDangerous class ExampleApp { def main(args: Array[String]): Unit = { - println(BadAndDangerous.hello()) - com.google.common.truth.Truth.assertThat(new Object()) + println(ExampleLib.hello()) } } diff --git a/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile b/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile index a943688516c..0637a088a01 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile +++ b/testprojects/src/jvm/org/pantsbuild/example/app/coursier_resolve.lockfile @@ -1,407 +1 @@ -[ - { - "coord": { - "group": "com.google.auto.value", - "artifact": "auto-value-annotations", - "version": "1.6.3", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.auto.value_auto-value-annotations_1.6.3.jar", - "file_digest": { - "fingerprint": "0e951fee8c31f60270bc46553a8586001b7b93dbb12aec06373aa99a150392c0", - "serialized_bytes_length": 5906 - } - }, - { - "coord": { - "group": "com.google.code.findbugs", - "artifact": "jsr305", - "version": "3.0.2", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.code.findbugs_jsr305_3.0.2.jar", - "file_digest": { - "fingerprint": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7", - "serialized_bytes_length": 19936 - } - }, - { - "coord": { - "group": "com.google.errorprone", - "artifact": "error_prone_annotations", - "version": "2.3.1", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.errorprone_error_prone_annotations_2.3.1.jar", - "file_digest": { - "fingerprint": "10a5949aa0f95c8de4fd47edfe20534d2acefd8c224f8afea1f607e112816120", - "serialized_bytes_length": 13162 - } - }, - { - "coord": { - "group": "com.google.guava", - "artifact": "failureaccess", - "version": "1.0.1", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.guava_failureaccess_1.0.1.jar", - "file_digest": { - "fingerprint": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", - "serialized_bytes_length": 4617 - } - }, - { - "coord": { - "group": "com.google.guava", - "artifact": "guava", - "version": "27.0.1-android", - "packaging": "jar" - }, - "directDependencies": [ - { - "group": "com.google.guava", - "artifact": "listenablefuture", - "version": "9999.0-empty-to-avoid-conflict-with-guava", - "packaging": "jar" - }, - { - "group": "com.google.code.findbugs", - "artifact": "jsr305", - "version": "3.0.2", - "packaging": "jar" - }, - { - "group": "com.google.errorprone", - "artifact": "error_prone_annotations", - "version": "2.3.1", - "packaging": "jar" - }, - { - "group": "org.codehaus.mojo", - "artifact": "animal-sniffer-annotations", - "version": "1.17", - "packaging": "jar" - }, - { - "group": "com.google.j2objc", - "artifact": "j2objc-annotations", - "version": "1.1", - "packaging": "jar" - }, - { - "group": "com.google.guava", - "artifact": "failureaccess", - "version": "1.0.1", - "packaging": "jar" - }, - { - "group": "org.checkerframework", - "artifact": "checker-compat-qual", - "version": "2.5.5", - "packaging": "jar" - } - ], - "dependencies": [ - { - "group": "com.google.guava", - "artifact": "listenablefuture", - "version": "9999.0-empty-to-avoid-conflict-with-guava", - "packaging": "jar" - }, - { - "group": "com.google.code.findbugs", - "artifact": "jsr305", - "version": "3.0.2", - "packaging": "jar" - }, - { - "group": "com.google.errorprone", - "artifact": "error_prone_annotations", - "version": "2.3.1", - "packaging": "jar" - }, - { - "group": "org.codehaus.mojo", - "artifact": "animal-sniffer-annotations", - "version": "1.17", - "packaging": "jar" - }, - { - "group": "com.google.j2objc", - "artifact": "j2objc-annotations", - "version": "1.1", - "packaging": "jar" - }, - { - "group": "com.google.guava", - "artifact": "failureaccess", - "version": "1.0.1", - "packaging": "jar" - }, - { - "group": "org.checkerframework", - "artifact": "checker-compat-qual", - "version": "2.5.5", - "packaging": "jar" - } - ], - "file_name": "com.google.guava_guava_27.0.1-android.jar", - "file_digest": { - "fingerprint": "caf0955aed29a1e6d149f85cfb625a89161b5cf88e0e246552b7ffa358204e28", - "serialized_bytes_length": 2603999 - } - }, - { - "coord": { - "group": "com.google.guava", - "artifact": "listenablefuture", - "version": "9999.0-empty-to-avoid-conflict-with-guava", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.guava_listenablefuture_9999.0-empty-to-avoid-conflict-with-guava.jar", - "file_digest": { - "fingerprint": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99", - "serialized_bytes_length": 2199 - } - }, - { - "coord": { - "group": "com.google.j2objc", - "artifact": "j2objc-annotations", - "version": "1.1", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.google.j2objc_j2objc-annotations_1.1.jar", - "file_digest": { - "fingerprint": "2994a7eb78f2710bd3d3bfb639b2c94e219cedac0d4d084d516e78c16dddecf6", - "serialized_bytes_length": 8782 - } - }, - { - "coord": { - "group": "com.google.truth", - "artifact": "truth", - "version": "0.45", - "packaging": "jar" - }, - "directDependencies": [ - { - "group": "com.google.guava", - "artifact": "guava", - "version": "27.0.1-android", - "packaging": "jar" - }, - { - "group": "junit", - "artifact": "junit", - "version": "4.12", - "packaging": "jar" - }, - { - "group": "com.google.errorprone", - "artifact": "error_prone_annotations", - "version": "2.3.1", - "packaging": "jar" - }, - { - "group": "com.googlecode.java-diff-utils", - "artifact": "diffutils", - "version": "1.3.0", - "packaging": "jar" - }, - { - "group": "com.google.auto.value", - "artifact": "auto-value-annotations", - "version": "1.6.3", - "packaging": "jar" - }, - { - "group": "org.checkerframework", - "artifact": "checker-compat-qual", - "version": "2.5.5", - "packaging": "jar" - } - ], - "dependencies": [ - { - "group": "com.google.guava", - "artifact": "listenablefuture", - "version": "9999.0-empty-to-avoid-conflict-with-guava", - "packaging": "jar" - }, - { - "group": "com.google.code.findbugs", - "artifact": "jsr305", - "version": "3.0.2", - "packaging": "jar" - }, - { - "group": "com.google.guava", - "artifact": "guava", - "version": "27.0.1-android", - "packaging": "jar" - }, - { - "group": "junit", - "artifact": "junit", - "version": "4.12", - "packaging": "jar" - }, - { - "group": "org.hamcrest", - "artifact": "hamcrest-core", - "version": "1.3", - "packaging": "jar" - }, - { - "group": "com.google.errorprone", - "artifact": "error_prone_annotations", - "version": "2.3.1", - "packaging": "jar" - }, - { - "group": "com.googlecode.java-diff-utils", - "artifact": "diffutils", - "version": "1.3.0", - "packaging": "jar" - }, - { - "group": "org.codehaus.mojo", - "artifact": "animal-sniffer-annotations", - "version": "1.17", - "packaging": "jar" - }, - { - "group": "com.google.j2objc", - "artifact": "j2objc-annotations", - "version": "1.1", - "packaging": "jar" - }, - { - "group": "com.google.guava", - "artifact": "failureaccess", - "version": "1.0.1", - "packaging": "jar" - }, - { - "group": "com.google.auto.value", - "artifact": "auto-value-annotations", - "version": "1.6.3", - "packaging": "jar" - }, - { - "group": "org.checkerframework", - "artifact": "checker-compat-qual", - "version": "2.5.5", - "packaging": "jar" - } - ], - "file_name": "com.google.truth_truth_0.45.jar", - "file_digest": { - "fingerprint": "0f7dced2a16e55a77e44fc3ff9c5be98d4bf4bb30abc18d78ffd735df950a69f", - "serialized_bytes_length": 257064 - } - }, - { - "coord": { - "group": "com.googlecode.java-diff-utils", - "artifact": "diffutils", - "version": "1.3.0", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "com.googlecode.java-diff-utils_diffutils_1.3.0.jar", - "file_digest": { - "fingerprint": "61ba4dc49adca95243beaa0569adc2a23aedb5292ae78aa01186fa782ebdc5c2", - "serialized_bytes_length": 34130 - } - }, - { - "coord": { - "group": "junit", - "artifact": "junit", - "version": "4.12", - "packaging": "jar" - }, - "directDependencies": [ - { - "group": "org.hamcrest", - "artifact": "hamcrest-core", - "version": "1.3", - "packaging": "jar" - } - ], - "dependencies": [ - { - "group": "org.hamcrest", - "artifact": "hamcrest-core", - "version": "1.3", - "packaging": "jar" - } - ], - "file_name": "junit_junit_4.12.jar", - "file_digest": { - "fingerprint": "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a", - "serialized_bytes_length": 314932 - } - }, - { - "coord": { - "group": "org.checkerframework", - "artifact": "checker-compat-qual", - "version": "2.5.5", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "org.checkerframework_checker-compat-qual_2.5.5.jar", - "file_digest": { - "fingerprint": "11d134b245e9cacc474514d2d66b5b8618f8039a1465cdc55bbc0b34e0008b7a", - "serialized_bytes_length": 5852 - } - }, - { - "coord": { - "group": "org.codehaus.mojo", - "artifact": "animal-sniffer-annotations", - "version": "1.17", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "org.codehaus.mojo_animal-sniffer-annotations_1.17.jar", - "file_digest": { - "fingerprint": "92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53", - "serialized_bytes_length": 3448 - } - }, - { - "coord": { - "group": "org.hamcrest", - "artifact": "hamcrest-core", - "version": "1.3", - "packaging": "jar" - }, - "directDependencies": [], - "dependencies": [], - "file_name": "org.hamcrest_hamcrest-core_1.3.jar", - "file_digest": { - "fingerprint": "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9", - "serialized_bytes_length": 45024 - } - } -] \ No newline at end of file +[] \ No newline at end of file diff --git a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD index 9e041058a3d..2563c023e16 100644 --- a/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD +++ b/testprojects/src/jvm/org/pantsbuild/example/lib/BUILD @@ -1,9 +1,4 @@ # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -java_sources( - compatible_resolves=["exampleapp"], - experimental_provides_types=[ - "com.google.common.truth.BadAndDangerous", - ], -) +java_sources(compatible_resolves=["exampleapp"]) diff --git a/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java b/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java deleted file mode 100644 index 646709b2af7..00000000000 --- a/testprojects/src/jvm/org/pantsbuild/example/lib/BadAndDangerous.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.google.common.truth; - -public class BadAndDangerous { - public static String hello() { - return "Hello, World!"; - } -}