From 57e398a6e920209f8fd7d351e077c793db963c00 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 18 Jan 2024 11:51:14 -0600 Subject: [PATCH] Make CommonLogger non-singleton --- .../gradle/tasks/AbstractServerTask.groovy | 2 +- .../tools/gradle/tasks/DeployTask.groovy | 2 +- .../tools/gradle/tasks/StartTask.groovy | 2 +- .../tools/gradle/tasks/UndeployTask.groovy | 4 +++- .../tools/gradle/utils/CommonLogger.groovy | 18 +++--------------- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy index b16e1b116..1c5fd5a3d 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy @@ -529,7 +529,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask { if (serverConfigFile != null && serverConfigFile.exists()) { try { Map props = combinedBootstrapProperties == null ? convertPropertiesToMap(server.bootstrapProperties) : combinedBootstrapProperties; - getServerConfigDocument(CommonLogger.getInstance(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, + getServerConfigDocument(new CommonLogger(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)); if (scd != null && isLocationFound( scd.getLocations(), fileName)) { logger.debug("Application configuration is found in server.xml : " + fileName) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy index 649260eeb..5bbeedb61 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy @@ -682,7 +682,7 @@ class DeployTask extends AbstractServerTask { File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml") try { - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(project), serverXML, server.configDirectory, + scd = getServerConfigDocument(new CommonLogger(project), serverXML, server.configDirectory, server.bootstrapPropertiesFile, combinedBootstrapProperties, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)) //appName will be set to a name derived from appFile if no name can be found. diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy index 52a81501f..244d24b38 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy @@ -86,7 +86,7 @@ class StartTask extends AbstractServerTask { if (serverConfigFile != null && serverConfigFile.exists()) { try { Map props = combinedBootstrapProperties == null ? convertPropertiesToMap(server.bootstrapProperties) : combinedBootstrapProperties; - getServerConfigDocument(CommonLogger.getInstance(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, + getServerConfigDocument(new CommonLogger(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)); if (scd != null) { appNames = scd.getNames() diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy index 5a4c99a1a..3b66e588b 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy @@ -23,6 +23,8 @@ import org.gradle.api.logging.LogLevel import io.openliberty.tools.ant.ServerTask import io.openliberty.tools.common.plugins.config.ServerConfigDocument +import io.openliberty.tools.gradle.utils.CommonLogger + class UndeployTask extends AbstractServerTask { private static final String STOP_APP_MESSAGE_CODE_REG = "CWWKZ0009I.*" @@ -77,7 +79,7 @@ class UndeployTask extends AbstractServerTask { File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml") try { - getServerConfigDocument(CommonLogger.getInstance(project), serverXML, server.configDirectory, + getServerConfigDocument(new CommonLogger(project), serverXML, server.configDirectory, server.bootstrapPropertiesFile, combinedBootstrapProperties, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)) //appName will be set to a name derived from appFile if no name can be found. diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/CommonLogger.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/CommonLogger.groovy index a5b00a440..c871ff64d 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/CommonLogger.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/CommonLogger.groovy @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2019, 2020. + * (C) Copyright IBM Corporation 2019, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,24 +21,12 @@ import org.gradle.api.Project public class CommonLogger implements CommonLoggerI { - private static CommonLogger logger = null - private static Project project + private Project project - CommonLogger(Project project) { + public CommonLogger(Project project) { this.project = project } - public static init(Project project) { - logger = new CommonLogger(project) - } - - public static CommonLogger getInstance(Project project) { - if (logger == null) { - CommonLogger.init(project) - } - return logger - } - @Override public void debug(String msg) { project.getLogger().debug(msg)