From e5216e4a4f2d710772ea55bcd7b4771dbbf7ba46 Mon Sep 17 00:00:00 2001 From: marcin Date: Tue, 23 Apr 2024 07:37:04 +0200 Subject: [PATCH] remove obsolete starters, open readme.md --- .../plugin/module/SkeletonStarterPanel.kt | 18 ++-------- .../plugin/module/VaadinModuleBuilder.kt | 35 +++++++++++++----- .../com/vaadin/plugin/module/VaadinPanel.kt | 6 ++-- ...asDownloadLink.kt => DownloadableModel.kt} | 4 ++- .../plugin/starter/QuickStarterModel.kt | 6 +++- .../com/vaadin/plugin/starter/StarterModel.kt | 6 +++- .../vaadin/plugin/starter/StarterSupport.kt | 36 ++----------------- .../vaadin/plugin/utils/VaadinProjectUtil.kt | 17 +++++++-- 8 files changed, 64 insertions(+), 64 deletions(-) rename src/main/kotlin/com/vaadin/plugin/starter/{HasDownloadLink.kt => DownloadableModel.kt} (67%) diff --git a/src/main/kotlin/com/vaadin/plugin/module/SkeletonStarterPanel.kt b/src/main/kotlin/com/vaadin/plugin/module/SkeletonStarterPanel.kt index 473bb43..0a98770 100644 --- a/src/main/kotlin/com/vaadin/plugin/module/SkeletonStarterPanel.kt +++ b/src/main/kotlin/com/vaadin/plugin/module/SkeletonStarterPanel.kt @@ -29,16 +29,10 @@ class SkeletonStarterPanel { StarterSupport.architectures.keys.first() ) - val root: DialogPanel? = panel { + val root: DialogPanel = panel { buttonsGroup { row("Framework") { - for (el in StarterSupport.frameworks.entries.filter { !it.key.contains("hilla") }) { - val r = radioButton(el.value, el.key).onChanged { refreshSupport() } - all["frameworks"]!![r.component] = el.key - } - }.topGap(TopGap.SMALL) - row("") { - for (el in StarterSupport.frameworks.entries.filter { it.key.contains("hilla") }) { + for (el in StarterSupport.frameworks.entries) { val r = radioButton(el.value, el.key).onChanged { refreshSupport() } all["frameworks"]!![r.component] = el.key } @@ -65,13 +59,7 @@ class SkeletonStarterPanel { }.bind(model::buildTool) buttonsGroup { row("Architecture") { - for (el in StarterSupport.architectures.entries.filterIndexed { i, _ -> i <= 3 }) { - val r = radioButton(el.value, el.key).onChanged { refreshSupport() } - all["architectures"]!![r.component] = el.key - } - }.topGap(TopGap.SMALL) - row("") { - for (el in StarterSupport.architectures.entries.filterIndexed { i, _ -> i > 3 }) { + for (el in StarterSupport.architectures.entries) { val r = radioButton(el.value, el.key).onChanged { refreshSupport() } all["architectures"]!![r.component] = el.key } diff --git a/src/main/kotlin/com/vaadin/plugin/module/VaadinModuleBuilder.kt b/src/main/kotlin/com/vaadin/plugin/module/VaadinModuleBuilder.kt index 7534ea9..029c916 100644 --- a/src/main/kotlin/com/vaadin/plugin/module/VaadinModuleBuilder.kt +++ b/src/main/kotlin/com/vaadin/plugin/module/VaadinModuleBuilder.kt @@ -3,16 +3,22 @@ package com.vaadin.plugin.module import com.intellij.ide.util.projectWizard.ModuleBuilder import com.intellij.ide.util.projectWizard.ModuleWizardStep import com.intellij.ide.util.projectWizard.WizardContext +import com.intellij.notification.NotificationType import com.intellij.openapi.Disposable -import com.intellij.openapi.module.ModifiableModuleModel -import com.intellij.openapi.module.Module +import com.intellij.openapi.fileEditor.OpenFileDescriptor +import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx import com.intellij.openapi.module.ModuleType -import com.vaadin.plugin.starter.HasDownloadLink +import com.intellij.openapi.project.ProjectType +import com.intellij.openapi.roots.ModifiableRootModel +import com.intellij.openapi.startup.StartupManager +import com.intellij.openapi.vfs.VfsUtil +import com.vaadin.plugin.starter.DownloadableModel import com.vaadin.plugin.utils.VaadinProjectUtil +import java.io.File class VaadinModuleBuilder : ModuleBuilder() { - private var model: HasDownloadLink? = null + private var model: DownloadableModel? = null override fun getBuilderId(): String { return "vaadin" @@ -26,13 +32,26 @@ class VaadinModuleBuilder : ModuleBuilder() { return VaadinCustomOptionsStep(this) } - fun setModel(model: HasDownloadLink) { + fun setModel(model: DownloadableModel) { this.model = model } - override fun createModule(moduleModel: ModifiableModuleModel): Module { - VaadinProjectUtil.downloadAndExtract(moduleModel.project, this.model!!.getDownloadLink(moduleModel.project)) - return super.createModule(moduleModel) + override fun setupRootModel(modifiableRootModel: ModifiableRootModel) { + val project = modifiableRootModel.project + StartupManager.getInstance(project).runAfterOpened { + VaadinProjectUtil.downloadAndExtract(project, this.model!!.getDownloadLink(project)) { + VaadinProjectUtil.notify("Vaadin project created", NotificationType.INFORMATION, project) + VfsUtil.findFileByIoFile(File(project.basePath, "README.md"), true)?.let { + val descriptor = OpenFileDescriptor(project, it) + descriptor.setUsePreviewTab(true) + FileEditorManagerEx.getInstanceEx(project).openEditor(descriptor, true) + } + } + } + } + + override fun getProjectType(): ProjectType? { + return this.model?.let { ProjectType.create(it.getProjectType()) } } } diff --git a/src/main/kotlin/com/vaadin/plugin/module/VaadinPanel.kt b/src/main/kotlin/com/vaadin/plugin/module/VaadinPanel.kt index db66b83..7ce83ea 100644 --- a/src/main/kotlin/com/vaadin/plugin/module/VaadinPanel.kt +++ b/src/main/kotlin/com/vaadin/plugin/module/VaadinPanel.kt @@ -4,7 +4,7 @@ import com.intellij.ide.wizard.withVisualPadding import com.intellij.openapi.ui.DialogPanel import com.intellij.ui.dsl.builder.CollapsibleRow import com.intellij.ui.dsl.builder.panel -import com.vaadin.plugin.starter.HasDownloadLink +import com.vaadin.plugin.starter.DownloadableModel class VaadinPanel { @@ -40,7 +40,7 @@ class VaadinPanel { } demoStarterGroup = collapsibleGroup("Demo Starters") { - row {}.cell(skeletonStarterPanel.root!!) + row {}.cell(skeletonStarterPanel.root) } separator() row { @@ -60,7 +60,7 @@ class VaadinPanel { return dialogPanel!! } - fun getModel(): HasDownloadLink { + fun getModel(): DownloadableModel { return if (quickStarterGroup!!.expanded) quickStarterPanel.model else skeletonStarterPanel.model } diff --git a/src/main/kotlin/com/vaadin/plugin/starter/HasDownloadLink.kt b/src/main/kotlin/com/vaadin/plugin/starter/DownloadableModel.kt similarity index 67% rename from src/main/kotlin/com/vaadin/plugin/starter/HasDownloadLink.kt rename to src/main/kotlin/com/vaadin/plugin/starter/DownloadableModel.kt index 2d51329..da213ab 100644 --- a/src/main/kotlin/com/vaadin/plugin/starter/HasDownloadLink.kt +++ b/src/main/kotlin/com/vaadin/plugin/starter/DownloadableModel.kt @@ -2,8 +2,10 @@ package com.vaadin.plugin.starter import com.intellij.openapi.project.Project -interface HasDownloadLink { +interface DownloadableModel { fun getDownloadLink(project: Project): String + fun getProjectType(): String + } \ No newline at end of file diff --git a/src/main/kotlin/com/vaadin/plugin/starter/QuickStarterModel.kt b/src/main/kotlin/com/vaadin/plugin/starter/QuickStarterModel.kt index 6d9d1e2..4c2e015 100644 --- a/src/main/kotlin/com/vaadin/plugin/starter/QuickStarterModel.kt +++ b/src/main/kotlin/com/vaadin/plugin/starter/QuickStarterModel.kt @@ -9,7 +9,7 @@ class QuickStarterModel( var exampleViews: Boolean, var authentication: Boolean, var version: String -) : BaseState(), HasDownloadLink { +) : BaseState(), DownloadableModel { override fun getDownloadLink(project: Project): String { var preset = "" @@ -32,4 +32,8 @@ class QuickStarterModel( return "https://start.vaadin.com/dl?preset=${preset}&projectName=${project.name}" } + + override fun getProjectType(): String { + return "maven" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/vaadin/plugin/starter/StarterModel.kt b/src/main/kotlin/com/vaadin/plugin/starter/StarterModel.kt index ed3eaf9..1ad9f2a 100644 --- a/src/main/kotlin/com/vaadin/plugin/starter/StarterModel.kt +++ b/src/main/kotlin/com/vaadin/plugin/starter/StarterModel.kt @@ -7,7 +7,7 @@ class StarterModel( var language: String, // 17 / kotlin var buildTool: String, // maven / gradle var architecture: String // springboot / servlet / ... -) : HasDownloadLink { +) : DownloadableModel { override fun getDownloadLink(project: Project): String { var key: String @@ -31,4 +31,8 @@ class StarterModel( return link.replace("", framework) } + override fun getProjectType(): String { + return buildTool + } + } diff --git a/src/main/kotlin/com/vaadin/plugin/starter/StarterSupport.kt b/src/main/kotlin/com/vaadin/plugin/starter/StarterSupport.kt index f088577..35c42a7 100644 --- a/src/main/kotlin/com/vaadin/plugin/starter/StarterSupport.kt +++ b/src/main/kotlin/com/vaadin/plugin/starter/StarterSupport.kt @@ -5,11 +5,8 @@ class StarterSupport { companion object { val frameworks = linkedMapOf( - "24" to "Vaadin Flow 24", - "23" to "Vaadin Flow 23", - "14" to "Vaadin Flow 14", - "hilla-react" to "Hilla + React", - "hilla-lit" to "Hilla + Lit" + "24" to "Flow / Java", + "hilla-react" to "Hilla / React" ) val languages = linkedMapOf( @@ -21,9 +18,7 @@ class StarterSupport { "springboot" to "Spring Boot", "quarkus" to "Quarkus", "jakartaee" to "Jakarta EE", - "servlet" to "Servlet", - "osgi" to "OSGI", - "karaf" to "Karaf" + "servlet" to "Servlet" ) val buildTools = linkedMapOf( @@ -33,9 +28,7 @@ class StarterSupport { val downloadLinks = mapOf( "hilla-react" to "https://github.com/vaadin/skeleton-starter-hilla-react/archive/master.zip", - "hilla-lit" to "https://github.com/vaadin/skeleton-starter-hilla-lit/archive/master.zip", "hilla-react-gradle" to "https://github.com/vaadin/skeleton-starter-hilla-react-gradle/archive/master.zip", - "hilla-lit-gradle" to "https://github.com/vaadin/skeleton-starter-hilla-lit-gradle/archive/master.zip", "kotlin" to "https://github.com/vaadin/skeleton-starter-kotlin-spring/archive/master.zip", "gradle-servlet" to "https://github.com/vaadin/base-starter-gradle/archive/v.zip", "gradle-springboot" to "https://github.com/vaadin/base-starter-spring-gradle/archive/v.zip", @@ -43,8 +36,6 @@ class StarterSupport { "quarkus" to "https://github.com/vaadin/base-starter-flow-quarkus/archive/v.zip", "jakartaee" to "https://github.com/vaadin/skeleton-starter-flow-cdi/archive/v.zip", "servlet" to "https://github.com/vaadin/skeleton-starter-flow/archive/v.zip", - "osgi" to "https://github.com/vaadin/base-starter-flow-osgi/archive/v.zip", - "karaf" to "https://github.com/vaadin/vaadin-flow-karaf-example/archive/v.zip" ) private val supportMatrix = arrayOf( @@ -55,20 +46,6 @@ class StarterSupport { buildTools.keys, 17 ), - StarterSupportMatrixElement( - "23", - setOf("17"), - architectures.keys, - buildTools.keys, - 11 - ), - StarterSupportMatrixElement( - "14", - setOf("17"), - setOf("springboot", "jakartaee", "servlet", "osgi"), - buildTools.keys, - 8 - ), StarterSupportMatrixElement( "hilla-react", setOf("17"), @@ -76,13 +53,6 @@ class StarterSupport { buildTools.keys, 17 ), - StarterSupportMatrixElement( - "hilla-lit", - setOf("17"), - setOf("springboot"), - buildTools.keys, - 17 - ) ) diff --git a/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt b/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt index fd7e99e..2da9e86 100644 --- a/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt +++ b/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt @@ -1,9 +1,13 @@ package com.vaadin.plugin.utils +import com.intellij.notification.Notification +import com.intellij.notification.NotificationType +import com.intellij.notification.Notifications import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.util.download.DownloadableFileService import com.intellij.util.io.ZipUtil import java.io.File @@ -18,7 +22,9 @@ class VaadinProjectUtil { private val LOG: Logger = Logger.getInstance(VaadinProjectUtil::class.java) - fun downloadAndExtract(project: Project, url: String) { + private const val NOTIFICATION_GROUP = "Vaadin" + + fun downloadAndExtract(project: Project, url: String, callback: () -> Unit) { val filename = "project.zip" LOG.info("Downloading $filename") val basePath: String = project.basePath!! @@ -29,7 +35,7 @@ class VaadinProjectUtil { DownloadableFileService.getInstance().createDownloader(listOf(description), "Vaadin Starter Project") WriteCommandAction.runWriteCommandAction(project, "Create Vaadin Project", "Vaadin", { - downloader.downloadWithBackgroundProgress(basePath, project).thenApply { + downloader.downloadWithBackgroundProgress(basePath, project).thenAccept { LOG.info("Extracting $downloadedFile") ZipUtil.extract(downloadedFile.toPath(), Path.of(basePath), null) // move contents from single zip directory @@ -40,6 +46,7 @@ class VaadinProjectUtil { } FileUtil.delete(downloadedFile) LOG.info("$downloadedFile deleted") + VirtualFileManager.getInstance().asyncRefresh(callback) } }) } @@ -62,6 +69,12 @@ class VaadinProjectUtil { } } + fun notify(content: String, type: NotificationType, project: Project?) { + Notifications.Bus.notify( + Notification(NOTIFICATION_GROUP, content, type), project + ) + } + } }