@Test public void getNPMArchiveLicenseNameWithMultipleLicensesTest() throws Exception { File packageFile = getFileFromClasspath("package-multiple-licenses.json"); String actual = JsonUtil.getNPMArchiveLicenseName(packageFile); Assert.assertEquals("MIT", actual); }
public static String getNPMArchiveLicenseName(final File file) throws IOException { final JSONObject obj = readJsconFile(file); final JSONArray licensesArray = obj.optJSONArray("licenses"); if (licensesArray != null) { final Iterator<Object> iter = licensesArray.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof JSONObject) { final JSONObject jobj = (JSONObject) o; final String typeValue = jobj.optString("type"); if (typeValue != null) { return typeValue; } } } } final JSONObject licenseObject = obj.optJSONObject("license"); if (licenseObject != null) { return licenseObject.optString("type"); } return obj.optString("license"); }
JsonUtil { public static String getNPMArchiveLicenseName(final File file) throws IOException { final JSONObject obj = readJsconFile(file); final JSONArray licensesArray = obj.optJSONArray("licenses"); if (licensesArray != null) { final Iterator<Object> iter = licensesArray.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof JSONObject) { final JSONObject jobj = (JSONObject) o; final String typeValue = jobj.optString("type"); if (typeValue != null) { return typeValue; } } } } final JSONObject licenseObject = obj.optJSONObject("license"); if (licenseObject != null) { return licenseObject.optString("type"); } return obj.optString("license"); } }
JsonUtil { public static String getNPMArchiveLicenseName(final File file) throws IOException { final JSONObject obj = readJsconFile(file); final JSONArray licensesArray = obj.optJSONArray("licenses"); if (licensesArray != null) { final Iterator<Object> iter = licensesArray.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof JSONObject) { final JSONObject jobj = (JSONObject) o; final String typeValue = jobj.optString("type"); if (typeValue != null) { return typeValue; } } } } final JSONObject licenseObject = obj.optJSONObject("license"); if (licenseObject != null) { return licenseObject.optString("type"); } return obj.optString("license"); } private  JsonUtil(); }
JsonUtil { public static String getNPMArchiveLicenseName(final File file) throws IOException { final JSONObject obj = readJsconFile(file); final JSONArray licensesArray = obj.optJSONArray("licenses"); if (licensesArray != null) { final Iterator<Object> iter = licensesArray.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof JSONObject) { final JSONObject jobj = (JSONObject) o; final String typeValue = jobj.optString("type"); if (typeValue != null) { return typeValue; } } } } final JSONObject licenseObject = obj.optJSONObject("license"); if (licenseObject != null) { return licenseObject.optString("type"); } return obj.optString("license"); } private  JsonUtil(); static ArchiveIdentifierVersion getNPMArchiveDescription(final File file); static String getNPMArchiveLicenseName(final File file); static String getNPMArchiveVendorName(final File file); static Author getNPMAuthor(final File file); }
JsonUtil { public static String getNPMArchiveLicenseName(final File file) throws IOException { final JSONObject obj = readJsconFile(file); final JSONArray licensesArray = obj.optJSONArray("licenses"); if (licensesArray != null) { final Iterator<Object> iter = licensesArray.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof JSONObject) { final JSONObject jobj = (JSONObject) o; final String typeValue = jobj.optString("type"); if (typeValue != null) { return typeValue; } } } } final JSONObject licenseObject = obj.optJSONObject("license"); if (licenseObject != null) { return licenseObject.optString("type"); } return obj.optString("license"); } private  JsonUtil(); static ArchiveIdentifierVersion getNPMArchiveDescription(final File file); static String getNPMArchiveLicenseName(final File file); static String getNPMArchiveVendorName(final File file); static Author getNPMAuthor(final File file);  }