@@ -117,23 +117,24 @@ private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOExce
117117 List <String > propertiesFileReferences = new ArrayList <>();
118118 if (jsonObject .has ("properties" )) {
119119 propertiesJSONObj = jsonObject .getJSONObject ("properties" );
120- loadJsonProperties (path == null ? null : path .getParent (), properties , propertiesJSONObj );
121120 for (Object p : propertiesJSONObj .keySet ()) {
122121 String key = p .toString ();
123122 if ("@files" .equals (key )) {
124123 JSONArray propertyFiles = propertiesJSONObj .getJSONArray (key );
125124 for (int i = 0 ; i < propertyFiles .length (); i ++) {
126125 propertiesFileReferences .add (propertyFiles .getString (i ));
127126 }
127+ } else {
128+ properties .put (key , propertiesJSONObj .getString (key ));
128129 }
129130 }
130131 }
131132
132133 GAV parent = null ;
133134 if (jsonObject .has ("parent" )) {
134- parent = GAV .parse (expandProperties ( properties , jsonObject .getString ("parent" ) ));
135+ parent = GAV .parse (jsonObject .getString ("parent" ));
135136 }
136- GAV gav = GAV .parse (expandProperties ( properties , jsonObject .getString ("module" ) ));
137+ GAV gav = GAV .parse (jsonObject .getString ("module" ));
137138
138139 String packaging = jsonObject .has ("packaging" ) ? jsonObject .getString ("packaging" ) : "jar" ;
139140
@@ -161,15 +162,45 @@ private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOExce
161162
162163 JSONArray array = jsonFragments .getJSONArray (type );
163164 for (int i = 0 ; i < array .length (); i ++) {
164- String url = expandProperties ( properties , array .getString (i ) );
165+ String url = array .getString (i );
165166 fragmentsForType .add (new ModuleFragment (url ));
166167 }
167168
168169 fragments .put (type , fragmentsForType );
169170 }
170171 }
171172
172- return new ModuleDescriptor (parent , gav , packaging , properties , fragments , dependencies );
173+ ModuleDescriptor parsedModuleDescriptor = new ModuleDescriptor (parent , gav , packaging , properties , propertiesFileReferences , fragments , dependencies , null );
174+
175+ // Interpolating stuff in parsed module descriptor ...
176+
177+ Map <String , String > interpolatedProperties = new LinkedHashMap <>();
178+ if (propertiesJSONObj != null ) {
179+ loadJsonProperties (path == null ? null : path .getParent (), interpolatedProperties , propertiesJSONObj );
180+ }
181+
182+ GAV interpolatedParent = parent ==null ?null :GAV .parse (expandProperties (interpolatedProperties , parent .toParseableString ()));
183+ GAV interpolatedGAV = GAV .parse (expandProperties (interpolatedProperties , gav .toParseableString ()));
184+
185+ Map <String , List <ModuleDependency >> interpolatedDependencies = new LinkedHashMap <>();
186+ for (Map .Entry <String ,List <ModuleDependency >> scopedDependenciesEntry : dependencies .entrySet ()) {
187+ List <ModuleDependency > scopedDependencies = new ArrayList <>();
188+ for (ModuleDependency dep : scopedDependenciesEntry .getValue ()) {
189+ scopedDependencies .add (new ModuleDependency (GAV .parse (expandProperties (interpolatedProperties , dep .getGav ().toParseableString ()))));
190+ }
191+ interpolatedDependencies .put (scopedDependenciesEntry .getKey (), scopedDependencies );
192+ }
193+
194+ Map <String , List <ModuleFragment >> interpolatedFragmentsPerModuleType = new LinkedHashMap <>();
195+ for (Map .Entry <String ,List <ModuleFragment >> perModuleTypeFragment : fragments .entrySet ()) {
196+ List <ModuleFragment > interpolatedFragments = new ArrayList <>();
197+ for (ModuleFragment fragment : perModuleTypeFragment .getValue ()) {
198+ interpolatedFragments .add (new ModuleFragment (expandProperties (interpolatedProperties , fragment .getUrl ())));
199+ }
200+ interpolatedFragmentsPerModuleType .put (perModuleTypeFragment .getKey (), interpolatedFragments );
201+ }
202+
203+ return new ModuleDescriptor (interpolatedParent , interpolatedGAV , packaging , interpolatedProperties , propertiesFileReferences , interpolatedFragmentsPerModuleType , interpolatedDependencies , parsedModuleDescriptor );
173204 }
174205
175206 private void loadJsonProperties (Path path , Map <String , String > properties , JSONObject props ) throws IOException {
@@ -186,10 +217,10 @@ private void loadJsonProperties(Path path, Map<String, String> properties, JSONO
186217 throw new IllegalArgumentException (
187218 "can't resolve property file " + propertyFilePath .toAbsolutePath () + "." +
188219 " Not found." +
189- (path == null ?
190- " Note that parsing from mere inputstream resolve files " +
191- "relative to current directory." :
192- "" ));
220+ (path == null ?
221+ " Note that parsing from mere inputstream resolve files " +
222+ "relative to current directory." :
223+ "" ));
193224 }
194225
195226 try (InputStreamReader reader = new InputStreamReader (Files .newInputStream (propertyFilePath ))) {
0 commit comments