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 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 /** @return options used by readers accessing the repository. */
67 public DfsReaderOptions getReaderOptions() {
68 return readerOptions;
69 }
70
71 /**
72 * Set the reader options.
73 *
74 * @param opt
75 * new reader options object.
76 * @return {@code this}
77 */
78 public B setReaderOptions(DfsReaderOptions opt) {
79 readerOptions = opt;
80 return self();
81 }
82
83 /** @return a description of the repository. */
84 public DfsRepositoryDescription getRepositoryDescription() {
85 return repoDesc;
86 }
87
88 /**
89 * Set the repository description.
90 *
91 * @param desc
92 * new repository description object.
93 * @return {@code this}
94 */
95 public B setRepositoryDescription(DfsRepositoryDescription desc) {
96 repoDesc = desc;
97 return self();
98 }
99
100 @Override
101 public B setup() throws IllegalArgumentException, IOException {
102 super.setup();
103 if (getReaderOptions() == null)
104 setReaderOptions(new DfsReaderOptions());
105 if (getRepositoryDescription() == null)
106 setRepositoryDescription(new DfsRepositoryDescription());
107 return self();
108 }
109
110 /**
111 * Create a repository matching the configuration in this builder.
112 * <p>
113 * If an option was not set, the build method will try to default the option
114 * based on other options. If insufficient information is available, an
115 * exception is thrown to the caller.
116 *
117 * @return a repository matching this configuration.
118 * @throws IllegalArgumentException
119 * insufficient parameters were set.
120 * @throws IOException
121 * the repository could not be accessed to configure the rest of
122 * the builder's parameters.
123 */
124 @Override
125 public abstract R build() throws IOException;
126
127 // We don't support local file IO and thus shouldn't permit these to set.
128
129 @Override
130 public B setGitDir(File gitDir) {
131 if (gitDir != null)
132 throw new IllegalArgumentException();
133 return self();
134 }
135
136 @Override
137 public B setObjectDirectory(File objectDirectory) {
138 if (objectDirectory != null)
139 throw new IllegalArgumentException();
140 return self();
141 }
142
143 @Override
144 public B addAlternateObjectDirectory(File other) {
145 throw new UnsupportedOperationException(
146 JGitText.get().unsupportedAlternates);
147 }
148
149 @Override
150 public B setWorkTree(File workTree) {
151 if (workTree != null)
152 throw new IllegalArgumentException();
153 return self();
154 }
155
156 @Override
157 public B setIndexFile(File indexFile) {
158 if (indexFile != null)
159 throw new IllegalArgumentException();
160 return self();
161 }
162 }