1 /*
2 * Copyright (C) 2011, Google Inc.
3 * and other copyright owners as documented in the project's IP log.
4 *
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
23 *
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 package org.eclipse.jgit.internal.storage.dfs;
45
46 import java.io.File;
47 import java.io.IOException;
48
49 import org.eclipse.jgit.internal.JGitText;
50 import org.eclipse.jgit.lib.BaseRepositoryBuilder;
51
52 /**
53 * Constructs a {@link org.eclipse.jgit.internal.storage.dfs.DfsRepository}.
54 *
55 * @param <B>
56 * type of the builder class.
57 * @param <R>
58 * type of the repository class.
59 */
60 public abstract class DfsRepositoryBuilder<B extends DfsRepositoryBuilder, R extends DfsRepository>
61 extends BaseRepositoryBuilder<B, R> {
62 private DfsReaderOptions readerOptions;
63
64 private DfsRepositoryDescription repoDesc;
65
66 /**
67 * Get options used by readers accessing the repository.
68 *
69 * @return options used by readers accessing the repository.
70 */
71 public DfsReaderOptions getReaderOptions() {
72 return readerOptions;
73 }
74
75 /**
76 * Set the reader options.
77 *
78 * @param opt
79 * new reader options object.
80 * @return {@code this}
81 */
82 public B setReaderOptions(DfsReaderOptions opt) {
83 readerOptions = opt;
84 return self();
85 }
86
87 /**
88 * Get the description of the repository.
89 *
90 * @return the description of the repository.
91 */
92 public DfsRepositoryDescription getRepositoryDescription() {
93 return repoDesc;
94 }
95
96 /**
97 * Set the repository description.
98 *
99 * @param desc
100 * new repository description object.
101 * @return {@code this}
102 */
103 public B setRepositoryDescription(DfsRepositoryDescription desc) {
104 repoDesc = desc;
105 return self();
106 }
107
108 /** {@inheritDoc} */
109 @Override
110 public B setup() throws IllegalArgumentException, IOException {
111 super.setup();
112 if (getReaderOptions() == null)
113 setReaderOptions(new DfsReaderOptions());
114 if (getRepositoryDescription() == null)
115 setRepositoryDescription(new DfsRepositoryDescription());
116 return self();
117 }
118
119 /**
120 * {@inheritDoc}
121 * <p>
122 * Create a repository matching the configuration in this builder.
123 * <p>
124 * If an option was not set, the build method will try to default the option
125 * based on other options. If insufficient information is available, an
126 * exception is thrown to the caller.
127 */
128 @Override
129 public abstract R build() throws IOException;
130
131 // We don't support local file IO and thus shouldn't permit these to set.
132
133 /** {@inheritDoc} */
134 @Override
135 public B setGitDir(File gitDir) {
136 if (gitDir != null)
137 throw new IllegalArgumentException();
138 return self();
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 public B setObjectDirectory(File objectDirectory) {
144 if (objectDirectory != null)
145 throw new IllegalArgumentException();
146 return self();
147 }
148
149 /** {@inheritDoc} */
150 @Override
151 public B addAlternateObjectDirectory(File other) {
152 throw new UnsupportedOperationException(
153 JGitText.get().unsupportedAlternates);
154 }
155
156 /** {@inheritDoc} */
157 @Override
158 public B setWorkTree(File workTree) {
159 if (workTree != null)
160 throw new IllegalArgumentException();
161 return self();
162 }
163
164 /** {@inheritDoc} */
165 @Override
166 public B setIndexFile(File indexFile) {
167 if (indexFile != null)
168 throw new IllegalArgumentException();
169 return self();
170 }
171 }