Index: org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/Main.java =================================================================== RCS file: /usr/local/cvsroot/org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/Attic/Main.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/Main.java 29 Aug 2007 07:09:18 -0000 1.1 @@ -0,0 +1,202 @@ +package org.lams.toolbuilder.renameTool; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Anthony Sukkar + * + */ +public class Main { + + static Set txtType = new HashSet(); + + static List nameList = new ArrayList(); + + public static void main(String[] args) { + + txtType.add("clay"); + txtType.add("classpath"); + txtType.add("txt"); + txtType.add("cvsignore"); + txtType.add("html"); + txtType.add("htm"); + txtType.add("java"); + txtType.add("js"); + txtType.add("jsp"); + txtType.add("MF"); + txtType.add("bat"); + txtType.add("myd"); + txtType.add("mymetadata"); + txtType.add("project"); + txtType.add("properties"); + txtType.add("sh"); + txtType.add("sql"); + txtType.add("tag"); + txtType.add("log"); + txtType.add("tld"); + txtType.add("xml"); + + + File tasklist = new File("src/org/lams/toolbuilder/renameTool/tasklist.conf"); + + if (!tasklist.exists()) { + System.out.println("Can't find 'tasklist.conf'"); + } + + File sourceDir = null; + try { + FileInputStream fis = new FileInputStream(tasklist); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + + String line; + while ((line = br.readLine()) != null) { + + line = line.trim(); + + if (line.length() == 0 || (line.charAt(0) == '#')) + continue; + + String[] strArray = line.split("\\s"); + + String command = strArray[0]; + + if (command.equals("Source")) { + sourceDir = getFile(strArray); + } + + if (command.equals("Rename")) { + + if (strArray.length != 3) { + continue; + } else { + String[] pair = { strArray[1], strArray[2] }; + nameList.add(pair); + } + } + + } + + visitFile(sourceDir, "rename"); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.exit(0); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void renameFile(File dir) { + for (String[] pair : nameList) { + String newFileName = updateFilename(dir.getName(), pair[0], pair[1]); + dir.renameTo(new File(dir.getParentFile(), newFileName)); + } + } + + private static String updateFilename(String currentFileName, String regex, + String replacement) { + + String newFileName = currentFileName.replaceAll(regex, replacement); + + if (!currentFileName.equals(newFileName)) { + + String format = "Renamed %1$-40s ---> %2$-1s\n"; + + System.out.format(format, currentFileName, newFileName); + + } + return newFileName; + } + + public static void replaceText(File file) { + + try { + FileInputStream fis = new FileInputStream(file); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + + File tmpfile = File.createTempFile("rename", "tmp", file + .getParentFile()); + + BufferedWriter bw = new BufferedWriter(new FileWriter(tmpfile)); + + String line; + while ((line = br.readLine()) != null) { + + for (String[] pair : nameList) { + line = line.replaceAll(pair[0], pair[1]); + } + + bw.write(line); + bw.newLine(); + } + + bw.close(); + br.close(); + + String fileName = file.getName(); + file.delete(); + tmpfile.renameTo(new File(tmpfile.getParentFile(), fileName)); + + } catch (FileNotFoundException fnfe) { + fnfe.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public static void visitFile(File file, String mode) { + + if (file.isDirectory() + && (file.getName().equals("CVS") || file.getName().equals( + "build"))) { + mode = "delete"; + } + + if (file.isDirectory()) { + String[] children = file.list(); + for (int i = 0; i < children.length; i++) { + visitFile(new File(file, children[i]), mode); + } + } + + if (mode.equals("rename")) { + + if (file.isFile()) { + + String[] a = file.getName().split("\\."); + + if ((a.length == 1) || txtType.contains(a[a.length-1])) { + replaceText(file); + } + } + renameFile(file); + } + + if (mode.equals("delete")) { + file.delete(); + System.out.println("Deleted file: " + file.getPath()); + } + } + + public static File getFile(String[] array) { + // merge remaining array elements and restoring spaces. + String path = ""; + for (int i = 1; i < array.length; i++) { + path += array[i] + " "; + } + return new File(path.trim()); + } +} Index: org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/readme.txt =================================================================== RCS file: /usr/local/cvsroot/org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/Attic/readme.txt,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/readme.txt 29 Aug 2007 07:09:18 -0000 1.1 @@ -0,0 +1,75 @@ +Readme.txt + +This application will try to generate a new lams tool based on an existing +lams tool by substituting given strings in the existing project with new +values. + +The program will look for a file called 'tasklist.conf' in the current +directory. The file contains two types of directives. + +These instructions assume you already have a tool signature for your tool. +If you do not have one, have a look at +http://wiki.lamsfoundation.org/display/lams/Tool+Signatures. +The tool signature is used in many places, such as the table names and it +is laborious to change it when you have a lot of code already written. + +Source + The 'Directory' should contain the lams tool that you want to rename. + +Rename : + Rename will replace all instances of with + for all files in the 'Directory' specified. It executes the replace + in the order they are listed. + +Step 1. + Determine which project you want to base your tool on. The Submit tool + is good candidate since it is very simple and will require the least + to remove unwanted functionality. + + Make a copy of the lams tool and place it in a new folder. + +Step 2. + Add the strings that need to be replaced to the 'tasklist.conf' file. + + These strings are used for the submit tool + + Rename lasbmt11 laex11 + Rename SubmitFiles Example + Rename submitFiles example + Rename sbmt example + Rename Sbmt Example + Rename Submit Example + Rename submit example + + Note: lasbmt11 and laex11 are the old and new tool signatures. + +Step 3. + Compile and execute the java program Main.java + + You should see a list of delete and rename operations that tool place. + +Step 4. + The 'Directory' should now contain the new lams tool. + + Copy this folder to eclipse workspace which contains other lams project. + + Import the project into eclipse. In Eclipse do File, New Project, select Java Project, click Next and + enter the name of the new project folder. Leave "Contents" set to "Create new project in workspace". + Then click Finished. This should create the new project in Eclipse. + +Step 5. + Make necessary changes to lams_build to include the new lams tool: + + In lams_build/shared.properties, add an entry for your new tool. e.g. tool_example_dir=lams_tool_example + + In lams_build/build.ml find the task "deploy-tools". Add a new section similar to: + + + + + To shorten the time it takes to rebuild the whole system, you can comment out + some of the other tools. If you comment out the tool_Lars_dir or tool_forum_dir + entries, make sure you also comment out deploy-learning-libraries. The deploy-learning-libraries + creates the combined share resources/forum activity in authoring and this requires + the share resources and forum tools. Index: org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/tasklist.conf =================================================================== RCS file: /usr/local/cvsroot/org.lams.toolbuilder/src/org/lams/toolbuilder/renameTool/Attic/tasklist.conf,v diff -u Binary files differ