001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.loader.archive;
018
019import java.io.IOException;
020import java.net.MalformedURLException;
021import java.net.URL;
022import java.util.List;
023import java.util.jar.Manifest;
024
025import org.springframework.boot.loader.Launcher;
026
027/**
028 * An archive that can be launched by the {@link Launcher}.
029 *
030 * @author Phillip Webb
031 * @see JarFileArchive
032 */
033public interface Archive extends Iterable<Archive.Entry> {
034
035        /**
036         * Returns a URL that can be used to load the archive.
037         * @return the archive URL
038         * @throws MalformedURLException if the URL is malformed
039         */
040        URL getUrl() throws MalformedURLException;
041
042        /**
043         * Returns the manifest of the archive.
044         * @return the manifest
045         * @throws IOException if the manifest cannot be read
046         */
047        Manifest getManifest() throws IOException;
048
049        /**
050         * Returns nested {@link Archive}s for entries that match the specified filter.
051         * @param filter the filter used to limit entries
052         * @return nested archives
053         * @throws IOException if nested archives cannot be read
054         */
055        List<Archive> getNestedArchives(EntryFilter filter) throws IOException;
056
057        /**
058         * Represents a single entry in the archive.
059         */
060        interface Entry {
061
062                /**
063                 * Returns {@code true} if the entry represents a directory.
064                 * @return if the entry is a directory
065                 */
066                boolean isDirectory();
067
068                /**
069                 * Returns the name of the entry.
070                 * @return the name of the entry
071                 */
072                String getName();
073
074        }
075
076        /**
077         * Strategy interface to filter {@link Entry Entries}.
078         */
079        interface EntryFilter {
080
081                /**
082                 * Apply the jar entry filter.
083                 * @param entry the entry to filter
084                 * @return {@code true} if the filter matches
085                 */
086                boolean matches(Entry entry);
087
088        }
089
090}