Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Refine provider id warning #62

Merged
merged 3 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Supplier;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
Expand Down Expand Up @@ -107,11 +108,11 @@ public void readCsv(final File filename, final LicenseStoreData licenseStoreData
throws IOException {
String line = "";
String cvsSplitBy = ",";

int lineNumber = 0;
try (final BufferedReader br = new BufferedReader(new FileReader(filename))) {

while ((line = br.readLine()) != null) {

lineNumber++;
// ignore lines commented out, empty lines and the header line
if (line.startsWith("#") || StringUtils.isEmpty(line) || line.startsWith("Type")) {
continue;
Expand Down Expand Up @@ -147,7 +148,8 @@ public void readCsv(final File filename, final LicenseStoreData licenseStoreData
}
final String documentationUrl = values[DOC_URL_INDEX].trim();
final String providerId = values[PROVIDER_INDEX].trim();
final Provider provider = getProviderFromId(providers, providerId, log);
final int lineNumberFinal = lineNumber;
final Provider provider = getProviderFromId(providers, providerId, log, ()-> filename.getName() + ": line " + lineNumberFinal);
final String noticeId = values[NOTICE_INDEX].trim();
final Notice notice = getNoticeFromId(notices, noticeId);

Expand Down Expand Up @@ -378,10 +380,14 @@ private static Notice getNoticeFromId(final Notices notices, final String notice
return notices.getNoticeByIdentifier(noticeId);
}

private static Provider getProviderFromId(final Providers providers, final String providerId, final ILFLog log) {
private static Provider getProviderFromId(final Providers providers, final String providerId, final ILFLog log, final Supplier<String> context) {
final Provider provider = providers.getProviderByIdentifier(providerId);
if (provider == null) {
log.warn("Cannot find provider with ID: '" + providerId + "'");
String message = "Cannot find provider with ID: '" + providerId + "'";
if (context != null && !StringUtils.isEmpty( context.get())) {
message += " ("+ context.get() + ")";
}
log.warn(message);
}
return provider;
}
Expand Down Expand Up @@ -677,7 +683,7 @@ public String getElementName() {
@Override
protected void processText(final String text) {
final String identifier = text;
provider = getProviderFromId(getProviders(), identifier, getLog());
provider = getProviderFromId(getProviders(), identifier, getLog(), ()-> ArchiveSaxHandler.this.getLocationString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public abstract class AbstractScanMojo extends AbstractMojo {
* Whether a skeleton archive XML file of all found archives should be written.
*
* <p>If enabled, the file is written to {@link #archiveXmlSkeletonFile}.</p>
*
* @see #archiveXmlSkeletonFile
*/
@Parameter(defaultValue = "false", property = "writeArchiveXmlSkeleton", required = false)
Expand Down Expand Up @@ -327,13 +328,15 @@ public void execute() throws MojoExecutionException {
runParameters.setNexusCentralBaseUrl(nexusCentralBaseUrl);
runParameters.setConnectTimeout(connectTimeout);
final AbstractFinder finder = createFinder(licenseStoreData, runParameters, log);
getLog().info("Starting scan on " + scanDirectory.getAbsolutePath() + "...");

try {
final FinderResult finderResult = finder.findLicenses();
if (finderResult == null) {
getLog().info("No finder results.");
return;
}
getLog().info("Evaluating licenses...");
LicenseUtil.evaluateLicenses(checkedArchives, finderResult.getArchiveFiles(), licenseStoreData);
filterGlobal(finderResult.getArchiveFiles(), globalFilters, log);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ protected Locator getDocumentLocator() {
return locator;
}

/**
* Obtains a string representing the document location, suitable for log
* messages.
*
* @return a string representing the location as returned by {@link #getDocumentLocator()}
*/
protected String getLocationString() {
return locator.getPublicId() + ":" + locator.getLineNumber() + ":" + locator.getColumnNumber();
}

/**
* Obtains the current line number from the locator, if present.
* @return the current line number as a string if the locator is present or an empty string if no locator is present
Expand Down