KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > utils > RepositoryMaintenance


1 /*
2  * RepositoryMaintenance.java
3  *
4  * Created on 21 April 2006, 17:58
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.test.subversion.utils;
11
12 import java.io.File JavaDoc;
13 import java.io.FileInputStream JavaDoc;
14 import java.io.FileOutputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16
17 /**
18  *
19  * @author peter
20  */

21 public final class RepositoryMaintenance {
22     
23     public static void deleteFolder(File JavaDoc folder) {
24         if (folder.isDirectory()) {
25             String JavaDoc[] files = folder.list();
26             for (int i = 0; i < files.length; i++) {
27                 deleteFolder(new File JavaDoc(folder, files[i]));
28             }
29         }
30         folder.delete();
31     }
32     
33     public static int loadRepositoryFromFile(String JavaDoc repoPath, String JavaDoc dumpPath){
34         int value = -1;
35         
36         File JavaDoc repo = new File JavaDoc(repoPath);
37         repo.mkdir();
38         File JavaDoc dump = new File JavaDoc(dumpPath);
39         
40         File JavaDoc tmpOutput = new File JavaDoc(repo.getParent() + File.separator + "output.txt");
41                 
42         StreamHandler shFile;
43         StreamHandler shError;
44         StreamHandler shOutput;
45         
46         try {
47             String JavaDoc[] cmd = {"svnadmin", "load", repo.getCanonicalPath()};
48             FileInputStream JavaDoc fis = new FileInputStream JavaDoc(dump);
49             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(tmpOutput);
50             Process JavaDoc 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 JavaDoc e) {
62             e.printStackTrace();
63         } catch (InterruptedException JavaDoc e) {
64             e.printStackTrace();
65         }
66         return value;
67     }
68     
69     public static int createRepository(String JavaDoc path) {
70         int value = -1;
71         
72         File JavaDoc file = new File JavaDoc(path);
73         file.mkdirs();
74         
75         String JavaDoc[] cmd = {"svnadmin", "create", path};
76         
77         try {
78             Process JavaDoc p = Runtime.getRuntime().exec(cmd);
79             value = p.waitFor();
80         } catch (IOException JavaDoc e) {
81             System.out.println("ex");
82         } catch (InterruptedException JavaDoc e) {
83             System.out.println("ex");
84         }
85         
86         return value;
87     }
88     
89     public static String JavaDoc changeFileSeparator(String JavaDoc path, boolean backed) {
90         String JavaDoc 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 /*create user/password - test/test
117         try {
118             BufferedWriter bw = new BufferedWriter(new FileWriter(path + File.separator + "conf" + File.separator + "passwd"));
119             String line = "[users]";
120             bw.append(line, 0, line.length());
121             bw.newLine();
122             line = "test = test";
123             bw.append(line, 0, line.length());
124             bw.flush();
125             bw.close();
126         } catch (IOException e) {
127         }
128         //rw access to repository for test user and r access for anonymous
129         try {
130             BufferedWriter bw = new BufferedWriter(new FileWriter(path + File.separator + "conf" + File.separator + "authz"));
131             String line = "[/]";
132             bw.append(line, 0, line.length());
133             bw.newLine();
134             line = "test = rw";
135             bw.append(line, 0, line.length());
136             bw.newLine();
137             line = "* = r";
138             bw.append(line, 0, line.length());
139             bw.flush();
140             bw.close();
141         } catch (IOException e) {
142         } */
Popular Tags