From 191b1564dc1229d5cb69bd27c80f4bf2b0b40138 Mon Sep 17 00:00:00 2001 From: AbzoX Date: Fri, 4 Dec 2015 15:54:05 -0600 Subject: [PATCH 1/4] whenFileExists parameter removed from README. --- README.md | 6 +++--- src/it/basic/build.xml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 39da0264..86f2daf5 100644 --- a/README.md +++ b/README.md @@ -245,12 +245,12 @@ To install the features from the `server.xml` file, don't specify any features i #### Examples 1. Install a single feature using the `name` parameter. ```ant - + ``` 2. Install one or more features using nested `feature` elements. ```ant - + mongodb-2.0 oauth-2.0 @@ -258,7 +258,7 @@ To install the features from the `server.xml` file, don't specify any features i 3. Install all the not-installed features from the server. ```ant - ``` diff --git a/src/it/basic/build.xml b/src/it/basic/build.xml index f6a64988..d2529eb2 100644 --- a/src/it/basic/build.xml +++ b/src/it/basic/build.xml @@ -31,6 +31,7 @@ + From f54259d194442bea4f149cab63cc2fa9085cf144 Mon Sep 17 00:00:00 2001 From: AbzoX Date: Fri, 4 Dec 2015 15:54:29 -0600 Subject: [PATCH 2/4] Deploy to configDropins/overrides as xml ability added to deploy task. --- .../java/net/wasdev/wlp/ant/DeployTask.java | 105 +++++++++++++++++- .../java/net/wasdev/wlp/ant/UndeployTask.java | 52 ++++++++- .../net/wasdev/wlp/ant/AntMessages.properties | 10 +- 3 files changed, 157 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/wasdev/wlp/ant/DeployTask.java b/src/main/java/net/wasdev/wlp/ant/DeployTask.java index 8dabc6d9..c47f77f3 100644 --- a/src/main/java/net/wasdev/wlp/ant/DeployTask.java +++ b/src/main/java/net/wasdev/wlp/ant/DeployTask.java @@ -16,7 +16,9 @@ package net.wasdev.wlp.ant; import java.io.IOException; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -37,9 +39,15 @@ public class DeployTask extends AbstractTask { private String filePath; private String timeout; private static final long APP_START_TIMEOUT_DEFAULT = 30 * 1000; + // Deploy destination + private String deployTo = "dropins"; + private long appStartTimeout; @Override public void execute() { + if (!deployTo.equals("dropins") && !deployTo.equals("configDropins")) { + throw new BuildException(MessageFormat.format(messages.getString("error.parameter.type.invalid"), "deployTo")); + } super.initTask(); @@ -50,11 +58,20 @@ public void execute() { final List files = scanFileSets(); - long appStartTimeout = APP_START_TIMEOUT_DEFAULT; + appStartTimeout = APP_START_TIMEOUT_DEFAULT; if (timeout != null && !timeout.equals("")) { appStartTimeout = Long.valueOf(timeout); } + + if (deployTo.equals("dropins")) { + deployToDropins(files); + } else { + deployToXml(files); + } + } + private void deployToDropins(List files) { + // Copy the files to serverConfigDir/dropins File dropInFolder = new File(serverConfigDir, "dropins"); for (File file : files) { File destFile = new File(dropInFolder, file.getName()); @@ -64,12 +81,74 @@ public void execute() { } catch (IOException e) { throw new BuildException(messages.getString("error.deploy.fail")); } - // Check start message code - String startMessage = START_APP_MESSAGE_CODE_REG + getFileName(file.getName()); - if (waitForStringInLog(startMessage, appStartTimeout, getLogFile()) == null) { - throw new BuildException(MessageFormat.format(messages.getString("error.deploy.fail"), file.getPath())); + + // Check the deploy, if it is not correct, don't delete the app file. + checkDeploy(destFile, false); + } + } + + private void deployToXml(List files) { + // Create a new file appName.extension.xml in serverConfigDir/configDropins/overrides + File overridesFolder = new File(serverConfigDir, "configDropins/overrides"); + + if (!overridesFolder.exists()) { + // If directory does not exist, create it + if (!overridesFolder.mkdirs()) { + // Fail if it can not be created + throw new BuildException(MessageFormat.format(messages.getString("error.deploy.fail"), overridesFolder.getPath())); } } + + for (File app : files) { + // For each file... + String appName = app.getName(); + String appLocation = app.getAbsolutePath(); + + // Create a new file in the configDropins/overrides with extension xml + File xmlApp = new File(overridesFolder, appName + ".xml"); + + if (xmlApp.exists()) { + // If app already deployed, send a log and continue to the next one + log(MessageFormat.format(messages.getString("info.app.already.deployed"), appName)); + continue; + } + + // The xml code to put in the file + String xml = "\n" + + "\n" + + ""; + + try { + // Create the file and add the xml + xmlApp.createNewFile(); + FileWriter fileWriter = new FileWriter(xmlApp.getAbsoluteFile()); + BufferedWriter buffer = new BufferedWriter(fileWriter); + buffer.write(xml); + buffer.close(); + } catch (IOException e) { + throw new BuildException(MessageFormat.format(messages.getString("error.deploy.fail"), xmlApp.getPath())); + } + + // Check the deploy, if it is not correct, delete the xml file created + checkDeploy(xmlApp, true); + + } + } + + /** + * Checks the messages.log to verify the deploy of the app + * @param file The file deployed. + * @param deleteIfFail If the start log is not found, delete the app file. + */ + private void checkDeploy(File file, boolean deleteIfFail) { + // Check start message code + String startMessage = START_APP_MESSAGE_CODE_REG + getFileName(file.getName()); + if (waitForStringInLog(startMessage, appStartTimeout, getLogFile()) == null) { + if (deleteIfFail) { + file.delete(); + } + throw new BuildException(MessageFormat.format(messages.getString("error.deploy.fail"), file.getPath())); + } } /** @@ -142,5 +221,21 @@ public String getTimeout() { public void setTimeout(String timeout) { this.timeout = timeout; } + + /** + * @return the deploy location + */ + public String getDeployTo() { + return deployTo; + } + + /** + * @param deployTo The deploy destination. If it is set to 'dropins', the apps will be copied to the dropins folder. + * Else if the value is 'xml', an entry of type 'application' will be added in the configDropins/overrides/appName.xml + * file. + */ + public void setDeployTo(String deployTo) { + this.deployTo = deployTo; + } } diff --git a/src/main/java/net/wasdev/wlp/ant/UndeployTask.java b/src/main/java/net/wasdev/wlp/ant/UndeployTask.java index e32d51ac..d3cac1c4 100644 --- a/src/main/java/net/wasdev/wlp/ant/UndeployTask.java +++ b/src/main/java/net/wasdev/wlp/ant/UndeployTask.java @@ -37,9 +37,14 @@ public class UndeployTask extends AbstractTask { private PatternSet pattern; private String timeout; private static final long APP_STOP_TIMEOUT_DEFAULT = 30 * 1000; + private String from = "dropins"; @Override public void execute() { + if (!from.equals("dropins") && !from.equals("configDropins")) { + throw new BuildException(MessageFormat.format(messages.getString("error.parameter.type.invalid"), "from")); + } + super.initTask(); final List files = scanFileSets(); @@ -50,6 +55,14 @@ public void execute() { } for (File file : files) { + if (from.equals("configDropins")) { + // If undeploying a xml file, change the file location to overrides + file = new File(serverConfigDir, "configDropins/overrides/" + file.getName()); + + if (!file.exists()) { + throw new BuildException(MessageFormat.format(messages.getString("error.undeploy.file.noexist"), file.getPath())); + } + } log(MessageFormat.format(messages.getString("info.undeploy"), file.getName())); FileUtils.delete(file); @@ -62,16 +75,37 @@ public void execute() { } private List scanFileSets() throws BuildException { - File dropinsDir = new File(serverConfigDir, "dropins"); + File dropinsDir; + + if (from.equals("dropins")) { + // If undeploying from dropins, set serverConfigDir/dropins as the root dir + dropinsDir = new File(serverConfigDir, "dropins"); + + } else { + // If undeploying from xml, set serverConfigDir/configDropins/overrides as the root dir + dropinsDir = new File(serverConfigDir, "configDropins/overrides"); + + } + final List list = new ArrayList(); if (fileName != null) { - File fileUndeploy = new File(dropinsDir, fileName); + File fileUndeploy; + + if (from.equals("dropins")) { + fileUndeploy = new File(dropinsDir, fileName); + + } else { + // If undeploying from xml, add the xml extension to the fileName + fileUndeploy = new File(dropinsDir, fileName + ".xml"); + } + if (fileUndeploy.exists()) { list.add(fileUndeploy); } else { throw new BuildException(MessageFormat.format(messages.getString("error.undeploy.file.noexist"), fileUndeploy.getPath())); } + } else { FileSet dropins = new FileSet(); dropins.setDir(dropinsDir); @@ -121,5 +155,19 @@ public void setTimeout(String timeout) { public void addPatternset(PatternSet pattern) { this.pattern=pattern; } + + /** + * @return From which location the app will be undeployed. + */ + public String getFrom() { + return from; + } + + /** + * @param from The location from which the app will be undeployed. + */ + public void setFrom(String from) { + this.from = from; + } } diff --git a/src/main/resources/net/wasdev/wlp/ant/AntMessages.properties b/src/main/resources/net/wasdev/wlp/ant/AntMessages.properties index 6b4e02f3..e3c3eff3 100644 --- a/src/main/resources/net/wasdev/wlp/ant/AntMessages.properties +++ b/src/main/resources/net/wasdev/wlp/ant/AntMessages.properties @@ -106,9 +106,9 @@ error.parameter.empty=CWWKM2027E: The {0} parameter is empty. error.parameter.empty.explanation=The {0} parameter is empty. error.parameter.empty.useraction=Correct the value of the file parameter. -error.parameter.type.invalid=CWWKM2028E: The {0} parameter is not supported. -error.parameter.type.invalid.explanation=The {0} parameter is not supported. -error.parameter.type.invalid.useraction=Correct the value of the file parameter. +error.parameter.type.invalid=CWWKM2028E: The {0} parameter value is not supported. +error.parameter.type.invalid.explanation=The {0} parameter value is not supported. +error.parameter.type.invalid.useraction=Correct the value of the parameter. info.element.cleaned=CWWKM2029I: All the {0} elements have been deleted. info.element.cleaned.explanation=All the {0} elements have been deleted. @@ -121,3 +121,7 @@ info.directory.noexist.useraction=No action is required. error.cannot.delete.file=CWWKM2031E: Cannot delete file {0}. error.cannot.delete.file.explanation=Cannot delete file {0}. error.cannot.delete.file.useraction=Verify that the file is not in use. + +info.app.already.deployed=CWWKM2032I: The application {0} is already deployed. +info.app.already.deployed.explanation=The application {0} is already deployed. +info.app.already.deployed.useraction=No action is required. From ace5421a4cc4e6447e4c4069da1d6b06a2000de3 Mon Sep 17 00:00:00 2001 From: AbzoX Date: Fri, 4 Dec 2015 15:54:32 -0600 Subject: [PATCH 3/4] Update IT: deploy/undeploy using xml files. --- src/it/basic/build.xml | 21 +++++++++++++++++++ src/it/basic/pom.xml | 8 +++++++ .../net/wasdev/wlp/ant/test/AppsTest.java | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/src/it/basic/build.xml b/src/it/basic/build.xml index d2529eb2..37c4a379 100644 --- a/src/it/basic/build.xml +++ b/src/it/basic/build.xml @@ -61,6 +61,27 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/basic/pom.xml b/src/it/basic/pom.xml index 5138ccfa..de4e7267 100644 --- a/src/it/basic/pom.xml +++ b/src/it/basic/pom.xml @@ -107,6 +107,7 @@ + @@ -118,6 +119,7 @@ + @@ -148,6 +150,9 @@ used if the server is installed by the installServer target.--> + + + @@ -159,6 +164,9 @@ + + + diff --git a/src/it/basic/src/test/java/net/wasdev/wlp/ant/test/AppsTest.java b/src/it/basic/src/test/java/net/wasdev/wlp/ant/test/AppsTest.java index dd92c08a..45bdf005 100644 --- a/src/it/basic/src/test/java/net/wasdev/wlp/ant/test/AppsTest.java +++ b/src/it/basic/src/test/java/net/wasdev/wlp/ant/test/AppsTest.java @@ -17,6 +17,11 @@ public void testHelloWAR() { public void testSimpleEBA() { runTest("test-wab/index.jsp"); } + + @Test + public void testHelloWARXml() { + runTest("test-war-xml/index.jsp"); + } private void runTest(String test) { String port = System.getProperty("HTTP_default", "9080"); From 62b5308fc52b7153b1350acd748f82a857a07d2c Mon Sep 17 00:00:00 2001 From: AbzoX Date: Fri, 4 Dec 2015 15:54:36 -0600 Subject: [PATCH 4/4] Update README: deployTo/from parameters added to deploy/undeploy tasks. --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 86f2daf5..bbefa2c8 100644 --- a/README.md +++ b/README.md @@ -157,10 +157,11 @@ The `deploy` task supports deployment of one or more applications to the Liberty | file | Location of a single application to be deployed. See [file attribute in Apache Ant](http://ant.apache.org/manual/Types/fileset.html). The application type can be war, ear, rar, eba, zip , or jar. | Yes, only when the `fileset` attribute is not specified. | | fileset | Location of multiple applications to be deployed. See [fileset attribute in Apache Ant](http://ant.apache.org/manual/Types/fileset.html). | Yes, only when the `file` attribute is not specified.| | timeout| Waiting time before the deployment completes successfully. The default value is 30 seconds. The unit is milliseconds. | No | +| deployTo| Specify the deploy destination. The possible values are `dropins` and `configDropins`. When deploying to `dropins`, the file will be copied to `${wlp_user_dir}/dropins`, but when deploying to `configDropins`, a new xml file _appName.extension.xml_ will be created in `${wlp_user_dir}/configDropins/overrides` (The directory will be created if it does not exist) containing the server _application_ entry with the file location and name. The default value is `dropins`. | No | #### Examples -1. Using `fileset`. +1. Deploy applications to the dropins folder using `fileset`. ```ant @@ -170,11 +171,27 @@ The `deploy` task supports deployment of one or more applications to the Liberty ``` -2. Using `file`. +2. Deploy of a single application to the dropins folder using `file`. ```ant -``` + ``` + +3. Deploy applications to the configDropins/overrides folder as _appName.extension.xml_ using `fileset`. + + ```ant + + + + + + ``` + +4. Deploy of a single application to the configDropins/overrides folder as _appName.extension.xml_ using `file`. + + ```ant + + ``` ### undeploy task --- @@ -193,17 +210,18 @@ The `undeploy` task supports undeployment of a single application from the Liber | file | Name of the application to be undeployed. The application type can be war, ear, rar, eba, zip , or jar. | No | | patternset | Includes and excludes patterns of applications to be undeployed. See [patternset attribute in Apache Ant](http://ant.apache.org/manual/Types/patternset.html). | No | | timeout | Waiting time before the undeployment completes successfully. The default value is 30 seconds. The unit is milliseconds. | No | +| from | From where the application will be undeployed. The possible values are `dropins` and `configDropins`. The default value is `dropins`. | No | When `file` has been set the `patternset` parameter will be ignored, also when the `file` and `patternset` parameters are not set the task will undeploy all the deployed applications. #### Examples -1. Undeploy the `SimpleOSGiApp.eba` application. +1. Undeploy the `SimpleOSGiApp.eba` application from the dropins folder. ```ant ``` -2. Undeploy all the applications with the `.war` extension except the `example.war` file. +2. Undeploy all the applications with the `.war` extension except the `example.war` file from the dropins folder. ```ant @@ -215,11 +233,35 @@ When `file` has been set the `patternset` parameter will be ignored, also when t ``` -3. Undeploy all the applications previously deployed on the server. +3. Undeploy all the applications previously deployed on the dropins folder. ```ant ``` + + 4. Undeploy the `SimpleOSGiApp.eba` application xml entry from the configDropins/overrides folder. + + ```ant + + ``` + +5. Undeploy all the applications with the `.war.xml` extension except the `example.war.xml` file from the configDropins/overrides folder. + + ```ant + + + + + + + + ``` + +6. Undeploy all the applications previously deployed on the configDropins/overrides folder. + + ```ant + + ``` ### install-feature task ---