@@ -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 ,
@@ -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,37 +404,28 @@ 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 (
419412 "alias(\n \t name = \" %s\" ,\n \t actual = \" %s\" ,\n \t visibility = [\" //visibility:public\" ],)" % (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 )
425- raw_artifact ["coordinates" ] = "original_" + artifact ["coordinates" ]
426415 raw_artifact ["maven_coordinates" ] = artifact ["coordinates" ]
427- raw_artifact ["out" ] = "original_" + artifact ["file" ]
428-
429- all_imports .extend (_generate_target (
430- repository_ctx ,
431- jar_versionless_target_labels ,
432- explicit_artifacts ,
433- srcjar_paths ,
434- labels_to_override ,
435- repository_urls ,
436- neverlink_artifacts ,
437- testonly_artifacts ,
438- default_visibilities ,
439- raw_artifact ,
440- ))
416+ raw_artifact ["out" ] = "@%s//file" % escape (artifact ["coordinates" ])
441417
442418 elif artifact_path != None :
419+ if artifact ["file" ] not in added_aliases :
420+ added_aliases [artifact ["file" ]] = True
421+ repo = escape (artifact ["coordinates" ])
422+ all_imports .append (
423+ _ARTIFACT_JAR .format (
424+ artifact_path = artifact ["file" ],
425+ source = "@%s//file" % repo
426+ )
427+ )
428+
443429 all_imports .extend (_generate_target (
444430 repository_ctx ,
445431 jar_versionless_target_labels ,
0 commit comments