Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Bundle |
|
| 1.1;1.1 |
1 | /* | |
2 | * #%L | |
3 | * JavaHg | |
4 | * %% | |
5 | * Copyright (C) 2011 aragost Trifork ag | |
6 | * %% | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | * #L% | |
25 | */ | |
26 | package com.aragost.javahg; | |
27 | ||
28 | import java.io.File; | |
29 | import java.io.IOException; | |
30 | import java.util.List; | |
31 | ||
32 | import com.aragost.javahg.internals.GenericCommand; | |
33 | ||
34 | public class Bundle { | |
35 | ||
36 | private final BaseRepository baseRepository; | |
37 | ||
38 | private OverlayRepository overlayRepository; | |
39 | ||
40 | private final File file; | |
41 | ||
42 | private boolean manageFile; | |
43 | ||
44 | private List<Changeset> changesets; | |
45 | ||
46 | /** | |
47 | * Create a new bundle. The bundle file will not be deleted on close. | |
48 | * | |
49 | * @param baseRepository | |
50 | * The base repository this bundle applies to | |
51 | * @param file | |
52 | * The bundle file. | |
53 | */ | |
54 | public Bundle(BaseRepository baseRepository, File file) { | |
55 | 0 | this(baseRepository, file, false); |
56 | 0 | } |
57 | ||
58 | /** | |
59 | * Create a new bundle. | |
60 | * | |
61 | * @param baseRepository | |
62 | * The base repository this bundle applies to | |
63 | * @param file | |
64 | * The bundle file | |
65 | * @param manageFile | |
66 | * Whether to delete the bundle file when this bundle is closed. | |
67 | */ | |
68 | 6 | public Bundle(BaseRepository baseRepository, File file, boolean manageFile) { |
69 | 6 | this.baseRepository = baseRepository; |
70 | 6 | this.overlayRepository = new OverlayRepository(baseRepository, this); |
71 | 6 | this.file = file; |
72 | 6 | this.manageFile = manageFile; |
73 | 6 | } |
74 | ||
75 | /** | |
76 | * @return the underlying file for the bundle | |
77 | */ | |
78 | public File getFile() { | |
79 | 14 | return file; |
80 | } | |
81 | ||
82 | /** | |
83 | * @param manageFile | |
84 | * Whether close should delete the bundle file | |
85 | */ | |
86 | public void setManageFile(boolean manageFile) { | |
87 | 0 | this.manageFile = manageFile; |
88 | 0 | } |
89 | ||
90 | /** | |
91 | * Do the final initialization of the bundle. | |
92 | * <p> | |
93 | * This method is only public so it can be called from | |
94 | * IncomingCommand | |
95 | * | |
96 | * @param changesets | |
97 | * the changesets contained in this Bundle | |
98 | */ | |
99 | public void init(List<Changeset> changesets) { | |
100 | 5 | this.changesets = changesets; |
101 | 5 | } |
102 | ||
103 | /** | |
104 | * Return the changeset for this bundle. The are sorted from low | |
105 | * revisions to high revisions. | |
106 | * | |
107 | * @return The changesets | |
108 | */ | |
109 | public List<Changeset> getChangesets() { | |
110 | 3 | return changesets; |
111 | } | |
112 | ||
113 | public void close() { | |
114 | 6 | Repository repo = this.overlayRepository; |
115 | 6 | repo.close(); |
116 | ||
117 | 6 | if (manageFile) { |
118 | 6 | getFile().delete(); |
119 | } | |
120 | ||
121 | 6 | this.overlayRepository = null; |
122 | 6 | } |
123 | ||
124 | public BaseRepository getBaseRepository() { | |
125 | 1 | return baseRepository; |
126 | } | |
127 | ||
128 | public OverlayRepository getOverlayRepository() { | |
129 | 10 | return overlayRepository; |
130 | } | |
131 | ||
132 | /** | |
133 | * Push the changesets in the bundle to its base repository. | |
134 | * | |
135 | * @throws IOException | |
136 | */ | |
137 | public void pushToRepository() throws IOException { | |
138 | 1 | final BaseRepository base = getBaseRepository(); |
139 | 1 | GenericCommand cmd = new GenericCommand(base, "pull"); |
140 | 1 | cmd.execute(getFile().getPath()); |
141 | 1 | } |
142 | } |