Skip to content
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 @@ -111,17 +111,9 @@ open class ImportClassPicker(
*/
private fun loadModel(kClass: Class<*>): ClassModel<*>? {
val selectedType = kClass.kotlin
try {
return ClassModel<Any>(selectedType,
selectedType.constructors.first(),
selectedType.declaredFunctions)
} catch (e: Exception) {
println("Caught !")
return null
} catch (e: Error) {
println("Caught !")
return null
}
return ClassModel<Any>(selectedType,
selectedType.constructors.first(),
selectedType.declaredFunctions)
}
/**
* Returns true if the class is eligible to used for code generation. It must follows all the constraints
Expand Down
2 changes: 1 addition & 1 deletion code/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gradlePlugin {

val javaLibraryCodegen by plugins.creating {
id = "com.android.gradle.replicator.java-library-codegen-plugin"
version = 0.1
version = Versions.pluginVersion
implementationClass = "com.android.gradle.replicator.codegen.plugin.JavaLibraryCodegenPlugin"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ class CodegenPlugin: Plugin<Project> {
// Randomizer values should be set during project replication along the number of java and kotlin files.
task.seed.set(Random.nextInt())

task.nbOfJavaFiles.set(10)
val hasKotlin = project.plugins.map { it.toString() }.find {
it.contains("org.jetbrains.kotlin")
} != null
if (hasKotlin) {
task.nbOfKotlinFiles.set(10)
} else {
task.nbOfJavaFiles.set(10)
}

// make sure we depend on our dependencies built artifacts so we have access to their generated classes.
projectDependencies.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ abstract class GenerateCode: DefaultTask() {
// generate files.
Main().process(
arrayOf(
"-gen", "Java",
"-module", path.removeSuffix(":$name").removePrefix(":").replace(':', '_'),
"-i", parameters.get().asFile.absolutePath,
"-o", outputDirectory.get().asFile.absolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import kotlin.random.Random
@Suppress("UnstableApiUsage")
class JavaLibraryCodegenPlugin: AbstractCodeGenPlugin() {
override fun apply(project: Project) {
println("Java Library plugin applied !")

val topProjectName by lazy {
var current = project
while (current.parent != null) current = current.parent!!
current.name
}

val hasKotlinSources = project.pluginManager.hasPlugin("org.jetbrains.kotlin.jvm")
val hasKotlinSources = project.plugins.map { it.toString() }.find {
it.contains("org.jetbrains.kotlin")
} != null

val generateTask = project.tasks.register(
"generateCodegenParams",
Expand Down Expand Up @@ -84,9 +84,12 @@ class JavaLibraryCodegenPlugin: AbstractCodeGenPlugin() {
// Randomizer values should be set during project replication along the number of java and kotlin files.
task.seed.set(Random.nextInt())

if (hasKotlinSources)
if (hasKotlinSources) {
task.nbOfKotlinFiles.set(10)
else task.nbOfJavaFiles.set(10) }
} else {
task.nbOfJavaFiles.set(10)
}
}

val generateCodeTask = project.tasks.register(
"generateCode",
Expand Down