55import com .google .gson .Gson ;
66
77import java .io .*;
8+ import java .util .List ;
89import java .util .regex .Matcher ;
910import java .util .regex .Pattern ;
1011
@@ -15,6 +16,7 @@ public class ModuleInfoGenerator {
1516
1617 private final Gson gson = new Gson ();
1718 private final String configFilePath = "module-info.json5" ;
19+ private ModuleInfo moduleInfo ;
1820
1921 private boolean collapseWhitespaces ;
2022
@@ -27,12 +29,13 @@ public ModuleInfoGenerator() {
2729 }
2830
2931 public void generate () {
30- ModuleInfo moduleInfo = gson .fromJson (readJsonString (configFilePath ), ModuleInfo .class );
32+ moduleInfo = gson .fromJson (readJsonString (configFilePath ), ModuleInfo .class );
3133
3234 try {
3335 moduleInfo .validateVariables ();
3436 moduleInfo .expandVariables ();
3537 moduleInfo .expandRoot ();
38+ moduleInfo .scanForModules ();
3639
3740 System .out .println (generateModuleInfoContent (moduleInfo ));
3841 } catch (IllegalArgumentException e ) {
@@ -91,6 +94,23 @@ public void generateTemplate() {
9194 }
9295 }
9396
97+ private void expandWildcard (SmartStringBuilder builder , String baseline , String s ) {
98+ String postfix = s .substring (1 );
99+ List <String > modules = moduleInfo .getModules ().stream ().filter (m -> m .endsWith (postfix )).toList ();
100+
101+ for (String module : modules ) {
102+ builder .appendFmtLn (baseline .replaceFirst ("%s" , module ));
103+ }
104+ }
105+
106+ private void addLine (SmartStringBuilder builder , String line , String value ) {
107+ if (value .startsWith ("*" )) {
108+ expandWildcard (builder , line , value );
109+ } else {
110+ builder .appendFmtLn (line , value );
111+ }
112+ }
113+
94114 private String generateModuleInfoContent (ModuleInfo moduleInfo ) {
95115 SmartStringBuilder outputBuilder = new SmartStringBuilder ();
96116
@@ -109,17 +129,17 @@ private String generateModuleInfoContent(ModuleInfo moduleInfo) {
109129 outputBuilder .appendSectionLn (() -> {
110130 outputBuilder .appendComment (moduleInfo .getComment ("exports" ));
111131 for (String export : moduleInfo .getExports ()) {
112- outputBuilder . appendFmtLn ( "exports %s;" , export );
132+ addLine ( outputBuilder , "exports %s;" , export );
113133 }
114134 });
115135
116136 outputBuilder .appendSectionLn (() -> {
117137 outputBuilder .appendComment (moduleInfo .getComment ("opens" ));
118138 for (OpensDeclaration opens : moduleInfo .getOpens ()) {
119- String baseLine = String .format ("opens %s to %s;" , "%s " , opens .getTargetModule ());
139+ String baseline = String .format ("opens %% s to %s;" , opens .getTargetModule ());
120140
121141 for (String sourceModule : opens .getSourceModules ()) {
122- outputBuilder . appendFmtLn ( baseLine , sourceModule );
142+ addLine ( outputBuilder , baseline , sourceModule );
123143 }
124144 }
125145 });
0 commit comments