}
public ModuleDescriptor parse(InputStream inputStream) throws IOException {
return parse(null, inputStream);
}
private ModuleDescriptor parse(Path path, InputStream inputStream) throws IOException {
JSONObject jsonObject = new JSONObject(new JSONTokener(new InputStreamReader(inputStream, "UTF-8")));
Map<String, String> properties = new LinkedHashMap<>();
if (jsonObject.has("properties")) {
loadJsonProperties(path == null ? null : path.getParent(), properties, jsonObject.getJSONObject("properties"));
}
GAV parent = null;
if (jsonObject.has("parent")) {
parent = GAV.parse(expandProperties(properties, jsonObject.getString("parent")));
}
GAV gav = GAV.parse(expandProperties(properties, jsonObject.getString("module")));
String packaging = jsonObject.has("packaging") ? jsonObject.getString("packaging") : "jar";
Map<String, List<ModuleDependency>> dependencies = new LinkedHashMap<>();
if (jsonObject.has("dependencies")) {
JSONObject scopes = jsonObject.getJSONObject("dependencies");
for (Object s : scopes.keySet()) {
String scope = s.toString();
List<ModuleDependency> scopeDeps = new ArrayList<>();
dependencies.put(scope, scopeDeps);
JSONArray deps = scopes.getJSONArray(scope);
for (int i = 0; i < deps.length(); i++) {
scopeDeps.add(new ModuleDependency(GAV.parse(deps.getString(i))));
}
}
}
Map<String, List<ModuleFragment>> fragments = new LinkedHashMap<>();
if (jsonObject.has("fragments")) {
JSONObject jsonFragments = jsonObject.getJSONObject("fragments");
for (Object key : jsonFragments.keySet()) {
String type = (String) key;
List<ModuleFragment> fragmentsForType = new ArrayList<>();
JSONArray array = jsonFragments.getJSONArray(type);
for (int i = 0; i < array.length(); i++) {
String url = expandProperties(properties, array.getString(i));
if (url.startsWith("classpath://")) {
String fragmentPath = url.substring("classpath://".length());