Skip to content

Commit

Permalink
Make thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Jan 17, 2024
1 parent 4ee535e commit e5da4d7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 43 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>io.openliberty.tools</groupId>
<artifactId>ci.common</artifactId>
<version>1.8.30</version>
<version>1.8.31-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.twdata.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -317,13 +313,13 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException {

try {
Map<String, File> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -135,13 +134,13 @@ protected void undeployApp(File file) throws MojoExecutionException {
File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml");

Map<String, File> 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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand All @@ -47,6 +48,8 @@
*/
public abstract class PluginConfigSupport extends StartDebugMojoSupport {

protected ServerConfigDocument scd = null;

/**
* Application directory.
*/
Expand Down Expand Up @@ -325,16 +328,14 @@ protected boolean isAnyAppConfiguredInSourceServerXml() {

protected Set<String> getAppConfigLocationsFromSourceServerXml() {

ServerConfigDocument scd = null;

File serverXML = new File(serverDirectory, "server.xml");

if (serverXML != null && serverXML.exists()) {
try {
Map<String, File> 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) {
Expand All @@ -345,6 +346,15 @@ protected Set<String> getAppConfigLocationsFromSourceServerXml() {
return scd != null ? scd.getLocations() : new HashSet<String>();
}

protected ServerConfigDocument getServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile,
Map<String, String> bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map<String, File> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1030,7 +1030,7 @@ private void makeParentDirectory(File file) {
}
}

public static boolean isConfigCopied() {
public boolean isConfigCopied() {
return configFilesCopied;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}

Expand Down

0 comments on commit e5da4d7

Please sign in to comment.