Improve diagnostics in importing tests and fix android test

This commit is contained in:
Andrey Uskov
2019-07-10 20:36:50 +03:00
parent afd2af01cd
commit 1336f65535
2 changed files with 35 additions and 20 deletions
@@ -265,25 +265,25 @@ class NewMultiplatformProjectImportingTest : MultiplePluginVersionGradleImportin
module("app") {
libraryDependency("Gradle: android-android-26", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.core:common:1.1.0@jar", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.core:runtime-1.1.0", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.core:runtime:1.1.0@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:common:1.1.0@jar", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:livedata-core-1.1.0", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:runtime-1.1.0", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:viewmodel-1.1.0", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support.constraint:constraint-layout-1.1.3", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:livedata-core:1.1.0@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:runtime:1.1.0@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: android.arch.lifecycle:viewmodel:1.1.0@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support.constraint:constraint-layout:1.1.3@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support.constraint:constraint-layout-solver:1.1.3@jar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support.test.espresso:espresso-core-3.0.2", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test.espresso:espresso-idling-resource-3.0.2", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test:monitor-1.0.2", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test:runner-1.0.2", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support:animated-vector-drawable-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:appcompat-v7-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support.test.espresso:espresso-core:3.0.2@aar", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test.espresso:espresso-idling-resource:3.0.2@aar", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test:monitor:1.0.2@aar", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support.test:runner:1.0.2@aar", DependencyScope.TEST)
libraryDependency("Gradle: com.android.support:animated-vector-drawable:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:appcompat-v7:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-annotations:27.1.1@jar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-compat-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-core-ui-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-core-utils-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-fragment-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-vector-drawable-27.1.1", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-compat:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-core-ui:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-core-utils:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-fragment:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.android.support:support-vector-drawable:27.1.1@aar", DependencyScope.COMPILE)
libraryDependency("Gradle: com.google.code.findbugs:jsr305:2.0.1@jar", DependencyScope.TEST)
libraryDependency("Gradle: com.squareup:javawriter:2.1.1@jar", DependencyScope.TEST)
libraryDependency("Gradle: javax.inject:javax.inject:1@jar", DependencyScope.TEST)
@@ -157,15 +157,30 @@ class ModuleInfo(
}
fun libraryDependency(libraryName: String, scope: DependencyScope) {
val libraryEntry = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>().singleOrNull { it.libraryName == libraryName }
checkLibrary(libraryEntry, libraryName, scope)
val libraryEntries = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>().filter { it.libraryName == libraryName }
if (libraryEntries.size > 1) {
projectInfo.messageCollector.report("Module '${module.name}': multiple entries for library $libraryName")
}
if (libraryEntries.isEmpty()) {
val mostProbableCandidate =
rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>().sortedWith(Comparator<LibraryOrderEntry> { o1, o2 ->
val o1len = o1?.libraryName?.commonPrefixWith(libraryName)?.length ?: 0
val o2len = o2?.libraryName?.commonPrefixWith(libraryName)?.length ?: 0
o2len - o1len
}).first()
projectInfo.messageCollector.report("Module '${module.name}': expected library dependency [$libraryName] but the most probable candidate [${mostProbableCandidate.libraryName}]")
}
checkLibrary(libraryEntries.singleOrNull(), libraryName, scope)
}
fun libraryDependencyByUrl(classesUrl: String, scope: DependencyScope) {
val libraryEntry = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>().singleOrNull { entry ->
val libraryEntries = rootModel.orderEntries.filterIsInstance<LibraryOrderEntry>().filter { entry ->
entry.library?.getUrls(OrderRootType.CLASSES)?.any { it == classesUrl } ?: false
}
checkLibrary(libraryEntry, classesUrl, scope)
if (libraryEntries.size > 1) {
projectInfo.messageCollector.report("Module '${module.name}': multiple entries for library $classesUrl")
}
checkLibrary(libraryEntries.singleOrNull(), classesUrl, scope)
}
private fun checkLibrary(libraryEntry: LibraryOrderEntry?, id: String, scope: DependencyScope) {