DfsRepositoryBuilder.java

  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. package org.eclipse.jgit.internal.storage.dfs;

  11. import java.io.File;
  12. import java.io.IOException;

  13. import org.eclipse.jgit.internal.JGitText;
  14. import org.eclipse.jgit.lib.BaseRepositoryBuilder;

  15. /**
  16.  * Constructs a {@link org.eclipse.jgit.internal.storage.dfs.DfsRepository}.
  17.  *
  18.  * @param <B>
  19.  *            type of the builder class.
  20.  * @param <R>
  21.  *            type of the repository class.
  22.  */
  23. public abstract class DfsRepositoryBuilder<B extends DfsRepositoryBuilder, R extends DfsRepository>
  24.         extends BaseRepositoryBuilder<B, R> {
  25.     private DfsReaderOptions readerOptions;

  26.     private DfsRepositoryDescription repoDesc;

  27.     /**
  28.      * Get options used by readers accessing the repository.
  29.      *
  30.      * @return options used by readers accessing the repository.
  31.      */
  32.     public DfsReaderOptions getReaderOptions() {
  33.         return readerOptions;
  34.     }

  35.     /**
  36.      * Set the reader options.
  37.      *
  38.      * @param opt
  39.      *            new reader options object.
  40.      * @return {@code this}
  41.      */
  42.     public B setReaderOptions(DfsReaderOptions opt) {
  43.         readerOptions = opt;
  44.         return self();
  45.     }

  46.     /**
  47.      * Get the description of the repository.
  48.      *
  49.      * @return the description of the repository.
  50.      */
  51.     public DfsRepositoryDescription getRepositoryDescription() {
  52.         return repoDesc;
  53.     }

  54.     /**
  55.      * Set the repository description.
  56.      *
  57.      * @param desc
  58.      *            new repository description object.
  59.      * @return {@code this}
  60.      */
  61.     public B setRepositoryDescription(DfsRepositoryDescription desc) {
  62.         repoDesc = desc;
  63.         return self();
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public B setup() throws IllegalArgumentException, IOException {
  68.         super.setup();
  69.         if (getReaderOptions() == null)
  70.             setReaderOptions(new DfsReaderOptions());
  71.         if (getRepositoryDescription() == null)
  72.             setRepositoryDescription(new DfsRepositoryDescription());
  73.         return self();
  74.     }

  75.     /**
  76.      * {@inheritDoc}
  77.      * <p>
  78.      * Create a repository matching the configuration in this builder.
  79.      * <p>
  80.      * If an option was not set, the build method will try to default the option
  81.      * based on other options. If insufficient information is available, an
  82.      * exception is thrown to the caller.
  83.      */
  84.     @Override
  85.     public abstract R build() throws IOException;

  86.     // We don't support local file IO and thus shouldn't permit these to set.

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public B setGitDir(File gitDir) {
  90.         if (gitDir != null)
  91.             throw new IllegalArgumentException();
  92.         return self();
  93.     }

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public B setObjectDirectory(File objectDirectory) {
  97.         if (objectDirectory != null)
  98.             throw new IllegalArgumentException();
  99.         return self();
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public B addAlternateObjectDirectory(File other) {
  104.         throw new UnsupportedOperationException(
  105.                 JGitText.get().unsupportedAlternates);
  106.     }

  107.     /** {@inheritDoc} */
  108.     @Override
  109.     public B setWorkTree(File workTree) {
  110.         if (workTree != null)
  111.             throw new IllegalArgumentException();
  112.         return self();
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     public B setIndexFile(File indexFile) {
  117.         if (indexFile != null)
  118.             throw new IllegalArgumentException();
  119.         return self();
  120.     }
  121. }