001: /*
002: * RepositoryMaintenance.java
003: *
004: * Created on 21 April 2006, 17:58
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package org.netbeans.test.subversion.utils;
011:
012: import java.io.File;
013: import java.io.FileInputStream;
014: import java.io.FileOutputStream;
015: import java.io.IOException;
016: import java.io.InputStream;
017: import java.util.zip.GZIPInputStream;
018:
019: /**
020: *
021: * @author peter
022: */
023: public final class RepositoryMaintenance {
024:
025: public static void deleteFolder(File folder) {
026: if (folder.isDirectory()) {
027: String[] files = folder.list();
028: for (int i = 0; i < files.length; i++) {
029: deleteFolder(new File(folder, files[i]));
030: }
031: }
032: folder.delete();
033: }
034:
035: public static int loadRepositoryFromFile(String repoPath,
036: String dumpPath) {
037: int value = -1;
038:
039: File repo = new File(repoPath);
040: repo.mkdir();
041: File dump = new File(dumpPath);
042: boolean gzip = false;
043: if (!dump.isFile()) {
044: File dumpgz = new File(dumpPath + ".gz");
045: if (dumpgz.isFile()) {
046: dump = dumpgz;
047: gzip = true;
048: }
049: }
050:
051: File tmpOutput = new File(repo.getParent() + File.separator
052: + "output.txt");
053:
054: StreamHandler shFile;
055: StreamHandler shError;
056: StreamHandler shOutput;
057:
058: try {
059: String[] cmd = { "svnadmin", "load",
060: repo.getCanonicalPath() };
061: InputStream fis = new FileInputStream(dump);
062: if (gzip) {
063: fis = new GZIPInputStream(fis);
064: }
065: FileOutputStream fos = new FileOutputStream(tmpOutput);
066: Process p = Runtime.getRuntime().exec(cmd);
067: shFile = new StreamHandler(fis, p.getOutputStream());
068: shError = new StreamHandler(p.getErrorStream(), System.err);
069: shOutput = new StreamHandler(p.getInputStream(), fos);
070: shFile.start();
071: shError.start();
072: shOutput.start();
073: value = p.waitFor();
074: shFile.join();
075: shError.join();
076: shOutput.join();
077: } catch (IOException e) {
078: e.printStackTrace();
079: } catch (InterruptedException e) {
080: e.printStackTrace();
081: }
082: return value;
083: }
084:
085: public static int createRepository(String path) {
086: int value = -1;
087:
088: File file = new File(path);
089: file.mkdirs();
090:
091: String[] cmd = { "svnadmin", "create", path };
092:
093: try {
094: Process p = Runtime.getRuntime().exec(cmd);
095: value = p.waitFor();
096: } catch (IOException e) {
097: System.out.println("ex");
098: } catch (InterruptedException e) {
099: System.out.println("ex");
100: }
101:
102: return value;
103: }
104:
105: public static String changeFileSeparator(String path, boolean backed) {
106: String changedPath = "";
107: if (!backed) {
108: for (int i = 0; i < path.length(); i++) {
109: if (path.charAt(i) == '\\') {
110: changedPath += '/';
111: } else {
112: changedPath += path.charAt(i);
113: }
114: }
115: } else {
116: for (int i = 0; i < path.length(); i++) {
117: if (path.charAt(i) == '/') {
118: changedPath += '\\' + '\\';
119: } else {
120: changedPath += path.charAt(i);
121: }
122: }
123: }
124: if (changedPath.startsWith("/"))
125: changedPath = changedPath
126: .substring(1, changedPath.length());
127: return changedPath;
128: }
129:
130: }
131:
132: /*create user/password - test/test
133: try {
134: BufferedWriter bw = new BufferedWriter(new FileWriter(path + File.separator + "conf" + File.separator + "passwd"));
135: String line = "[users]";
136: bw.append(line, 0, line.length());
137: bw.newLine();
138: line = "test = test";
139: bw.append(line, 0, line.length());
140: bw.flush();
141: bw.close();
142: } catch (IOException e) {
143: }
144: //rw access to repository for test user and r access for anonymous
145: try {
146: BufferedWriter bw = new BufferedWriter(new FileWriter(path + File.separator + "conf" + File.separator + "authz"));
147: String line = "[/]";
148: bw.append(line, 0, line.length());
149: bw.newLine();
150: line = "test = rw";
151: bw.append(line, 0, line.length());
152: bw.newLine();
153: line = "* = r";
154: bw.append(line, 0, line.length());
155: bw.flush();
156: bw.close();
157: } catch (IOException e) {
158: } */
|