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

Minor code cleanup: ternary if statement and lambda #692

Merged
merged 2 commits into from
Dec 21, 2023
Merged
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 @@ -490,7 +490,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 @@ -643,42 +642,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 Expand Up @@ -939,9 +936,6 @@ static String starEncrypt(String str) {
}

private static <T> T firstNonNull(final T t1, final T t2) {
if (t1 != null) {
return t1;
}
return t2;
return t1 == null ? t2 : t1;
}
}