├── .gitignore ├── settings.gradle.kts ├── src └── main │ ├── resources │ ├── messages │ │ └── HtmxBundle.properties │ └── META-INF │ │ ├── plugin.xml │ │ └── pluginIcon.svg │ └── kotlin │ └── com │ └── github │ └── hugohomesquita │ └── htmxjetbrains │ ├── Htmx.kt │ ├── AutoCompleteSuggestions.kt │ ├── AttributesProvider.kt │ ├── AttributeUtil.kt │ ├── HtmxAttributeDescriptor.kt │ ├── HtmxCompletionContributor.kt │ ├── completion │ ├── HxSwapCompletion.kt │ ├── HxSwapOobCompletion.kt │ └── HxTargetCompletion.kt │ ├── HtmxAttributeCompletionProvider.kt │ └── AttributeInfo.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── qodana.yml ├── .github ├── dependabot.yml └── workflows │ ├── run-ui-tests.yml │ ├── release.yml │ └── build.yml ├── .idea └── gradle.xml ├── .run ├── Run IDE for UI Tests.run.xml ├── Run IDE with Plugin.run.xml ├── Run Plugin Tests.run.xml ├── Run Qodana.run.xml └── Run Plugin Verification.run.xml ├── CHANGELOG.md ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | .qodana 4 | build 5 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "htmx-jetbrains" 2 | -------------------------------------------------------------------------------- /src/main/resources/messages/HtmxBundle.properties: -------------------------------------------------------------------------------- 1 | name=Htmx 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugohomesquita/htmx-jetbrains/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /qodana.yml: -------------------------------------------------------------------------------- 1 | # Qodana configuration: 2 | # https://www.jetbrains.com/help/qodana/qodana-yaml.html 3 | 4 | version: 1.0 5 | profile: 6 | name: qodana.recommended 7 | exclude: 8 | - name: All 9 | paths: 10 | - .qodana 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/Htmx.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.intellij.openapi.util.IconLoader 4 | 5 | object Htmx { 6 | @JvmField 7 | val ICON = IconLoader.getIcon("/pluginIcon.svg", javaClass) 8 | } 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/AutoCompleteSuggestions.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.intellij.psi.html.HtmlTag 4 | 5 | class AutoCompleteSuggestions(val htmlTag: HtmlTag, val partialAttribute: String) { 6 | 7 | val attributes: MutableList = mutableListOf() 8 | 9 | init { 10 | addAttributes() 11 | } 12 | 13 | private fun addAttributes() { 14 | for (attribute in AttributeUtil.attributes) { 15 | attributes.add(AttributeInfo(attribute)) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Dependabot configuration: 2 | # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates 3 | 4 | version: 2 5 | updates: 6 | # Maintain dependencies for Gradle dependencies 7 | - package-ecosystem: "gradle" 8 | directory: "/" 9 | target-branch: "next" 10 | schedule: 11 | interval: "daily" 12 | # Maintain dependencies for GitHub Actions 13 | - package-ecosystem: "github-actions" 14 | directory: "/" 15 | target-branch: "next" 16 | schedule: 17 | interval: "daily" 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/AttributesProvider.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.intellij.psi.impl.source.html.dtd.HtmlElementDescriptorImpl 4 | import com.intellij.psi.xml.XmlTag 5 | import com.intellij.xml.XmlAttributeDescriptor 6 | import com.intellij.xml.XmlAttributeDescriptorsProvider 7 | 8 | class AttributesProvider : XmlAttributeDescriptorsProvider { 9 | override fun getAttributeDescriptors(xmlTag: XmlTag): Array { 10 | return emptyArray() 11 | } 12 | 13 | @Suppress("ReturnCount") 14 | override fun getAttributeDescriptor(name: String, xmlTag: XmlTag): XmlAttributeDescriptor? { 15 | if (xmlTag.descriptor !is HtmlElementDescriptorImpl) return null 16 | val info = AttributeInfo(name) 17 | 18 | if (info.isHtmx()) { 19 | return HtmxAttributeDescriptor(name, xmlTag) 20 | } 21 | 22 | return null 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.github.hugohomesquita.htmxjetbrains 4 | HTMX Support 5 | 6 | 7 | Hugo Mesquita 8 | 9 | 10 | com.intellij.modules.platform 11 | com.intellij.modules.lang 12 | com.intellij.modules.xml 13 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.run/Run IDE for UI Tests.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 15 | 17 | true 18 | true 19 | false 20 | 21 | 22 | -------------------------------------------------------------------------------- /.run/Run IDE with Plugin.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /.run/Run Plugin Tests.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/AttributeUtil.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | object AttributeUtil { 4 | val attributes = arrayOf( 5 | "hx-boost", 6 | "hx-get", 7 | "hx-post", 8 | "hx-on", 9 | "hx-push-url", 10 | "hx-select", 11 | "hx-select-oob", 12 | "hx-swap", 13 | "hx-swap-oob", 14 | "hx-target", 15 | "hx-trigger", 16 | "hx-vals", 17 | "hx-confirm", 18 | "hx-delete", 19 | "hx-disable", 20 | "hx-disabled-elt", 21 | "hx-disinherit", 22 | "hx-encoding", 23 | "hx-ext", 24 | "hx-headers", 25 | "hx-history", 26 | "hx-history-elt", 27 | "hx-include", 28 | "hx-indicator", 29 | "hx-params", 30 | "hx-patch", 31 | "hx-preserve", 32 | "hx-prompt", 33 | "hx-put", 34 | "hx-replace-url", 35 | "hx-request", 36 | "hx-sse", 37 | "hx-sync", 38 | "hx-validate", 39 | "hx-vars", 40 | "hx-ws", 41 | ) 42 | } -------------------------------------------------------------------------------- /.run/Run Qodana.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 16 | 19 | 21 | true 22 | true 23 | false 24 | 25 | 26 | -------------------------------------------------------------------------------- /.run/Run Plugin Verification.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 25 | 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # htmx-jetbrains Changelog 4 | 5 | ## [Unreleased] 6 | 7 | ### Added 8 | 9 | ### Changed 10 | 11 | ### Deprecated 12 | 13 | ### Removed 14 | 15 | ### Fixed 16 | 17 | ### Security 18 | 19 | ## [0.0.10] 20 | 21 | ### Changed 22 | 23 | - Improved support for `hx-swap-oob` attribute 24 | 25 | ## [0.0.9] 26 | 27 | ### Added 28 | 29 | - Add support for `hx-disabled-elt` attribute 30 | 31 | ## [0.0.8] 32 | 33 | ### Added 34 | 35 | - Add support for `hx-on` attribute 36 | 37 | ### Fixed 38 | 39 | - Fix supported build number ranges and IntelliJ Platform versions 40 | 41 | ## [0.0.7] 42 | 43 | ### Fixed 44 | 45 | - Fix hx-target code completion inserts double # #3 46 | 47 | ## [0.0.6] 48 | 49 | ### Fixed 50 | 51 | - Support IntelliJ 2023.1 52 | 53 | ## [0.0.5] 54 | 55 | ### Fixed 56 | 57 | - Fix capitalization of `hx-swap` 58 | 59 | ## [0.0.4] 60 | 61 | ### Added 62 | 63 | - Added auto-completion with default values of `hx-swap` 64 | 65 | ## [0.0.3] 66 | 67 | ### Added 68 | 69 | - Added auto-completion with default values of `hx-target` and id css selectors 70 | 71 | ## [0.0.2] 72 | 73 | ### Fixed 74 | 75 | - Added icon to plugin 76 | 77 | ## [0.0.1] 78 | 79 | ### Added 80 | 81 | - Auto-complete for attributes 82 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html 2 | 3 | pluginGroup = com.github.hugohomesquita.htmxjetbrains 4 | pluginName = htmx-jetbrains 5 | pluginRepositoryUrl = https://github.com/hugohomesquita/htmx-jetbrains 6 | # SemVer format -> https://semver.org 7 | pluginVersion = 0.0.10 8 | 9 | # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html 10 | pluginSinceBuild = 222 11 | pluginUntilBuild = 12 | 13 | # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension 14 | platformType = IC 15 | platformVersion = 2022.2 16 | 17 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html 18 | # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 19 | platformPlugins = 20 | 21 | # Gradle Releases -> https://github.com/gradle/gradle/releases 22 | gradleVersion = 1.10.1 23 | 24 | # Opt-out flag for bundling Kotlin standard library -> https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library 25 | # suppress inspection "UnusedProperty" 26 | kotlin.stdlib.default.dependency = false 27 | 28 | # Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html 29 | org.gradle.unsafe.configuration-cache = true 30 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/HtmxAttributeDescriptor.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.intellij.psi.PsiElement 4 | import com.intellij.psi.meta.PsiPresentableMetaData 5 | import com.intellij.psi.xml.XmlTag 6 | import com.intellij.util.ArrayUtil 7 | import com.intellij.xml.impl.BasicXmlAttributeDescriptor 8 | 9 | class HtmxAttributeDescriptor( 10 | private val name: String, 11 | private val xmlTag: XmlTag 12 | ) : 13 | BasicXmlAttributeDescriptor(), 14 | PsiPresentableMetaData { 15 | 16 | private val info: AttributeInfo = AttributeInfo(name) 17 | 18 | override fun getIcon() = Htmx.ICON 19 | 20 | override fun getTypeName(): String { 21 | return info.typeText 22 | } 23 | 24 | override fun init(psiElement: PsiElement) {} 25 | 26 | override fun isRequired(): Boolean = false 27 | 28 | override fun hasIdType(): Boolean { 29 | return name == "id" 30 | } 31 | 32 | override fun hasIdRefType(): Boolean = false 33 | 34 | override fun isEnumerated(): Boolean { 35 | return !info.hasValue() 36 | } 37 | 38 | override fun getDeclaration(): PsiElement? = xmlTag 39 | 40 | override fun getName(): String = name 41 | 42 | override fun getDependencies(): Array = ArrayUtil.EMPTY_OBJECT_ARRAY 43 | 44 | override fun isFixed(): Boolean = false 45 | 46 | override fun getDefaultValue(): String? = null 47 | 48 | override fun getEnumeratedValues(): Array? = ArrayUtil.EMPTY_STRING_ARRAY 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # htmx-jetbrains 2 | 3 | ![Build](https://github.com/hugohomesquita/htmx-jetbrains/workflows/Build/badge.svg) 4 | [![Version](https://img.shields.io/jetbrains/plugin/v/20588-htmx-support)](https://plugins.jetbrains.com/plugin/20588-htmx-support) 5 | [![Downloads](https://img.shields.io/jetbrains/plugin/v/20588-htmx-support)](https://plugins.jetbrains.com/plugin/20588-htmx-support) 6 | ![Release](https://github.com/hugohomesquita/htmx-jetbrains/workflows/Release/badge.svg) 7 | 8 | ## Release Workflow 9 | 10 | 1. Update `gradle.properties` with the **new plugin version** 11 | 2. Update `CHANGELOG.md` to reflect the new changes in the **Unreleased** section 12 | 3. Push `main` branch and allow all GitHub Actions to run 13 | 4. Go to [releases page](https://github.com/hugohomesquita/htmx-jetbrains/releases) and edit/publish draft release 14 | 15 | ## Plugin Description 16 | 17 | 18 | This plugin adds support for the following [htmx](https://github.com/bigskysoftware/htmx) features: 19 | 20 | - Auto-complete htmx attributes such as `hx-get` 21 | 22 | 23 | 24 | ## Installation 25 | 26 | - Using IDE built-in plugin system: 27 | 28 | Preferences > Plugins > Marketplace > Search for "HTMX Support" > 29 | Install Plugin 30 | 31 | - Manually: 32 | 33 | Download the [latest release](https://github.com/hugohomesquita/htmx-jetbrains/releases/latest) and install it 34 | manually using 35 | Preferences > Plugins > ⚙️ > Install plugin from disk... 36 | 37 | --- 38 | Plugin based on the [IntelliJ Platform Plugin Template][template]. 39 | 40 | [template]: https://github.com/JetBrains/intellij-platform-plugin-template 41 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/HtmxCompletionContributor.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.github.hugohomesquita.htmxjetbrains.completion.HxSwapCompletion 4 | import com.github.hugohomesquita.htmxjetbrains.completion.HxSwapOobCompletion 5 | import com.github.hugohomesquita.htmxjetbrains.completion.HxTargetCompletion 6 | import com.intellij.codeInsight.completion.CompletionContributor 7 | import com.intellij.codeInsight.completion.CompletionType 8 | import com.intellij.patterns.PlatformPatterns 9 | import com.intellij.patterns.XmlPatterns 10 | import com.intellij.psi.xml.XmlTokenType 11 | 12 | class HtmxCompletionContributor : CompletionContributor() { 13 | init { 14 | extend( 15 | CompletionType.BASIC, 16 | PlatformPatterns.psiElement(XmlTokenType.XML_NAME).withParent(XmlPatterns.xmlAttribute()), 17 | HtmxAttributeCompletionProvider() 18 | ) 19 | extend( 20 | CompletionType.BASIC, 21 | PlatformPatterns 22 | .psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) 23 | .inside(XmlPatterns.xmlAttribute("hx-target")), 24 | HxTargetCompletion() 25 | ) 26 | extend( 27 | CompletionType.BASIC, 28 | PlatformPatterns 29 | .psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) 30 | .inside(XmlPatterns.xmlAttribute("hx-swap")), 31 | HxSwapCompletion() 32 | ) 33 | extend( 34 | CompletionType.BASIC, 35 | PlatformPatterns 36 | .psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) 37 | .inside(XmlPatterns.xmlAttribute("hx-swap-oob")), 38 | HxSwapOobCompletion() 39 | ) 40 | } 41 | } -------------------------------------------------------------------------------- /.github/workflows/run-ui-tests.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow for launching UI tests on Linux, Windows, and Mac in the following steps: 2 | # - prepare and launch IDE with your plugin and robot-server plugin, which is needed to interact with UI 3 | # - wait for IDE to start 4 | # - run UI tests with separate Gradle task 5 | # 6 | # Please check https://github.com/JetBrains/intellij-ui-test-robot for information about UI tests with IntelliJ Platform 7 | # 8 | # Workflow is triggered manually. 9 | 10 | name: Run UI Tests 11 | on: 12 | workflow_dispatch 13 | 14 | jobs: 15 | 16 | testUI: 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | include: 22 | - os: ubuntu-latest 23 | runIde: | 24 | export DISPLAY=:99.0 25 | Xvfb -ac :99 -screen 0 1920x1080x16 & 26 | gradle runIdeForUiTests & 27 | - os: windows-latest 28 | runIde: start gradlew.bat runIdeForUiTests 29 | - os: macos-latest 30 | runIde: ./gradlew runIdeForUiTests & 31 | 32 | steps: 33 | 34 | # Check out current repository 35 | - name: Fetch Sources 36 | uses: actions/checkout@v3 37 | 38 | # Setup Java 11 environment for the next steps 39 | - name: Setup Java 40 | uses: actions/setup-java@v3 41 | with: 42 | distribution: zulu 43 | java-version: 11 44 | 45 | # Run IDEA prepared for UI testing 46 | - name: Run IDE 47 | run: ${{ matrix.runIde }} 48 | 49 | # Wait for IDEA to be started 50 | - name: Health Check 51 | uses: jtalk/url-health-check-action@v3 52 | with: 53 | url: http://127.0.0.1:8082 54 | max-attempts: 15 55 | retry-delay: 30s 56 | 57 | # Run tests 58 | - name: Tests 59 | run: ./gradlew test 60 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/completion/HxSwapCompletion.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains.completion 2 | 3 | import com.github.hugohomesquita.htmxjetbrains.Htmx 4 | import com.intellij.codeInsight.completion.CompletionParameters 5 | import com.intellij.codeInsight.completion.CompletionProvider 6 | import com.intellij.codeInsight.completion.CompletionResultSet 7 | import com.intellij.codeInsight.lookup.LookupElementBuilder 8 | import com.intellij.lang.html.HTMLLanguage 9 | import com.intellij.util.ProcessingContext 10 | 11 | class HxSwapCompletion : CompletionProvider() { 12 | override fun addCompletions( 13 | parameters: CompletionParameters, 14 | context: ProcessingContext, 15 | result: CompletionResultSet 16 | ) { 17 | val position = parameters.position 18 | 19 | if (HTMLLanguage.INSTANCE !in position.containingFile.viewProvider.languages) { 20 | return 21 | } 22 | 23 | val options = hashMapOf( 24 | "innerHTML" to "The default, replace the inner html of the target element", 25 | "outerHTML" to "Replace the entire target element with the response", 26 | "beforebegin" to "Insert the response before the target element", 27 | "afterbegin" to "Insert the response before the first child of the target element", 28 | "beforeend" to "Insert the response after the last child of the target element", 29 | "afterend" to "Insert the response after the target element", 30 | "delete" to "Deletes the target element regardless of the response", 31 | "none" to "Does not append content from response (out of band items will still be processed)." 32 | ) 33 | 34 | options.map { (key, value) -> 35 | LookupElementBuilder.create(key).withIcon(Htmx.ICON).withTypeText(value) 36 | }.forEach { result.addElement(it) } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/completion/HxSwapOobCompletion.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains.completion 2 | 3 | import com.github.hugohomesquita.htmxjetbrains.Htmx 4 | import com.intellij.codeInsight.completion.CompletionParameters 5 | import com.intellij.codeInsight.completion.CompletionProvider 6 | import com.intellij.codeInsight.completion.CompletionResultSet 7 | import com.intellij.codeInsight.lookup.LookupElementBuilder 8 | import com.intellij.lang.html.HTMLLanguage 9 | import com.intellij.util.ProcessingContext 10 | 11 | class HxSwapOobCompletion : CompletionProvider() { 12 | override fun addCompletions( 13 | parameters: CompletionParameters, 14 | context: ProcessingContext, 15 | result: CompletionResultSet 16 | ) { 17 | val position = parameters.position 18 | 19 | if (HTMLLanguage.INSTANCE !in position.containingFile.viewProvider.languages) { 20 | return 21 | } 22 | 23 | val options = hashMapOf( 24 | "innerHTML" to "The default, replace the inner html of the target element", 25 | "outerHTML" to "Replace the entire target element with the response", 26 | "true" to "Equivalent to 'outerHTML'", 27 | "beforebegin" to "Insert the response before the target element", 28 | "afterbegin" to "Insert the response before the first child of the target element", 29 | "beforeend" to "Insert the response after the last child of the target element", 30 | "afterend" to "Insert the response after the target element", 31 | "delete" to "Deletes the target element regardless of the response", 32 | "none" to "Does not append content from response (out of band items will still be processed)." 33 | ) 34 | 35 | options.map { (key, value) -> 36 | LookupElementBuilder.create(key).withIcon(Htmx.ICON).withTypeText(value) 37 | }.forEach { result.addElement(it) } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/HtmxAttributeCompletionProvider.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | import com.intellij.codeInsight.completion.CompletionProvider 4 | import com.intellij.codeInsight.completion.CompletionParameters 5 | import com.intellij.codeInsight.completion.CompletionResultSet 6 | import com.intellij.codeInsight.completion.CompletionUtilCore 7 | import com.intellij.codeInsight.lookup.LookupElementBuilder 8 | import com.intellij.codeInsight.completion.XmlAttributeInsertHandler 9 | import com.intellij.lang.html.HTMLLanguage 10 | import com.intellij.openapi.util.text.StringUtil 11 | import com.intellij.psi.html.HtmlTag 12 | import com.intellij.psi.xml.XmlAttribute 13 | import com.intellij.util.ProcessingContext 14 | 15 | class HtmxAttributeCompletionProvider(vararg items: String) : CompletionProvider() { 16 | override fun addCompletions( 17 | parameters: CompletionParameters, 18 | context: ProcessingContext, 19 | result: CompletionResultSet 20 | ) { 21 | val position = parameters.position 22 | 23 | if (HTMLLanguage.INSTANCE !in position.containingFile.viewProvider.languages) { 24 | return 25 | } 26 | 27 | val attribute = position.parent as? XmlAttribute ?: return 28 | val xmlTag = attribute.parent as? HtmlTag ?: return 29 | 30 | val partialAttribute = StringUtil.trimEnd(attribute.name, CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED) 31 | 32 | if (partialAttribute.isEmpty()) { 33 | return 34 | } 35 | 36 | val suggestions = AutoCompleteSuggestions(xmlTag, partialAttribute) 37 | 38 | suggestions.attributes.forEach { 39 | val text = it.attribute 40 | 41 | var elementBuilder = LookupElementBuilder 42 | .create(text) 43 | .withCaseSensitivity(false) 44 | .withIcon(Htmx.ICON) 45 | .withTypeText(it.typeText) 46 | 47 | if (it.hasValue()) { 48 | elementBuilder = elementBuilder.withInsertHandler(XmlAttributeInsertHandler.INSTANCE) 49 | } 50 | 51 | result.addElement(elementBuilder) 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/completion/HxTargetCompletion.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains.completion 2 | 3 | import com.github.hugohomesquita.htmxjetbrains.Htmx 4 | import com.intellij.codeInsight.completion.CompletionParameters 5 | import com.intellij.codeInsight.completion.CompletionProvider 6 | import com.intellij.codeInsight.completion.CompletionResultSet 7 | import com.intellij.codeInsight.completion.PrioritizedLookupElement 8 | import com.intellij.codeInsight.lookup.LookupElementBuilder 9 | import com.intellij.lang.html.HTMLLanguage 10 | import com.intellij.psi.html.HtmlTag 11 | import com.intellij.psi.util.PsiTreeUtil 12 | import com.intellij.util.ProcessingContext 13 | 14 | class HxTargetCompletion : CompletionProvider() { 15 | override fun addCompletions( 16 | parameters: CompletionParameters, 17 | context: ProcessingContext, 18 | result: CompletionResultSet 19 | ) { 20 | val position = parameters.position 21 | 22 | if (HTMLLanguage.INSTANCE !in position.containingFile.viewProvider.languages) { 23 | return 24 | } 25 | 26 | val thisElement = LookupElementBuilder 27 | .create("this") 28 | .withIcon(Htmx.ICON) 29 | .withTypeText( 30 | "this which indicates that the element " + 31 | "that the attribute is on is the target hx-target" 32 | ) 33 | 34 | val closestElement = LookupElementBuilder 35 | .create("closest ") 36 | .withIcon(Htmx.ICON) 37 | .withTypeText( 38 | "closest which will find the closest parent ancestor that " + 39 | "matches the given CSS selector. (e.g. closest tr will target " + 40 | "the closest table row to the element)" 41 | ) 42 | 43 | val findElement = LookupElementBuilder 44 | .create("find ") 45 | .withIcon(Htmx.ICON) 46 | .withTypeText( 47 | "find which will find the first child " + 48 | "descendant element that matches the given CSS selector. (e.g find tr " + 49 | "will target the first child descendant row to the element)" 50 | ) 51 | 52 | result.addElement(PrioritizedLookupElement.withPriority(thisElement, 1.0)) 53 | result.addElement(PrioritizedLookupElement.withPriority(closestElement, 1.0)) 54 | result.addElement(PrioritizedLookupElement.withPriority(findElement, 1.0)) 55 | 56 | val allTags = PsiTreeUtil.findChildrenOfType(position.containingFile, HtmlTag::class.java) 57 | allTags.forEach { 58 | val id = it.getAttribute("id") 59 | if (id != null) { 60 | val idValue = id.valueElement?.value 61 | if (idValue != null) { 62 | val prefix = if (position.text.startsWith("#")) "" else "#" // if the user already typed #, don't add it again 63 | result.addElement( 64 | LookupElementBuilder 65 | .create("$prefix$idValue") 66 | .withIcon(Htmx.ICON) 67 | .withTypeText("id of ${it.name}") 68 | ) 69 | } 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for handling the release process based on the draft release prepared 2 | # with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided. 3 | 4 | name: Release 5 | on: 6 | release: 7 | types: [prereleased, released] 8 | 9 | jobs: 10 | 11 | # Prepare and publish the plugin to the Marketplace repository 12 | release: 13 | name: Publish Plugin 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: write 17 | pull-requests: write 18 | steps: 19 | 20 | # Check out current repository 21 | - name: Fetch Sources 22 | uses: actions/checkout@v3 23 | with: 24 | ref: ${{ github.event.release.tag_name }} 25 | 26 | # Setup Java 11 environment for the next steps 27 | - name: Setup Java 28 | uses: actions/setup-java@v3 29 | with: 30 | distribution: zulu 31 | java-version: 11 32 | 33 | # Set environment variables 34 | - name: Export Properties 35 | id: properties 36 | shell: bash 37 | run: | 38 | CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d' 39 | ${{ github.event.release.body }} 40 | EOM 41 | )" 42 | 43 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 44 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 45 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 46 | 47 | echo "::set-output name=changelog::$CHANGELOG" 48 | 49 | # Update Unreleased section with the current release note 50 | - name: Patch Changelog 51 | if: ${{ steps.properties.outputs.changelog != '' }} 52 | env: 53 | CHANGELOG: ${{ steps.properties.outputs.changelog }} 54 | run: | 55 | ./gradlew patchChangelog --release-note="$CHANGELOG" 56 | 57 | # Publish the plugin to the Marketplace 58 | - name: Publish Plugin 59 | env: 60 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} 61 | CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }} 62 | PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} 63 | PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }} 64 | run: ./gradlew publishPlugin 65 | 66 | # Upload artifact as a release asset 67 | - name: Upload Release Asset 68 | env: 69 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 70 | run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/* 71 | 72 | # Create pull request 73 | - name: Create Pull Request 74 | if: ${{ steps.properties.outputs.changelog != '' }} 75 | env: 76 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 77 | run: | 78 | VERSION="${{ github.event.release.tag_name }}" 79 | BRANCH="changelog-update-$VERSION" 80 | LABEL="release changelog" 81 | 82 | git config user.email "action@github.com" 83 | git config user.name "GitHub Action" 84 | 85 | git checkout -b $BRANCH 86 | git commit -am "Changelog update - $VERSION" 87 | git push --set-upstream origin $BRANCH 88 | 89 | gh label create "$LABEL" \ 90 | --description "Pull requests with release changelog update" \ 91 | || true 92 | 93 | gh pr create \ 94 | --title "Changelog update - \`$VERSION\`" \ 95 | --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ 96 | --label "$LABEL" \ 97 | --head $BRANCH 98 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/hugohomesquita/htmxjetbrains/AttributeInfo.kt: -------------------------------------------------------------------------------- 1 | package com.github.hugohomesquita.htmxjetbrains 2 | 3 | @Suppress("MemberVisibilityCanBePrivate") 4 | class AttributeInfo(val attribute: String) { 5 | private val typeTexts = hashMapOf( 6 | "hx-boost" to "Add or remove progressive enhancement for links and forms", 7 | "hx-get" to "Issues a GET to the specified URL", 8 | "hx-post" to "Issues a POST to the specified URL", 9 | "hx-on" to "Handle any event with a script inline", 10 | "hx-push-url" to "Pushes the URL into the browser location bar, creating a new history entry", 11 | "hx-select" to "Select content to swap in from a response", 12 | "hx-select-oob" to "Select content to swap in from a response, out of band (somewhere other than the target)", 13 | "hx-swap" to "Controls how content is swapped in (outerHTML, beforeEnd, afterend, ...)", 14 | "hx-swap-oob" to "Marks content in a response to be out of band (should swap in somewhere other than the target)", 15 | "hx-target" to "Specifies the event that triggers the request", 16 | "hx-trigger" to "Specifies the event that triggers the request", 17 | "hx-vals" to "Adds values to the parameters to submit with the request (JSON-formatted)", 18 | "hx-confirm" to "Shows a confim() dialog before issuing a request", 19 | "hx-delete" to "Issues a DELETE to the specified URL", 20 | "hx-disable" to "Disables htmx processing for the given node and any children nodes", 21 | "hx-disabled-elt" to "Adds the disabled attribute to the specified elements while a request is in flight", 22 | "hx-disinherit" to "Control and disable automatic attribute inheritance for child nodes", 23 | "hx-encoding" to "Changes the request encoding type", 24 | "hx-ext" to "Extensions to use for this element", 25 | "hx-headers" to "Adds to the headers that will be submitted with the request", 26 | "hx-history" to "Prevent sensitive data being saved to the history cache", 27 | "hx-history-elt" to "The element to snapshot and restore during history navigation", 28 | "hx-include" to "Include additional data in requests", 29 | "hx-indicator" to "The element to put the htmx-request class on during the request", 30 | "hx-params" to "Filters the parameters that will be submitted with a request", 31 | "hx-patch" to "Issues a PATCH to the specified URL", 32 | "hx-preserve" to "Specifies elements to keep unchanged between requests", 33 | "hx-prompt" to "Shows a prompt() before submitting a request", 34 | "hx-put" to "Issues a PUT to the specified URL", 35 | "hx-replace-url" to "Replace the URL in the browser location bar", 36 | "hx-request" to "Configures various aspects of the request", 37 | "hx-sse" to "Has been moved to an extension.", 38 | "hx-sync" to "Control how requests made by different elements are synchronized", 39 | "hx-validate" to "Force elements to validate themselves before a request", 40 | "hx-vars" to "Adds values dynamically to the parameters to submit with the request (deprecated, please use hx-vals)", 41 | "hx-ws" to "Has been moved to an extension. Documentation for older versions", 42 | ) 43 | 44 | val name: String 45 | 46 | val typeText: String 47 | 48 | init { 49 | name = attribute 50 | typeText = buildTypeText() 51 | } 52 | 53 | @Suppress("ComplexCondition") 54 | fun isHtmx(): Boolean { 55 | return this.isAttribute() 56 | } 57 | 58 | fun isAttribute(): Boolean { 59 | return AttributeUtil.attributes.contains(name) 60 | } 61 | 62 | fun hasValue(): Boolean { 63 | return name != "" 64 | } 65 | 66 | @Suppress("ReturnCount") 67 | private fun buildTypeText(): String { 68 | return typeTexts.getOrDefault(name, "Htmx") 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for testing and preparing the plugin release in following steps: 2 | # - validate Gradle Wrapper, 3 | # - run 'test' and 'verifyPlugin' tasks, 4 | # - run Qodana inspections, 5 | # - run 'buildPlugin' task and prepare artifact for the further tests, 6 | # - run 'runPluginVerifier' task, 7 | # - create a draft release. 8 | # 9 | # Workflow is triggered on push and pull_request events. 10 | # 11 | # GitHub Actions reference: https://help.github.com/en/actions 12 | # 13 | ## JBIJPPTPL 14 | 15 | name: Build 16 | on: 17 | # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) 18 | push: 19 | branches: [main] 20 | # Trigger the workflow on any pull request 21 | pull_request: 22 | 23 | jobs: 24 | 25 | # Run Gradle Wrapper Validation Action to verify the wrapper's checksum 26 | # Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks 27 | # Build plugin and provide the artifact for the next workflow jobs 28 | build: 29 | name: Build 30 | runs-on: ubuntu-latest 31 | outputs: 32 | version: ${{ steps.properties.outputs.version }} 33 | changelog: ${{ steps.properties.outputs.changelog }} 34 | steps: 35 | 36 | # Free GitHub Actions Environment Disk Space 37 | - name: Maximize Build Space 38 | run: | 39 | sudo rm -rf /usr/share/dotnet 40 | sudo rm -rf /usr/local/lib/android 41 | sudo rm -rf /opt/ghc 42 | 43 | # Check out current repository 44 | - name: Fetch Sources 45 | uses: actions/checkout@v3 46 | 47 | # Validate wrapper 48 | - name: Gradle Wrapper Validation 49 | uses: gradle/wrapper-validation-action@v1.0.5 50 | 51 | # Setup Java 11 environment for the next steps 52 | - name: Setup Java 53 | uses: actions/setup-java@v3 54 | with: 55 | distribution: zulu 56 | java-version: 11 57 | 58 | # Set environment variables 59 | - name: Export Properties 60 | id: properties 61 | shell: bash 62 | run: | 63 | PROPERTIES="$(./gradlew properties --console=plain -q)" 64 | VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" 65 | NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" 66 | CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" 67 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 68 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 69 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 70 | 71 | echo "::set-output name=version::$VERSION" 72 | echo "::set-output name=name::$NAME" 73 | echo "::set-output name=changelog::$CHANGELOG" 74 | echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" 75 | 76 | ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier 77 | 78 | # Run tests 79 | - name: Run Tests 80 | run: ./gradlew check 81 | 82 | # Collect Tests Result of failed tests 83 | - name: Collect Tests Result 84 | if: ${{ failure() }} 85 | uses: actions/upload-artifact@v3 86 | with: 87 | name: tests-result 88 | path: ${{ github.workspace }}/build/reports/tests 89 | 90 | # Upload Kover report to CodeCov 91 | - name: Upload Code Coverage Report 92 | uses: codecov/codecov-action@v3 93 | with: 94 | files: ${{ github.workspace }}/build/reports/kover/xml/report.xml 95 | 96 | # Cache Plugin Verifier IDEs 97 | - name: Setup Plugin Verifier IDEs Cache 98 | uses: actions/cache@v3 99 | with: 100 | path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides 101 | key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} 102 | 103 | # Run Verify Plugin task and IntelliJ Plugin Verifier tool 104 | - name: Run Plugin Verification tasks 105 | run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} 106 | 107 | # Collect Plugin Verifier Result 108 | - name: Collect Plugin Verifier Result 109 | if: ${{ always() }} 110 | uses: actions/upload-artifact@v3 111 | with: 112 | name: pluginVerifier-result 113 | path: ${{ github.workspace }}/build/reports/pluginVerifier 114 | 115 | # Run Qodana inspections 116 | - name: Qodana - Code Inspection 117 | uses: JetBrains/qodana-action@v2022.2.3 118 | 119 | # Prepare plugin archive content for creating artifact 120 | - name: Prepare Plugin Artifact 121 | id: artifact 122 | shell: bash 123 | run: | 124 | cd ${{ github.workspace }}/build/distributions 125 | FILENAME=`ls *.zip` 126 | unzip "$FILENAME" -d content 127 | 128 | echo "::set-output name=filename::${FILENAME:0:-4}" 129 | 130 | # Store already-built plugin as an artifact for downloading 131 | - name: Upload artifact 132 | uses: actions/upload-artifact@v3 133 | with: 134 | name: ${{ steps.artifact.outputs.filename }} 135 | path: ./build/distributions/content/*/* 136 | 137 | # Prepare a draft release for GitHub Releases page for the manual verification 138 | # If accepted and published, release workflow would be triggered 139 | releaseDraft: 140 | name: Release Draft 141 | if: github.event_name != 'pull_request' 142 | needs: build 143 | runs-on: ubuntu-latest 144 | permissions: 145 | contents: write 146 | steps: 147 | 148 | # Check out current repository 149 | - name: Fetch Sources 150 | uses: actions/checkout@v3 151 | 152 | # Remove old release drafts by using the curl request for the available releases with draft flag 153 | - name: Remove Old Release Drafts 154 | env: 155 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 156 | run: | 157 | gh api repos/{owner}/{repo}/releases \ 158 | --jq '.[] | select(.draft == true) | .id' \ 159 | | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} 160 | 161 | # Create new release draft - which is not publicly visible and requires manual acceptance 162 | - name: Create Release Draft 163 | env: 164 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 165 | run: | 166 | gh release create v${{ needs.build.outputs.version }} \ 167 | --draft \ 168 | --title "v${{ needs.build.outputs.version }}" \ 169 | --notes "$(cat << 'EOM' 170 | ${{ needs.build.outputs.changelog }} 171 | EOM 172 | )" 173 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/pluginIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | --------------------------------------------------------------------------------