1 9 10 package org.netbeans.test.subversion.utils; 11 12 import java.io.File ; 13 import java.io.FileInputStream ; 14 import java.io.FileOutputStream ; 15 import java.io.IOException ; 16 17 21 public final class RepositoryMaintenance { 22 23 public static void deleteFolder(File folder) { 24 if (folder.isDirectory()) { 25 String [] files = folder.list(); 26 for (int i = 0; i < files.length; i++) { 27 deleteFolder(new File (folder, files[i])); 28 } 29 } 30 folder.delete(); 31 } 32 33 public static int loadRepositoryFromFile(String repoPath, String dumpPath){ 34 int value = -1; 35 36 File repo = new File (repoPath); 37 repo.mkdir(); 38 File dump = new File (dumpPath); 39 40 File tmpOutput = new File (repo.getParent() + File.separator + "output.txt"); 41 42 StreamHandler shFile; 43 StreamHandler shError; 44 StreamHandler shOutput; 45 46 try { 47 String [] cmd = {"svnadmin", "load", repo.getCanonicalPath()}; 48 FileInputStream fis = new FileInputStream (dump); 49 FileOutputStream fos = new FileOutputStream (tmpOutput); 50 Process p = Runtime.getRuntime().exec(cmd); 51 shFile = new StreamHandler(fis, p.getOutputStream()); 52 shError = new StreamHandler(p.getErrorStream(), System.err); 53 shOutput = new StreamHandler(p.getInputStream(), fos); 54 shFile.start(); 55 shError.start(); 56 shOutput.start(); 57 value = p.waitFor(); 58 shFile.join(); 59 shError.join(); 60 shOutput.join(); 61 } catch (IOException e) { 62 e.printStackTrace(); 63 } catch (InterruptedException e) { 64 e.printStackTrace(); 65 } 66 return value; 67 } 68 69 public static int createRepository(String path) { 70 int value = -1; 71 72 File file = new File (path); 73 file.mkdirs(); 74 75 String [] cmd = {"svnadmin", "create", path}; 76 77 try { 78 Process p = Runtime.getRuntime().exec(cmd); 79 value = p.waitFor(); 80 } catch (IOException e) { 81 System.out.println("ex"); 82 } catch (InterruptedException e) { 83 System.out.println("ex"); 84 } 85 86 return value; 87 } 88 89 public static String changeFileSeparator(String path, boolean backed) { 90 String changedPath = ""; 91 if (!backed) { 92 for (int i = 0; i < path.length(); i++) { 93 if (path.charAt(i) == '\\') { 94 changedPath += '/'; 95 } else { 96 changedPath += path.charAt(i); 97 } 98 } 99 } else { 100 for (int i = 0; i < path.length(); i++) { 101 if (path.charAt(i) == '/') { 102 changedPath += '\\' + '\\'; 103 } else { 104 changedPath += path.charAt(i); 105 } 106 } 107 } 108 if (changedPath.startsWith("/")) 109 changedPath = changedPath.substring(1, changedPath.length()); 110 return changedPath; 111 } 112 113 } 114 115 116 | Popular Tags |