@@ -66,6 +66,13 @@ def _find_repository_url(artifact_url, repositories):
6666 longest_match = repository
6767 return longest_match
6868
69+ _ARTIFACT_JAR = """
70+ alias(
71+ name = "{artifact_path}",
72+ actual = "{source}",
73+ visibility = ["//visibility:public"],
74+ )"""
75+
6976def _generate_target (
7077 repository_ctx ,
7178 jar_versionless_target_labels ,
@@ -87,7 +94,7 @@ def _generate_target(
8794 # (jvm|aar)_import(
8895 #
8996 packaging = artifact_path .split ("." ).pop ()
90- if packaging == "jar" :
97+ if packaging == "jar" or artifact_path . endswith ( "//file" ) :
9198 # Regular `java_import` invokes ijar on all JARs, causing some Scala and
9299 # Kotlin compile interface JARs to be incorrect. We replace java_import
93100 # with a simple jvm_import Starlark rule that skips ijar.
@@ -120,7 +127,7 @@ def _generate_target(
120127 # srcjar = "https/repo1.maven.org/maven2/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3-sources.jar",
121128 #
122129 is_dylib = False
123- if packaging == "jar" :
130+ if packaging == "jar" or artifact_path . endswith ( "//file" ) :
124131 target_import_string .append ("\t jars = [\" %s\" ]," % artifact_path )
125132 if srcjar_paths != None and target_label in srcjar_paths :
126133 target_import_string .append ("\t srcjar = \" %s\" ," % srcjar_paths [target_label ])
@@ -320,18 +327,6 @@ genrule(
320327 to_return .append ("alias(\n \t name = \" %s\" ,\n \t actual = \" %s\" ,\n %s)" %
321328 (versioned_target_alias_label , target_label , alias_visibility ))
322329
323- # 11. If using maven_install.json, use a genrule to copy the file from the http_file
324- # repository into this repository.
325- #
326- # genrule(
327- # name = "org_hamcrest_hamcrest_library_1_3_extension",
328- # srcs = ["@org_hamcrest_hamcrest_library_1_3//file"],
329- # outs = ["@maven//:v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.jar"],
330- # cmd = "cp $< $@",
331- # )
332- if repository_ctx .attr .maven_install_json :
333- to_return .append (_genrule_copy_artifact_from_http_file (artifact , default_visibilities ))
334-
335330 return to_return
336331
337332# Generate BUILD file with jvm_import and aar_import for each artifact in
@@ -351,6 +346,8 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
351346 # seen_imports :: string -> bool
352347 seen_imports = {}
353348
349+ added_aliases = {}
350+
354351 # A list of versionless target labels for jar artifacts. This is used for
355352 # generating a compatibility layer for repositories. For example, if we generate
356353 # @maven//:junit_junit, we also generate @junit_junit//jar as an alias to it.
@@ -378,8 +375,6 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
378375 seen_imports [artifact_path ] = True
379376 target_label = escape (strip_packaging_and_classifier_and_version (artifact ["coordinates" ]))
380377 srcjar_paths [target_label ] = artifact_path
381- if repository_ctx .attr .maven_install_json :
382- all_imports .append (_genrule_copy_artifact_from_http_file (artifact , default_visibilities ))
383378
384379 # Iterate through the list of artifacts, and generate the target declaration strings.
385380 for artifact in dependencies :
@@ -409,23 +404,18 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
409404 all_imports .append (
410405 "alias(\n \t name = \" %s\" ,\n \t actual = \" %s\" ,\n \t visibility = [\" //visibility:public\" ],\n )" % (target_label , versioned_target_alias_label ),
411406 )
412- if repository_ctx .attr .maven_install_json :
413- all_imports .append (_genrule_copy_artifact_from_http_file (artifact , default_visibilities ))
414407 elif target_label in labels_to_override :
415408 # Override target labels with the user provided mapping, instead of generating
416409 # a jvm_import/aar_import based on information in dep_tree.
417410 seen_imports [target_label ] = True
418411 all_imports .append (
419- "alias(\n \t name = \" %s\" ,\n \t actual = \" %s\" ,\n \t visibility = [\" //visibility:public\" ],)" % (target_label , labels_to_override .get (target_label )),
412+ "alias(\n \t name = \" %s\" ,\n \t actual = \" %s\" ,\n \t visibility = [\" //visibility:public\" ],\n )" % (target_label , labels_to_override .get (target_label )),
420413 )
421- if repository_ctx .attr .maven_install_json :
422- # Provide the downloaded artifact as a file target.
423- all_imports .append (_genrule_copy_artifact_from_http_file (artifact , default_visibilities ))
424414 raw_artifact = dict (artifact )
425415 raw_artifact ["coordinates" ] = "original_" + artifact ["coordinates" ]
426416 raw_artifact ["maven_coordinates" ] = artifact ["coordinates" ]
427417 raw_artifact ["out" ] = "original_" + artifact ["file" ]
428-
418+ raw_artifact [ "file" ] = "@%s//file" % escape ( artifact [ "coordinates" ])
429419 all_imports .extend (_generate_target (
430420 repository_ctx ,
431421 jar_versionless_target_labels ,
@@ -439,7 +429,18 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
439429 raw_artifact ,
440430 ))
441431
432+
442433 elif artifact_path != None :
434+ if artifact ["file" ] not in added_aliases :
435+ added_aliases [artifact ["file" ]] = True
436+ repo = escape (artifact ["coordinates" ])
437+ all_imports .append (
438+ _ARTIFACT_JAR .format (
439+ artifact_path = artifact ["file" ],
440+ source = "@%s//file" % repo
441+ )
442+ )
443+
443444 all_imports .extend (_generate_target (
444445 repository_ctx ,
445446 jar_versionless_target_labels ,
0 commit comments