Skip to content

Commit

Permalink
Version 0.6.0.
Browse files Browse the repository at this point in the history
Upgrade to KVision 6.0.0
Upgrade to IntelliJ IDEA 2022.3.1
  • Loading branch information
rjaros committed Jan 2, 2023
1 parent 21e9d00 commit 25b7755
Show file tree
Hide file tree
Showing 29 changed files with 182 additions and 172 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'org.jetbrains.intellij' version '1.9.0'
id 'org.jetbrains.kotlin.jvm' version '1.6.20'
id 'org.jetbrains.intellij' version '1.11.0'
id 'org.jetbrains.kotlin.jvm' version '1.7.22'
id 'idea'
}

group 'tech.stonks'
version '0.5.1'
version '0.6.0'

repositories {
mavenCentral()
Expand All @@ -21,18 +21,18 @@ dependencies {
implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
}

sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = 17
targetCompatibility = 17

compileKotlin {
kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version = '2022.1.4'
version = '2022.3.1'
plugins = ['gradle', 'java', 'org.jetbrains.kotlin']
updateSinceUntilBuild = false
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
21 changes: 10 additions & 11 deletions src/main/kotlin/tech/stonks/kvizard/KVisionModuleBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class KVisionModuleBuilder : ModuleBuilder() {
var projectType: KVisionProjectType = KVisionProjectType.FRONTEND_ONLY
var groupId: String = "com.example"
var artifactId: String = "project"
var compilerBackend: CompilerBackend = CompilerBackend.IR
var selectedModules: List<String> = listOf("kvision-bootstrap", "kvision-bootstrap-css")
var selectedModules: List<String> = listOf("kvision-bootstrap")
var selectedInitializers: List<String> = listOf("BootstrapModule", "BootstrapCssModule")

override fun setupRootModel(modifiableRootModel: ModifiableRootModel) {
Expand All @@ -76,7 +75,7 @@ class KVisionModuleBuilder : ModuleBuilder() {
val generator: TreeGenerator = createGenerator()
modifiableRootModel.project.backgroundTask("Setting up project") {
try {
generator.generate(root, artifactId, groupId, compilerBackend, selectedModules, selectedInitializers, versionData)
generator.generate(root, artifactId, groupId, selectedModules, selectedInitializers, versionData)
} catch (ex: Exception) {
}
installGradleWrapper(modifiableRootModel.project)
Expand All @@ -89,7 +88,7 @@ class KVisionModuleBuilder : ModuleBuilder() {
}

private fun installGradleWrapper(project: Project) {
project.runGradle("wrapper --gradle-version 7.5.1 --distribution-type all")
project.runGradle("wrapper --gradle-version 7.6 --distribution-type all")
}

private fun createGenerator(): TreeGenerator {
Expand All @@ -115,22 +114,22 @@ class KVisionModuleBuilder : ModuleBuilder() {
}

override fun getCustomOptionsStep(context: WizardContext?, parentDisposable: Disposable?): ModuleWizardStep {
return LibraryChoiceStep(this)
return LibraryChoiceStep(this, parentDisposable)
}

private fun fetchVersionData(): VersionData {
return try {
VersionApi.create().getVersionData().blockingGet()
} catch (ex: Exception) {
VersionData(
kVision = "5.15.0",
kotlin = "1.7.10",
serialization = "1.4.0",
kVision = "6.0.1",
kotlin = "1.8.0",
serialization = "1.4.1",
coroutines = "1.6.4",
templateJooby = TemplateJooby("2.16.1"),
templateKtor = TemplateKtor("2.1.1"),
templateMicronaut = TemplateMicronaut("3.6.3"),
templateSpring = TemplateSpring(springBoot = "2.7.3"),
templateKtor = TemplateKtor("2.2.1"),
templateMicronaut = TemplateMicronaut("3.8.0"),
templateSpring = TemplateSpring(springBoot = "3.0.1"),
templateVertx = TemplateVertx(vertxPlugin = "1.3.0"),
modules = emptyList()
)
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/tech/stonks/kvizard/KVisionModuleType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,3 @@ enum class KVisionProjectType(val displayName: String) {
MICRONAUT("Micronaut fullstack project"),
VERTX("Vert.x fullstack project");
}

enum class CompilerBackend(val displayName: String) {
IR("IR"),
LEGACY("Legacy")
}
2 changes: 1 addition & 1 deletion src/main/kotlin/tech/stonks/kvizard/data/VersionApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import tech.stonks.kvizard.data.model.VersionData

interface VersionApi {

@GET("versions5.json")
@GET("versions6.json")
fun getVersionData(): Single<VersionData>

companion object {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/tech/stonks/kvizard/data/model/VersionData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ data class Module(
val description: String,
@SerializedName("excludes")
val excludes: List<String>?,
@SerializedName("initializer")
val initializer: String?
@SerializedName("initializers")
val initializers: List<String>?
)
10 changes: 2 additions & 8 deletions src/main/kotlin/tech/stonks/kvizard/generator/TreeGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package tech.stonks.kvizard.generator

import com.intellij.openapi.vfs.VirtualFile
import tech.stonks.kvizard.CompilerBackend
import tech.stonks.kvizard.data.model.VersionData
import tech.stonks.kvizard.utils.TemplateAttributes
import tech.stonks.kvizard.utils.build
import tech.stonks.kvizard.utils.dir
import tech.stonks.kvizard.utils.file
import tech.stonks.kvizard.utils.packages
import java.util.*

/**
* Base class for building KVision project.
Expand Down Expand Up @@ -46,8 +44,7 @@ abstract class TreeGenerator(
"bootstrap.js",
"css.js",
"file.js",
"handlebars.js",
"moment.js"
"handlebars.js"
),
private val webpackCustomFiles: Array<String> = arrayOf(
"webpack.js"
Expand Down Expand Up @@ -77,7 +74,6 @@ abstract class TreeGenerator(
root: VirtualFile,
artifactId: String,
groupId: String,
compilerBackend: CompilerBackend,
modules: List<String>,
initializers: List<String>,
versionData: VersionData
Expand All @@ -88,7 +84,7 @@ abstract class TreeGenerator(
.toMutableList()
.apply { add(artifactId) }
.toList()
val attrs = generateAttributes(artifactId, groupId, compilerBackend, modules, initializers, versionData, isFrontendOnly)
val attrs = generateAttributes(artifactId, groupId, modules, initializers, versionData, isFrontendOnly)
root.build {
dir("src") {
if (!isFrontendOnly) {
Expand Down Expand Up @@ -219,7 +215,6 @@ abstract class TreeGenerator(
private fun generateAttributes(
artifactId: String,
groupId: String,
compilerBackend: CompilerBackend,
modules: List<String>,
initializers: List<String>,
versionData: VersionData,
Expand All @@ -238,7 +233,6 @@ abstract class TreeGenerator(
"micronaut_version" to versionData.templateMicronaut.micronaut,
"spring_boot_version" to versionData.templateSpring.springBoot,
"vertx_plugin_version" to versionData.templateVertx.vertxPlugin,
"compiler_backend" to compilerBackend.name.lowercase(Locale.getDefault()),
"selected_modules" to modules,
"selected_initializers" to initializers,
"i18n_included" to modules.contains("kvision-i18n"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package tech.stonks.kvizard.step.library_choice

import com.intellij.ide.util.projectWizard.ModuleWizardStep
import com.intellij.openapi.Disposable
import tech.stonks.kvizard.KVisionModuleBuilder
import javax.swing.JComponent

class LibraryChoiceStep(private val _builder: KVisionModuleBuilder) : ModuleWizardStep() {
class LibraryChoiceStep(private val _builder: KVisionModuleBuilder, private val parentDisposable: Disposable?) : ModuleWizardStep() {
private val _view: LibraryChoiceView by lazy {
LibraryChoiceView(
_builder.projectType,
_builder.groupId,
_builder.artifactId,
_builder.compilerBackend,
_builder.selectedModules,
_builder.selectedInitializers,
_builder.versionData.modules
_builder.versionData.modules,
parentDisposable
).apply {
onChanged = {
updateDataModel()
}
}
}

override fun validate(): Boolean {
return _view.validateGroupName(_view.groupTextField.text) && _view.validateArtifactName(_view.artifactTextField.text)
}

override fun getComponent(): JComponent {
return _view
}
Expand All @@ -29,7 +34,6 @@ class LibraryChoiceStep(private val _builder: KVisionModuleBuilder) : ModuleWiza
_builder.projectType = _view.projectType
_builder.groupId = _view.groupId
_builder.artifactId = _view.artifactId
_builder.compilerBackend = _view.compilerBackend
_builder.selectedModules = _view.selectedModules
_builder.selectedInitializers = _view.selectedInitializers
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package tech.stonks.kvizard.step.library_choice

import com.intellij.ide.BrowserUtil
import com.intellij.openapi.Disposable
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.ComponentValidator
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.openapi.util.text.StringUtil
import com.intellij.ui.CheckBoxList
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.components.JBScrollPane
import tech.stonks.kvizard.CompilerBackend
import tech.stonks.kvizard.KVisionModuleBuilder
import tech.stonks.kvizard.KVisionProjectType
import tech.stonks.kvizard.data.model.Module
import tech.stonks.kvizard.utils.setOnTextChangedListener
import java.awt.Dimension
import java.awt.FlowLayout
import java.util.function.Supplier
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JButton
Expand All @@ -19,19 +24,22 @@ import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextField
import javax.swing.ListSelectionModel
import javax.swing.event.DocumentEvent


class LibraryChoiceView(
var projectType: KVisionProjectType,
var groupId: String,
var artifactId: String,
var compilerBackend: CompilerBackend,
var selectedModules: List<String>,
var selectedInitializers: List<String>,
val modules: List<Module>
val modules: List<Module>,
parentDisposable: Disposable?
) : JPanel() {

var onChanged: () -> Unit = {}
val groupTextField: JTextField
val artifactTextField: JTextField

init {
layout = FlowLayout(FlowLayout.LEFT)
Expand All @@ -50,31 +58,63 @@ class LibraryChoiceView(
}
}
})
add(JLabel("GroupId:").apply { alignmentX = LEFT_ALIGNMENT })
add(JLabel("Group:").apply { alignmentX = LEFT_ALIGNMENT })
add(JTextField(groupId).apply {
groupTextField = this
alignmentX = LEFT_ALIGNMENT
setOnTextChangedListener {
groupId = it
onChanged()
}
})
add(JLabel("ArtifactId:").apply { alignmentX = LEFT_ALIGNMENT })
ComponentValidator(parentDisposable!!).withValidator(Supplier<ValidationInfo> {
val groupIdValue = groupTextField.text
if (StringUtil.isNotEmpty(groupIdValue)) {
if (validateGroupName(groupIdValue)) {
null
} else {
ValidationInfo(
"Invalid group name (only lowercase letters (a-z), numbers (0-9), periods (.) and underscores (_) are valid)",
groupTextField
)
}
} else {
ValidationInfo("Value is required", groupTextField)
}
}).installOn(groupTextField)
groupTextField.document.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
ComponentValidator.getInstance(groupTextField).ifPresent { v: ComponentValidator -> v.revalidate() }
}
})
add(JLabel("Artifact:").apply { alignmentX = LEFT_ALIGNMENT })
add(JTextField(artifactId).apply {
artifactTextField = this
alignmentX = LEFT_ALIGNMENT
setOnTextChangedListener {
artifactId = it
onChanged()
}
})
add(JLabel("Kotlin/JS compiler backend:").apply { alignmentX = LEFT_ALIGNMENT })
add(ComboBox(CompilerBackend.values().map { it.displayName }.toTypedArray()).apply {
alignmentX = LEFT_ALIGNMENT
setMinimumAndPreferredWidth(250)
addItemListener { event: java.awt.event.ItemEvent ->
if (event.stateChange == java.awt.event.ItemEvent.SELECTED) {
compilerBackend = CompilerBackend.values().find { it.displayName == event.item }!!
onChanged()
ComponentValidator(parentDisposable).withValidator(Supplier<ValidationInfo> {
val artifactIdValue = artifactTextField.text
if (StringUtil.isNotEmpty(artifactIdValue)) {
if (validateArtifactName(artifactIdValue)) {
null
} else {
ValidationInfo(
"Invalid artifact name (only lowercase letters (a-z), numbers (0-9) and underscores (_) are valid)",
artifactTextField
)
}
} else {
ValidationInfo("Value is required", artifactTextField)
}
}).installOn(artifactTextField)
artifactTextField.document.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
ComponentValidator.getInstance(artifactTextField)
.ifPresent { v: ComponentValidator -> v.revalidate() }
}
})
add(JLabel("Optional modules:").apply { alignmentX = LEFT_ALIGNMENT })
Expand All @@ -98,7 +138,8 @@ class LibraryChoiceView(
}
}
selectedModules = modules.filter { isItemSelected(it) }.map { it.name }
selectedInitializers = modules.filter { isItemSelected(it) }.mapNotNull { it.initializer }.distinct()
selectedInitializers =
modules.filter { isItemSelected(it) }.flatMap { it.initializers ?: emptyList() }.distinct()
onChanged()
}
}
Expand All @@ -107,12 +148,20 @@ class LibraryChoiceView(
preferredSize = Dimension(570, 400)
})
add(Box.createRigidArea(Dimension(0, 20)))
add(JButton("Check KVision Website").apply {
add(JButton("Check KVision website").apply {
this.addActionListener {
BrowserUtil.browse("https://kvision.io")
}
})
}
add(panel)
}

fun validateGroupName(groupName: String?): Boolean {
return groupName?.matches("^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$".toRegex()) ?: false
}

fun validateArtifactName(artifactName: String?): Boolean {
return artifactName?.matches("^[a-z][a-z0-9_]*$".toRegex()) ?: false
}
}
Loading

0 comments on commit 25b7755

Please sign in to comment.