From 97bfc2534cc5ba86c3542afd0c24ec2357f50c1d Mon Sep 17 00:00:00 2001 From: sub101 Date: Sat, 28 Oct 2023 16:40:39 +0900 Subject: [PATCH] #3636 Makes Aggregator#process use walkInPlatformIndependentOrder --- .../hilt/android/plugin/root/Aggregator.kt | 2 +- .../plugin/main/src/test/kotlin/FilesTest.kt | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 java/dagger/hilt/android/plugin/main/src/test/kotlin/FilesTest.kt diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/root/Aggregator.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/root/Aggregator.kt index ba419352ac9..557e2c22668 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/root/Aggregator.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/root/Aggregator.kt @@ -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") } } diff --git a/java/dagger/hilt/android/plugin/main/src/test/kotlin/FilesTest.kt b/java/dagger/hilt/android/plugin/main/src/test/kotlin/FilesTest.kt new file mode 100644 index 00000000000..867b42869ef --- /dev/null +++ b/java/dagger/hilt/android/plugin/main/src/test/kotlin/FilesTest.kt @@ -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 = 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() + } +}