001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc;
013:
014: import java.io.File;
015: import java.io.IOException;
016: import java.io.OutputStream;
017:
018: import org.tmatesoft.svn.core.SVNErrorCode;
019: import org.tmatesoft.svn.core.SVNErrorMessage;
020: import org.tmatesoft.svn.core.SVNException;
021: import org.tmatesoft.svn.core.SVNNodeKind;
022:
023: /**
024: * @version 1.1.1
025: * @author TMate Software Ltd.
026: */
027: public class SVNAdminUtil {
028:
029: private static final byte[] FORMAT_TEXT;
030: private static final byte[] README_TEXT;
031: private static final boolean SKIP_README;
032:
033: private static final String BASE_EXT = ".svn-base";
034: private static final String REVERT_EXT = ".svn-revert";
035: private static final String WORK_EXT = ".svn-work";
036:
037: private static final String TEXT_BASE_DIR_NAME = "text-base";
038: private static final String PROP_BASE_DIR_NAME = "prop-base";
039: private static final String PROP_WORK_DIR_NAME = "props";
040: private static final String PROP_WC_DIR_NAME = "wcprops";
041: private static final String TMP_DIR_NAME = "tmp";
042:
043: private static final String DIR_PROPS_FILE = "dir-props";
044: private static final String DIR_BASE_PROPS_FILE = "dir-prop-base";
045: private static final String DIR_REVERT_PROPS_FILE = "dir-prop-revert";
046: private static final String DIR_WC_PROPS_FILE = "dir-wcprops";
047:
048: static {
049: String eol = System.getProperty("line.separator");
050: FORMAT_TEXT = new byte[] { '4', '\n' };
051: README_TEXT = ("This is a Subversion working copy administrative directory."
052: + eol
053: + "Visit http://subversion.tigris.org/ for more information." + eol)
054: .getBytes();
055: SKIP_README = Boolean.getBoolean("javasvn.skipReadme") ? true
056: : Boolean.getBoolean("svnkit.skipReadme");
057: }
058:
059: public static void createReadmeFile(File adminDir)
060: throws SVNException {
061: if (SKIP_README) {
062: return;
063: }
064: OutputStream os = null;
065: try {
066: os = SVNFileUtil.openFileForWriting(new File(adminDir,
067: "README.txt"));
068: os.write(README_TEXT);
069: } catch (IOException e) {
070: SVNErrorMessage err = SVNErrorMessage.create(
071: SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
072: SVNErrorManager.error(err, e);
073: } finally {
074: SVNFileUtil.closeFile(os);
075: }
076:
077: }
078:
079: public static void createFormatFile(File adminDir)
080: throws SVNException {
081: OutputStream os = null;
082: try {
083: os = SVNFileUtil.openFileForWriting(new File(adminDir,
084: "format"));
085: os.write(FORMAT_TEXT);
086: } catch (IOException e) {
087: SVNErrorMessage err = SVNErrorMessage.create(
088: SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
089: SVNErrorManager.error(err, e);
090: } finally {
091: SVNFileUtil.closeFile(os);
092: }
093: }
094:
095: public static String getTextBasePath(String name, boolean tmp) {
096: StringBuffer buffer = new StringBuffer();
097: buffer.append(SVNFileUtil.getAdminDirectoryName());
098: buffer.append('/');
099: if (tmp) {
100: buffer.append(TMP_DIR_NAME);
101: buffer.append('/');
102: }
103: buffer.append(TEXT_BASE_DIR_NAME);
104: buffer.append('/');
105: buffer.append(name);
106: buffer.append(BASE_EXT);
107: return buffer.toString();
108: }
109:
110: public static String getTextRevertPath(String name, boolean tmp) {
111: StringBuffer buffer = new StringBuffer();
112: buffer.append(SVNFileUtil.getAdminDirectoryName());
113: buffer.append('/');
114: if (tmp) {
115: buffer.append(TMP_DIR_NAME);
116: buffer.append('/');
117: }
118: buffer.append(TEXT_BASE_DIR_NAME);
119: buffer.append('/');
120: buffer.append(name);
121: buffer.append(REVERT_EXT);
122: return buffer.toString();
123: }
124:
125: public static String getPropPath(String name, SVNNodeKind kind,
126: boolean tmp) {
127: StringBuffer buffer = new StringBuffer();
128: buffer.append(SVNFileUtil.getAdminDirectoryName());
129: buffer.append('/');
130: if (tmp) {
131: buffer.append(TMP_DIR_NAME);
132: buffer.append('/');
133: }
134: if (kind == SVNNodeKind.DIR) {
135: buffer.append(DIR_PROPS_FILE);
136: } else {
137: buffer.append(PROP_WORK_DIR_NAME);
138: buffer.append('/');
139: buffer.append(name);
140: buffer.append(WORK_EXT);
141: }
142: return buffer.toString();
143: }
144:
145: public static String getPropBasePath(String name, SVNNodeKind kind,
146: boolean tmp) {
147: StringBuffer buffer = new StringBuffer();
148: buffer.append(SVNFileUtil.getAdminDirectoryName());
149: buffer.append('/');
150: if (tmp) {
151: buffer.append(TMP_DIR_NAME);
152: buffer.append('/');
153: }
154: if (kind == SVNNodeKind.DIR) {
155: buffer.append(DIR_BASE_PROPS_FILE);
156: } else {
157: buffer.append(PROP_BASE_DIR_NAME);
158: buffer.append('/');
159: buffer.append(name);
160: buffer.append(BASE_EXT);
161: }
162: return buffer.toString();
163: }
164:
165: public static String getPropRevertPath(String name,
166: SVNNodeKind kind, boolean tmp) {
167: StringBuffer buffer = new StringBuffer();
168: buffer.append(SVNFileUtil.getAdminDirectoryName());
169: buffer.append('/');
170: if (tmp) {
171: buffer.append(TMP_DIR_NAME);
172: buffer.append('/');
173: }
174: if (kind == SVNNodeKind.DIR) {
175: buffer.append(DIR_REVERT_PROPS_FILE);
176: } else {
177: buffer.append(PROP_BASE_DIR_NAME);
178: buffer.append('/');
179: buffer.append(name);
180: buffer.append(REVERT_EXT);
181: }
182: return buffer.toString();
183: }
184:
185: public static String getWCPropPath(String name, SVNNodeKind kind,
186: boolean tmp) {
187: StringBuffer buffer = new StringBuffer();
188: buffer.append(SVNFileUtil.getAdminDirectoryName());
189: buffer.append('/');
190: if (tmp) {
191: buffer.append(TMP_DIR_NAME);
192: buffer.append('/');
193: }
194: if (kind == SVNNodeKind.DIR) {
195: buffer.append(DIR_WC_PROPS_FILE);
196: } else {
197: buffer.append(PROP_WC_DIR_NAME);
198: buffer.append('/');
199: buffer.append(name);
200: buffer.append(WORK_EXT);
201: }
202: return buffer.toString();
203: }
204: }
|