Skip to content

Commit

Permalink
enhance log messages
Browse files Browse the repository at this point in the history
Signed-off-by: Valentijn Scholten <[email protected]>
  • Loading branch information
valentijnscholten committed Jan 13, 2025
1 parent 83d4fe1 commit e74ea99
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public MetaModel analyze(final Component component) {

final JSONObject repoRoot = getRepoRoot();
if (repoRoot == null) {
LOGGER.debug("repoRoot is null, fallback to v1 metadata url %s".formatted(PACKAGE_META_DATA_PATH_PATTERN_V1));
LOGGER.debug("%s: repoRoot is null for repository %s, fallback to v1 metadata url %s".formatted(composerPackageName, this.repositoryId, PACKAGE_META_DATA_PATH_PATTERN_V1));
// absence of packages.json shouldn't happen, but let's try to get metadata as
// we did in <=4.12.2
return analyzeFromMetadataUrl(meta, component, PACKAGE_META_DATA_PATH_PATTERN_V1);
Expand All @@ -128,7 +128,7 @@ public MetaModel analyze(final Component component) {
// According to https://github.com/composer/composer/blob/fb397acaa0648ba2668893e4b786af6465a41696/doc/05-repositories.md?plain=1#L197
// available-packages should contain ALL the packages in the repo.
// But in the Composer implementation the patterns are consulted even if available-packages is present and doesn't contain the package
LOGGER.debug("package not present in available-packages nor available-package-patterns");
LOGGER.debug("%s: package not present in available-packages nor available-package-patterns for repository %s".formatted(composerPackageName, this.repositoryId));
return meta;
}
}
Expand All @@ -142,7 +142,7 @@ public MetaModel analyze(final Component component) {
.anyMatch(pattern -> composerPackageName.matches(pattern));

if (!found) {
LOGGER.debug("package doesn't match available-package-patterns");
LOGGER.debug("%s: package doesn't match available-package-patterns in repository %s".formatted(composerPackageName, this.repositoryId));
return meta;
}
}
Expand All @@ -151,7 +151,7 @@ public MetaModel analyze(final Component component) {
// presence of metadata-url implies V2 repository, and takes precedence over
// included packages and other V1 features
final String packageMetaDataPathPattern = repoRoot.getString("metadata-url");
LOGGER.debug("using metadata-url pattern from packages.json: " + packageMetaDataPathPattern);
LOGGER.debug("%s: using metadata-url pattern from packages.json: %s".formatted(this.repositoryId, packageMetaDataPathPattern));
return analyzeFromMetadataUrl(meta, component, packageMetaDataPathPattern);
}

Expand All @@ -167,7 +167,7 @@ public MetaModel analyze(final Component component) {
JSONObject packages = repoRoot.getJSONObject("packages");
if (!packages.isEmpty()) {
if (!packages.has(getComposerPackageName(component))) {
LOGGER.debug("package %s not found in this repository.".formatted(component.getPurl()));
LOGGER.debug("%s: package not found in repository %s.".formatted(component.getPurl(), this.repositoryId));
return meta;
}
JSONObject packageVersions = packages.getJSONObject(getComposerPackageName(component));
Expand All @@ -177,7 +177,7 @@ public MetaModel analyze(final Component component) {

// V1 and no included packages, so we have to retrieve the package specific
// metadata
LOGGER.debug("no metadata-url pattern and package %s not found in included packages, analyzing using v1 url pattern: %s".formatted(component.getPurl(), PACKAGE_META_DATA_PATH_PATTERN_V1));
LOGGER.debug("%s: no metadata-url pattern and package not found in included packages for repository %s, analyzing using v1 url pattern: %s".formatted(component.getPurl(), this.repositoryId, PACKAGE_META_DATA_PATH_PATTERN_V1));
return analyzeFromMetadataUrl(meta, component, PACKAGE_META_DATA_PATH_PATTERN_V1);
}

Expand All @@ -197,20 +197,20 @@ private JSONObject getRepoRootFromUrl(String packageJsonUrl) {
LOGGER.warn("Failed to retrieve packages.json from " + packageJsonUrl + " HTTP status code: "
+ packageJsonResponse.getStatusLine().getStatusCode());
} else if (packageJsonResponse.getEntity().getContent() == null) {
LOGGER.warn("Null packages.json from " + packageJsonUrl);
LOGGER.warn("%s: Null packages.json from %s".formatted(this.repositoryId, packageJsonUrl));
} else {
final String packageJsonString = EntityUtils.toString(packageJsonResponse.getEntity());
if (JsonUtil.isBlankJson(packageJsonString)) {
LOGGER.warn("Empty packages.json from " + packageJsonUrl);
LOGGER.warn("%s: Empty packages.json from %s".formatted(this.repositoryId, packageJsonUrl));
} else {
repoRoot = new JSONObject(packageJsonString);
}
}
} catch (IOException e) {
LOGGER.error("Error retrieving packages.json from " + packageJsonUrl, e);
LOGGER.error("%s: Error retrieving packages.json from %s".formatted(this.repositoryId, packageJsonUrl), e);
handleRequestException(LOGGER, e);
}
LOGGER.debug("retrieved packages.json from: " + packageJsonUrl);
LOGGER.debug("%s: retrieved packages.json from: %s".formatted(this.repositoryId, packageJsonUrl));
return repoRoot;
}

Expand Down Expand Up @@ -252,19 +252,19 @@ private void loadIncludedPackages(final JSONObject repoRoot, final JSONObject da
LOGGER.warn("Failed to retrieve include " + includeFilename + " HTTP status code: "
+ includeResponse.getStatusLine().getStatusCode());
} else if (includeResponse.getEntity().getContent() == null) {
LOGGER.warn("Null include from " + includeFilename);
LOGGER.warn("%s: Null include from %s".formatted(this.repositoryId, includeFilename));
} else {
final String nextDataString = EntityUtils.toString(includeResponse.getEntity());
if (JsonUtil.isBlankJson(nextDataString)) {
LOGGER.warn("Empty include from " + includeFilename);
LOGGER.warn("%s: Empty include from %s".formatted(this.repositoryId, includeFilename));
} else {
JSONObject nextData = new JSONObject(nextDataString);

loadIncludedPackages(repoRoot, nextData, false);
}
}
} catch (IOException e) {
LOGGER.error("Error retrieving include from " + includeFilename, e);
LOGGER.error("%s: Error retrieving include from %s".formatted(this.repositoryId, includeFilename), e);
handleRequestException(LOGGER, e);
}
});
Expand Down Expand Up @@ -304,7 +304,7 @@ private MetaModel analyzeFromMetadataUrl(final MetaModel meta, final Component c
if (!responsePackages.has(expectedResponsePackage)) {
// the package no longer exists - for v2 there's no example (yet), v1 example
// https://repo.packagist.org/p/magento/adobe-ims.json
LOGGER.debug("Package %s no longer exists in this repository.". formatted(component.getPurl()));
LOGGER.debug("%s: Package no longer exists in repository %s.". formatted(component.getPurl(), this.repositoryId));
return meta;
}

Expand Down Expand Up @@ -353,7 +353,7 @@ private MetaModel analyzePackageVersions(final MetaModel meta, Component compone
final ComparableVersion latestVersion = new ComparableVersion(stripLeadingV(component.getPurl().getVersion()));
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

LOGGER.debug("analyzing package versions for: " + component.getPurl());
LOGGER.debug("%s: analyzing package versions in %s: ".formatted(component.getPurl(), this.repositoryId));
packageVersions.names().forEach(item -> {
JSONObject packageVersion = packageVersions.getJSONObject((String) item);
// Sometimes the JSON key differs from the the version inside the JSON value. The latter is leading.
Expand Down Expand Up @@ -389,14 +389,14 @@ private MetaModel analyzePackageVersions(final MetaModel meta, Component compone
try {
meta.setPublishedTimestamp(dateFormat.parse(published));
} catch (Exception e) {
LOGGER.warn("An error occurred while parsing time", e);
LOGGER.warn("%s: An error occurred while parsing time in repository %s".formatted(component.getPurl(), this.repositoryId), e);
}
} else {
// TODO some repositories like packages.drupal.org include a 'dateStamp' field,
// example 1700068743
// Some repositories like packages.drupal.org and composer.amasty.com/entprise
// do not include the name field for a version, so print purl
LOGGER.warn("Field 'time' not present in metadata for " + component.getPurl());
LOGGER.warn("%s: Field 'time' not present in metadata in repository %s".formatted(component.getPurl(), this.repositoryId));
}
});
return meta;
Expand Down

0 comments on commit e74ea99

Please sign in to comment.