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 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..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 @@ -23,28 +24,43 @@ internal fun FileSystem.fileSequence( ): Sequence { checkGlobsContainAbsolutePath(globs) - val pathMatchers = if (globs.isEmpty()) { + val result = mutableListOf() + + 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 + 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() {