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.

ArchiveFormats.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2013 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.archive;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import org.eclipse.jgit.api.ArchiveCommand;
  14. /**
  15. * Registers all format types from the org.eclipse.jgit.archive package for use
  16. * via the ArchiveCommand API.
  17. *
  18. * See {@link org.eclipse.jgit.archive.FormatActivator} for an OSGi bundle
  19. * activator that performs the same registration automatically.
  20. */
  21. public class ArchiveFormats {
  22. private static final List<String> myFormats = new ArrayList<>();
  23. private static final void register(String name, ArchiveCommand.Format<?> fmt) {
  24. myFormats.add(name);
  25. ArchiveCommand.registerFormat(name, fmt);
  26. }
  27. /**
  28. * Register all included archive formats so they can be used
  29. * as arguments to the ArchiveCommand.setFormat() method.
  30. *
  31. * Not thread-safe.
  32. */
  33. public static void registerAll() {
  34. register("tar", new TarFormat()); //$NON-NLS-1$
  35. register("tgz", new TgzFormat()); //$NON-NLS-1$
  36. register("tbz2", new Tbz2Format()); //$NON-NLS-1$
  37. register("txz", new TxzFormat()); //$NON-NLS-1$
  38. register("zip", new ZipFormat()); //$NON-NLS-1$
  39. }
  40. /**
  41. * Clean up by deregistering all formats that were registered
  42. * by registerAll().
  43. *
  44. * Not thread-safe.
  45. */
  46. public static void unregisterAll() {
  47. for (String name : myFormats) {
  48. ArchiveCommand.unregisterFormat(name);
  49. }
  50. myFormats.clear();
  51. }
  52. }