1 18 package sync4j.test.tools.ant; 19 20 import java.io.File ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.TreeMap ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.taskdefs.Ant; 28 import org.apache.tools.ant.types.PatternSet; 29 30 31 37 public abstract class TestSyncMLBaseTask extends org.apache.tools.ant.Task { 38 39 41 protected String url = null; 42 public void setUrl(String url) { 43 this.url = url; 44 } 45 46 protected String test = null; 47 public void setTest(String test) { 48 this.test = test; 49 } 50 51 protected String basedir = null; 52 public void setBasedir(String basedir) { 53 this.basedir = basedir; 54 } 55 56 protected ArrayList xpathPatterns = new ArrayList (); 57 58 public void addPatternset(PatternSet set) { 59 xpathPatterns.add(set); 60 } 61 62 64 66 protected void validateAttributes() throws BuildException { 67 try { 68 new java.net.URL (url); 69 } catch (Exception e) { 70 new BuildException("Malformed url exception: " + url); 71 } 72 } 73 74 protected Ant loadAntTask(String test) { 75 Ant antTask = null; 76 if ( (new File (basedir + File.separator + test + File.separator + "build.xml").exists()) ) { 77 antTask = (Ant)getProject().createTask("ant"); 78 antTask.setAntfile(basedir+ File.separator + test + File.separator + "build.xml"); 79 antTask.setDir(new File (basedir, test)); 80 } 81 return antTask; 82 } 83 84 protected String [] removeBuildFile(String [] filesList) { 85 List newFilesList = new ArrayList (); 86 for (int i=0; i<filesList.length; i++) { 87 88 log("called removeBuildFile ["+i+"]"); 89 log("filesList[i]: " + filesList[i]); 90 91 if (!filesList[i].equalsIgnoreCase("build.xml")) { 92 newFilesList.add(filesList[i]); 93 } 94 } 95 return (String [])newFilesList.toArray(new String [0]); 96 } 97 98 105 protected static String [] ordersAndFilterFiles(String [] files) { 106 int numFiles = files.length; 107 108 TreeMap map = new TreeMap (); 109 110 String fileName = null; 111 int index = -1; 112 113 int numValidFiles = 0; 114 115 for (int i = 0; i < numFiles; i++) { 116 fileName = files[i]; 117 118 index = getIndexOfFile(fileName); 119 120 if (index == -1) { 121 continue; 122 } 123 numValidFiles++; 124 map.put(new Integer (index), fileName); 125 } 126 127 String [] newFilesList = new String [numValidFiles]; 128 129 Iterator it = map.keySet().iterator(); 130 int i = 0; 131 132 while (it.hasNext()) { 133 newFilesList[i++] = (String ) (map.get(it.next())); 134 } 135 136 return newFilesList; 137 } 138 139 144 protected static int getIndexOfFile(String fileName) { 145 146 int indexMsg = fileName.indexOf("msg"); 147 148 if (indexMsg == -1) { 149 return -1; 150 } 151 152 int indexExtension = fileName.lastIndexOf('.'); 153 154 if (indexExtension == -1) { 155 return -1; 156 } 157 158 int indexOfFile = -1; 159 160 try { 161 indexOfFile = Integer.parseInt(fileName.substring(3, indexExtension)); 162 } catch (NumberFormatException ex) { 163 return -1; 164 } 165 166 return indexOfFile; 167 } 168 } 169 | Popular Tags |