Skip to content

Commit

Permalink
Merge pull request #97 from hhru/MOB-32847__fix_template_creation_in_…
Browse files Browse the repository at this point in the history
…androidTest

[MOB-32847] Исправляет создание файлов в папке androidTest
  • Loading branch information
horseunnamed authored Aug 23, 2023
2 parents 01850a8 + 1e78315 commit 8e5d8f2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
6 changes: 6 additions & 0 deletions plugins/hh-geminio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Geminio


## [1.6.1]

### Fixed

- Fixed files creation in `androidTest` directory.

## [1.6.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion plugins/hh-geminio/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion=1.6.0
pluginVersion=1.6.1

pluginGroup=ru.hh.plugins
pluginName=hh-geminio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,32 +144,44 @@ class ConfigureTemplateParametersStepFactory(
val originalModuleTemplates = this.getModuleTemplates(targetDirectory)
assert(originalModuleTemplates.isNotEmpty())

val firstNamedModuleTemplate = originalModuleTemplates.first()
return if (firstNamedModuleTemplate.paths.getAidlDirectory("stub.package") != null) {
originalModuleTemplates
} else {
HHLogger.d("There is no AIDL directory in original module template -> create stub module path module")
/**
* Sometimes after fetching module templates information from [org.jetbrains.android.facet.AndroidFacet]
* there is no information about AIDL sources directory.
*
* But this directory is necessary for [com.android.tools.idea.npw.template.ModuleTemplateDataBuilder] in
* `build` method (has line with `aidlDir!!`) which leads to NullPointerException crash -->
* not modules templates skip files generation.
*
* So, we need to manually fix this problem through simple wrapper over
* [com.android.tools.idea.projectsystem.AndroidModulePaths].
*/
val fixedAidlNamedModuleTemplate = firstNamedModuleTemplate.copy(
paths = StubAndroidModulePaths(firstNamedModuleTemplate.paths)
val moduleTemplate = originalModuleTemplates.first()

/**
* Sometimes after fetching module templates information from [org.jetbrains.android.facet.AndroidFacet]
* there is no information about AIDL and SRC sources directory.
*
* But AIDL directory is necessary for [com.android.tools.idea.npw.template.ModuleTemplateDataBuilder] in
* `build` method (has line with `aidlDir!!`) which leads to NullPointerException crash -->
* not modules templates skip files generation.
*
* And SRC directory is necessary for files creation, without specifing this directory
* [com.android.tools.idea.npw.model.RenderTemplateModel] will not start files creation.
*
* So, we need to manually fix this problem through simple wrapper over
* [com.android.tools.idea.projectsystem.AndroidModulePaths].
*/
val shouldReplaceAidlDirectory = moduleTemplate.paths.getAidlDirectory("stub.package") == null
val shouldReplaceSrcDirectory = moduleTemplate.paths.getSrcDirectory("stub.package") == null

HHLogger.d("Should replace AIDL directory: $shouldReplaceAidlDirectory")
HHLogger.d("Should replace SRC directory: $shouldReplaceSrcDirectory")
return listOf(
moduleTemplate.copy(
paths = StubAndroidModulePaths(
original = moduleTemplate.paths,
baseModuleName = moduleTemplate.name,
shouldReplaceAidlDirectory = shouldReplaceAidlDirectory,
shouldReplaceSrcDirectory = shouldReplaceSrcDirectory,
),
)

return listOf(fixedAidlNamedModuleTemplate)
}
)
}

private class StubAndroidModulePaths(
private val original: AndroidModulePaths
private val original: AndroidModulePaths,
private val baseModuleName: String,
private val shouldReplaceAidlDirectory: Boolean,
private val shouldReplaceSrcDirectory: Boolean,
) : AndroidModulePaths {
override val manifestDirectory: File?
get() = original.manifestDirectory
Expand All @@ -179,12 +191,21 @@ class ConfigureTemplateParametersStepFactory(
get() = original.resDirectories

override fun getAidlDirectory(packageName: String?): File? {
return original.moduleRoot
?.resolve("src/main/aidl" + packageName?.toSlashedFilePath().orEmpty())
return if (shouldReplaceAidlDirectory) {
original.moduleRoot
?.resolve("src/$baseModuleName/aidl" + packageName?.toSlashedFilePath().orEmpty())
} else {
original.getAidlDirectory(packageName)
}
}

override fun getSrcDirectory(packageName: String?): File? {
return original.getSrcDirectory(packageName)
return if (shouldReplaceSrcDirectory) {
original.moduleRoot
?.resolve("src/$baseModuleName/java" + packageName?.toSlashedFilePath().orEmpty())
} else {
original.getSrcDirectory(packageName)
}
}

override fun getTestDirectory(packageName: String?): File? {
Expand Down

0 comments on commit 8e5d8f2

Please sign in to comment.