diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1100f1d1..0c266d6a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -33,7 +33,7 @@ jobs: # Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target # # Java 17 disabled, because we are running into https://bugs.openjdk.java.net/browse/JDK-8270866 - java: [8, 11, 16, 21] + java: [8, 11, 17, 21] fail-fast: false runs-on: ${{ matrix.os }} @@ -59,7 +59,7 @@ jobs: cache: 'maven' - name: Build with Maven - run: ./mvnw -e -B -V -ntp clean package site + run: ./mvnw -e -B -V -ntp clean install site # as of 20220505: Invalid workflow file # The workflow is not valid. .github/workflows/maven.yml (Line: 55, Col: 1): Unexpected value 'notifications' diff --git a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/LicenseConfiguration.java b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/LicenseConfiguration.java index f5e094f0..88d3a8e0 100644 --- a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/LicenseConfiguration.java +++ b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/LicenseConfiguration.java @@ -30,7 +30,7 @@ public enum LicenseConfiguration { /** * Default to include source URLs. */ - public static LicenseConfiguration DEFAULT_LICENSE_CONFIGURATION = INCLUDE_SOURCE_URLS; + public static final LicenseConfiguration DEFAULT_LICENSE_CONFIGURATION = INCLUDE_SOURCE_URLS; /** * Replaces null with DEFAULT_LICENSE_CONFIGURATION. diff --git a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/analysis/ResourceDescription.java b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/analysis/ResourceDescription.java index 6eb6021a..74517bf7 100644 --- a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/analysis/ResourceDescription.java +++ b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/analysis/ResourceDescription.java @@ -97,13 +97,8 @@ public boolean equals(final Object obj) { return false; } if (resource == null) { - if (other.resource != null) { - return false; - } - } else if (!resource.equals(other.resource)) { - return false; - } - return true; + return other.resource == null; + } else return resource.equals(other.resource); } /** diff --git a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/out/WriteResultsIntoDirectoryFactory.java b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/out/WriteResultsIntoDirectoryFactory.java index fd02c63b..b3f4d9fb 100644 --- a/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/out/WriteResultsIntoDirectoryFactory.java +++ b/apache-whisker-app/src/main/java/org/apache/creadur/whisker/app/out/WriteResultsIntoDirectoryFactory.java @@ -62,7 +62,9 @@ public WriteResultsIntoDirectoryFactory( public Writer writerFor(final Result result) throws IOException { return new BufferedWriter( - new FileWriterWithEncoding( - result.within(directory), encoding)); + FileWriterWithEncoding.builder() + .setFile(result.within(directory)) + .setCharset(encoding) + .get()); } } diff --git a/apache-whisker-cli/pom.xml b/apache-whisker-cli/pom.xml index 9439310a..e7adffc4 100644 --- a/apache-whisker-cli/pom.xml +++ b/apache-whisker-cli/pom.xml @@ -28,8 +28,8 @@ jar - commons-logging - commons-logging-api + org.apache.logging.log4j + log4j-api commons-cli diff --git a/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/Main.java b/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/Main.java index 528eb784..2c31b710 100644 --- a/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/Main.java +++ b/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/Main.java @@ -128,7 +128,7 @@ public Whisker configure(final String[] args) throws ParseException { */ private Whisker configure( final CommandLine commandLine) throws MissingOptionException { - whisker.setEngine(new VelocityEngine(new SystemLog())); + whisker.setEngine(new VelocityEngine()); whisker.setSource(CommandLineOption.SOURCE.getOptionValue(commandLine)); whisker.setLicenseDescriptor( new StreamableResourceFactory().streamFromResource( diff --git a/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/SystemLog.java b/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/SystemLog.java deleted file mode 100644 index acb98345..00000000 --- a/apache-whisker-cli/src/main/java/org/apache/creadur/whisker/cli/SystemLog.java +++ /dev/null @@ -1,203 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.creadur.whisker.cli; - -import org.apache.commons.logging.Log; - -/** - * Logs important messages to system err. - */ -public final class SystemLog implements Log { - - /** - * Ignored. - * @param message possibly null - * @see org.apache.commons.logging.Log#debug(java.lang.Object) - */ - public void debug(final Object message) { } - - /** - * Ignored. - * @param message possibly null - * @param t possibly null - * @see Log#debug(java.lang.Object, java.lang.Throwable) - */ - public void debug(final Object message, final Throwable t) { } - - /** - * Logs to stderr. - * @param message possibly null - * @see org.apache.commons.logging.Log#error(java.lang.Object) - */ - public void error(final Object message) { - err(message); - } - - /** - * Logs to stderr. - * @param message not null - */ - private void err(final Object message) { - System.err.println(message); - } - - /** - * Logs to stderr. - * @param message possibly null - * @param t possibly null - * @see Log#error(java.lang.Object, java.lang.Throwable) - */ - public void error(final Object message, final Throwable t) { - err(message, t); - } - - /** - * Logs to stderr. - * @param message possibly null - * @param t possibly null - */ - private void err(final Object message, final Throwable t) { - err(message); - t.printStackTrace(); - } - - /** - * Logs to stderr. - * @param message possibly null - * @see org.apache.commons.logging.Log#fatal(java.lang.Object) - */ - public void fatal(final Object message) { - err(message); - } - - /** - * Logs to stderr. - * @param message possibly null - * @param t possibly null - * @see Log#fatal(java.lang.Object, java.lang.Throwable) - */ - public void fatal(final Object message, final Throwable t) { - err(message, t); - } - - /** - * Ignored. - * @param message possibly null - * @see Log#info(java.lang.Object) - */ - public void info(final Object message) { - } - - /** - * Ignored. - * @param message possibly null - * @param t possibly null - * @see #info(java.lang.Object, java.lang.Throwable) - */ - public void info(final Object message, final Throwable t) { - } - - /** - * Disabled. - * @return false - * @see org.apache.commons.logging.Log#isDebugEnabled() - */ - public boolean isDebugEnabled() { - return false; - } - - /** - * Enabled. - * @return true - * @see org.apache.commons.logging.Log#isErrorEnabled() - */ - public boolean isErrorEnabled() { - return true; - } - - /** - * Enabled. - * @return true - * @see org.apache.commons.logging.Log#isFatalEnabled() - */ - public boolean isFatalEnabled() { - return true; - } - - /** - * Disabled. - * @return false - * @see org.apache.commons.logging.Log#isInfoEnabled() - */ - public boolean isInfoEnabled() { - return false; - } - - /** - * Disabled. - * @return false - * @see org.apache.commons.logging.Log#isTraceEnabled() - */ - public boolean isTraceEnabled() { - return false; - } - - /** - * Disabled. - * @return false - * @see org.apache.commons.logging.Log#isWarnEnabled() - */ - public boolean isWarnEnabled() { - return false; - } - - /** - * Ignored. - * @param message possibly null - * @see org.apache.commons.logging.Log#trace(java.lang.Object) - */ - public void trace(final Object message) { - } - - /** - * Ignored. - * @param message possibly null - * @param t possibly null - * @see Log#trace(java.lang.Object, java.lang.Throwable) - */ - public void trace(final Object message, final Throwable t) { - } - - /** - * Ignored. - * @param message possibly null - * @see org.apache.commons.logging.Log#warn(java.lang.Object) - */ - public void warn(final Object message) { - } - - /** - * Ignored. - * @param message possibly null - * @param t possibly null - * @see Log#warn(java.lang.Object, java.lang.Throwable) - */ - public void warn(final Object message, final Throwable t) { - } -} diff --git a/apache-whisker-maven-plugin/pom.xml b/apache-whisker-maven-plugin/pom.xml index 7fad5d7a..77fd5998 100644 --- a/apache-whisker-maven-plugin/pom.xml +++ b/apache-whisker-maven-plugin/pom.xml @@ -45,8 +45,16 @@ commons-lang3 - commons-logging - commons-logging-api + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-to-slf4j junit @@ -127,6 +135,7 @@ maven-invoker-plugin + -X true src/it ${project.build.directory}/it diff --git a/apache-whisker-maven-plugin/src/it/example-copyright-notices/verify.groovy b/apache-whisker-maven-plugin/src/it/example-copyright-notices/verify.groovy index 31501ad0..7eaa0fc8 100644 --- a/apache-whisker-maven-plugin/src/it/example-copyright-notices/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/example-copyright-notices/verify.groovy @@ -19,7 +19,7 @@ import static org.apache.creadur.whisker.it.Helpers.* -results = results(); +results = results() if (noticeIsMissing(basedir)) { results.fail("NOTICE is missing") @@ -29,7 +29,7 @@ if (licenseIsMissing(basedir)) { } if (results.hasFailed()) { - return results.report(); + return results.report() } else { license = licenseIn(basedir) license.expectThat(aLineContainsCDDL1()) diff --git a/apache-whisker-maven-plugin/src/it/in-5/invoker.properties b/apache-whisker-maven-plugin/src/it/in-5/invoker.properties new file mode 100644 index 00000000..3fbe9b2a --- /dev/null +++ b/apache-whisker-maven-plugin/src/it/in-5/invoker.properties @@ -0,0 +1 @@ +invoker.goals = install -X -e diff --git a/apache-whisker-maven-plugin/src/it/in-5/verify.groovy b/apache-whisker-maven-plugin/src/it/in-5/verify.groovy index 8b5bc266..0da1565d 100644 --- a/apache-whisker-maven-plugin/src/it/in-5/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/in-5/verify.groovy @@ -20,7 +20,7 @@ assert !new File(basedir, "target/NOTICE").exists() def license = new File(basedir, "target/LICENSE") -assert license.exists() +assert license.exists() def reader = new BufferedReader(new InputStreamReader(new FileInputStream(license), "UTF-8")) @@ -90,4 +90,4 @@ assert !six assert seven assert eight -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/license-family/verify.groovy b/apache-whisker-maven-plugin/src/it/license-family/verify.groovy index 927a62df..6c809e32 100644 --- a/apache-whisker-maven-plugin/src/it/license-family/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/license-family/verify.groovy @@ -49,4 +49,4 @@ assert alv2 assert substituted assert thirdParty -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/minimal/verify.groovy b/apache-whisker-maven-plugin/src/it/minimal/verify.groovy index 3a0243d9..6617546e 100644 --- a/apache-whisker-maven-plugin/src/it/minimal/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/minimal/verify.groovy @@ -17,8 +17,8 @@ * under the License. */ -File license = new File(basedir, "target/LICENSE"); -File notice = new File(basedir, "target/NOTICE"); +File license = new File(basedir, "target/LICENSE") +File notice = new File(basedir, "target/NOTICE") assert license.exists() assert !notice.exists() @@ -37,4 +37,4 @@ while (line != null) { assert copyright -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/primary-license-with-copyright-notice/verify.groovy b/apache-whisker-maven-plugin/src/it/primary-license-with-copyright-notice/verify.groovy index 7df432ce..a660312f 100644 --- a/apache-whisker-maven-plugin/src/it/primary-license-with-copyright-notice/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/primary-license-with-copyright-notice/verify.groovy @@ -48,4 +48,4 @@ assert dependent assert resource -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/third-party-corp/verify.groovy b/apache-whisker-maven-plugin/src/it/third-party-corp/verify.groovy index 56491732..c661c957 100644 --- a/apache-whisker-maven-plugin/src/it/third-party-corp/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/third-party-corp/verify.groovy @@ -45,4 +45,4 @@ assert apache assert foundation -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/third-party-group/verify.groovy b/apache-whisker-maven-plugin/src/it/third-party-group/verify.groovy index cfb508de..3a11ce3a 100644 --- a/apache-whisker-maven-plugin/src/it/third-party-group/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/third-party-group/verify.groovy @@ -45,4 +45,4 @@ assert apache assert group -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/third-party/verify.groovy b/apache-whisker-maven-plugin/src/it/third-party/verify.groovy index 07f42304..a0def7fe 100644 --- a/apache-whisker-maven-plugin/src/it/third-party/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/third-party/verify.groovy @@ -45,4 +45,4 @@ assert apache assert samSmith -return true; \ No newline at end of file +return true \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/it/whisker-10/verify.groovy b/apache-whisker-maven-plugin/src/it/whisker-10/verify.groovy index b9c93942..44199df8 100644 --- a/apache-whisker-maven-plugin/src/it/whisker-10/verify.groovy +++ b/apache-whisker-maven-plugin/src/it/whisker-10/verify.groovy @@ -19,7 +19,7 @@ import static org.apache.creadur.whisker.it.Helpers.* -results = results(); +results = results() if (noticeIsMissing(basedir)) { results.fail("NOTICE is missing") @@ -29,7 +29,7 @@ if (licenseIsMissing(basedir)) { } if (results.hasFailed()) { - return results.report(); + return results.report() } else { license = licenseIn(basedir) license.expectThat(aLineContainsCDDL1()) diff --git a/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/GenerateMojo.java b/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/GenerateMojo.java index 65807ab8..820a4261 100644 --- a/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/GenerateMojo.java +++ b/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/GenerateMojo.java @@ -63,10 +63,11 @@ public class GenerateMojo extends AbstractMojo { */ public void execute() throws MojoExecutionException { if (descriptor.exists()) { + getLog().info("Reading descriptor from " + descriptor); if (descriptor.canRead()) { try { new Whisker().setLicenseDescriptor(new StreamableResourceFactory().streamFromFileResource(descriptor)) - .setEngine(new VelocityEngine(new MojoToJCLLog(getLog()))) + .setEngine(new VelocityEngine()) .setWriterFactory(new WriteResultsIntoDirectoryFactory(outputDirectory, outputEncoding)) .setAct(Act.GENERATE).act(); } catch (Exception e) { @@ -76,6 +77,7 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Read permission requires on Whisker descriptor file: " + descriptor); } } else { + getLog().error("No descriptor found " + descriptor); throw new MojoExecutionException("Whisker descriptor file is missing: " + descriptor); } } diff --git a/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/MojoToJCLLog.java b/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/MojoToJCLLog.java deleted file mode 100644 index 97c6dc52..00000000 --- a/apache-whisker-maven-plugin/src/main/java/org/apache/creadur/whisker/plugin/maven/MojoToJCLLog.java +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.creadur.whisker.plugin.maven; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.maven.plugin.logging.Log; - -/** - * Adapts commons logging calls to Maven. - */ -public class MojoToJCLLog implements org.apache.commons.logging.Log { - - /** Maven's log */ - private final Log log; - - /** - * Constructs a log than delegates to Maven. - * @param log not null - */ - public MojoToJCLLog(final Log log) { - super(); - this.log = log; - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#debug(java.lang.Object) - */ - public void debug(final Object message) { - log.debug(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#debug(java.lang.Object, java.lang.Throwable) - */ - public void debug(final Object message, final Throwable t) { - log.debug(new ToStringBuilder(message).toString(), t); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#error(java.lang.Object) - */ - public void error(final Object message) { - log.error(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#error(java.lang.Object, java.lang.Throwable) - */ - public void error(final Object message, final Throwable t) { - log.error(new ToStringBuilder(message).toString(), t); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#fatal(java.lang.Object) - */ - public void fatal(final Object message) { - log.error(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#fatal(java.lang.Object, java.lang.Throwable) - */ - public void fatal(final Object message, final Throwable t) { - log.error(new ToStringBuilder(message).toString(), t); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#info(java.lang.Object) - */ - public void info(final Object message) { - log.info(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#info(java.lang.Object, java.lang.Throwable) - */ - public void info(final Object message, final Throwable t) { - log.info(new ToStringBuilder(message).toString(), t); - } - - /** - * Delegates to Maven. - * @return true when debug is enabled in Maven - * @see org.apache.commons.logging.Log#isDebugEnabled() - */ - public boolean isDebugEnabled() { - return log.isDebugEnabled(); - } - - /** - * Delegates to Maven. - * @return true when error is enabled in Maven - * @see org.apache.commons.logging.Log#isErrorEnabled() - */ - public boolean isErrorEnabled() { - return log.isErrorEnabled(); - } - - /** - * Delegates to Maven. - * @return true when error is enabled in Maven - * @see org.apache.commons.logging.Log#isFatalEnabled() - */ - public boolean isFatalEnabled() { - return log.isErrorEnabled(); - } - - /** - * Delegates to Maven. - * @return true when info is enabled in Maven - * @see org.apache.commons.logging.Log#isInfoEnabled() - */ - public boolean isInfoEnabled() { - return log.isInfoEnabled(); - } - - /** - * Delegates to Maven. - * @return true when trace is enabled in Maven - * @see org.apache.commons.logging.Log#isTraceEnabled() - */ - public boolean isTraceEnabled() { - return log.isDebugEnabled(); - } - - /** - * Delegates to Maven. - * @return true when warn is enabled in Maven - * @see org.apache.commons.logging.Log#isWarnEnabled() - */ - public boolean isWarnEnabled() { - return log.isWarnEnabled(); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#trace(java.lang.Object) - */ - public void trace(final Object message) { - log.debug(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#trace(java.lang.Object, java.lang.Throwable) - */ - public void trace(final Object message, final Throwable t) { - log.debug(new ToStringBuilder(message).toString(), t); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @see org.apache.commons.logging.Log#warn(java.lang.Object) - */ - public void warn(final Object message) { - log.warn(new ToStringBuilder(message).toString()); - } - - /** - * Delegates to Maven. - * @param message possibly null - * @param t cause - * @see org.apache.commons.logging.Log#warn(java.lang.Object, java.lang.Throwable) - */ - public void warn(final Object message, final Throwable t) { - log.warn(new ToStringBuilder(message).toString(), t); - } -} diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/AnyCheck.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/AnyCheck.java index 9425af3f..a3368014 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/AnyCheck.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/AnyCheck.java @@ -39,7 +39,7 @@ public void check(final String line) { } public boolean hasPassed() { - return checks.size() == 0 || anyPassed(checks); + return checks.isEmpty() || anyPassed(checks); } public void report(final Results results) { diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Check.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Check.java index 9adc1c9f..1b52b432 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Check.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Check.java @@ -20,10 +20,10 @@ public interface Check { - public abstract void check(String line); + void check(String line); - public abstract boolean hasPassed(); + boolean hasPassed(); - public abstract void report(Results result); + void report(Results result); } \ No newline at end of file diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/FileVerifier.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/FileVerifier.java index e1f37905..14bc98e5 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/FileVerifier.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/FileVerifier.java @@ -21,6 +21,7 @@ import static org.apache.creadur.whisker.it.CheckHelpers.*; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -44,7 +45,7 @@ public FileVerifier expectThat(final Check check) { public String failures() throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(licenseFile), "UTF-8")); + new FileInputStream(licenseFile), StandardCharsets.UTF_8)); try { String line = null; do { diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Helpers.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Helpers.java index 824aeac1..5b8d9770 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Helpers.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Helpers.java @@ -33,11 +33,7 @@ public static String aggregate(final String firstFailureReport, final String secondFailureReport) { final String result; if (firstFailureReport == null) { - if (secondFailureReport == null) { - result = null; - } else { - result = secondFailureReport; - } + result = secondFailureReport; } else { if (secondFailureReport == null) { result = firstFailureReport; diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Latch.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Latch.java index 0cb37b00..d419839f 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Latch.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/Latch.java @@ -22,15 +22,11 @@ public enum Latch { UP, DOWN; - private Latch() {} + Latch() {} public Latch push() { final Latch result; - if (this == DOWN) { - result = this; - } else { - result = DOWN; - } + result = DOWN; return result; } } diff --git a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java index 7053bc71..c61489e5 100644 --- a/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java +++ b/apache-whisker-maven-plugin/src/test/java/org/apache/creadur/whisker/it/TestAnyCheck.java @@ -34,7 +34,7 @@ public class TestAnyCheck extends TestCase { protected void setUp() throws Exception { super.setUp(); results = new Results(); - checks = new ArrayList(); + checks = new ArrayList<>(); } protected void tearDown() throws Exception { diff --git a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/ByOrganisation.java b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/ByOrganisation.java index d0f0ac53..6d3cb91c 100644 --- a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/ByOrganisation.java +++ b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/ByOrganisation.java @@ -123,13 +123,8 @@ public boolean equals(final Object obj) { } final ByOrganisation other = (ByOrganisation) obj; if (this.organisation == null) { - if (other.organisation != null) { - return false; - } - } else if (!this.organisation.equals(other.organisation)) { - return false; - } - return true; + return other.organisation == null; + } else return this.organisation.equals(other.organisation); } /** diff --git a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java index f817cf2d..d51d7c5d 100644 --- a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java +++ b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java @@ -319,7 +319,7 @@ public boolean primaryNoticeExists() { */ public boolean isPrimaryOnly() { final boolean result; - if (contents.size() > 0) { + if (!contents.isEmpty()) { final LicenseAndOrganisationCollator collator = new LicenseAndOrganisationCollator(); for (final WithinDirectory directory : contents) { directory.accept(collator); diff --git a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Organisation.java b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Organisation.java index 151bc07f..f2d773b8 100644 --- a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Organisation.java +++ b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Organisation.java @@ -110,13 +110,8 @@ public boolean equals(final Object obj) { } final Organisation other = (Organisation) obj; if (this.id == null) { - if (other.id != null) { - return false; - } - } else if (!this.id.equals(other.id)) { - return false; - } - return true; + return other.id == null; + } else return this.id.equals(other.id); } /** diff --git a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Resource.java b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Resource.java index d4e1be57..46d50dd1 100644 --- a/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Resource.java +++ b/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Resource.java @@ -100,13 +100,8 @@ public boolean equals(final Object obj) { } final Resource other = (Resource) obj; if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return other.name == null; + } else return this.name.equals(other.name); } /** diff --git a/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/Directory.java b/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/Directory.java index 950ce399..51ab5600 100644 --- a/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/Directory.java +++ b/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/Directory.java @@ -92,11 +92,8 @@ public boolean equals(final Object obj) { return false; Directory other = (Directory) obj; if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; + return other.name == null; + } else return name.equals(other.name); } /** diff --git a/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/FromFileSystem.java b/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/FromFileSystem.java index 625f98a7..029418a9 100644 --- a/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/FromFileSystem.java +++ b/apache-whisker-scan/src/main/java/org/apache/creadur/whisker/scan/FromFileSystem.java @@ -331,13 +331,8 @@ public boolean equals(final Object obj) { } else if (!file.equals(other.file)) return false; if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; + return other.name == null; + } else return name.equals(other.name); } /** diff --git a/apache-whisker-velocity/pom.xml b/apache-whisker-velocity/pom.xml index 87e8e8b2..7b838319 100644 --- a/apache-whisker-velocity/pom.xml +++ b/apache-whisker-velocity/pom.xml @@ -40,8 +40,12 @@ commons-io - commons-logging - commons-logging-api + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core junit diff --git a/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java b/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java index 4633811f..d1500bc2 100644 --- a/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java +++ b/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java @@ -20,30 +20,27 @@ import java.util.Collection; -import org.apache.commons.logging.Log; import org.apache.creadur.whisker.app.AbstractEngine; import org.apache.creadur.whisker.app.Configuration; import org.apache.creadur.whisker.app.ResultWriterFactory; import org.apache.creadur.whisker.app.analysis.LicenseAnalyst; import org.apache.creadur.whisker.model.Descriptor; import org.apache.creadur.whisker.scan.Directory; - +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * Uses Apache Velocity to implement {@link AbstractEngine}. * * @see Apache Velocity */ public class VelocityEngine extends AbstractEngine { - /** Not null. */ - private final Log log; + private static final Logger LOGGER = LogManager.getLogger(); /** * Constructs an engine running on Apache Velocity. - * @param log not null */ - public VelocityEngine(final Log log) { + public VelocityEngine() { super(); - this.log = log; } /** @@ -71,7 +68,7 @@ public final AbstractEngine skeleton( * @return a reporter, not null */ private VelocityReports reporter(final ResultWriterFactory writerFactory) { - return new VelocityReports(writerFactory, log); + return new VelocityReports(writerFactory); } /** diff --git a/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java b/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java index 37b68d27..9730c22b 100644 --- a/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java +++ b/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java @@ -24,19 +24,24 @@ import java.util.List; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; import org.apache.creadur.whisker.app.Configuration; import org.apache.creadur.whisker.app.ResultWriterFactory; import org.apache.creadur.whisker.app.analysis.LicenseAnalyst; import org.apache.creadur.whisker.model.Descriptor; import org.apache.creadur.whisker.scan.Directory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; /** * Wraps velocity engine. */ public class VelocityReports { + /** The logger. */ + private static final Logger LOGGER = LogManager.getLogger(); + /** XML generation template. */ private static final Product[] PRODUCTS_THAT_GENERATE_TEMPLATES = {Product.XML_TEMPLATE}; @@ -54,23 +59,18 @@ public class VelocityReports { private final ResultWriterFactory writerFactory; /** Merges templates, not null. */ private final VelocityEngine engine; - /** Logs messages, not null. */ - private final Log log; /** * Constructs a reporter using Apache Velocity. * @param writerFactory not null - * @param log not null */ public VelocityReports( - final ResultWriterFactory writerFactory, final Log log) { + final ResultWriterFactory writerFactory) { this.writerFactory = writerFactory; - this.log = log; engine = new VelocityEngine(); - engine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath"); - engine.setProperty("classpath.resource.loader.class", - "org.apache.velocity.runtime.resource.loader." - + "ClasspathResourceLoader"); + engine.setProperty("resource.loaders", "class"); + engine.setProperty("resource.loader.class.class", + ClasspathResourceLoader.class.getName()); engine.init(); } @@ -95,8 +95,8 @@ public final void generate(final Descriptor work, } - final Product[] pruductArray = new Product[products.size()]; - merge(products.toArray(pruductArray), context(work, configuration)); + final Product[] productArray = new Product[products.size()]; + merge(products.toArray(productArray), context(work, configuration)); } /** diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/EmptyLog.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/EmptyLog.java deleted file mode 100644 index b25da440..00000000 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/EmptyLog.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.creadur.whisker.out.velocity; - -import org.apache.commons.logging.Log; - -public class EmptyLog implements Log { - - public void debug(Object arg0, Throwable arg1) { - } - - public void debug(Object arg0) { - } - - public void error(Object arg0, Throwable arg1) { - } - - public void error(Object arg0) { - } - - public void fatal(Object arg0, Throwable arg1) { - } - - public void fatal(Object arg0) { - } - - public void info(Object arg0, Throwable arg1) { - } - - public void info(Object arg0) { - } - - public boolean isDebugEnabled() { - return false; - } - - public boolean isErrorEnabled() { - return false; - } - - public boolean isFatalEnabled() { - return false; - } - - public boolean isInfoEnabled() { - return false; - } - - public boolean isTraceEnabled() { - return false; - } - - public boolean isWarnEnabled() { - return false; - } - - public void trace(Object arg0, Throwable arg1) { - } - - public void trace(Object arg0) { - } - - public void warn(Object arg0, Throwable arg1) { - } - - public void warn(Object arg0) { - } - -} diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java index 11fd461c..256ec7c9 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java @@ -36,7 +36,7 @@ public class TestLicenseGeneration extends TestCase { protected void setUp() throws Exception { super.setUp(); writerFactory = new StringResultWriterFactory(); - subject = new VelocityEngine(new EmptyLog()); + subject = new VelocityEngine(); builder = new DescriptorBuilderForTesting(); } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java index 674f4caa..3df83498 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java @@ -36,7 +36,7 @@ public class TestLicenseGenerationSourceURLs extends TestCase { protected void setUp() throws Exception { super.setUp(); writerFactory = new StringResultWriterFactory(); - subject = new VelocityEngine(new EmptyLog()); + subject = new VelocityEngine(); builder = new DescriptorBuilderForTesting().withSourceURL(); work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory(".").build(); } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java index 179d6192..a8c02a51 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java @@ -50,7 +50,7 @@ public class TestNoticeGeneration extends TestCase { protected void setUp() throws Exception { super.setUp(); writerFactory = new StringResultWriterFactory(); - subject = new VelocityEngine(new EmptyLog()); + subject = new VelocityEngine(); primaryLicense.storeIn(licenses); } diff --git a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java index d5301d38..50fd5ce6 100644 --- a/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java +++ b/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java @@ -46,25 +46,25 @@ protected void setUp() throws Exception { public void testSourceWithSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().withSourceURLsInLicense().build()); - assertEquals(subject.sourceUrl(resourceWithSourceUrl), " from " + A_SOURCE_URL); + assertEquals(" from " + A_SOURCE_URL, subject.sourceUrl(resourceWithSourceUrl)); } public void testSourceNoSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().noSourceURLsInLicense().build()); - assertEquals(subject.sourceUrl(resourceWithSourceUrl), ""); + assertEquals("", subject.sourceUrl(resourceWithSourceUrl)); } public void testNoSourceWithSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().withSourceURLsInLicense().build()); - assertEquals(subject.sourceUrl(resourceNoSourceUrl), ""); + assertEquals("", subject.sourceUrl(resourceNoSourceUrl)); } public void testNoSourceNoSourceUrlsConfiguration() { subject = new RenderingHelper(work, aConfiguration().noSourceURLsInLicense().build()); - assertEquals(subject.sourceUrl(resourceNoSourceUrl), ""); + assertEquals("", subject.sourceUrl(resourceNoSourceUrl)); } } diff --git a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java index 6d734459..2c0bab94 100644 --- a/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java +++ b/apache-whisker-xml/src/test/java/org/apache/creadur/whisker/fromxml/JDomBuilderWorkTest.java @@ -171,7 +171,7 @@ public void testMapOrganisationsExpectedToBeImmutable() throws Exception { public void testMapOrganisationsFindOrganisationDefinedInDocument() throws Exception { for (int i=1;i<256;i++) { checkMapOrganisationsWith(i); - }; + } } /** @@ -242,7 +242,7 @@ public void testPrimaryCopyright() throws Exception { new Element("primary-license").setAttribute("id", "The primary ID") .addContent( new Element("copyright-notice").addContent(copyrightNoticeSet))))); - assertEquals("Builder should set primary copyright notice", result, copyrightNoticeSet); + assertEquals("Builder should set primary copyright notice", copyrightNoticeSet, result); } public void testBuildPrimaryCopyright() throws Exception { @@ -257,7 +257,7 @@ public void testBuildPrimaryCopyright() throws Exception { .addContent( new Element("copyright-notice").addContent(copyrightNoticeSet)))) ).getPrimaryCopyrightNotice(); - assertEquals("Builder should set primary copyright notice", result, copyrightNoticeSet); + assertEquals("Builder should set primary copyright notice", copyrightNoticeSet, result); } public void testThrowsMissingIDExceptionWhenPrimaryLicenseMissing() throws Exception { @@ -322,7 +322,7 @@ public void testCollectContentsReturneEmptyWhenDocumentHasNoContents() throws Ex public void testCollectDirectoriesDefinedInDocument() throws Exception { for (int i=1;i<256;i++) { checkCollectDirectoriesWith(i); - }; + } } /** diff --git a/pom.xml b/pom.xml index a272f9d0..d175bde5 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,6 @@ apache-whisker 0.2-SNAPSHOT pom - org.apache apache @@ -57,9 +56,11 @@ 2.18.0 - commons-logging - commons-logging-api - 1.1 + org.apache.logging.log4j + log4j-bom + 2.24.3 + import + pom org.apache.commons @@ -78,6 +79,21 @@ 2.13.1 test + + org.apache.logging.log4j + log4j-api + ${log4j2.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + + + org.apache.logging.log4j + log4j-to-slf4j + ${log4j2.version} + @@ -90,6 +106,7 @@ apache-whisker-maven-plugin + 2.24.3 UTF-8 1.8 @@ -228,6 +245,13 @@ + + + org.apache.logging.log4j + log4j-core + runtime + + clean install @@ -257,7 +281,9 @@ 0.16.1 + **/log4j*.xml **/.mvn/** + **/invoker.properties/** .asf.yaml README.md **/src/site/javadocFont/** @@ -320,7 +346,7 @@ - 3.0.5 + 3.1.0 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 39daf9ef..93ba0a15 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -35,7 +35,7 @@ then tweak the formatting if necessary and commit. Run with changes.version-parameter in order to not generate a SNAPSHOT changelog -The type attribute can be add,update,fix,remove. +The type attribute can be: add,update,fix,remove. Please list action attributes in the following order: issue - required @@ -60,6 +60,9 @@ The type attribute can be add,update,fix,remove. --> + + Migrate to log4j2. Minimal Maven set to >=3.1.0 to benefit from slf4j log bridging to log errors to console by default as before. + Fix build warning and ensure Maven >=3.0.5 is used to build the project. diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml new file mode 100644 index 00000000..21c4919a --- /dev/null +++ b/src/main/resources/log4j.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/log4j2-test.xml b/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000..c5b9853c --- /dev/null +++ b/src/test/resources/log4j2-test.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +