use of org.eclipse.dash.licenses.IContentData in project dash-licenses by eclipse.
the class EclipseFoundationSupport method queryLicenseData.
@Override
public void queryLicenseData(Collection<IContentId> ids, Consumer<IContentData> consumer) {
if (ids.isEmpty())
return;
String url = settings.getLicenseCheckUrl();
if (url.isBlank()) {
logger.debug("Bypassing Eclipse Foundation.");
return;
}
logger.info("Querying Eclipse Foundation for license data for {} items.", ids.size());
String form = encodeRequestPayload(ids);
int code = httpClientService.post(url, "application/x-www-form-urlencoded", form, response -> {
AtomicInteger counter = new AtomicInteger();
JsonReader reader = Json.createReader(new StringReader(response));
JsonObject read = (JsonObject) reader.read();
JsonObject approved = read.getJsonObject("approved");
if (approved != null)
approved.forEach((key, each) -> {
FoundationData data = new FoundationData(each.asJsonObject());
logger.debug("EF approved: {} ({}) score: {} {} {}", data.getId(), data.getRule(), data.getScore(), data.getLicense(), data.getAuthority());
consumer.accept(data);
counter.incrementAndGet();
});
JsonObject restricted = read.getJsonObject("restricted");
if (restricted != null)
restricted.forEach((key, each) -> {
FoundationData data = new FoundationData(each.asJsonObject());
logger.debug("EF restricted: {} score: {} {} {}", data.getId(), data.getScore(), data.getLicense(), data.getAuthority());
consumer.accept(data);
counter.incrementAndGet();
});
logger.info("Found {} items.", counter.get());
});
if (code != 200) {
logger.error("Error response from the Eclipse Foundation {}", code);
throw new RuntimeException("Received an error response from the Eclipse Foundation.");
}
}
use of org.eclipse.dash.licenses.IContentData in project dash-licenses by eclipse.
the class ClearlyDefinedSupportTests method testMatchRestricted.
@Test
void testMatchRestricted() {
List<IContentData> results = new ArrayList<>();
clearlyDefined.queryLicenseData(Collections.singleton(ContentId.getContentId("npm/npmjs/@yarnpkg/lockfile/1.1.0")), data -> results.add(data));
assertEquals(1, results.size());
IContentData write = results.get(0);
assertEquals("npm/npmjs/@yarnpkg/lockfile/1.1.0", write.getId().toString());
assertEquals("clearlydefined", write.getAuthority());
assertEquals("BSD-2-Clause", write.getLicense());
assertEquals("https://clearlydefined.io/definitions/npm/npmjs/@yarnpkg/lockfile/1.1.0", write.getUrl());
assertEquals(53, write.getScore());
assertEquals(LicenseSupport.Status.Restricted, write.getStatus());
}
use of org.eclipse.dash.licenses.IContentData in project dash-licenses by eclipse.
the class ClearlyDefinedSupportTests method testMatchApproved.
@Test
void testMatchApproved() {
List<IContentData> results = new ArrayList<>();
clearlyDefined.queryLicenseData(Collections.singleton(ContentId.getContentId("npm/npmjs/-/write/1.0.3")), data -> results.add(data));
assertEquals(1, results.size());
IContentData write = results.get(0);
assertEquals("npm/npmjs/-/write/1.0.3", write.getId().toString());
assertEquals("clearlydefined", write.getAuthority());
assertEquals("MIT", write.getLicense());
assertEquals("https://clearlydefined.io/definitions/npm/npmjs/-/write/1.0.3", write.getUrl());
assertEquals(94, write.getScore());
assertEquals(LicenseSupport.Status.Approved, write.getStatus());
}
Aggregations