Index: lams_build/deploy-tool/lib/lams-tool-deploy.jar =================================================================== RCS file: /usr/local/cvsroot/lams_build/deploy-tool/lib/lams-tool-deploy.jar,v diff -u -r1.24.2.2 -r1.24.2.3 Binary files differ Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java,v diff -u -r1.6.6.1 -r1.6.6.2 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java 5 May 2009 02:03:03 -0000 1.6.6.1 +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/CreatePackageTask.java 5 May 2009 02:27:01 -0000 1.6.6.2 @@ -38,169 +38,184 @@ import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; + /** * @author mtruong, Original design by Fiona Malikoff - * + * * Parent class to all tasks related to the creation of the deployment package. * */ -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"; - - protected DeployConfig deployConfig; - - private Properties inputProperties; - private Properties deployProperties; - - private static String templateFileName = "deploy_template.xml"; - private static String outputFilename = "deploy.xml"; - - /* Ant Task Attributes */ - 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 abstract class CreatePackageTask extends Task implements + DynamicConfigurator { - 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"); - } - - public abstract void execute(); - - /** - * add the ant defined properties to deployConfig - */ - protected void applyParameters() { + public static final String MODE = "mode"; + public static final String MODE_DEVELOPMENT = "development"; + public static final String MODE_PRODUCTION = "production"; - 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. - // The only vectors will be filesets. - deployConfig.setProperty(key, (String) inputProperties.getProperty(key)); - } - } + public static final String CONFIG_FILE = "configFile"; + public static final String OUTPUT_PATH = "outputPath"; + public static final String SCRIPT_PATH = "scriptPath"; - protected void applyFilesets(String key, Vector filesets) { - ArrayList filenames = new ArrayList(); - for ( FileSet fileset : filesets) { - DirectoryScanner ds = fileset.getDirectoryScanner(getProject()); - String[] files = ds.getIncludedFiles(); - for ( String filename: files ) { - filenames.add(ds.getBasedir()+File.separator+filename); - } - } - - deployConfig.setFilenames(key, filenames); - } + protected DeployConfig deployConfig; - protected 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 - */ - protected void writeConfigFile() throws IOException { - - String outputName = outputPath+File.separator+outputFilename; - - - BufferedWriter out=null; - BufferedWriter out2=null; - try { - out = new BufferedWriter(new FileWriter(outputName)); - deployConfig.writePropertiesToFile(out); - log("File "+outputName+" written."); - - if (deployConfig instanceof DeployToolConfig){ - DeployToolConfig deployToolConfig = (DeployToolConfig)deployConfig; - deployToolConfig.setGenerateForInstallers(true); - deployToolConfig.convertForInstallers(); - String outputName2 = outputPath+File.separator+templateFileName; - - out2 = new BufferedWriter(new FileWriter(outputName2)); - deployToolConfig.writePropertiesToFile(out2); - log("File "+outputName2+" written."); - } - } catch (Exception e) { - throw new BuildException("Unable to write out " - +outputName+". Error "+e.getMessage(),e); - } finally { - out.close(); - out2.close(); - } - } + private Properties inputProperties; + private Properties deployProperties; - /* private URL getTemplateDeployName() { - URL url = CreatePackageTask_original.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; - } - } - - - - + // private static String defaultFilename = "templateDeployTool.xml"; + private static String outputFilename = "deploy.xml"; + private static String templateFileName = "deploy_template.xml"; + /* Ant Task Attributes */ + 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() { + 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"); + } + + public abstract void execute(); + + /** + * add the ant defined properties to deployConfig + */ + protected 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. + // The only vectors will be filesets. + deployConfig.setProperty(key, (String) inputProperties + .getProperty(key)); + } + } + + protected void applyFilesets(String key, Vector filesets) { + ArrayList filenames = new ArrayList(); + for (FileSet fileset : filesets) { + DirectoryScanner ds = fileset.getDirectoryScanner(getProject()); + String[] files = ds.getIncludedFiles(); + for (String filename : files) { + filenames.add(ds.getBasedir() + File.separator + filename); + } + } + + deployConfig.setFilenames(key, filenames); + } + + protected 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 + */ + protected void writeConfigFile() throws IOException { + + String outputName = outputPath + File.separator + outputFilename; + + BufferedWriter out = null; + try { + 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(); + + // Writing the template file for tools + BufferedWriter out2 = null; + try { + if (deployConfig instanceof DeployToolConfig) { + DeployToolConfig deployToolConfig = (DeployToolConfig) deployConfig; + deployToolConfig.setGenerateForInstallers(true); + deployToolConfig.convertForInstallers(); + String outputName2 = outputPath + File.separator + + templateFileName; + + out2 = new BufferedWriter(new FileWriter(outputName2)); + deployToolConfig.writePropertiesToFile(out2); + log("File " + outputName2 + " written."); + } + } catch (Exception e) { + + } finally { + out.close(); + } + } + + /* + * private URL getTemplateDeployName() { URL url = + * CreatePackageTask_original.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; + } + } + }