View Javadoc
1   /*
2    * Copyright (C) 2011, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.internal.storage.dfs;
12  
13  import java.io.File;
14  import java.io.IOException;
15  
16  import org.eclipse.jgit.internal.JGitText;
17  import org.eclipse.jgit.lib.BaseRepositoryBuilder;
18  
19  /**
20   * Constructs a {@link org.eclipse.jgit.internal.storage.dfs.DfsRepository}.
21   *
22   * @param <B>
23   *            type of the builder class.
24   * @param <R>
25   *            type of the repository class.
26   */
27  public abstract class DfsRepositoryBuilder<B extends DfsRepositoryBuilder, R extends DfsRepository>
28  		extends BaseRepositoryBuilder<B, R> {
29  	private DfsReaderOptions readerOptions;
30  
31  	private DfsRepositoryDescription repoDesc;
32  
33  	/**
34  	 * Get options used by readers accessing the repository.
35  	 *
36  	 * @return options used by readers accessing the repository.
37  	 */
38  	public DfsReaderOptions getReaderOptions() {
39  		return readerOptions;
40  	}
41  
42  	/**
43  	 * Set the reader options.
44  	 *
45  	 * @param opt
46  	 *            new reader options object.
47  	 * @return {@code this}
48  	 */
49  	public B setReaderOptions(DfsReaderOptions opt) {
50  		readerOptions = opt;
51  		return self();
52  	}
53  
54  	/**
55  	 * Get the description of the repository.
56  	 *
57  	 * @return the description of the repository.
58  	 */
59  	public DfsRepositoryDescription getRepositoryDescription() {
60  		return repoDesc;
61  	}
62  
63  	/**
64  	 * Set the repository description.
65  	 *
66  	 * @param desc
67  	 *            new repository description object.
68  	 * @return {@code this}
69  	 */
70  	public B setRepositoryDescription(DfsRepositoryDescription desc) {
71  		repoDesc = desc;
72  		return self();
73  	}
74  
75  	/** {@inheritDoc} */
76  	@Override
77  	public B setup() throws IllegalArgumentException, IOException {
78  		super.setup();
79  		if (getReaderOptions() == null)
80  			setReaderOptions(new DfsReaderOptions());
81  		if (getRepositoryDescription() == null)
82  			setRepositoryDescription(new DfsRepositoryDescription());
83  		return self();
84  	}
85  
86  	/**
87  	 * {@inheritDoc}
88  	 * <p>
89  	 * Create a repository matching the configuration in this builder.
90  	 * <p>
91  	 * If an option was not set, the build method will try to default the option
92  	 * based on other options. If insufficient information is available, an
93  	 * exception is thrown to the caller.
94  	 */
95  	@Override
96  	public abstract R build() throws IOException;
97  
98  	// We don't support local file IO and thus shouldn't permit these to set.
99  
100 	/** {@inheritDoc} */
101 	@Override
102 	public B setGitDir(File gitDir) {
103 		if (gitDir != null)
104 			throw new IllegalArgumentException();
105 		return self();
106 	}
107 
108 	/** {@inheritDoc} */
109 	@Override
110 	public B setObjectDirectory(File objectDirectory) {
111 		if (objectDirectory != null)
112 			throw new IllegalArgumentException();
113 		return self();
114 	}
115 
116 	/** {@inheritDoc} */
117 	@Override
118 	public B addAlternateObjectDirectory(File other) {
119 		throw new UnsupportedOperationException(
120 				JGitText.get().unsupportedAlternates);
121 	}
122 
123 	/** {@inheritDoc} */
124 	@Override
125 	public B setWorkTree(File workTree) {
126 		if (workTree != null)
127 			throw new IllegalArgumentException();
128 		return self();
129 	}
130 
131 	/** {@inheritDoc} */
132 	@Override
133 	public B setIndexFile(File indexFile) {
134 		if (indexFile != null)
135 			throw new IllegalArgumentException();
136 		return self();
137 	}
138 }