Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scancode file adapter #193

Merged
merged 16 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.devonfw.tools.solicitor.common.IOHelper;
import com.devonfw.tools.solicitor.common.content.web.DirectUrlWebContentProvider;
import com.devonfw.tools.solicitor.common.packageurl.AllKindsPackageURLHandler;
import com.devonfw.tools.solicitor.componentinfo.ComponentContentProvider;
import com.devonfw.tools.solicitor.componentinfo.ComponentInfoAdapterException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -160,29 +159,16 @@ public String retrieveContent(String packageUrl, String fileUri) {
return this.contentProvider.getContentForUri(directUrl).getContent();
}

/**
* Checks if the argument seems to be a (relative) path pointing to some content within the package.
*
* @param path the path to check
* @return <code>true</code> if the seems to be a correct path, <code>false</code> otherwise.
*/
@Override
public boolean isLocalContentPath(String path) {
public boolean isLocalContentPath(String packageUrl, String path) {

return (path != null && path.startsWith(SOURCES_DIR));
}

/**
* Creates a pkgcontent-URI (see {@link ComponentContentProvider}) from the relative local file path.
*
* @param path the path referencing file content
* @return a pkgContent URI which might be used for retrieving the content vis
* {@link ComponentContentProvider#retrieveContent(String, String)}
*/
@Override
public String pkgContentUriFromPath(String path) {
public String pkgContentUriFromPath(String packageUrl, String path) {

if (!isLocalContentPath(path)) {
if (!isLocalContentPath(packageUrl, path)) {
throw new IllegalArgumentException("'" + path + "' is not a valid path to content within the package");
}
return PKG_CONTENT_SCHEMA_PREFIX + path.substring(SOURCES_DIR.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ public interface ScancodeRawComponentInfoPovider extends ComponentContentProvide
/**
* Creates a pkgcontent-URI (see {@link ComponentContentProvider}) from the relative local file path.
*
* @param packageUrl the PackageUrl of the component
* @param path the path referencing file content
*
* @return a pkgContent URI which might be used for retrieving the content vis
* {@link ComponentContentProvider#retrieveContent(String, String)}
*/
String pkgContentUriFromPath(String path);
String pkgContentUriFromPath(String packageUrl, String path);

/**
* Checks if the argument seems to be a (relative) path pointing to some content within the package.
*
* @param packageUrl the PackageUrl of the component
* @param path the path to check
*
* @return <code>true</code> if the seems to be a correct path, <code>false</code> otherwise.
*/
boolean isLocalContentPath(String path);
boolean isLocalContentPath(String packageUrl, String path);
ohecker marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private ScancodeComponentInfo parseAndMapScancodeJson(String packageUrl, Scancod
}
if (file.get("path").asText().contains("/NOTICE")) {
componentScancodeInfos.addNoticeFilePath(
this.fileScancodeRawComponentInfoProvider.pkgContentUriFromPath(file.get("path").asText()), 100.0);
this.fileScancodeRawComponentInfoProvider.pkgContentUriFromPath(packageUrl, file.get("path").asText()),
100.0);
}
double licenseTextRatio = file.get("percentage_of_license_text").asDouble();
boolean takeCompleteFile = licenseTextRatio >= this.licenseToTextRatioToTakeCompleteFile;
Expand Down Expand Up @@ -255,8 +256,9 @@ private String normalizeLicenseUrl(String packageUrl, String licenseFilePath) {
"https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses",
"https://scancode-licensedb.aboutcode.org");
adjustedLicenseFilePath = adjustedLicenseFilePath.replace("github.com", "raw.github.com").replace("/tree", "");
} else if (this.fileScancodeRawComponentInfoProvider.isLocalContentPath(licenseFilePath)) {
adjustedLicenseFilePath = this.fileScancodeRawComponentInfoProvider.pkgContentUriFromPath(licenseFilePath);
} else if (this.fileScancodeRawComponentInfoProvider.isLocalContentPath(packageUrl, licenseFilePath)) {
adjustedLicenseFilePath = this.fileScancodeRawComponentInfoProvider.pkgContentUriFromPath(packageUrl,
licenseFilePath);
LOG.debug("LOCAL LICENSE: " + licenseFilePath);
}
}
Expand Down