├── src
└── main
│ ├── resources
│ ├── fileTemplates
│ │ ├── +page.svelte.ft
│ │ ├── +layout.svelte.ft
│ │ ├── +layout.ts.ft
│ │ ├── +page.ts.ft
│ │ ├── +page.server.ts.ft
│ │ └── +layout.server.ts.ft
│ ├── images
│ │ ├── routes.png
│ │ ├── tabs.png
│ │ ├── nesting.png
│ │ └── goto-file.png
│ ├── icons
│ │ ├── error.svg
│ │ ├── layout.svg
│ │ ├── page-js.svg
│ │ ├── page-ts.svg
│ │ ├── server.svg
│ │ ├── svelte.svg
│ │ └── page.svg
│ └── META-INF
│ │ ├── plugin.xml
│ │ └── pluginIcon.svg
│ └── kotlin
│ └── net
│ └── prestalife
│ └── svirtual
│ ├── SvirtualFileIconProvider.kt
│ ├── SvirtualEditorTabTitleProvider.kt
│ ├── Icons.kt
│ ├── SvirtualProjectViewNodeDecorator.kt
│ ├── SvirtualProjectViewNestingRulesProvider.kt
│ ├── settings
│ ├── AppSettingsState.kt
│ └── AppSettingsConfigurable.kt
│ ├── SvirtualFileSearchContributor.kt
│ ├── helpers
│ └── SvirtualFile.kt
│ └── SvirtualCreateFromTemplateActionReplacer.kt
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle.kts
├── .idea
├── vcs.xml
├── kotlinc.xml
├── misc.xml
├── inspectionProfiles
│ └── Project_Default.xml
└── gradle.xml
├── gradle.properties
├── CHANGELOG.md
├── .gitignore
├── .run
└── Run Plugin.run.xml
├── Readme.md
├── gradlew.bat
└── gradlew
/src/main/resources/fileTemplates/+page.svelte.ft:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unlocomqx/intellij-virtual-kit/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/main/resources/images/routes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unlocomqx/intellij-virtual-kit/HEAD/src/main/resources/images/routes.png
--------------------------------------------------------------------------------
/src/main/resources/images/tabs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unlocomqx/intellij-virtual-kit/HEAD/src/main/resources/images/tabs.png
--------------------------------------------------------------------------------
/src/main/resources/images/nesting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unlocomqx/intellij-virtual-kit/HEAD/src/main/resources/images/nesting.png
--------------------------------------------------------------------------------
/src/main/resources/images/goto-file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/unlocomqx/intellij-virtual-kit/HEAD/src/main/resources/images/goto-file.png
--------------------------------------------------------------------------------
/src/main/resources/fileTemplates/+layout.svelte.ft:
--------------------------------------------------------------------------------
1 |
4 |
5 | {@render children()}
6 |
--------------------------------------------------------------------------------
/src/main/resources/fileTemplates/+layout.ts.ft:
--------------------------------------------------------------------------------
1 | import type { LayoutLoad } from './\$types';
2 |
3 | export const load: LayoutLoad = () => {
4 | return {};
5 | };
--------------------------------------------------------------------------------
/src/main/resources/fileTemplates/+page.ts.ft:
--------------------------------------------------------------------------------
1 | import type { PageLoad } from './\$types';
2 |
3 | export const load: PageLoad = ({ request }) => {
4 | return {};
5 | };
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | mavenCentral()
4 | gradlePluginPortal()
5 | }
6 | }
7 |
8 | rootProject.name = "svirtual"
--------------------------------------------------------------------------------
/src/main/resources/fileTemplates/+page.server.ts.ft:
--------------------------------------------------------------------------------
1 | import type { PageServerLoad } from './\$types';
2 |
3 | export const load: PageServerLoad = async (event) => {
4 | return {};
5 | };
--------------------------------------------------------------------------------
/src/main/resources/fileTemplates/+layout.server.ts.ft:
--------------------------------------------------------------------------------
1 | import type { LayoutServerLoad } from './\$types';
2 |
3 | export const load: LayoutServerLoad = async ({ request }) => {
4 | return {};
5 | };
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.stdlib.default.dependency=false
2 | # TODO temporary workaround for Kotlin 1.8.20+ (https://jb.gg/intellij-platform-kotlin-oom)
3 | kotlin.incremental.useClasspathSnapshot=false
4 | runIde.autoReloadPlugins=true
5 |
6 | pluginVersion = 1.6.2
7 | pluginSinceBuild = 242
8 | pluginUntilBuild =
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
16 |
17 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Change the displayed names of SvelteKit files for easier navigation and route identification.
4 |
5 | - Route files are respresented by name
6 | - Similar files are nested under a common parent
7 | - Tabs labels are modified to reflect their corresponding route
8 |
9 | ## (1.6.1) - 2025-09-05
10 |
11 | ### Added
12 |
13 | - Handle any file extension given that the filename starts with +page or +server and so on.
14 |
15 | ## (1.5.1) - 2024-02-01
16 |
17 | ### Changed
18 |
19 | - Reworked icons (Thanks to @wiverson)
20 |
21 | ## (1.5.0) - 2024-02-01
22 |
23 | ### Changed
24 |
25 | - Reworked settings UI
26 |
27 | ## (1.4.0) - 2024-02-01
28 |
29 | ### Added
30 |
31 | - Rename error page and change its icon
32 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualFileIconProvider.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.ide.FileIconProvider
4 | import com.intellij.openapi.project.Project
5 | import com.intellij.openapi.vfs.VirtualFile
6 | import net.prestalife.svirtual.helpers.SvirtualFile
7 | import net.prestalife.svirtual.settings.AppSettingsState
8 | import javax.swing.Icon
9 |
10 | class SvirtualFileIconProvider : FileIconProvider {
11 | override fun getIcon(file: VirtualFile, flags: Int, project: Project?): Icon? {
12 | val settings = AppSettingsState.instance
13 | if (!settings.modifyFileIcons) {
14 | return null
15 | }
16 |
17 | return SvirtualFile.generateIcon(file.name)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualEditorTabTitleProvider.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider
4 | import com.intellij.openapi.project.Project
5 | import com.intellij.openapi.vfs.VirtualFile
6 | import net.prestalife.svirtual.helpers.SvirtualFile
7 | import net.prestalife.svirtual.settings.AppSettingsState
8 |
9 | class SvirtualEditorTabTitleProvider : EditorTabTitleProvider {
10 | override fun getEditorTabTitle(project: Project, file: VirtualFile): String? {
11 | val settings = AppSettingsState.instance
12 | if (!settings.modifyTabsTitles) {
13 | return null
14 | }
15 |
16 | return SvirtualFile.generateNameFromFile(file)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/Icons.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.openapi.util.IconLoader
4 | import com.intellij.ui.IconManager
5 | import javax.swing.Icon
6 |
7 |
8 | // I couldn't generate this using gradle!
9 |
10 | object Icons {
11 | private fun load(path: String): Icon {
12 | return IconLoader.getIcon(
13 | path,
14 | Icons.javaClass.classLoader
15 | )
16 | }
17 |
18 | val Svelte = load("icons/svelte.svg")
19 |
20 | val Page = load("icons/page.svg")
21 | val Server = load("icons/server.svg")
22 | val PageTS = load("icons/page-ts.svg")
23 | val PageJS = load("icons/page-js.svg")
24 |
25 | val Layout = load("icons/layout.svg")
26 | val Error = load("icons/error.svg")
27 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/.name
9 | .idea/copilot
10 | .idea/shelf
11 | .idea/modules.xml
12 | .idea/jarRepositories.xml
13 | .idea/compiler.xml
14 | .idea/libraries/
15 | .idea/workspace.xml
16 | *.iws
17 | *.iml
18 | *.ipr
19 | out/
20 | !**/src/main/**/out/
21 | !**/src/test/**/out/
22 |
23 | ### Eclipse ###
24 | .apt_generated
25 | .classpath
26 | .factorypath
27 | .project
28 | .settings
29 | .springBeans
30 | .sts4-cache
31 | bin/
32 | !**/src/main/**/bin/
33 | !**/src/test/**/bin/
34 |
35 | ### NetBeans ###
36 | /nbproject/private/
37 | /nbbuild/
38 | /dist/
39 | /nbdist/
40 | /.nb-gradle/
41 |
42 | ### VS Code ###
43 | .vscode/
44 |
45 | ### Mac OS ###
46 | .DS_Store
--------------------------------------------------------------------------------
/src/main/resources/icons/error.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/icons/layout.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/.run/Run Plugin.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | true
20 | true
21 | false
22 | false
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualProjectViewNodeDecorator.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.ide.projectView.PresentationData
4 | import com.intellij.ide.projectView.ProjectViewNode
5 | import com.intellij.ide.projectView.ProjectViewNodeDecorator
6 | import net.prestalife.svirtual.helpers.SvirtualFile
7 | import net.prestalife.svirtual.settings.AppSettingsState
8 |
9 | class SvirtualProjectViewNodeDecorator : ProjectViewNodeDecorator {
10 | override fun decorate(node: ProjectViewNode<*>, presentation: PresentationData) {
11 | val settings = AppSettingsState.instance
12 | if (!settings.modifyProjectTree) {
13 | return
14 | }
15 |
16 | val newName = SvirtualFile.generateNameFromFile(node.virtualFile!!)
17 |
18 | if (newName != null) {
19 | presentation.presentableText = newName
20 | }
21 |
22 | if (settings.modifyFileIcons) {
23 | val icon = SvirtualFile.generateIcon(node.virtualFile!!.name)
24 | if (icon != null) {
25 | presentation.setIcon(icon)
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/resources/icons/page-js.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualProjectViewNestingRulesProvider.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.ide.projectView.ProjectViewNestingRulesProvider
4 | import net.prestalife.svirtual.settings.AppSettingsState
5 |
6 | class SvirtualProjectViewNestingRulesProvider : ProjectViewNestingRulesProvider {
7 | override fun addFileNestingRules(consumer: ProjectViewNestingRulesProvider.Consumer) {
8 | val settings = AppSettingsState.instance
9 | if (!settings.nestRouteFiles) {
10 | return
11 | }
12 | consumer.addNestingRule("+page.svelte", "+page.server.ts")
13 | consumer.addNestingRule("+page.svelte", "+page.server.js")
14 | consumer.addNestingRule("+page.svelte", "+page.ts")
15 | consumer.addNestingRule("+page.svelte", "+page.js")
16 | consumer.addNestingRule("+page.svelte", "+server.ts")
17 | consumer.addNestingRule("+page.svelte", "+server.js")
18 |
19 | consumer.addNestingRule("+layout.svelte", "+layout.server.ts")
20 | consumer.addNestingRule("+layout.svelte", "+layout.server.js")
21 | consumer.addNestingRule("+layout.svelte", "+layout.ts")
22 | consumer.addNestingRule("+layout.svelte", "+layout.js")
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # VirtualKit
2 |
3 | An Intellij plugin to modify the SvelteKit project tree to make it easier to navigate between files.
4 |
5 | ## Features
6 |
7 | ### Route files are respresented by name
8 |
9 | - +page.svelte is modified to {route}.svelte
10 | - +page.server.js is modified to {route}.server.js
11 | - +page.js is modified to {route}.js
12 | - +layout.svelte is modified to {route}.layout.svelte
13 | - +error.svelte is modified to {route}.error.svelte
14 |
15 | Same for ts files
16 |
17 |
18 |
19 |
20 |
21 | ### Nesting
22 |
23 | +page.server.js and +page.js are nested under +page.svelte
24 |
25 |
26 |
27 |
28 |
29 | ### Tabs
30 |
31 | The tab titles are modified to show the route name
32 |
33 |
34 |
35 |
36 |
37 | ### Goto file
38 |
39 | The goto file dialog is modified to show the new file names
40 |
41 |
42 |
43 |
44 |
45 | ## Todo
46 |
47 | - [x] Add a setting toggle nesting
48 | - [x] Handle layout files
49 | - [x] Handle routes with params
50 | - [x] Extend file search
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/settings/AppSettingsState.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual.settings
2 |
3 | import com.intellij.openapi.application.ApplicationManager
4 | import com.intellij.openapi.components.PersistentStateComponent
5 | import com.intellij.openapi.components.State
6 | import com.intellij.openapi.components.Storage
7 | import com.intellij.util.xmlb.XmlSerializerUtil
8 | import org.jetbrains.annotations.NotNull
9 | import org.jetbrains.annotations.Nullable
10 |
11 |
12 | /**
13 | * Supports storing the application settings in a persistent way.
14 | * The [State] and [Storage] annotations define the name of the data and the file name where
15 | * these persistent application settings are stored.
16 | */
17 | @State(
18 | name = "net.prestalife.svirtual.settings.AppSettingsState",
19 | storages = [Storage(value = "VirtualKitPlugin.xml")]
20 | )
21 | class AppSettingsState : PersistentStateComponent {
22 | var nestRouteFiles = true
23 | var modifyProjectTree = true
24 | var modifyFileIcons = true
25 | var modifyTabsTitles = true
26 |
27 | @Nullable
28 | override fun getState(): AppSettingsState {
29 | return this
30 | }
31 |
32 | override fun loadState(@NotNull state: AppSettingsState) {
33 | XmlSerializerUtil.copyBean(state, this)
34 | }
35 |
36 | companion object {
37 | val instance: AppSettingsState
38 | get() = ApplicationManager.getApplication().getService(
39 | AppSettingsState::class.java
40 | )
41 | }
42 | }
--------------------------------------------------------------------------------
/src/main/resources/icons/page-ts.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/icons/server.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/src/main/resources/icons/svelte.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/icons/page.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualFileSearchContributor.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.navigation.ChooseByNameContributorEx
4 | import com.intellij.navigation.NavigationItem
5 | import com.intellij.openapi.diagnostic.Logger
6 | import com.intellij.openapi.vfs.VirtualFile
7 | import com.intellij.psi.search.FilenameIndex
8 | import com.intellij.psi.search.GlobalSearchScope
9 | import com.intellij.util.Processor
10 | import com.intellij.util.TimeoutUtil
11 | import com.intellij.util.indexing.FindSymbolParameters
12 | import com.intellij.util.indexing.IdFilter
13 | import net.prestalife.svirtual.helpers.SvirtualFile
14 |
15 | class SvirtualFileSearchContributor : ChooseByNameContributorEx {
16 | companion object {
17 | val filesMap = mutableMapOf()
18 | private val LOG = Logger.getInstance(
19 | SvirtualFileSearchContributor::class.java
20 | )
21 | }
22 |
23 | override fun processNames(processor: Processor, scope: GlobalSearchScope, filter: IdFilter?) {
24 | val start = System.nanoTime()
25 | filesMap.clear()
26 |
27 | val names = mutableListOf()
28 |
29 | val filePatterns = arrayOf("+page", "+layout", "+server", "+error")
30 | val files = mutableListOf()
31 |
32 | FilenameIndex.processAllFileNames({ filename ->
33 | if (filePatterns.any { pattern -> filename.startsWith(pattern) }) {
34 | FilenameIndex.getVirtualFilesByName(filename, scope).forEach { file ->
35 | files.add(file)
36 | }
37 | }
38 | true
39 | }, scope, filter)
40 |
41 | files.forEach {
42 | val name = SvirtualFile.generateNameFromFile(it)
43 | if (name != null) {
44 | names.add(name)
45 | filesMap[name] = it
46 | }
47 | }
48 |
49 | names.forEach { if (!processor.process(it)) return@forEach }
50 | if (LOG.isDebugEnabled) {
51 | LOG.debug("All SvelteKit names retrieved:" + TimeoutUtil.getDurationMillis(start))
52 | }
53 | }
54 |
55 | override fun processElementsWithName(
56 | name: String, processor: Processor, parameters: FindSymbolParameters
57 | ) {
58 | val files = filesMap.filter { it.key == name }.values
59 |
60 | SvirtualFile.convertVirtualFilesToPsiFiles(parameters.project, files)
61 | .forEach { if (!processor.process(it)) return@forEach }
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/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 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net.prestalife.svirtual
5 |
6 |
8 | VirtualKit
9 |
10 |
11 | PrestaLife
12 |
13 |
14 |
17 | Change the displayed names of SvelteKit files for easier navigation and route identification.
19 |
20 | This plugin changes the displayed names of SvelteKit files to make it clearer which file belongs to which route.
21 |
22 | - +page.svelte → {route}.svelte
23 | - +page.ts → {route}.ts
24 | - +page.server.ts → {route}.server.ts
25 |
26 | The same will be done to layout and error files.
27 | This will solve the issue of having many files with the same name, thus improving file navigation.
28 | ]]>
29 |
30 |
32 | com.intellij.modules.platform
33 |
34 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
44 |
46 |
51 |
52 |
54 |
55 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/helpers/SvirtualFile.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual.helpers
2 |
3 | import com.intellij.openapi.project.Project
4 | import com.intellij.openapi.vfs.VirtualFile
5 | import com.intellij.psi.PsiFile
6 | import com.intellij.psi.PsiManager
7 | import net.prestalife.svirtual.Icons
8 | import javax.swing.Icon
9 |
10 | class SvirtualFile {
11 |
12 | companion object {
13 | fun generateNameFromFile(file: VirtualFile): String? {
14 | val name = file.name
15 | val extension = file.extension
16 | val dir = file.parent
17 |
18 | if (extension.isNullOrEmpty()) {
19 | return null
20 | }
21 |
22 | return generateNameFromFilename(dir, name, extension)
23 | }
24 |
25 | fun generateNameFromFilename(
26 | dir: VirtualFile?,
27 | name: String,
28 | extension: String
29 | ): String? {
30 | val route = getRoute(dir) ?: return null
31 |
32 | if (name.matches(Regex("\\+page(@.*)?\\.svelte"))) {
33 | return name.replace("+page", route)
34 | }
35 |
36 | if (name.matches(Regex("\\+layout(@.*)?\\.svelte"))) {
37 | return name.replace("+layout", "$route.layout")
38 | }
39 |
40 | if (name.matches(Regex("\\+error(@.*)?\\.svelte"))) {
41 | return name.replace("+error", "$route.error")
42 | }
43 |
44 | if (name.matches(Regex("\\+page\\.server\\.(.*)"))) {
45 | return "$route.server.$extension"
46 | }
47 |
48 | if (name.matches(Regex("\\+page\\.(.*)"))) {
49 | return "$route.$extension"
50 | }
51 |
52 | if (name.matches(Regex("\\+server\\.(.*)"))) {
53 | return "$route.endpoint.$extension"
54 | }
55 |
56 | if (name.matches(Regex("\\+layout\\.server\\.(.*)"))) {
57 | return "$route.layout.server.$extension"
58 | }
59 |
60 | if (name.matches(Regex("\\+layout\\.(.*)"))) {
61 | return "$route.layout.$extension"
62 | }
63 |
64 | return null
65 | }
66 |
67 | private fun getRoute(dir: VirtualFile?): String? {
68 | var parent: VirtualFile = dir ?: return null
69 |
70 | var routeName = sanitizeName(parent.name)
71 |
72 | while (routeName.startsWith('[')) {
73 | parent = parent.parent ?: return routeName
74 | val parentRoute = sanitizeName(parent.name)
75 | routeName = "$parentRoute/$routeName"
76 | }
77 |
78 | return routeName
79 | }
80 |
81 | private fun sanitizeName(name: String): String {
82 | if (name == "routes") {
83 | return "index"
84 | }
85 |
86 | return name
87 | }
88 |
89 | fun convertVirtualFilesToPsiFiles(project: Project, files: Collection): Collection {
90 | val psiFiles: MutableCollection = HashSet()
91 | var psiManager: PsiManager? = null
92 | for (file in files) {
93 | if (psiManager == null) {
94 | psiManager = PsiManager.getInstance(project)
95 | }
96 | val psiFile = psiManager.findFile(file!!)
97 | if (psiFile != null) {
98 | psiFiles.add(psiFile)
99 | }
100 | }
101 | return psiFiles
102 | }
103 |
104 | fun generateIcon(filename: String): Icon? {
105 | val extension = filename.substringAfterLast('.')
106 |
107 | if (filename.matches(Regex("\\+page(@.*)?\\.svelte"))) {
108 | return Icons.Page
109 | }
110 |
111 | if (filename.matches(Regex("\\+layout(@.*)?\\.svelte"))) {
112 | return Icons.Layout
113 | }
114 |
115 | if (filename.matches(Regex("\\+error(@.*)?\\.svelte"))) {
116 | return Icons.Error
117 | }
118 |
119 | if (filename.matches(Regex("\\+(page|layout)\\.server\\.(ts|js)"))) {
120 | return Icons.Server
121 | }
122 |
123 | if (filename.matches(Regex("\\+(page|layout)\\.(ts|js)"))) {
124 | return if (extension == "ts") Icons.PageTS else Icons.PageJS
125 | }
126 |
127 | if (filename.matches(Regex("\\+server\\.(ts|js)"))) {
128 | return if (extension == "ts") Icons.PageTS else Icons.PageJS
129 | }
130 |
131 | return null
132 | }
133 | }
134 | }
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/settings/AppSettingsConfigurable.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual.settings
2 |
3 | import com.intellij.openapi.options.Configurable
4 | import com.intellij.openapi.project.ProjectManager
5 | import com.intellij.ui.components.JBCheckBox
6 | import com.intellij.util.ui.FormBuilder
7 | import com.intellij.util.ui.JBUI
8 | import com.intellij.util.ui.UI
9 | import org.jetbrains.annotations.Nls
10 | import org.jetbrains.annotations.NotNull
11 | import org.jetbrains.annotations.Nullable
12 | import javax.swing.JComponent
13 | import javax.swing.JPanel
14 |
15 |
16 | /**
17 | * Provides controller functionality for application settings.
18 | */
19 | class AppSettingsConfigurable : Configurable {
20 |
21 | private var mySettingsComponent: AppSettingsComponent? = null
22 |
23 | // A default constructor with no arguments is required because this implementation
24 | // is registered in an applicationConfigurable EP
25 | override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String {
26 | return "VirtualKit Settings"
27 | }
28 |
29 | override fun getPreferredFocusedComponent(): JComponent {
30 | return mySettingsComponent!!.preferredFocusedComponent
31 | }
32 |
33 | @Nullable
34 | override fun createComponent(): JComponent {
35 | mySettingsComponent = AppSettingsComponent()
36 | return mySettingsComponent!!.panel
37 | }
38 |
39 | override fun isModified(): Boolean {
40 | val settings = AppSettingsState.instance
41 | return mySettingsComponent!!.nestRouteFiles != settings.nestRouteFiles ||
42 | mySettingsComponent!!.modifyProjectTree != settings.modifyProjectTree ||
43 | mySettingsComponent!!.modifyTabsTitles != settings.modifyTabsTitles ||
44 | mySettingsComponent!!.modifyFileIcons != settings.modifyFileIcons
45 | }
46 |
47 | override fun apply() {
48 | val settings = AppSettingsState.instance
49 | settings.nestRouteFiles = mySettingsComponent!!.nestRouteFiles
50 | settings.modifyProjectTree = mySettingsComponent!!.modifyProjectTree
51 | settings.modifyFileIcons = mySettingsComponent!!.modifyFileIcons
52 | settings.modifyTabsTitles = mySettingsComponent!!.modifyTabsTitles
53 | ProjectManager.getInstance().openProjects.forEach { ProjectManager.getInstance().reloadProject(it) }
54 | }
55 |
56 | override fun reset() {
57 | val settings = AppSettingsState.instance
58 | mySettingsComponent!!.nestRouteFiles = settings.nestRouteFiles
59 | mySettingsComponent!!.modifyProjectTree = settings.modifyProjectTree
60 | mySettingsComponent!!.modifyFileIcons = settings.modifyFileIcons
61 | mySettingsComponent!!.modifyTabsTitles = settings.modifyTabsTitles
62 | }
63 |
64 | override fun disposeUIResources() {
65 | mySettingsComponent = null
66 | }
67 | }
68 |
69 | /**
70 | * Supports creating and managing a [JPanel] for the Settings Dialog.
71 | */
72 | class AppSettingsComponent {
73 | val panel: JPanel
74 | private val nestRouteFilesCheckbox = JBCheckBox("Nest route files")
75 | private val modifyProjectTreeCheckbox = JBCheckBox("Modify project tree")
76 | private val modifyFileIconsCheckbox = JBCheckBox("Modify file icons")
77 | private val modifyTabsTitlesCheckbox = JBCheckBox("Modify tabs titles")
78 |
79 | init {
80 | panel = FormBuilder.createFormBuilder()
81 | .addComponent(
82 | nestRouteFilesCheckbox,
83 | )
84 | .addTooltip("Nest +page.server.js and +page.js under +page.svelte. May require restart.")
85 | .addSeparator()
86 |
87 | .addComponent(
88 | modifyProjectTreeCheckbox,
89 | )
90 | .addTooltip("Rename route files to {route}.svelte and {route}.server.js etc...")
91 | .addSeparator()
92 |
93 |
94 | .addComponent(
95 | modifyFileIconsCheckbox,
96 | )
97 | .addTooltip("Display different icons for route file types")
98 | .addSeparator()
99 |
100 |
101 | .addComponent(
102 | modifyTabsTitlesCheckbox,
103 | )
104 | .addComponentFillVertically(JPanel(), 0)
105 | .panel
106 | }
107 |
108 | val preferredFocusedComponent: JComponent
109 | get() = nestRouteFilesCheckbox
110 |
111 | @get:NotNull
112 | var nestRouteFiles: Boolean
113 | get() = nestRouteFilesCheckbox.isSelected
114 | set(state) {
115 | nestRouteFilesCheckbox.isSelected = state
116 | }
117 | var modifyProjectTree: Boolean
118 | get() = modifyProjectTreeCheckbox.isSelected
119 | set(state) {
120 | modifyProjectTreeCheckbox.isSelected = state
121 | }
122 |
123 | var modifyFileIcons: Boolean
124 | get() = modifyFileIconsCheckbox.isSelected
125 | set(state) {
126 | modifyFileIconsCheckbox.isSelected = state
127 | }
128 |
129 | var modifyTabsTitles: Boolean
130 | get() = modifyTabsTitlesCheckbox.isSelected
131 | set(state) {
132 | modifyTabsTitlesCheckbox.isSelected = state
133 | }
134 | }
135 |
136 |
--------------------------------------------------------------------------------
/src/main/kotlin/net/prestalife/svirtual/SvirtualCreateFromTemplateActionReplacer.kt:
--------------------------------------------------------------------------------
1 | package net.prestalife.svirtual
2 |
3 | import com.intellij.ide.fileTemplates.CreateFromTemplateActionReplacer
4 | import com.intellij.ide.fileTemplates.FileTemplate
5 | import com.intellij.ide.fileTemplates.FileTemplateUtil
6 | import com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction
7 | import com.intellij.ide.fileTemplates.impl.BundledFileTemplate
8 | import com.intellij.ide.projectView.ProjectView
9 | import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode
10 | import com.intellij.ide.projectView.impl.nodes.PsiFileNode
11 | import com.intellij.openapi.actionSystem.ActionUpdateThread
12 | import com.intellij.openapi.actionSystem.AnAction
13 | import com.intellij.openapi.actionSystem.AnActionEvent
14 | import com.intellij.openapi.actionSystem.CommonDataKeys
15 | import com.intellij.openapi.application.ApplicationManager
16 | import com.intellij.openapi.fileEditor.FileEditorManager
17 | import com.intellij.openapi.ui.Messages
18 | import com.intellij.psi.PsiFile
19 | import com.intellij.psi.PsiManager
20 | import net.prestalife.svirtual.helpers.SvirtualFile
21 | import javax.swing.Icon
22 |
23 |
24 | class SvirtualCreateFromTemplateActionReplacer : CreateFromTemplateActionReplacer {
25 |
26 | override fun replaceCreateFromFileTemplateAction(fileTemplate: FileTemplate?): AnAction {
27 | if (fileTemplate is BundledFileTemplate && fileTemplate.pluginDescriptor.pluginId.idString == "net.prestalife.svirtual") {
28 | val filename = (fileTemplate.name + "." + fileTemplate.extension)
29 | val icon = SvirtualFile.generateIcon(filename) ?: Icons.Svelte
30 | return CreateSvelteKitFileAction(fileTemplate, filename, icon)
31 | }
32 | return CreateFromTemplateAction(fileTemplate!!)
33 | }
34 |
35 | class CreateSvelteKitFileAction(
36 | private val fileTemplate: FileTemplate?, private val filename: String, icon: Icon
37 | ) : AnAction(filename, null, icon) {
38 |
39 | override fun getActionUpdateThread(): ActionUpdateThread {
40 | return ActionUpdateThread.BGT
41 | }
42 |
43 | override fun update(e: AnActionEvent) {
44 | val selectedItems = e.getData(com.intellij.openapi.actionSystem.PlatformCoreDataKeys.SELECTED_ITEMS)
45 | val selectedItem = (if (selectedItems is Array<*>) selectedItems.firstOrNull() else selectedItems) ?: return
46 |
47 | if (selectedItem is PsiDirectoryNode) {
48 | if (selectedItem.virtualFile != null && fileTemplate?.name != null) {
49 | val text = SvirtualFile.generateNameFromFilename(
50 | selectedItem.virtualFile, filename, fileTemplate.extension
51 | )
52 | if (text != null) e.presentation.text = text
53 | }
54 | } else if (selectedItem is PsiFileNode) {
55 | if (selectedItem.virtualFile != null && fileTemplate?.name != null) {
56 | val text = SvirtualFile.generateNameFromFilename(
57 | selectedItem.virtualFile!!.parent, filename, fileTemplate.extension
58 | )
59 | if (text != null) e.presentation.text = text
60 | }
61 | }
62 |
63 | super.update(e)
64 | }
65 |
66 | override fun actionPerformed(e: AnActionEvent) {
67 | val project = e.project
68 | if (project == null) {
69 | Messages.showErrorDialog("No project found.", "Error")
70 | return
71 | }
72 |
73 | val target = e.getData(CommonDataKeys.VIRTUAL_FILE)
74 | val targetDir = if (target?.isDirectory == true) target else target?.parent
75 | if (targetDir == null) {
76 | Messages.showErrorDialog("Cannot determine the target directory.", "Error")
77 | return
78 | }
79 |
80 | val targetPsiDir = PsiManager.getInstance(project).findDirectory(targetDir)
81 | if (targetPsiDir == null) {
82 | Messages.showErrorDialog("Cannot determine the target directory.", "Error")
83 | return
84 | }
85 |
86 | // check if the file already exists
87 | val fileName = fileTemplate?.name + "." + fileTemplate?.extension
88 | val targetFile = targetDir.findChild(fileName)
89 | if (targetFile != null) {
90 | Messages.showErrorDialog("File already exists.", "Error")
91 | return
92 | }
93 |
94 | if (fileTemplate != null) {
95 | ApplicationManager.getApplication().runWriteAction {
96 | val psiFile = FileTemplateUtil.createFromTemplate(
97 | fileTemplate, fileName, null, targetPsiDir
98 | )
99 | if ((psiFile as PsiFile).virtualFile != null) {
100 | FileEditorManager.getInstance(project).openFile(psiFile.virtualFile, true)
101 | ProjectView.getInstance(project).select(psiFile, psiFile.virtualFile, true)
102 | }
103 | }
104 | }
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/pluginIcon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
80 |
--------------------------------------------------------------------------------
/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/master/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 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
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 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------