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.ModuleLocation; 019import io.github.ascopes.jct.workspaces.PathRoot; 020import java.util.Map; 021import java.util.Set; 022import javax.tools.JavaFileManager.Location; 023import org.apiguardian.api.API; 024import org.apiguardian.api.API.Status; 025import org.jspecify.annotations.Nullable; 026 027/** 028 * A container group implementation that holds zero or more modules. 029 * 030 * <p>These modules can be accessed by their module name. Each one holds a separate group of 031 * containers, and has the ability to produce a custom class loader. 032 * 033 * @author Ashley Scopes 034 * @since 0.0.1 035 */ 036@API(since = "0.0.1", status = Status.STABLE) 037public interface ModuleContainerGroup extends ContainerGroup { 038 039 /** 040 * Add a container to this group. 041 * 042 * <p>The provided container will be closed when this container group is closed. 043 * 044 * @param module the module that the container is for. 045 * @param container the container to add. 046 */ 047 void addModule(String module, Container container); 048 049 /** 050 * Add a path to this group for a module. 051 * 052 * @param module the name of the module that this is for. 053 * @param path the path to add. 054 */ 055 void addModule(String module, PathRoot path); 056 057 /** 058 * Find the package container group for the given module. 059 * 060 * @param module the module name. 061 * @return the container group, or {@code null} if no module was found by that name. 062 */ 063 @Nullable 064 PackageContainerGroup getModule(String module); 065 066 /** 067 * Get the {@link PackageContainerGroup} for a given module name, creating it if it does not yet 068 * exist. 069 * 070 * @param moduleName the module name to look up. 071 * @return the container group. 072 */ 073 PackageContainerGroup getOrCreateModule(String moduleName); 074 075 /** 076 * Get the module-oriented location. 077 * 078 * @return the module-oriented location. 079 */ 080 @Override 081 Location getLocation(); 082 083 /** 084 * Get all locations that are modules. 085 * 086 * @return the locations that are modules. 087 */ 088 Set<Location> getLocationsForModules(); 089 090 /** 091 * Get the module container impl in this group. 092 * 093 * @return the container implementation. 094 */ 095 Map<ModuleLocation, PackageContainerGroup> getModules(); 096 097 /** 098 * Determine if this group contains a given module. 099 * 100 * @param location the module location to look for. 101 * @return {@code true} if present, or {@code false} if not. 102 */ 103 boolean hasLocation(ModuleLocation location); 104}