Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3636 Makes Aggregator#process use walkInPlatformIndependentOrder #4115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private constructor(
files.forEach { file ->
when {
file.isFile -> visitFile(file)
file.isDirectory -> file.walkTopDown().filter { it.isFile }.forEach { visitFile(it) }
file.isDirectory -> file.walkInPlatformIndependentOrder().filter { it.isFile }.forEach { visitFile(it) }
else -> logger.warn("Can't process file/directory that doesn't exist: $file")
}
}
Expand Down
69 changes: 69 additions & 0 deletions java/dagger/hilt/android/plugin/main/src/test/kotlin/FilesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2023 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File

class FilesTest {

@get:Rule
val testProjectDir = TemporaryFolder()

@Test
fun testWalkInPlatformIndependentOrder() {
val testDir = testProjectDir.root

/**
* testDir
* ├── dir1
* │ ├── file1
* └── dir2
* │ ├── dir3
* │ │ └── file2
* │ └── file3
* └── file4
*/
File(testDir, "dir2").mkdir()
File(testDir, "dir2/dir3").mkdir()
File(testDir, "dir2/dir3/file2").mkdir()
File(testDir, "dir2/file3").createNewFile()
File(testDir, "dir1").mkdir()
File(testDir, "dir1/file1").createNewFile()
File(testDir, "file4").createNewFile()
val filesInOrder = testDir.walkInPlatformIndependentOrder().toList()

val expected: List<File> = listOf(
File(testDir, ""),
File(testDir, "dir1"),
File(testDir, "dir1/file1"),
File(testDir, "dir2"),
File(testDir, "dir2/dir3"),
File(testDir, "dir2/dir3/file2"),
File(testDir, "dir2/file3"),
File(testDir, "file4"),
)
assertEquals(expected, filesInOrder)

val filesNotInOrder = testDir.walkTopDown().toList()
assertTrue(filesInOrder != filesNotInOrder)

testDir.deleteRecursively()
}
}