View Javadoc
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  
13  import java.io.File;
14  import java.io.IOException;
15  
16  import org.eclipse.jgit.attributes.AttributesNode;
17  import org.eclipse.jgit.lib.Constants;
18  import org.eclipse.jgit.lib.Repository;
19  import org.eclipse.jgit.util.FS;
20  
21  /**
22   * Attribute node loaded from the $GIT_DIR/info/attributes file.
23   */
24  public class InfoAttributesNode extends AttributesNode {
25  	final Repository repository;
26  
27  	/**
28  	 * Constructor for InfoAttributesNode.
29  	 *
30  	 * @param repository
31  	 *            the {@link org.eclipse.jgit.lib.Repository}.
32  	 */
33  	public InfoAttributesNode(Repository repository) {
34  		this.repository = repository;
35  	}
36  
37  	/**
38  	 * Load the attributes node
39  	 *
40  	 * @return the attributes node
41  	 * @throws java.io.IOException
42  	 */
43  	public AttributesNode load() throws IOException {
44  		AttributesNode r = new AttributesNode();
45  
46  		FS fs = repository.getFS();
47  
48  		File attributes = fs.resolve(repository.getDirectory(),
49  				Constants.INFO_ATTRIBUTES);
50  		FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributes);
51  
52  		return r.getRules().isEmpty() ? null : r;
53  	}
54  
55  }