Skip to content

Commit

Permalink
Merge pull request #1848 from arunvenmany-ibm/varProcessing_new
Browse files Browse the repository at this point in the history
 Adapting to ServerConfigDocument constructor changes
  • Loading branch information
arunvenmany-ibm authored Dec 3, 2024
2 parents 3ca66be + 2213a6e commit a9279a2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -673,49 +672,6 @@ private String getWlpOutputDir() throws IOException {
return (String) envvars.get("WLP_OUTPUT_DIR");
}

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

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() {

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<String,File> ();
}

protected void setContainerEngine(AbstractContainerSupportUtil util) throws PluginExecutionException {
String LIBERTY_DEV_PODMAN = "liberty.dev.podman";
Object podmanPropValue = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -236,7 +238,7 @@ else if (util == null && !noFeaturesSection) {
Set<String> dependencyFeatures = getDependencyFeatures();
Set<String> serverFeatures = new HashSet<String>();
Set<String> serverPlatforms = new HashSet<String>();
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ private void installSpringBootApp() throws MojoExecutionException, IOException {
File fatArchiveSrc = SpringBootUtil.getSpringBootUberJAR(project, getLog());
File serverXML = new File(serverDirectory, "server.xml");

Map<String, File> 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,9 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException {
try {
File serverXML = new File(serverDirectory, "server.xml");

Map<String, File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ protected void undeployApp(File file) throws MojoExecutionException {
try {
File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml");

Map<String, File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ protected Set<String> getAppConfigLocationsFromSourceServerXml() {

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

protected ServerConfigDocument getServerConfigDocument(CommonLoggerI log, File serverXML, Map<String, File> 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());
}
Expand Down

0 comments on commit a9279a2

Please sign in to comment.