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