1679382fbSJonathan Nieder /* 2*5c5f7c6bSMatthias Sohn * Copyright (C) 2013 Google Inc. and others 3679382fbSJonathan Nieder * 4*5c5f7c6bSMatthias Sohn * This program and the accompanying materials are made available under the 5*5c5f7c6bSMatthias Sohn * terms of the Eclipse Distribution License v. 1.0 which is available at 6*5c5f7c6bSMatthias Sohn * https://www.eclipse.org/org/documents/edl-v10.php. 7679382fbSJonathan Nieder * 8*5c5f7c6bSMatthias Sohn * SPDX-License-Identifier: BSD-3-Clause 9679382fbSJonathan Nieder */ 10679382fbSJonathan Nieder package org.eclipse.jgit.archive; 11679382fbSJonathan Nieder 12679382fbSJonathan Nieder import java.util.ArrayList; 13679382fbSJonathan Nieder import java.util.List; 14679382fbSJonathan Nieder 15679382fbSJonathan Nieder import org.eclipse.jgit.api.ArchiveCommand; 16679382fbSJonathan Nieder 17679382fbSJonathan Nieder /** 1832022e97SMatthias Sohn * Registers all format types from the org.eclipse.jgit.archive package for use 1932022e97SMatthias Sohn * via the ArchiveCommand API. 20679382fbSJonathan Nieder * 2132022e97SMatthias Sohn * See {@link org.eclipse.jgit.archive.FormatActivator} for an OSGi bundle 2232022e97SMatthias Sohn * activator that performs the same registration automatically. 23679382fbSJonathan Nieder */ 24679382fbSJonathan Nieder public class ArchiveFormats { 253b444863SDavid Pursehouse private static final List<String> myFormats = new ArrayList<>(); 26679382fbSJonathan Nieder register(String name, ArchiveCommand.Format<?> fmt)27679382fbSJonathan Nieder private static final void register(String name, ArchiveCommand.Format<?> fmt) { 28679382fbSJonathan Nieder myFormats.add(name); 29679382fbSJonathan Nieder ArchiveCommand.registerFormat(name, fmt); 30679382fbSJonathan Nieder } 31679382fbSJonathan Nieder 32679382fbSJonathan Nieder /** 33679382fbSJonathan Nieder * Register all included archive formats so they can be used 34679382fbSJonathan Nieder * as arguments to the ArchiveCommand.setFormat() method. 35679382fbSJonathan Nieder * 36679382fbSJonathan Nieder * Not thread-safe. 37679382fbSJonathan Nieder */ registerAll()38679382fbSJonathan Nieder public static void registerAll() { 394ceb25b6SRobin Rosenberg register("tar", new TarFormat()); //$NON-NLS-1$ 404ceb25b6SRobin Rosenberg register("tgz", new TgzFormat()); //$NON-NLS-1$ 414ceb25b6SRobin Rosenberg register("tbz2", new Tbz2Format()); //$NON-NLS-1$ 424ceb25b6SRobin Rosenberg register("txz", new TxzFormat()); //$NON-NLS-1$ 434ceb25b6SRobin Rosenberg register("zip", new ZipFormat()); //$NON-NLS-1$ 44679382fbSJonathan Nieder } 45679382fbSJonathan Nieder 46679382fbSJonathan Nieder /** 47679382fbSJonathan Nieder * Clean up by deregistering all formats that were registered 48679382fbSJonathan Nieder * by registerAll(). 49679382fbSJonathan Nieder * 50679382fbSJonathan Nieder * Not thread-safe. 51679382fbSJonathan Nieder */ unregisterAll()52679382fbSJonathan Nieder public static void unregisterAll() { 53679382fbSJonathan Nieder for (String name : myFormats) { 54679382fbSJonathan Nieder ArchiveCommand.unregisterFormat(name); 55679382fbSJonathan Nieder } 56679382fbSJonathan Nieder myFormats.clear(); 57679382fbSJonathan Nieder } 58679382fbSJonathan Nieder } 59