Trying to do in a similar sourceforge open-source community, so applicants need to project
to provide remote SVN configuration. Here are their own code and ideas, first, in order to
exchange with you and, more importantly, make a suggestion to allow you to see what
content needs.
The function is now available:
Svn warehouse for the project to create, modify svn account password, modify
configuration, such as svn permissions
Code is as follows:
First of all, the definition of an exception:
package commandLineTest; class SvnException extends Exception { public SvnException(String s) { super(s); } }
The following is the operation of svn:
package commandLineTest; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class SvnCommander { private String svn_home = "D:/SVN/<a href="http://blog.950buy.com/">InternetResources</a>/"; /** * For a specific project to create svn server storage, when the user selects to open svn service, * this method will be called for users to create svn warehouse project * * @param project * project name * @throws SvnException **/ public void createRepository(String project) throws SvnException { try { Process p = new ProcessBuilder("svnadmin", "create", svn_home + project).start(); StringBuffer buffer = new StringBuffer(); String tmp; BufferedReader reader = new BufferedReader(new InputStreamReader(p .getErrorStream())); while ((tmp = reader.readLine()) != null) buffer.append(tmp); if (buffer.length() > 0) throw new SvnException(buffer.toString()); initSvnServer(project); initAuthz(project); } catch (IOException e) { e.printStackTrace(); } } /** * Modify svnserve.conf * @param project * project name * @throws SvnException **/ public void initSvnServer(String project) throws SvnException { File svnserve = new File(svn_home + project + "/conf/svnserve.conf"); try { BufferedReader reader = new BufferedReader(new FileReader(svnserve)); StringBuffer buffer = new StringBuffer(); String tmp; while ((tmp = reader.readLine()) != null) buffer.append(tmp + "\n"); reader.close(); int index = buffer.indexOf("# anon"); buffer.delete(index, index + 2); index = buffer.indexOf("# auth"); buffer.delete(index, index + 2); index = buffer.indexOf("# pass"); buffer.delete(index, index + 2); index = buffer.indexOf("# auth"); buffer.delete(index, index + 2); BufferedWriter writer = new BufferedWriter(new FileWriter(svnserve)); writer.write(buffer.toString()); writer.close(); } catch (FileNotFoundException e) { throw new SvnException("SvnException: Svnserve.conf Not Found: " + e.toString()); } catch (IOException e) { throw new SvnException("SvnException: Svnserve.conf IO Error:" + e.toString()); } } /** * Svn user password * * @param project * The user's project name * @param name * username * @param key * password * @throws SvnException **/ public void setPassword(String project, String name, String key) throws SvnException { File file = new File(svn_home + project); if (!file.exists()) throw new SvnException("SvnException: The project has not yet opened svn service"); File passwd = new File(svn_home + project + "/conf/passwd"); try { BufferedReader reader = new BufferedReader(new FileReader(passwd)); StringBuffer buffer = new StringBuffer(); String tmp; while ((tmp = reader.readLine()) != null) buffer.append(tmp + "\n"); reader.close(); int index = buffer.indexOf(name + " = "); if (index != -1) { int line_end = buffer.indexOf("\n", index); if (line_end == -1) line_end = buffer.length(); buffer.replace(index + name.length() + 3, line_end, key); } else { buffer.append(name + " = " + key); } BufferedWriter writer = new BufferedWriter(new FileWriter(passwd)); writer.write(buffer.toString()); writer.close(); } catch (FileNotFoundException e) { throw new SvnException("SvnException: passwd file not Found: " + e.toString()); } catch (IOException e) { throw new SvnException("SvnException: passwd file IO Error: " + e.toString()); } } private void initAuthz(String project) throws SvnException { File template = new File("authz_template.txt"); File authz = new File(svn_home + project + "/conf/authz"); try { BufferedReader reader = new BufferedReader(new FileReader(template)); BufferedWriter writer = new BufferedWriter(new FileWriter(authz)); String tmp; while ((tmp = reader.readLine()) != null) writer.write(tmp); reader.close(); writer.close(); } catch (FileNotFoundException e) { throw new SvnException("SvnException: passwd file not Found: " + e.toString()); } catch (IOException e) { throw new SvnException("SvnException: passwd file IO Error: " + e.toString()); } } /** * Set up individual users access to the svn * @param project * project name * @param path * Corresponding folder permissions, the parameters should be "/ foo / bar" in the form of * @param name * User name, all users should use "*" to indicate * @param right * Permissions for "r" or "rw" */ public void setAuthz(String project, String path, String name, String right) throws SvnException { File passwd = new File(svn_home + project + "/conf/authz"); try { BufferedReader reader = new BufferedReader(new FileReader(passwd)); StringBuffer buffer = new StringBuffer(); String tmp; while ((tmp = reader.readLine()) != null) buffer.append(tmp + "\n"); reader.close(); int begin = buffer.indexOf("[" + project + ":" + path + "]"); System.err.println(begin); if (begin != -1) { int end = buffer.indexOf("[" + project, begin+1); System.err.println(end); if (end == -1) end = buffer.length(); int index = buffer.indexOf(name, begin); System.err.println(index); if (index < end && index != -1) { int line_end = buffer.indexOf("\n", index); if (line_end == -1) line_end = buffer.length(); buffer.replace(index + name.length() + 3, line_end, right); } else { int line_end = buffer.indexOf("\n", begin); if (line_end == -1) line_end = buffer.length(); buffer.insert(line_end + 1, name + " = " + right + "\n"); } } else { buffer.append("[" + project + ":" + path + "]\n"); buffer.append(name + " = " + right + "\n"); } BufferedWriter writer = new BufferedWriter(new FileWriter(passwd)); writer.write(buffer.toString()); writer.close(); } catch (FileNotFoundException e) { throw new SvnException("SvnException: authz file not Found: " + e.toString()); } catch (IOException e) { throw new SvnException("SvnException: authz file IO Error: " + e.toString()); } } /** * @param args */ public static void main(String[] args) { SvnCommander s = new SvnCommander(); try { s.setAuthz("lala","/","haha","rw"); } catch (SvnException e) { System.err.print(e.toString()); } } }
Svn storage is created by calling
Process p = new ProcessBuilder ( "svnadmin", "create", svn_home + Project). Start ();
Carried out. Capture system at the same time to return to see if there is any abnormal
BufferedReader reader = new BufferedReader (new InputStreamReader (p . getErrorStream ())); while ((tmp = reader.readLine ())! = null) buffer.append (tmp); / / System.err.println (buffer.toString ()); if (buffer.length ()> 0) throw new SvnException (buffer.toString ());
Password and permissions for changes to the svn by default passwd and authz file
for text manipulation.
Since it is the other b/s mode to display the page of course, would not elaborate
because of the length of pyronaridine
Finally, there are two issues would also like to ask you:
1. Is the operation of the text can only be read into the memory modified to re-write it?
Are there any relatively efficient way to do that?
2. Also need additional functionality? Due to svn some of the basic operations
(such as import and export) in fact, through the svn client svn address can access the

No Responses to “Java remote configuration SVN”