MCPcopy Index your code
hub / github.com/compiler-explorer/compiler-explorer / getMainClassName

Method getMainClassName

lib/compilers/java.ts:218–249  ·  view source on GitHub ↗
(dirPath: string)

Source from the content-addressed store, hash-verified

216 }
217
218 async getMainClassName(dirPath: string) {
219 const maxSize = this.env.ceProps('max-asm-size', 64 * 1024 * 1024);
220 const files = await fs.readdir(dirPath);
221 const results = await Promise.all(
222 files
223 .filter(f => f.endsWith('.class'))
224 .map(async classFile => {
225 const options = {
226 maxOutput: maxSize,
227 customCwd: dirPath,
228 };
229 const objResult = await this.exec(this.compiler.objdumper, [classFile], options);
230 if (objResult.code !== 0) {
231 return null;
232 }
233
234 if (this.mainRegex.test(objResult.stdout)) {
235 return classFile;
236 }
237 return null;
238 }),
239 );
240
241 const candidates = results.filter(file => file !== null);
242 if (candidates.length > 0) {
243 // In case of multiple candidates, we'll just take the first one.
244 const fileName = unwrap(candidates[0]);
245 return fileName.substring(0, fileName.lastIndexOf('.'));
246 }
247 // We were unable to find a main method, let's error out assuming "Main"
248 return 'Main';
249 }
250
251 override getArgumentParserClass() {
252 return JavaParser;

Callers 1

handleInterpretingMethod · 0.95

Calls 4

testMethod · 0.80
unwrapFunction · 0.50
readdirMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected