001/*
002 * Copyright (C) 2022 - 2023, 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.compilers;
017
018import io.github.ascopes.jct.ex.JctCompilerException;
019import io.github.ascopes.jct.filemanagers.JctFileManager;
020import java.util.Collection;
021import java.util.List;
022import javax.tools.JavaCompiler;
023import org.apiguardian.api.API;
024import org.apiguardian.api.API.Status;
025
026/**
027 * Factory for producing {@link JctCompilation} objects by performing a physical compilation with a
028 * compiler.
029 *
030 * @author Ashley Scopes
031 * @since 0.0.1 (0.0.1-M7)
032 */
033@API(since = "0.0.1", status = Status.STABLE)
034public interface JctCompilationFactory {
035
036  /**
037   * Create a compilation.
038   *
039   * @param flags          the flags to pass to the compiler.
040   * @param fileManager    the file manager to use for file management.
041   * @param jsr199Compiler the compiler backend to use.
042   * @param classNames     the binary names of the classes to compile. If this is null, then classes
043   *                       should be discovered automatically.
044   * @return the compilation result that contains whether the compiler succeeded or failed, amongst
045   *     other information.
046   * @throws JctCompilerException if any prerequisites fail, such as no compilation units being
047   *    found, or if the underlying JSR-199 compiler raises an unhandled exception and cannot
048   *    complete when invoked.
049   */
050  JctCompilation createCompilation(
051      List<String> flags,
052      JctFileManager fileManager,
053      JavaCompiler jsr199Compiler,
054      Collection<String> classNames
055  );
056}