use of org.eclipse.dash.licenses.IContentId in project dash-licenses by eclipse.
the class MavenIdParserTests method testEclipseFeature.
@Test
public void testEclipseFeature() {
IContentId value = parser.parseId("org.eclipse.acceleo.features:org.eclipse.acceleo.doc:eclipse-feature:3.7.10-SNAPSHOT:provided");
// TODO The default values for type and source are obviously bogus in this case
assertEquals("maven", value.getType());
assertEquals("mavencentral", value.getSource());
assertEquals("org.eclipse.acceleo.features", value.getNamespace());
assertEquals("org.eclipse.acceleo.doc", value.getName());
assertEquals("3.7.10-SNAPSHOT", value.getVersion());
}
use of org.eclipse.dash.licenses.IContentId in project dash-licenses by eclipse.
the class PackageLockFileReaderTests method testV2Format.
@Test
void testV2Format() throws IOException {
try (InputStream input = this.getClass().getResourceAsStream(PACKAGE_LOCK_V2_JSON)) {
PackageLockFileReader reader = new PackageLockFileReader(input);
// This "test" is a little... abridged. At least this test proves
// that we're getting something in the right format from the reader
// without having to enumerate all 574 (I think) records).
String[] expected = { "npm/npmjs/@babel/code-frame/7.12.13", "npm/npmjs/@babel/compat-data/7.13.15", "npm/npmjs/@babel/core/7.13.15" };
String[] found = reader.getContentIds().stream().limit(3).map(IContentId::toString).sorted().toArray(String[]::new);
assertArrayEquals(expected, found);
}
}
use of org.eclipse.dash.licenses.IContentId 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.IContentId in project dash-licenses by eclipse.
the class Main method main.
public static void main(String[] args) {
CommandLineSettings settings = CommandLineSettings.getSettings(args);
if (!settings.isValid()) {
CommandLineSettings.printUsage(System.out);
System.exit(1);
}
if (settings.isShowHelp()) {
CommandLineSettings.printHelp(System.out);
System.exit(0);
}
Injector injector = Guice.createInjector(new LicenseToolModule(settings));
LicenseChecker checker = injector.getInstance(LicenseChecker.class);
List<IResultsCollector> collectors = new ArrayList<>();
// TODO Set up collectors based on command line parameters
IResultsCollector primaryCollector = new NeedsReviewCollector();
collectors.add(primaryCollector);
String summaryPath = settings.getSummaryFilePath();
if (summaryPath != null) {
try {
collectors.add(new CSVCollector(getWriter(summaryPath)));
} catch (FileNotFoundException e1) {
System.out.println("Can't write to " + summaryPath);
System.exit(1);
}
}
if (settings.isReview()) {
collectors.add(new CreateReviewRequestCollector(injector.getInstance(GitLabSupport.class), (id, url) -> {
}));
}
Arrays.stream(settings.getFileNames()).forEach(name -> {
IDependencyListReader reader = null;
try {
reader = getReader(name);
} catch (FileNotFoundException e) {
System.out.println(String.format("The file \"%s\" does not exist.", name));
CommandLineSettings.printUsage(System.out);
System.exit(1);
}
if (reader != null) {
Collection<IContentId> dependencies = reader.getContentIds();
checker.getLicenseData(dependencies).forEach((id, licenseData) -> {
collectors.forEach(collector -> collector.accept(licenseData));
});
}
});
collectors.forEach(IResultsCollector::close);
System.exit(primaryCollector.getStatus());
}
use of org.eclipse.dash.licenses.IContentId in project dash-licenses by eclipse.
the class YarnLockFileReaderTests method testSingleEntry.
@Test
void testSingleEntry() throws IOException {
// @formatter:off
String contents = "spawn-command@^0.0.2-1:\n" + " version \"0.0.2-1\"\n" + " resolved \"https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0\"\n" + " integrity sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=\n" + "";
// @formatter:on
var ids = new YarnLockFileReader(new StringReader(contents)).getContentIds();
IContentId id = ids.get(0);
assertEquals("-", id.getNamespace());
assertEquals("spawn-command", id.getName());
assertEquals("0.0.2-1", id.getVersion());
}
Aggregations