Index: lams_tool_deploy/.classpath =================================================================== diff -u --- lams_tool_deploy/.classpath (revision 0) +++ lams_tool_deploy/.classpath (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + Index: lams_tool_deploy/.project =================================================================== diff -u --- lams_tool_deploy/.project (revision 0) +++ lams_tool_deploy/.project (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -0,0 +1,22 @@ + + + lams_tool_deploy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.ibm.sse.model.structuredbuilder + + + + + + org.eclipse.jdt.core.javanature + + Index: lams_tool_deploy/build.xml =================================================================== diff -u -rb9682e51114d632fd77ff0feabf3f2de634744bd -r60f8ad90ac03834ede1c4a45585f7f117d5844de --- lams_tool_deploy/build.xml (.../build.xml) (revision b9682e51114d632fd77ff0feabf3f2de634744bd) +++ lams_tool_deploy/build.xml (.../build.xml) (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -29,7 +29,7 @@ - + @@ -79,6 +79,11 @@ + + + + + @@ -102,4 +107,6 @@ + + Index: lams_tool_deploy/deploy.bat =================================================================== diff -u --- lams_tool_deploy/deploy.bat (revision 0) +++ lams_tool_deploy/deploy.bat (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -0,0 +1 @@ +java -classpath lib/lams-tool-deploy.jar;lib/commons-configuration-1.1.jar;lib/commons-lang-2.0.jar;lib/commons-collections.jar;lib/commons-logging.jar;lib/commons-io-1.0.jar;lib/commons-dbutils-1.0.jar;lib/mysql-connector-java-3.1.7-bin.jar org.lamsfoundation.lams.tool.deploy.Deploy ./deploy.properties Index: lams_tool_deploy/deploy.sh =================================================================== diff -u --- lams_tool_deploy/deploy.sh (revision 0) +++ lams_tool_deploy/deploy.sh (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -0,0 +1,4 @@ +#!/bin/sh + + +java -classpath lib/lams-tool-deploy.jar:lib/commons-configuration-1.1.jar:lib/commons-lang-2.0.jar:lib/commons-collections.jar:lib/commons-logging.jar:lib/commons-io-1.0.jar:lib/commons-dbutils-1.0.jar:lib/mysql-connector-java-3.1.7-bin.jar org.lamsfoundation.lams.tool.deploy.Deploy ./deploy.properties Index: lams_tool_deploy/lib/jakarta-commmons/commons-collections-3.1.jar =================================================================== diff -u -r5a1e4424a7fee54a37abf1504b699077bd9f41fa -r60f8ad90ac03834ede1c4a45585f7f117d5844de Binary files differ Index: lams_tool_deploy/lib/jakarta-commmons/commons-collections.jar =================================================================== diff -u Binary files differ Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java =================================================================== diff -u -rabb3194da8bc2d0b6a661e486fd007aa03412ffc -r60f8ad90ac03834ede1c4a45585f7f117d5844de --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java (.../AddWebAppToApplicationXmlTask.java) (revision abb3194da8bc2d0b6a661e486fd007aa03412ffc) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java (.../AddWebAppToApplicationXmlTask.java) (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -23,6 +23,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; /** * Task to add a web application entry to an EAR application XML @@ -44,9 +45,14 @@ protected void updateApplicationXml(Document doc) throws DeployException { - + //find & remove web uri element + Element moduleElement = findElementWithWebURI(doc); + if ( moduleElement != null ) { + doc.getDocumentElement().removeChild(moduleElement); + } + //create new module - Element moduleElement = doc.createElement("module"); + moduleElement = doc.createElement("module"); Element webElement = doc.createElement("web"); moduleElement.appendChild(webElement); //create new web-uri element in the web element Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -0,0 +1,216 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ +package org.lamsfoundation.lams.tool.deploy; + +import java.io.File; +import java.io.FileOutputStream; +import java.net.URL; +import java.util.Iterator; +import java.util.Properties; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DynamicConfigurator; +import org.apache.tools.ant.Task; + +/** + * Create a deployment package. Ant Task. + * + * This class can be used to generate just enough of the deployment (i.e. the + * properties file) to run the deploy as an ant ask, or can create + * the whole deploy package for sending to someone else. + * + * Files created: deploy.properties + * + * A deploy.properties file is created. It is built from three sources - templateDeploy.properties + * in this class' package, a configuration file supplied at runtime and ant task parameter. + * + * First the templateDeploy.properties file is read into a DeployConfig object. + * Then the configuration file is read and the DeployConfig object updated, with the configuration + * file values override the templateDeploy.properties. If the program is running as an ant task, + * the task parameters are checked and all task parameters except for mode and configFile are + * added to the DeployConfig object. So the customised properties can be set up in either + * a configuration file (handy if you aren't using ant) or in a mixture of a configuration file + * and build.xml. Finally, the DeployConfig object is written out to a deploy.properties. + * + * Ant task parameters: + *
    + *
  • (Mandatory) outputPath: path for deploy.properties file.
  • + *
  • (Optional) mode: Values are either development or production. + * If "development" just creates the properties file. + * If "production" then creates the entire package. + * Defaults to "development".
  • + *
  • (Optional) configFile: path to the configuration file that + * contains parameters.
  • + *
  • (Optional) scriptPath: source path for sql files e.g db/sql. + * Must be set if any of the sql script names are set (see next entry).
  • + *
  • (Optional) toolTablesScript, toolActivityInsertScript, + * toolLibraryInsertScript, toolInsertScript: define the name of the + * scripts to be copied from the scriptPath directory to deploy/sql. + * Generates the toolInsertScriptPath, toolLibraryInsertScriptPath, + * toolActivityInsertScriptPath and toolTablesScriptPath entries.
  • + *
  • (Optional) all other parameters go into the deploy.properties file.
  • + *
+ * + * @author Fiona Malikoff + */ +public class CreatePackageTask extends Task implements DynamicConfigurator { + + public static final String MODE = "mode"; + public static final String MODE_DEVELOPMENT = "development"; + public static final String MODE_PRODUCTION = "production"; + + public static final String CONFIG_FILE = "configFile"; + public static final String OUTPUT_PATH = "outputPath"; + public static final String SCRIPT_PATH = "scriptPath"; + + private static String defaultFilename = "templateDeploy.properties"; + private static String outputFilename = "deploy.properties"; + private DeployConfig deployConfig; + private Properties inputProperties; + private Properties deployProperties; + + /* Ant Task Attributes */ + public String mode = MODE_DEVELOPMENT; + public File outputPath = null; + public File configFile = null; + + /* Dependent on outputPath, and set when outputPath is set */ + private File outputPathLib = null; + private File outputPathSql = null; + /** + * + */ + public CreatePackageTask() { + super(); + deployConfig = null; + deployProperties = null; + inputProperties = new Properties(); + } + + /* ************** Dynamic Configurator Methods *****************************/ + public void setDynamicAttribute(String name, String value) { + inputProperties.setProperty(name, value); + } + + public Object createDynamicElement(String name) throws BuildException { + throw new BuildException("CreatePackage does not support elements"); + } + + /* ************** ANT Task Methods *****************************/ + public void execute() { + log("Create Deployment Package."); + + // create the new configuration file, using the template + deployConfig = new DeployConfig(getTemplateDeployName(),false); + + // override with values from an optional config file + if ( configFile != null && configFile.length() > 0 ) { + log("Applying configuration file "+configFile.getAbsolutePath()); + deployConfig.updateConfiguration(configFile.getAbsolutePath(), false); + } + + applyParameters(); + deployConfig.validateProperties(); + writeConfigFile(); + + } + + /* ************** End Interface/Inherited Methods *****************************/ + + /** + * add the ant defined properties to deployConfig + */ + private void applyParameters() { + + log("Applying task properties"); + + Iterator iter = inputProperties.keySet().iterator(); + while ( iter.hasNext() ) { + String key = (String) iter.next(); + // any keys not known to the deployConfig are ignored, so it doesn't matter if we pass mode, etc. + deployConfig.setProperty(key, inputProperties.getProperty(key)); + } + } + + private void createDirectory(File dir) { + if ( dir.exists() ) { + if ( ! dir.isDirectory() ) { + throw new BuildException("Unable to write out deploy.properties - path " + +dir+" exists but is not a directory."); + } + if ( ! dir.canWrite() ) { + throw new BuildException("Unable to write out deploy.properties - path " + +dir+" exists but is read only."); + } + } else { + dir.mkdirs(); + } + } + + /** + * @param deployConfig + */ + private void writeConfigFile() { + + String outputName = outputPath+File.separator+outputFilename; + + FileOutputStream os=null; + try { + os = new FileOutputStream(outputName); + deployConfig.writeProperties(os); + } catch (Exception e) { + throw new BuildException("Unable to write out " + +outputName+". Error "+e.getMessage(),e); + } + log("File "+outputName+" written."); + } + + private URL getTemplateDeployName() { + URL url = CreatePackageTask.class.getResource(defaultFilename); + return url; + } + + /** + * @param configFile The configFile to set. + */ + public void setConfigFile(File configFile) { + this.configFile = configFile; + } + /** + * @param mode The mode to set. + */ + public void setMode(String mode) { + this.mode = mode; + } + /** + * @param outputPath The outputPath to set. + */ + public void setOutputPath(File outputPath) { + this.outputPath = outputPath; + if ( outputPath != null ) { + this.outputPathLib = new File(outputPath.getAbsoluteFile()+File.separator+"lib"); + this.outputPathSql = new File(outputPath.getAbsoluteFile()+File.separator+"sql"); + } else { + this.outputPathLib = null; + this.outputPathSql = null; + } + } +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java =================================================================== diff -u -rabb3194da8bc2d0b6a661e486fd007aa03412ffc -r60f8ad90ac03834ede1c4a45585f7f117d5844de --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java (.../Deploy.java) (revision abb3194da8bc2d0b6a661e486fd007aa03412ffc) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java (.../Deploy.java) (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -23,7 +23,15 @@ /** * Tool Deployer Main Class - * @author chris + * + * Command Line Parameters: + * properties_file_path: mandatory + * forcedb: optional, defaults to false. if true, deletes any old entries in db. + * + * Only use forceDB for development - not designed for production. If forceDB is set, + * then toolSignature and toolTablesDeleteScriptPath are needed. + * + * @author Chris Perfect, modifications by Fiona Malikoff */ public class Deploy { @@ -40,17 +48,34 @@ public static void main(String[] args) throws Exception { - if ((args.length != 1) || (args[0] == null)) + if ((args.length < 1) || (args[0] == null)) { - throw new IllegalArgumentException("Usage: Deployer "); + throw new IllegalArgumentException("Usage: Deployer "); } System.out.println("Starting Tool Deploy"); try { - System.out.println("Reading Configuration File"); - DeployConfig config = new DeployConfig(args[0]); + System.out.println("Reading Configuration File"+args[0]); + DeployConfig config = new DeployConfig(args[0],true); + Boolean forceDB = Boolean.FALSE; + if ( args.length == 2 && args[1] != null) { + forceDB = new Boolean(args[1]); + } + + if ( forceDB.booleanValue() ) { + System.out.println("Removing old tool entries from database"); + ToolDBRemoveToolEntriesTask dbRemoveTask = new ToolDBRemoveToolEntriesTask(); + dbRemoveTask.setDbUsername(config.getDbUsername()); + dbRemoveTask.setDbPassword(config.getDbPassword()); + dbRemoveTask.setDbDriverClass(config.getDbDriverClass()); + dbRemoveTask.setDbDriverUrl(config.getDbDriverUrl()); + dbRemoveTask.setToolSignature(config.getToolSignature()); + dbRemoveTask.setToolTablesDeleteScriptPath(config.getToolTablesDeleteScriptPath()); + dbRemoveTask.execute(); + } + System.out.println("Running Tool DB Deploy"); ToolDBDeployTask dbDeployTask = new ToolDBDeployTask(); dbDeployTask.setDbUsername(config.getDbUsername()); @@ -63,7 +88,6 @@ dbDeployTask.setToolTablesScriptPath(config.getToolTablesScriptPath()); dbDeployTask.execute(); - System.out.println("Updating application.xml"); AddWebAppToApplicationXmlTask addWebAppTask = new AddWebAppToApplicationXmlTask(); addWebAppTask.setLamsEarPath(config.getLamsEarPath()); addWebAppTask.setContextRoot(config.getToolContextRoot()); Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java =================================================================== diff -u -rabb3194da8bc2d0b6a661e486fd007aa03412ffc -r60f8ad90ac03834ede1c4a45585f7f117d5844de --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java (.../DeployConfig.java) (revision abb3194da8bc2d0b6a661e486fd007aa03412ffc) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java (.../DeployConfig.java) (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) @@ -21,33 +21,45 @@ package org.lamsfoundation.lams.tool.deploy; -import java.util.List; +import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; -import org.apache.commons.configuration.PropertiesConfiguration; +import java.util.List; + import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; /** * Encapsulates configuration data for the Deployer. * @author chris */ public class DeployConfig { - //public static final String PROPERTIES_FILE_PATH = "/home/chris/workspace/lams_tool_deploy/test/file/deploy.properties"; + public static final String TOOL_SIGNATURE_KEY = "toolSignature"; public static final String TOOL_WEB_URI_KEY = "toolWebUri"; public static final String TOOL_CONTEXT_KEY = "toolContext"; public static final String LAMS_EAR_PATH_KEY = "lamsEarPath"; public static final String TOOL_INSERT_SCRIPT_PATH_KEY = "toolInsertScriptPath"; public static final String TOOL_LIBRARY_INSERT_SCRIPT_PATH_KEY = "toolLibraryInsertScriptPath"; public static final String TOOL_ACTIVITY_INSERT_SCRIPT_PATH_KEY = "toolActivityInsertScriptPath"; public static final String TOOL_TABLES_SCRIPT_PATH_KEY = "toolTablesScriptPath"; + public static final String TOOL_TABLES_DELETE_SCRIPT_PATH_KEY = "toolTablesDeleteScriptPath"; public static final String DB_USERNAME_KEY = "dbUsername"; public static final String DB_PASSWORD_KEY = "dbPassword"; public static final String DB_DRIVER_CLASS_KEY = "dbDriverClass"; public static final String DB_DRIVER_URL_KEY = "dbDriverUrl"; public static final String DEPLOY_FILES_KEY = "deployFiles"; private PropertiesConfiguration props = null; + private String validationError = ""; + + /** + * Holds value of property toolSignature. + */ + private String toolSignature; + + /** * Holds value of property toolWebUri. */ private String toolWebUri; @@ -83,6 +95,11 @@ private String toolTablesScriptPath; /** + * Holds value of property toolTablesDeleteScriptPath. + */ + private String toolTablesDeleteScriptPath; + + /** * Holds value of property deployFiles. */ private List deployFiles; @@ -107,40 +124,182 @@ */ private String dbDriverUrl; - /** Creates a new instance of DeployConfig */ - public DeployConfig(final String deployPropertiesFilePath) throws DeployException + /** Creates a new instance of DeployConfig + * @param deployPropertiesFilePath file to load + * @param validate validate the properties after loading. Set to false if + * intending to load some more properties later. + * @throws DeployException if a configuration error occurs or if the validation fails. + */ + public DeployConfig(final String deployPropertiesFilePath, final boolean validate) throws DeployException { - try - { - props = new PropertiesConfiguration(deployPropertiesFilePath); - toolWebUri = getProperty(TOOL_WEB_URI_KEY); - toolContextRoot = getProperty(TOOL_CONTEXT_KEY); - lamsEarPath = getProperty(LAMS_EAR_PATH_KEY); - toolInsertScriptPath = getProperty(TOOL_INSERT_SCRIPT_PATH_KEY); - toolLibraryInsertScriptPath = getProperty(TOOL_LIBRARY_INSERT_SCRIPT_PATH_KEY); - toolActivityInsertScriptPath = getProperty(TOOL_ACTIVITY_INSERT_SCRIPT_PATH_KEY); - toolTablesScriptPath = getProperty(TOOL_TABLES_SCRIPT_PATH_KEY); - dbUsername = getProperty(DB_USERNAME_KEY); - dbPassword = getProperty(DB_PASSWORD_KEY); - dbDriverClass = getProperty(DB_DRIVER_CLASS_KEY); - dbDriverUrl = getProperty(DB_DRIVER_URL_KEY); - deployFiles = getPropertyList(DEPLOY_FILES_KEY); - + updateConfiguration(deployPropertiesFilePath, validate); + } + /** Creates a new instance of DeployConfig + * @param deployPropertiesFilePath file to load + * @param validate validate the properties after loading. Set to false if + * intending to load some more properties later. + * @throws DeployException if a configuration error occurs or if the validation fails. + */ + public DeployConfig(final URL deployPropertiesFilePath, final boolean validate) throws DeployException + { + updateConfiguration(deployPropertiesFilePath, validate); + } + + /** Update the configuration. Only updates a value if a particular property is found. + * @param deployPropertiesFilePath: file to load + * @param validate validate the properties after loading. Set to false if + * intending to load some more properties later. + * @throws DeployException if a configuration error occurs or if the validation fails. + */ + public void updateConfiguration(final URL deployPropertiesFilePath, final boolean validate) + throws DeployException + { + try { + props = new PropertiesConfiguration(deployPropertiesFilePath); + updateConfigurationFromProps(validate); + } catch (ConfigurationException confex) { + throw new DeployException("Failed to load configuration", confex); + } + } + + /** Update the configuration. Only updates a value if a particular property is found. + * @param deployPropertiesFilePath: file to load + * @param validate validate the properties after loading. Set to false if + * intending to load some more properties later. + * @throws DeployException if a configuration error occurs or if the validation fails. + */ + public void updateConfiguration(final String deployPropertiesFilePath, final boolean validate) + throws DeployException + { + try { + props = new PropertiesConfiguration(deployPropertiesFilePath); + updateConfigurationFromProps(validate); + } catch (ConfigurationException confex) { + throw new DeployException("Failed to load configuration", confex); + } + } + + + /** Update the current configuration from the props variable - which should + * have already been set by the calling function. + * @param validate validate the properties after loading. Set to false if + * intending to load some more properties later. + */ + private void updateConfigurationFromProps (final boolean validate) { + + String value = getProperty(TOOL_SIGNATURE_KEY); + if ( value != null ) { + toolSignature = value; } - catch (ConfigurationException confex) - { - throw new DeployException("Failed to load configuration", confex); + + value = getProperty(TOOL_WEB_URI_KEY); + if ( value != null ) { + toolWebUri = value; } + + value = getProperty(TOOL_CONTEXT_KEY); + if ( value != null ) { + toolContextRoot = value; + } + + value = getProperty(LAMS_EAR_PATH_KEY); + if ( value != null ) { + lamsEarPath = value; + } + + value = getProperty(TOOL_INSERT_SCRIPT_PATH_KEY); + if ( value != null ) { + toolInsertScriptPath = value; + } + + value = getProperty(TOOL_LIBRARY_INSERT_SCRIPT_PATH_KEY); + if ( value != null ) { + toolLibraryInsertScriptPath = value; + } + + value = getProperty(TOOL_ACTIVITY_INSERT_SCRIPT_PATH_KEY); + if ( value != null ) { + toolActivityInsertScriptPath = value; + } + + value = getProperty(TOOL_TABLES_SCRIPT_PATH_KEY); + if ( value != null ) { + toolTablesScriptPath = value; + } + + value = getProperty(TOOL_TABLES_DELETE_SCRIPT_PATH_KEY); + if ( value != null ) { + toolTablesDeleteScriptPath = value; + } + + value = getProperty(DB_USERNAME_KEY); + if ( value != null ) { + dbUsername = value; + } + + value = getProperty(DB_PASSWORD_KEY); + if ( value != null ) { + dbPassword = value; + } + + value = getProperty(DB_DRIVER_CLASS_KEY); + if ( value != null ) { + dbDriverClass = value; + } + + value = getProperty(DB_DRIVER_URL_KEY); + if ( value != null ) { + dbDriverUrl = value; + } + + List listValue = getPropertyList(DEPLOY_FILES_KEY); + if ( listValue != null && listValue.size() > 0) { + deployFiles = listValue; + } + + if ( validate ) + validateProperties(); } + + /** + * Write out the current settings to the supplied stream. + * + * @param outputStream + */ + public void writeProperties(OutputStream os) { + if ( os == null ) { + throw new DeployException("Invalid parameter - outputStream os is null"); + } + + PropertiesConfiguration newProps = new PropertiesConfiguration(); + newProps.setProperty(TOOL_SIGNATURE_KEY,toolSignature); + newProps.setProperty(TOOL_WEB_URI_KEY,toolWebUri); + newProps.setProperty(TOOL_CONTEXT_KEY,toolContextRoot); + newProps.setProperty(LAMS_EAR_PATH_KEY,lamsEarPath); + newProps.setProperty(TOOL_INSERT_SCRIPT_PATH_KEY,toolInsertScriptPath); + newProps.setProperty(TOOL_LIBRARY_INSERT_SCRIPT_PATH_KEY,toolLibraryInsertScriptPath); + newProps.setProperty(TOOL_ACTIVITY_INSERT_SCRIPT_PATH_KEY,toolActivityInsertScriptPath); + newProps.setProperty(TOOL_TABLES_SCRIPT_PATH_KEY,toolTablesScriptPath); + newProps.setProperty(TOOL_TABLES_DELETE_SCRIPT_PATH_KEY,toolTablesDeleteScriptPath); + newProps.setProperty(DB_USERNAME_KEY,dbUsername); + newProps.setProperty(DB_PASSWORD_KEY,dbPassword); + newProps.setProperty(DB_DRIVER_CLASS_KEY,dbDriverClass); + newProps.setProperty(DB_DRIVER_URL_KEY,dbDriverUrl); + newProps.setProperty(DEPLOY_FILES_KEY,deployFiles); + + try { + newProps.save(os); + } catch (ConfigurationException e) { + throw new DeployException("Unable to create generate properties: "+e.getMessage(), e); + } + } /** * The value to be used in the web-uri element of the application xml * for the tool being deployed. * @return Value of property toolWebAppUri. */ public String getToolWebUri() - - { return this.toolWebUri; @@ -267,34 +426,246 @@ } /** - * Tries to load the property for the given key. + * Set an arbitrary property. Note: these will probably have come through + * ant, and that removes the case of the key, so ignore case. + */ + protected void setProperty(String key, String value) throws DeployException { + if ( key == null ) + throw new DeployException("Invalid parameter: Key is null. "); + + if ( key.equalsIgnoreCase(TOOL_SIGNATURE_KEY) ) { + toolSignature = value; + } + + if ( key.equalsIgnoreCase(TOOL_WEB_URI_KEY) ) { + toolWebUri = value; + } + + if ( key.equalsIgnoreCase(TOOL_CONTEXT_KEY) ) { + toolContextRoot = value; + } + + if ( key.equalsIgnoreCase(LAMS_EAR_PATH_KEY) ) { + lamsEarPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_INSERT_SCRIPT_PATH_KEY) ) { + toolInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_LIBRARY_INSERT_SCRIPT_PATH_KEY) ) { + toolLibraryInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_ACTIVITY_INSERT_SCRIPT_PATH_KEY) ) { + toolActivityInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_TABLES_SCRIPT_PATH_KEY) ) { + toolTablesScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_TABLES_DELETE_SCRIPT_PATH_KEY) ) { + toolTablesDeleteScriptPath = value; + } + + if ( key.equalsIgnoreCase(DB_USERNAME_KEY) ) { + dbUsername = value; + } + + if ( key.equalsIgnoreCase(DB_PASSWORD_KEY) ) { + dbPassword = value; + } + + if ( key.equalsIgnoreCase(DB_DRIVER_CLASS_KEY) ) { + dbDriverClass = value; + } + + if ( key.equalsIgnoreCase(DB_DRIVER_URL_KEY) ) { + dbDriverUrl = value; + } + + if ( key.equalsIgnoreCase(DEPLOY_FILES_KEY) ) { + deployFiles = convertList(value); + } + + } + /** + * @param dbDriverUrl The dbDriverUrl to set. + */ + protected void setDbDriverUrl(String dbDriverUrl) { + this.dbDriverUrl = dbDriverUrl; + } + /** + * @param dbPassword The dbPassword to set. + */ + protected void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + /** + * @param dbUsername The dbUsername to set. + */ + protected void setDbUsername(String dbUsername) { + this.dbUsername = dbUsername; + } + /** + * @param deployFiles The deployFiles to set. + */ + protected void setDeployFiles(List deployFiles) { + this.deployFiles = deployFiles; + } + /** + * @param lamsEarPath The lamsEarPath to set. + */ + protected void setLamsEarPath(String lamsEarPath) { + this.lamsEarPath = lamsEarPath; + } + /** + * @param toolActivityInsertScriptPath The toolActivityInsertScriptPath to set. + */ + protected void setToolActivityInsertScriptPath( + String toolActivityInsertScriptPath) { + this.toolActivityInsertScriptPath = toolActivityInsertScriptPath; + } + /** + * @param toolContextRoot The toolContextRoot to set. + */ + protected void setToolContextRoot(String toolContextRoot) { + this.toolContextRoot = toolContextRoot; + } + /** + * @param toolInsertScriptPath The toolInsertScriptPath to set. + */ + protected void setToolInsertScriptPath(String toolInsertScriptPath) { + this.toolInsertScriptPath = toolInsertScriptPath; + } + /** + * @param toolLibraryInsertScriptPath The toolLibraryInsertScriptPath to set. + */ + protected void setToolLibraryInsertScriptPath( + String toolLibraryInsertScriptPath) { + this.toolLibraryInsertScriptPath = toolLibraryInsertScriptPath; + } + /** + * @param toolTablesScriptPath The toolTablesScriptPath to set. + */ + protected void setToolTablesScriptPath(String toolTablesScriptPath) { + this.toolTablesScriptPath = toolTablesScriptPath; + } + /** + * @param toolWebUri The toolWebUri to set. + */ + protected void setToolWebUri(String toolWebUri) { + this.toolWebUri = toolWebUri; + } + + /** + * Tries to load the property for the given key from the props object. * @param key the key to the desired property. - * @return String the property value - * @throws DeployException if the property cannot be found. + * @return String the property value or null if not found in props. */ protected String getProperty(final String key) throws DeployException { String property = props.getString(key); - if ((property == null) || (property.length() < 1)) - { - throw new DeployException("Property "+key+" is missing or has no value"); + if ( property !=null && property.length() > 0 ) { + return property; + } else { + return null; } - return property; } - + /** - * Returns a list of property strings for the given key. + * Returns a list of property strings for the given key from the props object. * @param key identifies the property to locate - * @return List of (String) properties - * @throws DeployException if there are no matches + * @return List of (String) properties, null if not found. */ protected List getPropertyList(final String key) throws DeployException { List propsList = props.getList(key); - if ((propsList == null) || (propsList.isEmpty())) + if ((propsList != null) && !propsList.isEmpty()) { - throw new DeployException("Property List "+key+" is missing or empty"); + return propsList; + } else { + return null; } - return propsList; } + + /** + * Converts a String to a List. Entries should be comma separated. + * @param Input string containing entries. + * @return List of (String) properties, null if not found. + */ + protected List convertList(String input) throws DeployException + { + String[] strings = input.split(","); + List list = new ArrayList(strings.length); + for ( int i=0; i 0); + } }