@@ -3526,6 +3526,57 @@ public void testRunIjarWithOutputParameterIsPrivateApi() throws Exception {
35263526 assertContainsEvent ("got unexpected keyword argument: output" );
35273527 }
35283528
3529+ @ Test
3530+ public void testPackSourcesWithExternalResourceArtifact () throws Exception {
3531+ JavaTestUtil .writeBuildFileForJavaToolchain (scratch );
3532+ scratch .file (
3533+ "foo/custom_rule.bzl" ,
3534+ "def _impl(ctx):" ,
3535+ " out = ctx.actions.declare_file('output.jar')" ,
3536+ " java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo]" ,
3537+ " java_common.pack_sources(" ,
3538+ " ctx.actions," ,
3539+ " java_toolchain = java_toolchain," ,
3540+ " output_source_jar = out," ,
3541+ " sources = ctx.files.srcs," ,
3542+ " )" ,
3543+ " return [DefaultInfo(files = depset([out]))]" ,
3544+ "java_custom_library = rule(" ,
3545+ " implementation = _impl," ,
3546+ " attrs = {" ,
3547+ " 'srcs': attr.label_list(allow_files = True)," ,
3548+ " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain'))," ,
3549+ " }," ,
3550+ " toolchains = ['" + TestConstants .JAVA_TOOLCHAIN_TYPE + "']," ,
3551+ " fragments = ['java']" ,
3552+ ")" );
3553+ scratch .file ("my_other_repo/WORKSPACE" );
3554+ scratch .file ("my_other_repo/external-file.txt" );
3555+ scratch .file ("my_other_repo/BUILD" , "exports_files(['external-file.txt'])" );
3556+ rewriteWorkspace ("local_repository(name = 'other_repo', path = './my_other_repo')" );
3557+ scratch .file (
3558+ "foo/BUILD" ,
3559+ "load(':custom_rule.bzl', 'java_custom_library')" ,
3560+ "java_custom_library(" ,
3561+ " name = 'custom'," ,
3562+ " srcs = [" ,
3563+ " 'internal-file.txt'," ,
3564+ " '@other_repo//:external-file.txt'," ,
3565+ " ]" ,
3566+ ")" );
3567+
3568+ List <String > arguments =
3569+ ((SpawnAction ) getGeneratingAction (getConfiguredTarget ("//foo:custom" ), "foo/output.jar" ))
3570+ .getArguments ();
3571+
3572+ assertThat (arguments )
3573+ .containsAtLeast (
3574+ "--resources" ,
3575+ "foo/internal-file.txt:foo/internal-file.txt" ,
3576+ "external/other_repo/external-file.txt:external-file.txt" )
3577+ .inOrder ();
3578+ }
3579+
35293580 @ Test
35303581 public void mergeAddExports () throws Exception {
35313582 scratch .file (
0 commit comments