From 0c1a66d59fbdef7e903ce96e707f8137349832ac Mon Sep 17 00:00:00 2001 From: Riccardo Ciovati Date: Sat, 8 May 2021 12:54:20 +0200 Subject: [PATCH 1/3] Improve ktlint performances when the input patterns are absolute paths --- .../pinterest/ktlint/internal/FileUtils.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt index 2646e17a29..ace9242f7d 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt @@ -23,28 +23,37 @@ internal fun FileSystem.fileSequence( ): Sequence { checkGlobsContainAbsolutePath(globs) - val pathMatchers = if (globs.isEmpty()) { + val result = mutableListOf() + + val (existingFiles, actualGlobs) = globs.partition { Files.isRegularFile(rootDir.resolve(it)) } + existingFiles.mapTo(result) { rootDir.resolve(it) } + + // Return early and don't traverse the file system if all the input globs are absolute paths + if (result.isNotEmpty() && actualGlobs.isEmpty()) { + return result.asSequence() + } + + val pathMatchers = if (actualGlobs.isEmpty()) { setOf( getPathMatcher("glob:**$globSeparator*.kt"), getPathMatcher("glob:**$globSeparator*.kts") ) } else { - globs + actualGlobs .filterNot { it.startsWith("!") } .map { getPathMatcher(it.toGlob(rootDir)) } } - val negatedPathMatchers = if (globs.isEmpty()) { + val negatedPathMatchers = if (actualGlobs.isEmpty()) { emptySet() } else { - globs + actualGlobs .filter { it.startsWith("!") } .map { getPathMatcher(it.removePrefix("!").toGlob(rootDir)) } } - val result = mutableListOf() Files.walkFileTree( rootDir, object : SimpleFileVisitor() { From f873257c8d6404bd079a4a6adf80e5940abad3d8 Mon Sep 17 00:00:00 2001 From: Sha Sha Chu Date: Mon, 14 Jun 2021 11:48:40 -0700 Subject: [PATCH 2/3] stacktrace call in build --- .github/workflows/gradle-pr-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle-pr-build.yml b/.github/workflows/gradle-pr-build.yml index 549e025780..6d4b2bb5de 100644 --- a/.github/workflows/gradle-pr-build.yml +++ b/.github/workflows/gradle-pr-build.yml @@ -8,7 +8,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] java: [ 8, 11 ] runs-on: ${{ matrix.os }} steps: @@ -20,7 +20,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with release Kotlin version - run: ./gradlew clean build ktlint + run: ./gradlew --stacktrace clean build ktlint - name: Upload artifacts uses: actions/upload-artifact@v2 if: failure() @@ -29,4 +29,4 @@ jobs: path: '**/build/**/dependency-verification-report.html' if-no-files-found: warn - name: Build with dev Kotlin version - run: ./gradlew -PkotlinDev clean build ktlint + run: ./gradlew --stacktrace -PkotlinDev clean build ktlint From c8ef1dec8a3e837a614757d24dda5605cf627b28 Mon Sep 17 00:00:00 2001 From: Sha Sha Chu Date: Mon, 14 Jun 2021 12:29:54 -0700 Subject: [PATCH 3/3] ?? --- .../kotlin/com/pinterest/ktlint/internal/FileUtils.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt index ace9242f7d..74e07684b6 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt @@ -8,6 +8,7 @@ import java.io.File import java.nio.file.FileSystem import java.nio.file.FileVisitResult import java.nio.file.Files +import java.nio.file.InvalidPathException import java.nio.file.Path import java.nio.file.Paths import java.nio.file.SimpleFileVisitor @@ -25,7 +26,13 @@ internal fun FileSystem.fileSequence( val result = mutableListOf() - val (existingFiles, actualGlobs) = globs.partition { Files.isRegularFile(rootDir.resolve(it)) } + val (existingFiles, actualGlobs) = globs.partition { + try { + Files.isRegularFile(rootDir.resolve(it)) + } catch (e: InvalidPathException) { + false + } + } existingFiles.mapTo(result) { rootDir.resolve(it) } // Return early and don't traverse the file system if all the input globs are absolute paths