package net.brutex.xservices.util; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * A struct containing the various bits of information in a CVS root string, * allowing easy retrieval of individual items of information */ public class CVSRoot { public String connectionType; public String user; public String host; public String repository; public CVSRoot(String root) throws IllegalArgumentException { if (!root.startsWith(":")) throw new IllegalArgumentException(); int oldColonPosition = 0; int colonPosition = root.indexOf(':', 1); if (colonPosition == -1) throw new IllegalArgumentException(); connectionType = root.substring(oldColonPosition + 1, colonPosition); oldColonPosition = colonPosition; colonPosition = root.indexOf('@', colonPosition + 1); if (colonPosition == -1) throw new IllegalArgumentException(); user = root.substring(oldColonPosition + 1, colonPosition); oldColonPosition = colonPosition; colonPosition = root.indexOf(':', colonPosition + 1); if (colonPosition == -1) throw new IllegalArgumentException(); host = root.substring(oldColonPosition + 1, colonPosition); repository = root.substring(colonPosition + 1); if (connectionType == null || user == null || host == null || repository == null) throw new IllegalArgumentException(); } public String getCVSRoot(File directory) { String root = null; BufferedReader r = null; try { File rootFile = new File(directory, "CVS/Root"); if (rootFile.exists()) { r = new BufferedReader(new FileReader(rootFile)); root = r.readLine(); } } catch (IOException e) { // ignore } finally { try { if (r != null) r.close(); } catch (IOException e) { System.err.println("Warning: could not close CVS/Root file!"); } } if (root == null) { root = System.getProperty("cvs.root"); } return root; } }