diff --git a/.github/readme/getting-started_use-this-template.png b/.github/readme/getting-started_use-this-template.png new file mode 100644 index 0000000..0a293ae Binary files /dev/null and b/.github/readme/getting-started_use-this-template.png differ diff --git a/.github/template-cleanup/CHANGELOG.md b/.github/template-cleanup/CHANGELOG.md new file mode 100644 index 0000000..7b8435d --- /dev/null +++ b/.github/template-cleanup/CHANGELOG.md @@ -0,0 +1,7 @@ + + +# %NAME% Changelog + +## [Unreleased] +### Added +- Initial scaffold created from [IntelliJ Plugin Template](https://github.com/JetBrains/intellij-plugin-template) diff --git a/.github/template-cleanup/README.md b/.github/template-cleanup/README.md new file mode 100644 index 0000000..873819b --- /dev/null +++ b/.github/template-cleanup/README.md @@ -0,0 +1,28 @@ +# %NAME% + +![Build](https://github.com/hsz/intellij-plugin-template/workflows/Build/badge.svg) + + +This Fancy IntelliJ Plugin is going to be your implementation of the brilliant ideas that you have. + +This specific section is a source for the [plugin.xml](./src/main/resources/META-INF/plugin.xml) file which will be +extracted by the [Gradle](./build.gradle.kts) during the build process. + +To keep everything working, do not remove `` sections. + + +## Installation + +- Using IDE built-in plugin system: + + Preferences > Plugins > Marketplace > Search for "%NAME%" > + Install Plugin + +- Manually: + + Download the [latest release](https://github.com/%REPOSITORY%/releases/latest) and install it manually using + Preferences > Plugins > ⚙️ > Install plugin from disk... + + +--- +Plugin based on the [IntelliJ Plugin Template](https://github.com/JetBrains/intellij-plugin-template). diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b33f86..6a255a4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,11 @@ -# GitHub Actions Workflow created for testing the plugin in three steps: -# - test using Gradle tasks, such as tes and verifyPlugin, -# - test building process by preparing the artifact using buildPlugin Gradle task, -# - run IntelliJ Plugin Verifier. +# GitHub Actions Workflow created for testing and preparing the plugin release in following steps: +# - validate Gradle Wrapper, +# - run test and verifyPlugin tasks, +# - run buildPlugin task and prepare artifact for the further tests, +# - run IntelliJ Plugin Verifier, +# - create a draft release. # -# Workflow is triggered on push or pull request event. +# Workflow is triggered on push and pull_request events. # # Docs: # - GitHub Actions: https://help.github.com/en/actions @@ -156,7 +158,7 @@ jobs: # If accepted and published, release workflow would be triggered. releaseDraft: name: Release Draft -# if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' needs: [build, verify] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6f8148..4f48bb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,6 @@ +# GitHub Actions Workflow created for handling the release process based on the draft release prepared +# with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided. + name: Release on: release: diff --git a/.github/workflows/template-cleanup.yml b/.github/workflows/template-cleanup.yml new file mode 100644 index 0000000..f157921 --- /dev/null +++ b/.github/workflows/template-cleanup.yml @@ -0,0 +1,67 @@ +# GitHub Actions Workflow responsible for cleaning up the IntelliJ Plugin Template repository from +# the template-specific files and configurations. This workflow is supposed to be triggered automatically +# when a new template-based repository has been created. + +name: Tempalte Cleanup +on: + push: + branches: + - master + +jobs: + + # Run cleaning process only if workflow is triggered by the non-JetBrains/intellij-plugin-template repository. + template-cleanup: + name: Template Cleanup + runs-on: ubuntu-latest + if: github.repository != 'JetBrains/intellij-plugin-template' + steps: + + # Check out current repository + - name: Fetch Sources + uses: actions/checkout@v2 + + # Cleanup project + - name: Cleanup + run: | + export LC_CTYPE=C + export LANG=C + + # Prepare variables + NAME="${GITHUB_REPOSITORY##*/}" + SAFE_NAME=$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') + ACTOR=$(echo $GITHUB_ACTOR | tr '[:upper:]' '[:lower:]') + GROUP="com.github.$ACTOR.$SAFE_NAME" + + # Replace placeholders in the template-cleanup files + sed -i '' "s/%NAME%/$NAME/g" .github/template-cleanup/* + sed -i '' "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" .github/template-cleanup/* + sed -i '' "s/%GROUP%/$GROUP/g" .github/template-cleanup/* + + # Replace template package name in project files with $GROUP + sed -i '' "s/org.jetbrains.plugins.template/$GROUP/g" gradle.properties + find . -type f -exec sed -i '' "s/org.jetbrains.plugins.template/$GROUP/g" {} + + + # Move content + mkdir -p src/main/kotlin/${GROUP//.//} + cp -R .github/template-cleanup/* . + cp -R src/main/kotlin/org/jetbrains/plugins/template/* src/main/kotlin/${GROUP//.//}/ + + # Cleanup + rm -rf .github/readme + rm -rf .github/template-cleanup + rm -rf src/main/kotlin/org + rm .github/workflows/template-cleanup.yml + + # Commit modified files + - name: Commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -m "Template cleanup" -a + + # Push changes + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 1ace8f1..d2bbb4d 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ [![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) ![Build](https://github.com/hsz/intellij-plugin-template/workflows/Build/badge.svg) -IntelliJ Plugin Template is a repository that provides a pure boilerplate for creating a plugin project with ease -designed as a GitHub template repository (check the [Creating a repository from a template][gh-template] article). + +**IntelliJ Plugin Template** is a repository that provides a pure boilerplate for creating a plugin project with ease +designed as a **GitHub Template Repository** (check the [Creating a repository from a template][gh-template] article). The main goal for this Template is to speed up the setup phase of the plugin development for the new as well as existing -developers by preconfiguring the project scaffold, CI and linking to the proper documentation pages as well as keeping +developers by preconfiguring the project scaffold, CI and linking to the proper documentation pages and keeping everything in the most straightforward manner. + -We can detail here the following parts: +We can highlight here the following parts: - Gradle configuration - Sample code: @@ -21,9 +23,21 @@ We can detail here the following parts: - CI based on GitHub actions - Release and changelog maintenance flow -## Getting started +## Getting Started -TODO +Before diving into the plugin development and everything that happens around, it is worth mentioning the fundamental +idea behind the GitHub Templates: by creating a new project using the current template, you start with no history +and no reference to this repository - it is the cut corner for creating a new repository with copy-pasting the content +or cloning repositories and clearing the history by your own. + +The only thing that you have to do is clicking the **Use this template** button. + +![Use this template][file:getting-started_use-this-template.png] + +After creating your blank project from the template, there will be the [Template Cleanup][file:template_cleanup.yml] +workflow triggered to override or remove template-specific configuration, like plugin name, current changelog, etc. + +As a last step, it is required to manually specify the `pluginName` and `pluginGroup` in the `gradle.properties` file. ## Gradle @@ -39,7 +53,10 @@ TODO ## Continuous Integration -TODO +Unit tests +Detekt +verifyPlugin +intellij-plugin-verifier ## Release Flow @@ -55,6 +72,10 @@ and inside of the Plugin Manager's item details. There are many different methods of handling the project's changelog. One of them, used in the current template project, is the [Keep a Changelog][keep-a-changelog] approach. +# Publishing Plugin + +Cannot find org.jetbrains.plugins.template. Note that you need to upload the plugin to the repository at least once manually (to specify options like the license, repository URL etc.). Follow the instructions: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/publishing_plugin.html + ## Useful Links - [IntelliJ Platform SDK DevGuide][sdk-docs] @@ -73,3 +94,6 @@ is the [Keep a Changelog][keep-a-changelog] approach. [slack]: https://plugins.jetbrains.com/slack [forum]: https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development [keep-a-changelog]: https://keepachangelog.com + +[file:getting-started_use-this-template.png]: ./.github/readme/getting-started_use-this-template.png +[file:template_cleanup.yml]: ./.github/workflows/template-cleanup.yml diff --git a/build.gradle.kts b/build.gradle.kts index db453bd..dc4ee03 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.changelog.closure +import org.jetbrains.changelog.markdownToHTML import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -10,7 +11,7 @@ plugins { // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin id("org.jetbrains.intellij") version "0.4.21" // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin - id("org.jetbrains.changelog") version "0.3.1" + id("org.jetbrains.changelog") version "0.3.2" // detekt linter - read more: https://detekt.github.io/detekt/kotlindsl.html id("io.gitlab.arturbosch.detekt") version "1.10.0-RC1" } @@ -82,6 +83,15 @@ tasks { version(pluginVersion) sinceBuild(pluginSinceBuild) untilBuild(pluginUntilBuild) + + // Extract the section from README.md and provide for the plugin's manifest + pluginDescription(closure { + File("./README.md").readText().lines().run { + subList(indexOf("") + 1, indexOf("")) + }.joinToString("\n").run { markdownToHTML(this) } + }) + + // Get the latest available change notes from the changelog file changeNotes(closure { changelog.getLatest().toHTML() }) diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3b58236 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,6 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } +} diff --git a/src/main/kotlin/org/jetbrains/plugins/template/TemplateBundle.kt b/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt similarity index 83% rename from src/main/kotlin/org/jetbrains/plugins/template/TemplateBundle.kt rename to src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt index 6bc8a04..be0c472 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/TemplateBundle.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt @@ -5,9 +5,9 @@ import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.PropertyKey @NonNls -private const val BUNDLE = "messages.TemplateBundle" +private const val BUNDLE = "messages.MyBundle" -object TemplateBundle : DynamicBundle(BUNDLE) { +object MyBundle : DynamicBundle(BUNDLE) { @Suppress("SpreadOperator") @JvmStatic diff --git a/src/main/kotlin/org/jetbrains/plugins/template/services/MyApplicationService.kt b/src/main/kotlin/org/jetbrains/plugins/template/services/MyApplicationService.kt index 8be1e09..2997c27 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/services/MyApplicationService.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/services/MyApplicationService.kt @@ -1,10 +1,10 @@ package org.jetbrains.plugins.template.services -import org.jetbrains.plugins.template.TemplateBundle +import org.jetbrains.plugins.template.MyBundle class MyApplicationService { init { - println(TemplateBundle.message("applicationService")) + println(MyBundle.message("applicationService")) } } diff --git a/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt b/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt index 51bdf3c..df4b01f 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt @@ -1,11 +1,11 @@ package org.jetbrains.plugins.template.services import com.intellij.openapi.project.Project -import org.jetbrains.plugins.template.TemplateBundle +import org.jetbrains.plugins.template.MyBundle class MyProjectService(project: Project) { init { - println(TemplateBundle.message("projectService", project.name)) + println(MyBundle.message("projectService", project.name)) } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 67ca842..f9d230d 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -2,7 +2,6 @@ org.jetbrains.plugins.template Template JetBrains - Demonstrates various aspects of interacting with project model diff --git a/src/main/resources/messages/TemplateBundle.properties b/src/main/resources/messages/MyBundle.properties similarity index 78% rename from src/main/resources/messages/TemplateBundle.properties rename to src/main/resources/messages/MyBundle.properties index 45b5d87..78dbb24 100644 --- a/src/main/resources/messages/TemplateBundle.properties +++ b/src/main/resources/messages/MyBundle.properties @@ -1,3 +1,3 @@ -name=Template Plugin +name=My Plugin applicationService=Application service projectService=Project service: {0}