Skip to content

Commit

Permalink
[lambda] Run document properties loader in lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz authored and mathieucarbou committed Dec 21, 2023
1 parent 15e4c34 commit 981c386
Showing 1 changed file with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ public void checkUnknown() throws MojoExecutionException {

}

@SuppressWarnings({"unchecked"})
protected final void execute(final Callback callback) throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("License Plugin is Skipped");
Expand Down Expand Up @@ -638,42 +637,40 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca
propertiesProviders.add(provider);
}

final DocumentPropertiesLoader perDocumentProperties = new DocumentPropertiesLoader() {
@Override
public Map<String, String> load(final Document document) {
// then add per document properties
Map<String, String> perDoc = new LinkedHashMap<>(globalProperties);
perDoc.put("file.name", document.getFile().getName());

Map<String, String> readOnly = Collections.unmodifiableMap(perDoc);

for (final PropertiesProvider provider : propertiesProviders) {
try {
final Map<String, String> adjustments = provider.adjustProperties(
AbstractLicenseMojo.this, readOnly, document);
if (getLog().isDebugEnabled()) {
getLog().debug("provider: " + provider.getClass() + " adjusted these properties:\n"
+ adjustments);
}
for (Map.Entry<String, String> entry : adjustments.entrySet()) {
if (entry.getValue() != null) {
perDoc.put(entry.getKey(), entry.getValue());
} else {
perDoc.remove(entry.getKey());
}
final DocumentPropertiesLoader perDocumentProperties = document -> {

// then add per document properties
Map<String, String> perDoc = new LinkedHashMap<>(globalProperties);
perDoc.put("file.name", document.getFile().getName());

Map<String, String> readOnly = Collections.unmodifiableMap(perDoc);

for (final PropertiesProvider provider : propertiesProviders) {
try {
final Map<String, String> adjustments = provider.adjustProperties(
AbstractLicenseMojo.this, readOnly, document);
if (getLog().isDebugEnabled()) {
getLog().debug("provider: " + provider.getClass() + " adjusted these properties:\n"
+ adjustments);
}
for (Map.Entry<String, String> entry : adjustments.entrySet()) {
if (entry.getValue() != null) {
perDoc.put(entry.getKey(), entry.getValue());
} else {
perDoc.remove(entry.getKey());
}
} catch (Exception e) {
getLog().warn("failure occurred while calling " + provider.getClass(), e);
}
} catch (Exception e) {
getLog().warn("failure occurred while calling " + provider.getClass(), e);
}
}

if (getLog().isDebugEnabled()) {
getLog().debug("properties for " + document + ":\n - " + perDoc.entrySet().stream()
.map(Objects::toString).collect(Collectors.joining("\n - ")));
}

return perDoc;
if (getLog().isDebugEnabled()) {
getLog().debug("properties for " + document + ":\n - " + perDoc.entrySet().stream()
.map(Objects::toString).collect(Collectors.joining("\n - ")));
}

return perDoc;
};

final DocumentFactory documentFactory = new DocumentFactory(
Expand Down

0 comments on commit 981c386

Please sign in to comment.