From e5da4d75aa0b483247e7a85f786769d1a38eba76 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Wed, 17 Jan 2024 15:12:34 -0600 Subject: [PATCH] Make thread safe --- .github/workflows/maven.yml | 5 +++-- liberty-maven-plugin/pom.xml | 2 +- .../tools/maven/applications/DeployMojo.java | 5 ++--- .../maven/applications/DeployMojoSupport.java | 12 ++++------- .../maven/applications/UndeployAppMojo.java | 9 ++++----- .../maven/server/PluginConfigSupport.java | 20 ++++++++++++++----- .../maven/server/StartDebugMojoSupport.java | 4 ++-- .../tools/maven/utils/CommonLogger.java | 19 ++---------------- 8 files changed, 33 insertions(+), 43 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5c5bb1be0..e48781e1f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -48,7 +48,8 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.common + repository: cherylking/ci.common + ref: makeThreadSafe path: ci.common - name: Checkout ci.ant uses: actions/checkout@v3 @@ -102,7 +103,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.maven repos to C drive run: | cp -r D:/a/ci.maven/ci.maven C:/ci.maven - git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common + git clone https://github.com/cherylking/ci.common.git --branch makeThreadSafe --single-branch C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index 4b3065125..c6c919883 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -88,7 +88,7 @@ io.openliberty.tools ci.common - 1.8.30 + 1.8.31-SNAPSHOT org.twdata.maven diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index b8425cbdb..335b1c258 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2023. + * (C) Copyright IBM Corporation 2014, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,6 @@ import io.openliberty.tools.maven.utils.SpringBootUtil; import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument; import io.openliberty.tools.common.plugins.config.LooseConfigData; -import io.openliberty.tools.common.plugins.config.ServerConfigDocument; import io.openliberty.tools.common.plugins.util.DevUtil; /** @@ -304,7 +303,7 @@ private static LooseConfigData createLooseConfigData() throws MojoExecutionExcep private void cleanupPreviousExecution() { if (ApplicationXmlDocument.getApplicationXmlFile(serverDirectory).exists()) { ApplicationXmlDocument.getApplicationXmlFile(serverDirectory).delete(); - ServerConfigDocument.markInstanceStale(); + scd = null; // force reinitialization of ServerConfigDocument } } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index 7fc8222a8..ef15812f8 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2016, 2023. + * (C) Copyright IBM Corporation 2016, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,12 +44,8 @@ import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument; import io.openliberty.tools.common.plugins.config.LooseApplication; import io.openliberty.tools.common.plugins.config.LooseConfigData; -import io.openliberty.tools.common.plugins.config.ServerConfigDocument; import io.openliberty.tools.common.plugins.util.DevUtil; -import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; -import io.openliberty.tools.common.plugins.util.InstallFeatureUtil.ProductProperties; import io.openliberty.tools.common.plugins.util.OSUtil; -import io.openliberty.tools.common.plugins.util.PluginExecutionException; /** * Support for installing and deploying applications to a Liberty server. @@ -317,13 +313,13 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException { try { Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - CommonLogger logger = CommonLogger.getInstance(getLog()); + CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - ServerConfigDocument.getInstance(logger, serverXML, configDirectory, + getServerConfigDocument(logger, serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from appFile if no name can be found. - appName = ServerConfigDocument.findNameForLocation(appFile); + appName = scd.findNameForLocation(appFile); } catch (Exception e) { getLog().warn(e.getLocalizedMessage()); getLog().debug(e); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java index 3d303acf1..036fe8111 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2023. + * (C) Copyright IBM Corporation 2014, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.apache.maven.project.MavenProject; import io.openliberty.tools.ant.ServerTask; -import io.openliberty.tools.common.plugins.config.ServerConfigDocument; import io.openliberty.tools.maven.utils.CommonLogger; /** @@ -135,13 +134,13 @@ protected void undeployApp(File file) throws MojoExecutionException { File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml"); Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - CommonLogger logger = CommonLogger.getInstance(getLog()); + CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - ServerConfigDocument.getInstance(logger, serverXML, configDirectory, + getServerConfigDocument(logger, serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from file if no name can be found. - appName = ServerConfigDocument.findNameForLocation(appName); + appName = scd.findNameForLocation(appName); } catch (Exception e) { getLog().warn(e.getLocalizedMessage()); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index 13af4401d..c23253872 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2017, 2023. + * (C) Copyright IBM Corporation 2017, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ import io.openliberty.tools.maven.PluginConfigXmlDocument; import io.openliberty.tools.maven.utils.CommonLogger; +import io.openliberty.tools.common.CommonLoggerI; import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument; import io.openliberty.tools.common.plugins.config.ServerConfigDocument; @@ -47,6 +48,8 @@ */ public abstract class PluginConfigSupport extends StartDebugMojoSupport { + protected ServerConfigDocument scd = null; + /** * Application directory. */ @@ -325,16 +328,14 @@ protected boolean isAnyAppConfiguredInSourceServerXml() { protected Set getAppConfigLocationsFromSourceServerXml() { - ServerConfigDocument scd = null; - File serverXML = new File(serverDirectory, "server.xml"); if (serverXML != null && serverXML.exists()) { try { Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - CommonLogger logger = CommonLogger.getInstance(getLog()); + CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - scd = ServerConfigDocument.getInstance(logger, serverXML, configDirectory, + scd = getServerConfigDocument(logger, serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); } catch (Exception e) { @@ -345,6 +346,15 @@ protected Set getAppConfigLocationsFromSourceServerXml() { return scd != null ? scd.getLocations() : new HashSet(); } + protected ServerConfigDocument getServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, + Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) throws IOException { + if (scd == null || !scd.getServerXML().getCanonicalPath().equals(serverXML.getCanonicalPath())) { + scd = new ServerConfigDocument(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles); + } + + return scd; + } + protected String getAppsDirectory() { return getAppsDirectory(true); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java index 442b2a06f..224b54a90 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java @@ -85,7 +85,7 @@ public abstract class StartDebugMojoSupport extends ServerFeatureSupport { private static final String LATE_PROP_RESOLUTION_SYNTAX = "@\\{(.+?)\\}"; private static final Pattern LATE_PROP_PATTERN = Pattern.compile(LATE_PROP_RESOLUTION_SYNTAX); - private static boolean configFilesCopied = false; + private boolean configFilesCopied = false; protected final String PLUGIN_VARIABLE_CONFIG_OVERRIDES_XML = "configDropins/overrides/liberty-plugin-variable-config.xml"; protected final String PLUGIN_VARIABLE_CONFIG_DEFAULTS_XML = "configDropins/defaults/liberty-plugin-variable-config.xml"; @@ -1030,7 +1030,7 @@ private void makeParentDirectory(File file) { } } - public static boolean isConfigCopied() { + public boolean isConfigCopied() { return configFilesCopied; } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java index 65a9552d8..6e5a44bf9 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2019, 2023. + * (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. @@ -22,24 +22,9 @@ public class CommonLogger implements CommonLoggerI { - private static CommonLogger logger = null; private Log loggerImpl; - public static CommonLogger getInstance(Log mojoLogger) { - if (logger == null) { - logger = new CommonLogger(mojoLogger); - } else { - logger.setLogger(mojoLogger); - } - - return logger; - } - - private CommonLogger(Log mojoLogger) { - loggerImpl = mojoLogger; - } - - private void setLogger(Log mojoLogger) { + public CommonLogger(Log mojoLogger) { loggerImpl = mojoLogger; }