Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring serverConfigDocument constructor and moved getLibertyDire… #923

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ jobs:
- name: Checkout ci.common
uses: actions/checkout@v3
with:
repository: OpenLiberty/ci.common
repository: arunvenmany-ibm/ci.common
path: ci.common
ref: varProcessing_lcls
- name: Checkout ci.ant
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -124,7 +125,7 @@ jobs:
- name: Clone ci.ant, ci.common, ci.gradle repos to C drive
run: |
cp -r D:/a/ci.gradle/ci.gradle C:/ci.gradle
git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common
git clone https://github.com/arunvenmany-ibm/ci.common.git --branch varProcessing_lcls --single-branch C:/ci.common
git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant
# Cache mvn/gradle packages
- name: Cache Maven packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument
import io.openliberty.tools.common.plugins.config.ServerConfigDocument
import io.openliberty.tools.common.plugins.config.ServerConfigXmlDocument
import io.openliberty.tools.common.plugins.util.DevUtil
import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility
import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil
import io.openliberty.tools.gradle.utils.CommonLogger
import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils
Expand Down Expand Up @@ -506,11 +506,11 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
configureMultipleAppsConfigDropins(serverNode)
}

protected ServerConfigDocument getServerConfigDocument(CommonLogger log, File serverXML, Map<String, File> libertyDirPropertyFiles) throws IOException {
protected ServerConfigDocument getServerConfigDocument(CommonLogger log, File serverXML) throws IOException {

if (scd == null || !scd.getOriginalServerXMLFile().getCanonicalPath().equals(serverXML.getCanonicalPath())) {
try {
scd = new ServerConfigDocument(log, serverXML, libertyDirPropertyFiles);
scd = new ServerConfigDocument(log, serverXML, getInstallDir(project), getUserDir(project), getServerDir(project));
} catch (PluginExecutionException e) {
throw new GradleException(e.getMessage());
}
Expand All @@ -525,7 +525,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
if (serverConfigFile != null && serverConfigFile.exists()) {
try {
Map<String,String> props = combinedBootstrapProperties == null ? convertPropertiesToMap(server.bootstrapProperties) : combinedBootstrapProperties;
getServerConfigDocument(new CommonLogger(project), serverConfigFile, getLibertyDirectoryPropertyFiles(null));
getServerConfigDocument(new CommonLogger(project), serverConfigFile);
if (scd != null && isLocationFound( scd.getLocations(), fileName)) {
logger.debug("Application configuration is found in server.xml : " + fileName)
configured = true
Expand Down Expand Up @@ -1138,57 +1138,18 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
return serverTask
}

static public Map<String,File> getLibertyDirectoryPropertyFiles(File installDir, File userDir, File serverDir) throws Exception {
Map<String, File> libertyDirectoryPropertyToFile = new HashMap<String,File>()
protected Map<String, File> getLibertyDirectoryPropertyFiles(String serverDirectoryParam) {

if (serverDir.exists()) {
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverDir.getCanonicalFile())

libertyDirectoryPropertyToFile.put(ServerFeatureUtil.WLP_INSTALL_DIR, installDir.getCanonicalFile())

libertyDirectoryPropertyToFile.put(ServerFeatureUtil.WLP_USER_DIR, userDir.getCanonicalFile())

File userExtDir = new File(userDir, "extension")
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.USR_EXTENSION_DIR, userExtDir.getCanonicalFile())

File userSharedDir = new File(userDir, "shared")
File userSharedAppDir = new File(userSharedDir, "app")
File userSharedConfigDir = new File(userSharedDir, "config")
File userSharedResourcesDir = new File(userSharedDir, "resources")
File userSharedStackGroupsDir = new File(userSharedDir, "stackGroups")

libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_APP_DIR, userSharedAppDir.getCanonicalFile())
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_CONFIG_DIR, userSharedConfigDir.getCanonicalFile())
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_RESOURCES_DIR, userSharedResourcesDir.getCanonicalFile())
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_STACKGROUP_DIR, userSharedStackGroupsDir.getCanonicalFile())
}
return libertyDirectoryPropertyToFile
}

protected Map<String,File> getLibertyDirectoryPropertyFiles(String serverDirectoryParam) {

File serverConfigDir = getServerDir(project)

// if DevMode provides a server directory parameter use that for finding the server config dir
if (serverDirectoryParam != null) {
serverConfigDir = new File(serverDirectoryParam)
}
File wlpInstallDir = getInstallDir(project)
File wlpUserDir = getUserDir(project, wlpInstallDir)

if (serverConfigDir.exists()) {
try {
File wlpInstallDir = getInstallDir(project)
File wlpUserDir = getUserDir(project, wlpInstallDir)

return getLibertyDirectoryPropertyFiles(wlpInstallDir, wlpUserDir, serverConfigDir)
} catch (Exception e) {
logger.warn("The properties for directories could not be initialized because an error occurred when accessing the directories.")
logger.debug("Exception received: "+e.getMessage(), (Throwable) e)
}
} else {
logger.warn("The " + serverConfigDir + " directory cannot be accessed. The properties for directories could not be initialized.")
}

return new HashMap<String,File> ()
return LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(project), wlpInstallDir, wlpUserDir, serverConfigDir)
}

// Return the loose application configuration xml file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class DeployTask extends AbstractServerTask {
params.put('targetLibCachePath', getTargetLibCachePath())

File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml")
ServerConfigDocument scd = getServerConfigDocument(new CommonLogger(project), serverXML, getLibertyDirectoryPropertyFiles(null))
ServerConfigDocument scd = getServerConfigDocument(new CommonLogger(project), serverXML)
if (scd != null && scd.getSpringBootAppNodeLocation().isPresent()) {
targetThinAppPath = getTargetThinAppPath(appsDir, scd.getSpringBootAppNodeLocation().get())
} else {
Expand Down Expand Up @@ -690,7 +690,7 @@ class DeployTask extends AbstractServerTask {
File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml")

try {
scd = getServerConfigDocument(new CommonLogger(project), serverXML, getLibertyDirectoryPropertyFiles(null))
scd = getServerConfigDocument(new CommonLogger(project), serverXML)

//appName will be set to a name derived from appFile if no name can be found.
appName = scd.findNameForLocation(appFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import io.openliberty.tools.common.plugins.util.BinaryScannerUtil
import io.openliberty.tools.common.plugins.util.DevUtil
import io.openliberty.tools.common.plugins.util.InstallFeatureUtil
import io.openliberty.tools.common.plugins.util.JavaCompilerOptions
import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility
import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.util.PluginScenarioException
import io.openliberty.tools.common.plugins.util.ProjectModule
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms
import io.openliberty.tools.common.plugins.util.ServerStatusUtil
import io.openliberty.tools.gradle.utils.CommonLogger
import io.openliberty.tools.gradle.utils.DevTaskHelper
import org.gradle.api.GradleException
import org.gradle.api.Project
Expand Down Expand Up @@ -386,7 +388,7 @@ class DevTask extends AbstractFeatureTask {
null /* compileOptions not needed since useBuildRecompile is true */, keepTempContainerfile, mavenCacheLocation, projectModuleList /* multi module upstream projects */,
projectModuleList.size() > 0 /* recompileDependencies as true for multi module */, packagingType, buildFile, parentBuildGradle /* parent build files */, generateFeatures, null /* compileArtifactPaths */, null /* testArtifactPaths */, webResourceDirs /* webResources */
);
this.libertyDirPropertyFiles = AbstractServerTask.getLibertyDirectoryPropertyFiles(installDirectory, userDirectory, serverDirectory);
this.libertyDirPropertyFiles = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(project), installDirectory, userDirectory, serverDirectory);
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class StartTask extends AbstractServerTask {
File serverConfigFile = new File(getServerDir(project), 'server.xml')
if (serverConfigFile != null && serverConfigFile.exists()) {
try {
getServerConfigDocument(new CommonLogger(project), serverConfigFile, getLibertyDirectoryPropertyFiles(null));
getServerConfigDocument(new CommonLogger(project), serverConfigFile);
if (scd != null) {
appNames = scd.getNames()
appNames += scd.getNamelessLocations().collect { String location ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ package io.openliberty.tools.gradle.tasks
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.tasks.TaskAction
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

Expand Down Expand Up @@ -79,7 +77,7 @@ class UndeployTask extends AbstractServerTask {
File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml")

try {
getServerConfigDocument(new CommonLogger(project), serverXML, getLibertyDirectoryPropertyFiles(null))
getServerConfigDocument(new CommonLogger(project), serverXML)

//appName will be set to a name derived from appFile if no name can be found.
appName = scd.findNameForLocation(file)
Expand Down
Loading