001/*
002 * Copyright (C) 2022 - 2024, 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 */
016package io.github.ascopes.jct.containers;
017
018import io.github.ascopes.jct.filemanagers.PathFileObject;
019import java.io.Closeable;
020import java.util.ServiceLoader;
021import javax.tools.JavaFileManager.Location;
022import org.apiguardian.api.API;
023import org.apiguardian.api.API.Status;
024
025/**
026 * Base container group interface.
027 *
028 * <p>Closing an implementation of this interface will free up any internal resources that have
029 * been opened. Resources passed to the implementation in an already-open state will not be closed.
030 *
031 * @author Ashley Scopes
032 * @since 0.0.1
033 */
034@API(since = "0.0.1", status = Status.STABLE)
035public interface ContainerGroup extends Closeable {
036
037  /**
038   * Determine whether this group contains the given file object anywhere.
039   *
040   * @param fileObject the file object to look for.
041   * @return {@code true} if the file object is contained in this group, or {@code false} otherwise.
042   */
043  boolean contains(PathFileObject fileObject);
044
045  /**
046   * Get the location of this container group.
047   *
048   * @return the location.
049   */
050  Location getLocation();
051
052  /**
053   * Get the effective Java release being targeted by the compiler that owns this container group.
054   *
055   * <p>This is used to calculate Multi-Release JAR packages correctly.
056   *
057   * @return the effective release version.
058   */
059  String getRelease();
060
061  /**
062   * Get a service loader for the given service class, or throw an exception if the operation is not
063   * supported.
064   *
065   * @param service the service class to get.
066   * @param <S>     the service class type.
067   * @return the service loader.
068   * @throws UnsupportedOperationException if the container group does not provide this
069   *                                       functionality.
070   */
071  <S> ServiceLoader<S> getServiceLoader(Class<S> service);
072}