From 2eea26babd5636e02a42421cee7d512562396a49 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 7 Nov 2023 19:17:51 -0500 Subject: [PATCH 1/2] [ci] Use ternary if statement --- .../com/mycila/maven/plugin/license/AbstractLicenseMojo.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index ab89e7402..0d18e954a 100644 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -939,9 +939,6 @@ static String starEncrypt(String str) { } private static T firstNonNull(final T t1, final T t2) { - if (t1 != null) { - return t1; - } - return t2; + return t1 == null ? t2 : t1; } } From 6edd78c4bf4c38ff68f2ccd162581deba9b06799 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 7 Nov 2023 19:22:07 -0500 Subject: [PATCH 2/2] [lambda] Run document properties loader in lambda --- .../plugin/license/AbstractLicenseMojo.java | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java index 0d18e954a..527adb6f6 100644 --- a/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java +++ b/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/AbstractLicenseMojo.java @@ -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"); @@ -643,42 +642,40 @@ private void executeForLicenseSet(final LicenseSet licenseSet, final Callback ca propertiesProviders.add(provider); } - final DocumentPropertiesLoader perDocumentProperties = new DocumentPropertiesLoader() { - @Override - public Map load(final Document document) { - // then add per document properties - Map perDoc = new LinkedHashMap<>(globalProperties); - perDoc.put("file.name", document.getFile().getName()); - - Map readOnly = Collections.unmodifiableMap(perDoc); - - for (final PropertiesProvider provider : propertiesProviders) { - try { - final Map adjustments = provider.adjustProperties( - AbstractLicenseMojo.this, readOnly, document); - if (getLog().isDebugEnabled()) { - getLog().debug("provider: " + provider.getClass() + " adjusted these properties:\n" - + adjustments); - } - for (Map.Entry 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 perDoc = new LinkedHashMap<>(globalProperties); + perDoc.put("file.name", document.getFile().getName()); + + Map readOnly = Collections.unmodifiableMap(perDoc); + + for (final PropertiesProvider provider : propertiesProviders) { + try { + final Map adjustments = provider.adjustProperties( + AbstractLicenseMojo.this, readOnly, document); + if (getLog().isDebugEnabled()) { + getLog().debug("provider: " + provider.getClass() + " adjusted these properties:\n" + + adjustments); + } + for (Map.Entry 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(