1 5 package org.enhydra.ant.taskdefs; 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import org.apache.tools.ant.BuildException; 10 import org.apache.tools.ant.types.EnumeratedAttribute; 11 12 33 public class SQLSplitterTask extends org.apache.tools.ant.taskdefs.Javac { 34 protected File dir = null; 35 protected File resultsql = null; 36 protected boolean forceBuild = false; 37 protected boolean splitsqlprimary = true; 38 public static class BooleanAttribute extends EnumeratedAttribute { 39 40 43 public String [] getValues() { 44 return (new String [] {"yes", "no", "true", "false" }); 45 } 46 47 public BooleanAttribute() {} 48 } 49 public SQLSplitterTask() { 50 dir = null; 51 resultsql = null; 52 } 53 54 58 public void execute() throws org.apache.tools.ant.BuildException { 59 if (dir == null) { 60 throw new BuildException("dir attribute must be set!"); 61 } 62 if (resultsql == null) { 63 throw new BuildException("resultsql attribute must be set!"); 64 } else { 65 int dirpos = -1; 66 67 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 68 dirpos = resultsql.getAbsolutePath().lastIndexOf("\\"); 69 } else { 70 dirpos = resultsql.getAbsolutePath().lastIndexOf("/"); 71 } 72 String resultsqldir = null; 73 String beginfilename = null; 74 75 if (dirpos != -1) { 76 resultsqldir = resultsql.getAbsolutePath().substring(0, dirpos); 77 String sqlfilename = resultsql.getAbsolutePath().substring(dirpos 78 + 1); 79 int pointpos = sqlfilename.indexOf(".sql"); 80 81 if (pointpos != -1) { 82 beginfilename = sqlfilename.substring(0, pointpos); 83 } else { 84 beginfilename = sqlfilename; 85 } 86 } else { 87 resultsqldir = "."; 88 int pointpos = resultsql.getAbsolutePath().indexOf(".sql"); 89 90 if (pointpos != -1) { 91 beginfilename = resultsql.getAbsolutePath().substring(0, 92 pointpos); 93 } else { 94 beginfilename = resultsql.getAbsolutePath(); 95 } 96 } 97 String [] files = (new File (resultsqldir)).list(); 98 99 for (int i = 0; i < files.length; i++) { 100 if ((files[i].startsWith(beginfilename)) 101 && (files[i].endsWith(".sql"))) { 102 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 103 (new File (resultsqldir + "\\" + files[i])).delete(); 104 } else { 105 (new File (resultsqldir + "/" + files[i])).delete(); 106 } 107 108 } 109 } 110 111 } 112 113 java.util.ArrayList argsList = new ArrayList (); 114 115 argsList.add(dir.getAbsolutePath()); 116 argsList.add(resultsql.getAbsolutePath()); 117 if(!splitsqlprimary){ 118 argsList.add("false"); 119 } 120 try { 121 String splitterClassName = "org.webdocwf.util.sql.SQLSplitter"; 122 java.lang.reflect.Method m = null; 123 java.lang.Class c = null; 124 125 try { 126 c = java.lang.Class.forName(splitterClassName); 127 m = c.getMethod("main", new java.lang.Class [] { 128 String [].class 129 }); 130 } catch (java.lang.Exception e) { 131 ((java.lang.Throwable ) (e)).printStackTrace(); 132 throw new BuildException(((java.lang.Throwable ) (e))); 133 } 134 String args[] = (String []) argsList.toArray(((java.lang.Object []) ( 135 new String [argsList.size()]))); 136 137 if (m != null) { 138 m.invoke(((java.lang.Object ) (null)), new java.lang.Object [] { 139 args 140 }); 141 } 142 } catch (java.lang.reflect.InvocationTargetException ite) { 143 ite.printStackTrace(); 144 throw new BuildException(((java.lang.Throwable ) (ite))); 145 } catch (java.lang.Exception e) { 146 ((java.lang.Throwable ) (e)).printStackTrace(); 147 throw new BuildException(((java.lang.Throwable ) (e))); 148 } 149 150 155 } 156 157 161 public void setDir(File sqlDir) { 162 this.dir = sqlDir; 163 } 164 165 170 public void setResultsql(File sqlBase) { 171 this.resultsql = sqlBase; 172 } 173 174 179 public void setSplitsqlprimary(String splitPrimary) { 180 this.splitsqlprimary = (new Boolean (splitPrimary)).booleanValue(); 181 } 182 183 187 public void setForce(String force) { 188 forceBuild = (new Boolean (force)).booleanValue(); 189 } 190 } 191 | Popular Tags |