diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java index 572e7ca25..b6b9d530f 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java @@ -46,7 +46,6 @@ import io.openliberty.tools.ant.install.InstallLibertyTask; import io.openliberty.tools.common.plugins.util.AbstractContainerSupportUtil; import io.openliberty.tools.common.plugins.util.PluginExecutionException; -import io.openliberty.tools.common.plugins.util.ServerFeatureUtil; /** * Basic Liberty Mojo Support @@ -673,49 +672,6 @@ private String getWlpOutputDir() throws IOException { return (String) envvars.get("WLP_OUTPUT_DIR"); } - static public Map getLibertyDirectoryPropertyFiles(File installDir, File userDir, File serverDir) throws IOException { - Map libertyDirectoryPropertyToFile = new HashMap(); - - 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 getLibertyDirectoryPropertyFiles() { - - if (serverDirectory.exists()) { - try { - return getLibertyDirectoryPropertyFiles(installDirectory, userDirectory, serverDirectory); - } catch (Exception e) { - getLog().warn("The properties for directories could not be initialized because an error occurred when accessing the directories."); - getLog().debug("Exception received: "+e.getMessage(), (Throwable) e); - } - } else { - getLog().warn("The " + serverDirectory + " directory cannot be accessed. The properties for directories could not be initialized."); - } - - return new HashMap (); - } - protected void setContainerEngine(AbstractContainerSupportUtil util) throws PluginExecutionException { String LIBERTY_DEV_PODMAN = "liberty.dev.podman"; Object podmanPropValue = null; diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java index 61f1c19a6..54c3568e8 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Set; +import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility; +import io.openliberty.tools.maven.utils.CommonLogger; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; @@ -236,7 +238,7 @@ else if (util == null && !noFeaturesSection) { Set dependencyFeatures = getDependencyFeatures(); Set serverFeatures = new HashSet(); Set serverPlatforms = new HashSet(); - FeaturesPlatforms getServerResult = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, getLibertyDirectoryPropertyFiles()) : null; + FeaturesPlatforms getServerResult = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(getLog()), installDirectory, userDirectory, serverDirectory)) : null; if (getServerResult != null) { serverFeatures = getServerResult.getFeatures(); serverPlatforms = getServerResult.getPlatforms(); 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 a7f487870..933d24cb1 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 @@ -118,10 +118,10 @@ private void installSpringBootApp() throws MojoExecutionException, IOException { File fatArchiveSrc = SpringBootUtil.getSpringBootUberJAR(project, getLog()); File serverXML = new File(serverDirectory, "server.xml"); - Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); + CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - getServerConfigDocument(logger, serverXML, libertyDirPropertyFiles); + getServerConfigDocument(logger, serverXML); // Check if the archiveSrc is executable and then invokeSpringUtilCommand. if (io.openliberty.tools.common.plugins.util.SpringBootUtil.isSpringBootUberJar(fatArchiveSrc)) { 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 ed4ac54c5..f890d41ce 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 @@ -312,10 +312,9 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException { try { File serverXML = new File(serverDirectory, "server.xml"); - Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - scd = getServerConfigDocument(logger, serverXML, libertyDirPropertyFiles); + scd = getServerConfigDocument(logger, serverXML); //appName will be set to a name derived from appFile if no name can be found. appName = scd.findNameForLocation(appFile); 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 ad1d4cd40..066bd0029 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 @@ -133,10 +133,9 @@ protected void undeployApp(File file) throws MojoExecutionException { try { File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml"); - Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - scd = getServerConfigDocument(logger, serverXML, libertyDirPropertyFiles); + scd = getServerConfigDocument(logger, serverXML); //appName will be set to a name derived from file if no name can be found. appName = scd.findNameForLocation(appName); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 2fb569b54..67e2ed601 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -41,6 +41,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility; +import io.openliberty.tools.maven.utils.CommonLogger; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.execution.MavenSession; @@ -359,8 +361,8 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou keepTempContainerfile, mavenCacheLocation, upstreamProjects, recompileDeps, project.getPackaging(), pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs); - this.libertyDirPropertyFiles = BasicSupport.getLibertyDirectoryPropertyFiles(installDir, userDir, - serverDirectory); + this.libertyDirPropertyFiles = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(getLog()), installDir, userDir, + serverDirectory); ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); if (fp != null) { 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 4ba41602c..4717e21e4 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 @@ -372,10 +372,9 @@ protected Set getAppConfigLocationsFromSourceServerXml() { if (serverXML != null && serverXML.exists()) { try { - Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); CommonLogger logger = new CommonLogger(getLog()); setLog(logger.getLog()); - scd = getServerConfigDocument(logger, serverXML, libertyDirPropertyFiles); + scd = getServerConfigDocument(logger, serverXML); } catch (Exception e) { getLog().warn(e.getLocalizedMessage()); getLog().debug(e); @@ -384,10 +383,10 @@ protected Set getAppConfigLocationsFromSourceServerXml() { return scd != null ? scd.getLocations() : new HashSet(); } - protected ServerConfigDocument getServerConfigDocument(CommonLoggerI log, File serverXML, Map libertyDirPropertyFiles) throws IOException, MojoExecutionException { + protected ServerConfigDocument getServerConfigDocument(CommonLoggerI log, File serverXML) throws IOException, MojoExecutionException { if (scd == null || !scd.getOriginalServerXMLFile().getCanonicalPath().equals(serverXML.getCanonicalPath())) { try { - scd = new ServerConfigDocument(log, serverXML, libertyDirPropertyFiles); + scd = new ServerConfigDocument(log, serverXML, installDirectory,userDirectory,serverDirectory); } catch (PluginExecutionException e) { throw new MojoExecutionException(e.getMessage()); }