Skip to content

Commit

Permalink
fix: Kotlin recognition fixed & improved detector
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzzaki committed Dec 14, 2019
1 parent 5f0b614 commit c5aaa4c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/detectors/Java/JavaLanguageDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit c5aaa4c

Please sign in to comment.