@@ -117,23 +117,24 @@ private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOExce
117
117
List <String > propertiesFileReferences = new ArrayList <>();
118
118
if (jsonObject .has ("properties" )) {
119
119
propertiesJSONObj = jsonObject .getJSONObject ("properties" );
120
- loadJsonProperties (path == null ? null : path .getParent (), properties , propertiesJSONObj );
121
120
for (Object p : propertiesJSONObj .keySet ()) {
122
121
String key = p .toString ();
123
122
if ("@files" .equals (key )) {
124
123
JSONArray propertyFiles = propertiesJSONObj .getJSONArray (key );
125
124
for (int i = 0 ; i < propertyFiles .length (); i ++) {
126
125
propertiesFileReferences .add (propertyFiles .getString (i ));
127
126
}
127
+ } else {
128
+ properties .put (key , propertiesJSONObj .getString (key ));
128
129
}
129
130
}
130
131
}
131
132
132
133
GAV parent = null ;
133
134
if (jsonObject .has ("parent" )) {
134
- parent = GAV .parse (expandProperties ( properties , jsonObject .getString ("parent" ) ));
135
+ parent = GAV .parse (jsonObject .getString ("parent" ));
135
136
}
136
- GAV gav = GAV .parse (expandProperties ( properties , jsonObject .getString ("module" ) ));
137
+ GAV gav = GAV .parse (jsonObject .getString ("module" ));
137
138
138
139
String packaging = jsonObject .has ("packaging" ) ? jsonObject .getString ("packaging" ) : "jar" ;
139
140
@@ -161,15 +162,45 @@ private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOExce
161
162
162
163
JSONArray array = jsonFragments .getJSONArray (type );
163
164
for (int i = 0 ; i < array .length (); i ++) {
164
- String url = expandProperties ( properties , array .getString (i ) );
165
+ String url = array .getString (i );
165
166
fragmentsForType .add (new ModuleFragment (url ));
166
167
}
167
168
168
169
fragments .put (type , fragmentsForType );
169
170
}
170
171
}
171
172
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 );
173
204
}
174
205
175
206
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
186
217
throw new IllegalArgumentException (
187
218
"can't resolve property file " + propertyFilePath .toAbsolutePath () + "." +
188
219
" 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
+ "" ));
193
224
}
194
225
195
226
try (InputStreamReader reader = new InputStreamReader (Files .newInputStream (propertyFilePath ))) {
0 commit comments