Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java =================================================================== diff -u -r60f8ad90ac03834ede1c4a45585f7f117d5844de -r0703d2e19ba200ce75a7a3c38ba4318158bf8e27 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java (.../CreatePackageTask.java) (revision 60f8ad90ac03834ede1c4a45585f7f117d5844de) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java (.../CreatePackageTask.java) (revision 0703d2e19ba200ce75a7a3c38ba4318158bf8e27) @@ -18,127 +18,83 @@ http://www.gnu.org/licenses/gpl.txt */ + +/* + * Created on 29/11/2005 + */ package org.lamsfoundation.lams.tool.deploy; +import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; import java.net.URL; import java.util.Iterator; import java.util.Properties; +import javax.xml.parsers.ParserConfigurationException; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Task; - +import org.xml.sax.SAXException; /** - * 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: - * + * @author mtruong, Original design by Fiona Malikoff * - * @author Fiona Malikoff + * Parent class to all tasks related to the creation of the deployment package. + * */ -public class CreatePackageTask extends Task implements DynamicConfigurator { - +public abstract 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; + + protected DeployConfig deployConfig; + private Properties inputProperties; private Properties deployProperties; + // private static String defaultFilename = "templateDeployTool.xml"; + private static String outputFilename = "deploy.xml"; + /* Ant Task Attributes */ - public String mode = MODE_DEVELOPMENT; + public String mode = MODE_PRODUCTION; 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() { + + 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(); - - } + public abstract void execute(); - /* ************** End Interface/Inherited Methods *****************************/ - /** * add the ant defined properties to deployConfig */ - private void applyParameters() { + protected void applyParameters() { log("Applying task properties"); @@ -150,7 +106,7 @@ } } - private void createDirectory(File dir) { + protected void createDirectory(File dir) { if ( dir.exists() ) { if ( ! dir.isDirectory() ) { throw new BuildException("Unable to write out deploy.properties - path " @@ -168,25 +124,26 @@ /** * @param deployConfig */ - private void writeConfigFile() { + protected void writeConfigFile() throws IOException { String outputName = outputPath+File.separator+outputFilename; - FileOutputStream os=null; + BufferedWriter out=null; try { - os = new FileOutputStream(outputName); - deployConfig.writeProperties(os); + out = new BufferedWriter(new FileWriter(outputName)); + deployConfig.writePropertiesToFile(out); } catch (Exception e) { throw new BuildException("Unable to write out " +outputName+". Error "+e.getMessage(),e); } log("File "+outputName+" written."); + out.close(); } - private URL getTemplateDeployName() { - URL url = CreatePackageTask.class.getResource(defaultFilename); + /* private URL getTemplateDeployName() { + URL url = CreatePackageTask_original.class.getResource(defaultFilename); return url; - } + } */ /** * @param configFile The configFile to set. @@ -213,4 +170,9 @@ this.outputPathSql = null; } } + + + + + }