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.containers.ModuleContainerGroup;
019import io.github.ascopes.jct.containers.OutputContainerGroup;
020import io.github.ascopes.jct.containers.PackageContainerGroup;
021import io.github.ascopes.jct.diagnostics.TraceDiagnostic;
022import io.github.ascopes.jct.filemanagers.JctFileManager;
023import java.util.List;
024import java.util.Set;
025import javax.tools.JavaFileObject;
026import javax.tools.StandardLocation;
027import org.apiguardian.api.API;
028import org.apiguardian.api.API.Status;
029
030/**
031 * Interface representing the result of a compilation.
032 *
033 * @author Ashley Scopes
034 * @since 0.0.1
035 */
036@API(since = "0.0.1", status = Status.STABLE)
037public interface JctCompilation {
038
039  /**
040   * Determine if warnings were treated as errors.
041   *
042   * @return {@code true} if warnings were treated as errors, or {@code false} otherwise.
043   */
044  boolean isFailOnWarnings();
045
046  /**
047   * Determine if the compilation was successful or not.
048   *
049   * @return {@code true} if successful, or {@code false} if not successful.
050   */
051  boolean isSuccessful();
052
053  /**
054   * Determine if the compilation was a failure or not.
055   *
056   * @return {@code true} if not successful, or {@code false} if successful.
057   */
058  default boolean isFailure() {
059    return !isSuccessful();
060  }
061
062  /**
063   * Get the lines of output produced by the compiler, if any were captured.
064   *
065   * <p>This is separate to diagnostics.
066   *
067   * @return the lines of output.
068   */
069  List<String> getOutputLines();
070
071  /**
072   * Get the compilation units used in the compilation.
073   *
074   * @return the compilation units.
075   */
076  Set<JavaFileObject> getCompilationUnits();
077
078  /**
079   * Get the diagnostics that were reported by the compilation.
080   *
081   * @return the diagnostics
082   */
083  List<TraceDiagnostic<JavaFileObject>> getDiagnostics();
084
085  /**
086   * Get the file manager that was used to store and manage files.
087   *
088   * @return the file manager.
089   */
090  JctFileManager getFileManager();
091
092  /**
093   * Get the output container group for class outputs.
094   *
095   * @return the output container group, or {@code null} if it does not exist.
096   */
097  default OutputContainerGroup getClassOutputs() {
098    return getFileManager().getOutputContainerGroup(StandardLocation.CLASS_OUTPUT);
099  }
100
101  /**
102   * Get the output container group for source outputs.
103   *
104   * @return the output container group, or {@code null} if it does not exist.
105   */
106  default OutputContainerGroup getSourceOutputs() {
107    return getFileManager().getOutputContainerGroup(StandardLocation.SOURCE_OUTPUT);
108  }
109
110  /**
111   * Get the package container group for the class path.
112   *
113   * @return the package container group, or {@code null} if it does not exist.
114   */
115  default PackageContainerGroup getClassPath() {
116    return getFileManager().getPackageContainerGroup(StandardLocation.CLASS_PATH);
117  }
118
119  /**
120   * Get the package container group for the source path.
121   *
122   * @return the package container group, or {@code null} if it does not exist.
123   */
124  default PackageContainerGroup getSourcePath() {
125    return getFileManager().getPackageContainerGroup(StandardLocation.SOURCE_PATH);
126  }
127
128  /**
129   * Get the package container group for the annotation processor path.
130   *
131   * @return the package container group, or {@code null} if it does not exist.
132   */
133  default PackageContainerGroup getAnnotationProcessorPath() {
134    return getFileManager().getPackageContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_PATH);
135  }
136
137  /**
138   * Get the module container group for the annotation processor module path.
139   *
140   * @return the module container group, or {@code null} if it does not exist.
141   */
142  default ModuleContainerGroup getAnnotationProcessorModulePath() {
143    return getFileManager()
144        .getModuleContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH);
145  }
146
147  /**
148   * Get the package container group for the platform class path (a.k.a. the bootstrap class path).
149   *
150   * @return the package container group, or {@code null} if it does not exist.
151   */
152  default PackageContainerGroup getPlatformClassPath() {
153    return getFileManager().getPackageContainerGroup(StandardLocation.PLATFORM_CLASS_PATH);
154  }
155
156  /**
157   * Get the output container group for the native header file outputs.
158   *
159   * @return the output container group, or {@code null} if it does not exist.
160   */
161  default OutputContainerGroup getNativeHeaderOutputs() {
162    return getFileManager().getOutputContainerGroup(StandardLocation.NATIVE_HEADER_OUTPUT);
163  }
164
165  /**
166   * Get the module container group for the module source path.
167   *
168   * @return the module container group, or {@code null} if it does not exist.
169   */
170  default ModuleContainerGroup getModuleSourcePath() {
171    return getFileManager().getModuleContainerGroup(StandardLocation.MODULE_SOURCE_PATH);
172  }
173
174  /**
175   * Get the module container group for the upgrade module path.
176   *
177   * @return the module container group, or {@code null} if it does not exist.
178   */
179  default ModuleContainerGroup getUpgradeModulePath() {
180    return getFileManager().getModuleContainerGroup(StandardLocation.UPGRADE_MODULE_PATH);
181  }
182
183  /**
184   * Get the module container group for all system modules that are part of the JDK distribution.
185   *
186   * @return the module container group, or {@code null} if it does not exist.
187   */
188  default ModuleContainerGroup getSystemModules() {
189    return getFileManager().getModuleContainerGroup(StandardLocation.SYSTEM_MODULES);
190  }
191
192  /**
193   * Get the module container group for the module path.
194   *
195   * @return the module container group, or {@code null} if it does not exist.
196   */
197  default ModuleContainerGroup getModulePath() {
198    return getFileManager().getModuleContainerGroup(StandardLocation.MODULE_PATH);
199  }
200
201  /**
202   * Get the module container group for the patch module path.
203   *
204   * @return the module container group, or {@code null} if it does not exist.
205   */
206  default ModuleContainerGroup getPatchModulePath() {
207    return getFileManager().getModuleContainerGroup(StandardLocation.PATCH_MODULE_PATH);
208  }
209}