| 47 | import {JavaParser} from './argument-parsers.js'; |
| 48 | |
| 49 | export class JavaCompiler extends BaseCompiler implements SimpleOutputFilenameCompiler { |
| 50 | static get key() { |
| 51 | return 'java'; |
| 52 | } |
| 53 | |
| 54 | javaRuntime: string; |
| 55 | mainRegex: RegExp; |
| 56 | |
| 57 | libPaths: string[]; |
| 58 | |
| 59 | constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) { |
| 60 | super( |
| 61 | { |
| 62 | // Default is to disable all "cosmetic" filters |
| 63 | disabledFilters: ['labels', 'directives', 'commentOnly', 'trim', 'debugCalls'], |
| 64 | ...compilerInfo, |
| 65 | }, |
| 66 | env, |
| 67 | ); |
| 68 | this.javaRuntime = this.compilerProps<string>(`compiler.${this.compiler.id}.runtime`); |
| 69 | this.mainRegex = /public static ?(.*?) void main\(java\.lang\.String\[]\)/; |
| 70 | this.libPaths = []; |
| 71 | } |
| 72 | |
| 73 | override getSharedLibraryPathsAsArguments() { |
| 74 | return []; |
| 75 | } |
| 76 | |
| 77 | override async runCompiler( |
| 78 | compiler: string, |
| 79 | options: string[], |
| 80 | inputFilename: string, |
| 81 | execOptions: ExecutionOptionsWithEnv, |
| 82 | filters?: ParseFiltersAndOutputOptions, |
| 83 | ): Promise<CompilationResult> { |
| 84 | if (!execOptions) { |
| 85 | execOptions = this.getDefaultExecOptions(); |
| 86 | } |
| 87 | |
| 88 | if (!execOptions.customCwd) { |
| 89 | execOptions.customCwd = path.dirname(inputFilename); |
| 90 | } |
| 91 | |
| 92 | // The items in 'options' before the source file are user inputs. |
| 93 | const sourceFileOptionIndex = options.findIndex(option => { |
| 94 | return option.endsWith('.java'); |
| 95 | }); |
| 96 | const userOptions = options.slice(0, sourceFileOptionIndex); |
| 97 | const javaOptions = _.compact([...this.getClasspathArgument(), ...userOptions, inputFilename]); |
| 98 | const result = await this.exec(compiler, javaOptions, execOptions); |
| 99 | return { |
| 100 | ...this.transformToCompilationResult(result, inputFilename), |
| 101 | languageId: this.getCompilerResultLanguageId(filters), |
| 102 | instructionSet: this.getInstructionSetFromCompilerArgs(options), |
| 103 | }; |
| 104 | } |
| 105 | |
| 106 | async readdir(dirPath: string): Promise<string[]> { |
nothing calls this directly
no outgoing calls
no test coverage detected