You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GlobalAttributesNode.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.CoreConfig;
  16. import org.eclipse.jgit.lib.Repository;
  17. import org.eclipse.jgit.util.FS;
  18. /**
  19. * Attribute node loaded from global system-wide file.
  20. */
  21. public class GlobalAttributesNode extends AttributesNode {
  22. final Repository repository;
  23. /**
  24. * Constructor for GlobalAttributesNode.
  25. *
  26. * @param repository
  27. * the {@link org.eclipse.jgit.lib.Repository}.
  28. */
  29. public GlobalAttributesNode(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. String path = repository.getConfig().get(CoreConfig.KEY)
  42. .getAttributesFile();
  43. if (path != null) {
  44. File attributesFile;
  45. if (path.startsWith("~/")) { //$NON-NLS-1$
  46. attributesFile = fs.resolve(fs.userHome(),
  47. path.substring(2));
  48. } else {
  49. attributesFile = fs.resolve(null, path);
  50. }
  51. FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributesFile);
  52. }
  53. return r.getRules().isEmpty() ? null : r;
  54. }
  55. }