Skip to content

Commit

Permalink
Merge pull request #4 from JakubNeukirch/invoke-gradle-tasks
Browse files Browse the repository at this point in the history
Invoke gradle tasks
  • Loading branch information
JakubNeukirch authored Nov 17, 2020
2 parents 6c09443 + 5f47755 commit e950486
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.1'
plugins = ['gradle']
}
patchPluginXml {
changeNotes """
Expand Down
29 changes: 20 additions & 9 deletions src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package tech.stonks.kvizard

import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.ide.util.projectWizard.ModuleBuilder
import com.intellij.ide.util.projectWizard.ModuleWizardStep
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.module.ModuleType
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.file.PsiDirectoryFactory
import tech.stonks.kvizard.data.VersionApi
import tech.stonks.kvizard.data.model.*
import org.jetbrains.plugins.gradle.action.GradleExecuteTaskAction
import tech.stonks.kvizard.generator.FrontendTreeGenerator
import tech.stonks.kvizard.generator.KtorTreeGenerator
import tech.stonks.kvizard.generator.TreeGenerator
import tech.stonks.kvizard.step.library_choice.LibraryChoiceStep
import tech.stonks.kvizard.utils.*
import tech.stonks.kvizard.utils.backgroundTask
import tech.stonks.kvizard.utils.runGradle
import java.io.File

class KVisionModuleBuilder : ModuleBuilder() {
Expand All @@ -28,8 +30,8 @@ class KVisionModuleBuilder : ModuleBuilder() {
* Here add libraries that were newly supported
*/
val supportedBackendLibraries = arrayOf(
KVisionBackendLibrary.KTOR,
KVisionBackendLibrary.FRONTEND_ONLY
KVisionBackendLibrary.KTOR,
KVisionBackendLibrary.FRONTEND_ONLY
)
}

Expand All @@ -44,21 +46,30 @@ class KVisionModuleBuilder : ModuleBuilder() {
ApplicationManager.getApplication().runWriteAction {
val manager = PsiManager.getInstance(modifiableRootModel.project)
manager.findFile(root)?.add(
PsiDirectoryFactory.getInstance(manager.project)
.createDirectory(root.createChildDirectory(null, "webpack"))
PsiDirectoryFactory.getInstance(manager.project)
.createDirectory(root.createChildDirectory(null, "webpack"))
)
}
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
val generator: TreeGenerator = createGenerator()
modifiableRootModel.project.backgroundTask("Setting up project") {
generator.generate(root, artifactId, groupId)
try {
generator.generate(root, artifactId, groupId)
} catch (ex: Exception) {

}
runGradleTasks(modifiableRootModel.project)
}
}

private fun runGradleTasks(project: Project) {
project.runGradle("compileKotlinMetadata")
}

private fun createGenerator(): TreeGenerator {
return when(backendLibrary) {
return when (backendLibrary) {
KVisionBackendLibrary.KTOR -> KtorTreeGenerator()
KVisionBackendLibrary.FRONTEND_ONLY -> FrontendTreeGenerator()
else -> throw IllegalStateException("${backendLibrary.name} is not supported yet.")
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/tech/stonks/kvizard/utils/file.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package tech.stonks.kvizard.utils

import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.ide.fileTemplates.FileTemplateManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.plugins.gradle.action.GradleExecuteTaskAction
import java.io.File

fun File.dir(name: String, body: File.() -> Unit = {}) {
Expand Down Expand Up @@ -45,6 +47,10 @@ private fun getTemplateData(templateName: String, attributes: Map<String, String
}
}

fun Project.runGradle(command: String) {
GradleExecuteTaskAction.runGradle(this, DefaultRunExecutor.getRunExecutorInstance(), this.basePath!!, command)
}

fun Project.getRootFile(): VirtualFile? {
return projectFile?.parent?.parent
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.gradle</depends>

<extensions defaultExtensionNs="com.intellij">
<moduleType id="KVISION_WIZARD" implementationClass="tech.stonks.kvizard.KVisionModuleType" />
Expand Down

0 comments on commit e950486

Please sign in to comment.