comparison hg4j/src/main/java/org/tmatesoft/hg/internal/Internals.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.internal;
18
19 import static org.tmatesoft.hg.internal.RequiresFile.*;
20
21 import java.io.File;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.tmatesoft.hg.repo.HgRepository;
28 import org.tmatesoft.hg.util.PathRewrite;
29
30 /**
31 * Fields/members that shall not be visible
32 *
33 * @author Artem Tikhomirov
34 * @author TMate Software Ltd.
35 */
36 public class Internals {
37
38 private int requiresFlags = 0;
39 private List<Filter.Factory> filterFactories;
40
41
42 public Internals() {
43 }
44
45 public/*for tests, otherwise pkg*/ void setStorageConfig(int version, int flags) {
46 requiresFlags = flags;
47 }
48
49 // XXX perhaps, should keep both fields right here, not in the HgRepository
50 public PathRewrite buildDataFilesHelper() {
51 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0);
52 }
53
54 public PathRewrite buildRepositoryFilesHelper() {
55 if ((requiresFlags & STORE) != 0) {
56 return new PathRewrite() {
57 public String rewrite(String path) {
58 return "store/" + path;
59 }
60 };
61 } else {
62 return new PathRewrite() {
63 public String rewrite(String path) {
64 //no-op
65 return path;
66 }
67 };
68 }
69 }
70
71 public ConfigFile newConfigFile() {
72 return new ConfigFile();
73 }
74
75 public List<Filter.Factory> getFilters(HgRepository hgRepo, ConfigFile cfg) {
76 if (filterFactories == null) {
77 filterFactories = new ArrayList<Filter.Factory>();
78 if (cfg.hasEnabledExtension("eol")) {
79 NewlineFilter.Factory ff = new NewlineFilter.Factory();
80 ff.initialize(hgRepo, cfg);
81 filterFactories.add(ff);
82 }
83 if (cfg.hasEnabledExtension("keyword")) {
84 KeywordFilter.Factory ff = new KeywordFilter.Factory();
85 ff.initialize(hgRepo, cfg);
86 filterFactories.add(ff);
87 }
88 }
89 return filterFactories;
90 }
91
92 public void initEmptyRepository(File hgDir) throws IOException {
93 hgDir.mkdir();
94 FileOutputStream requiresFile = new FileOutputStream(new File(hgDir, "requires"));
95 StringBuilder sb = new StringBuilder(40);
96 sb.append("revlogv1\n");
97 if ((requiresFlags & STORE) != 0) {
98 sb.append("store\n");
99 }
100 if ((requiresFlags & FNCACHE) != 0) {
101 sb.append("fncache\n");
102 }
103 if ((requiresFlags & DOTENCODE) != 0) {
104 sb.append("dotencode\n");
105 }
106 requiresFile.write(sb.toString().getBytes());
107 requiresFile.close();
108 new File(hgDir, "store").mkdir(); // with that, hg verify says ok.
109 }
110
111 }