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