InfoAttributesNode.java

  1. /*
  2.  * Copyright (C) 2014, Arthur Daussy <arthur.daussy@obeo.fr>
  3.  * Copyright (C) 2015, Christian Halstrick <christian.halstrick@sap.com> and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */
  11. package org.eclipse.jgit.internal.storage.file;

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

  14. import org.eclipse.jgit.attributes.AttributesNode;
  15. import org.eclipse.jgit.lib.Constants;
  16. import org.eclipse.jgit.lib.Repository;
  17. import org.eclipse.jgit.util.FS;

  18. /**
  19.  * Attribute node loaded from the $GIT_DIR/info/attributes file.
  20.  */
  21. public class InfoAttributesNode extends AttributesNode {
  22.     final Repository repository;

  23.     /**
  24.      * Constructor for InfoAttributesNode.
  25.      *
  26.      * @param repository
  27.      *            the {@link org.eclipse.jgit.lib.Repository}.
  28.      */
  29.     public InfoAttributesNode(Repository repository) {
  30.         this.repository = repository;
  31.     }

  32.     /**
  33.      * Load the attributes node
  34.      *
  35.      * @return the attributes node
  36.      * @throws java.io.IOException
  37.      */
  38.     public AttributesNode load() throws IOException {
  39.         AttributesNode r = new AttributesNode();

  40.         FS fs = repository.getFS();

  41.         File attributes = fs.resolve(repository.getDirectory(),
  42.                 Constants.INFO_ATTRIBUTES);
  43.         FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributes);

  44.         return r.getRules().isEmpty() ? null : r;
  45.     }

  46. }