diff --git a/src/detectors/Java/JavaLanguageDetector.ts b/src/detectors/Java/JavaLanguageDetector.ts index a24fbeb78..491743979 100644 --- a/src/detectors/Java/JavaLanguageDetector.ts +++ b/src/detectors/Java/JavaLanguageDetector.ts @@ -19,19 +19,21 @@ export class JavaLanguageDetector implements ILanguageDetector { const result: LanguageAtPath[] = []; let packageFiles: Metadata[] = await this.fileInspector.scanFor(fileNameRegExp('pom.xml'), '/'); const isMaven: boolean = packageFiles.length > 0; - const hasKtFiles = (await this.fileInspector.scanFor(fileExtensionRegExp(['kt', 'kts']), '/')).length > 0; + const ktFiles: Metadata[] = await this.fileInspector.scanFor(fileExtensionRegExp(['kt', 'kts']), '/'); + const hasKtFiles = ktFiles.length > 0; if (!isMaven) { packageFiles = await this.fileInspector.scanFor(fileNameRegExp('build.gradle'), '/'); } if (packageFiles.length > 0) { for (const path of packageFiles.map((file) => nodePath.dirname(file.path))) { - result.push({ language: ProgrammingLanguage.Java, path }); + result.push({ language: hasKtFiles ? ProgrammingLanguage.Kotlin : ProgrammingLanguage.Java, path }); } } else { - const javaOrKtFiles: Metadata[] = await this.fileInspector.scanFor(fileExtensionRegExp(['java', 'kt', 'kts']), '/'); - if (javaOrKtFiles.length === 0) { + const javaFiles: Metadata[] = await this.fileInspector.scanFor(fileExtensionRegExp(['java']), '/'); + if (javaFiles.length === 0 && ktFiles.length === 0) { return result; } + const javaOrKtFiles = javaFiles.concat(ktFiles); const dirsWithProjects = uniq(javaOrKtFiles.map((f) => nodePath.dirname(f.path))); const commonPath = sharedSubpath(dirsWithProjects); result.push({ language: hasKtFiles ? ProgrammingLanguage.Kotlin : ProgrammingLanguage.Java, path: commonPath });