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