@@ -1015,4 +1015,66 @@ public void testModCommandGraph_withCycle() throws ParseException, IOException {
1015101510161016 .inOrder ();
10171017 }
1018+
1019+ @ Test
1020+ public void testGraphWithExtensionFilterOnRoot () throws Exception {
1021+ ImmutableMap <ModuleKey , AugmentedModule > depGraph =
1022+ new ImmutableMap .Builder <ModuleKey , AugmentedModule >()
1023+ .put (
1024+ buildAugmentedModule (ModuleKey .ROOT , "main" , Version .parse ("1.0" ), true )
1025+ .buildEntry ())
1026+ .buildOrThrow ();
1027+
1028+ ModuleExtensionId mavenId = createExtensionId ("extensions" , "maven" );
1029+ ImmutableTable <ModuleExtensionId , ModuleKey , ModuleExtensionUsage > extensionUsages =
1030+ new ImmutableTable .Builder <ModuleExtensionId , ModuleKey , ModuleExtensionUsage >()
1031+ .put (
1032+ mavenId ,
1033+ ModuleKey .ROOT ,
1034+ ModuleExtensionUsage .builder ()
1035+ .setExtensionBzlFile ("//extensions:extensions.bzl" )
1036+ .setExtensionName ("maven" )
1037+ .setRepoOverrides (ImmutableMap .of ())
1038+ .addProxy (
1039+ ModuleExtensionUsage .Proxy .builder ()
1040+ .setLocation (Location .fromFileLineColumn ("MODULE.bazel" , 1 , 1 ))
1041+ .setImports (ImmutableBiMap .of ("repo1" , "repo1" ))
1042+ .setDevDependency (false )
1043+ .setContainingModuleFilePath (LabelConstants .MODULE_DOT_BAZEL_FILE_NAME )
1044+ .build ())
1045+ .build ())
1046+ .buildOrThrow ();
1047+
1048+ ImmutableSetMultimap <ModuleExtensionId , String > extensionRepos =
1049+ new ImmutableSetMultimap .Builder <ModuleExtensionId , String >()
1050+ .putAll (mavenId , ImmutableSet .of ("repo1" ))
1051+ .build ();
1052+
1053+ ModOptions options = ModOptions .getDefaultOptions ();
1054+ options .outputFormat = OutputFormat .TEXT ;
1055+ options .extensionInfo = ExtensionShow .ALL ;
1056+
1057+ File file = File .createTempFile ("output_text_repro" , "txt" );
1058+ file .deleteOnExit ();
1059+ Writer writer = new OutputStreamWriter (new FileOutputStream (file ), UTF_8 );
1060+
1061+ ModExecutor executor =
1062+ new ModExecutor (
1063+ depGraph ,
1064+ extensionUsages ,
1065+ extensionRepos ,
1066+ Optional .of (MaybeCompleteSet .copyOf (ImmutableSet .of (mavenId ))),
1067+ options ,
1068+ writer );
1069+
1070+ // This should not throw NPE
1071+ executor .graph (ImmutableSet .of (ModuleKey .ROOT ));
1072+ writer .close ();
1073+
1074+ List <String > textOutput = Files .readAllLines (file .toPath ());
1075+ assertThat (textOutput )
1076+ .containsExactly (
1077+ "<root> ([email protected] )" ,
"└───$@@//extensions:extensions%maven " ,
" └───repo1" ,
"" )
1078+ .inOrder ();
1079+ }
10181080}
0 commit comments