Skip to content

Commit eb3485e

Browse files
committed
Refactor URL handling to use URI instead of URL and add android-only plugin configuration
1 parent 3c0f320 commit eb3485e

10 files changed

Lines changed: 51 additions & 27 deletions

File tree

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pluginRepositoryUrl = https://github.com/cnrture/QuickProjectWizard
77
pluginVersion = 0.0.7
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
10-
pluginSinceBuild = 241
11-
pluginUntilBuild = 251.26094.121
10+
pluginSinceBuild=241
11+
pluginUntilBuild=251.*
1212

1313
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
1414
platformType = AI

src/main/kotlin/com/github/cnrture/quickprojectwizard/common/Extensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.github.cnrture.quickprojectwizard.projectwizard.gradle.Version
99
import com.intellij.openapi.project.Project
1010
import com.intellij.openapi.vfs.VfsUtil
1111
import java.io.File
12-
import java.net.URL
12+
import java.net.URI
1313
import com.github.cnrture.quickprojectwizard.common.file.File as ProjectFile
1414

1515
fun Project.getCurrentlySelectedFile(selectedSrc: String): File =
@@ -161,6 +161,6 @@ fun getImage(className: String, imagePath: String): Thumb {
161161
return if (imageUrl != null) {
162162
Thumb { imageUrl }
163163
} else {
164-
Thumb { URL("https://canerture.com/$imagePath.png") }
164+
Thumb { URI("https://canerture.com/$imagePath.png").toURL() }
165165
}
166-
}
166+
}

src/main/kotlin/com/github/cnrture/quickprojectwizard/projectwizard/CMPTemplate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ val composeMultiplatformTemplate = template {
8080
CheckBoxWidget(isDataDomainDiUiEnable),
8181
TextFieldWidget(screens),
8282
LabelWidget(
83-
"Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
83+
text = "Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
8484
"\nNote: First item is start destination"
8585
),
8686
UrlLinkWidget("Created by Caner Ture", "https://candroid.dev"),

src/main/kotlin/com/github/cnrture/quickprojectwizard/projectwizard/ComposeTemplate.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ val composeTemplate = template {
103103
EnumWidget(selectedImageLibrary),
104104
TextFieldWidget(screens),
105105
LabelWidget(
106-
"Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
106+
text = "Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
107107
"\nNote: First item is start destination"
108108
),
109-
LabelWidget(" "),
109+
LabelWidget(text = " "),
110110
TextFieldWidget(javaJvmVersion),
111-
LabelWidget("8 or 11 or 17 etc."),
112-
LabelWidget(" "),
111+
LabelWidget(text = "8 or 11 or 17 etc."),
112+
LabelWidget(text = " "),
113113
UrlLinkWidget("Created by Caner Ture", "https://candroid.dev"),
114114
PackageNameWidget(defaultPackageNameParameter),
115115
)

src/main/kotlin/com/github/cnrture/quickprojectwizard/projectwizard/XMLTemplate.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ val xmlTemplate = template {
9999
EnumWidget(selectedImageLibrary),
100100
TextFieldWidget(screens),
101101
LabelWidget(
102-
"Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
102+
text = "Please enter the screens you want to create. (e.g. Home, Detail, Profile)" +
103103
"\nNote: First item is start destination"
104104
),
105-
LabelWidget(" "),
105+
LabelWidget(text = " "),
106106
TextFieldWidget(javaJvmVersion),
107-
LabelWidget("8 or 11 or 17 etc."),
108-
LabelWidget(" "),
107+
LabelWidget(text = "8 or 11 or 17 etc."),
108+
LabelWidget(text = " "),
109109
UrlLinkWidget("Created by Caner Ture", "https://candroid.dev"),
110110
PackageNameWidget(defaultPackageNameParameter),
111111
)

src/main/kotlin/com/github/cnrture/quickprojectwizard/projectwizard/recipes/ModuleTemplateDataExtensions.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,52 @@ package com.github.cnrture.quickprojectwizard.projectwizard.recipes
22

33
import com.android.tools.idea.wizard.template.ModuleTemplateData
44

5+
/**
6+
* Extension function to get minimum API level from ModuleTemplateData
7+
* Uses reflection to handle different API versions and changes
8+
*/
59
fun ModuleTemplateData.getMinApiLevel(): Int {
610
return try {
11+
// Try modern API first
712
val minApi = this.apis.minApi
13+
14+
// Try getApiLevel method
815
val apiLevelMethod = minApi.javaClass.getDeclaredMethod("getApiLevel")
16+
apiLevelMethod.isAccessible = true
917
apiLevelMethod.invoke(minApi) as Int
1018
} catch (_: Exception) {
1119
try {
20+
// Fallback to getApi method
1221
val minApi = this.apis.minApi
1322
val apiMethod = minApi.javaClass.getDeclaredMethod("getApi")
23+
apiMethod.isAccessible = true
1424
apiMethod.invoke(minApi) as Int
1525
} catch (_: Exception) {
1626
try {
27+
// Fallback to apiLevel field
1728
val minApi = this.apis.minApi
1829
val apiLevelField = minApi.javaClass.getDeclaredField("apiLevel")
1930
apiLevelField.isAccessible = true
2031
apiLevelField.get(minApi) as Int
2132
} catch (_: Exception) {
2233
try {
34+
// Fallback to api field
2335
val minApi = this.apis.minApi
2436
val apiField = minApi.javaClass.getDeclaredField("api")
2537
apiField.isAccessible = true
2638
apiField.get(minApi) as Int
2739
} catch (_: Exception) {
28-
23
40+
try {
41+
// Try toString parsing as last resort
42+
val minApi = this.apis.minApi
43+
val apiString = minApi.toString()
44+
val regex = Regex("\\d+")
45+
val match = regex.find(apiString)
46+
match?.value?.toIntOrNull() ?: 23
47+
} catch (_: Exception) {
48+
// Default to API 23 (Android 6.0) as safe fallback
49+
23
50+
}
2951
}
3052
}
3153
}

src/main/kotlin/com/github/cnrture/quickprojectwizard/service/AnalyticsService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.intellij.openapi.application.ApplicationManager
55
import com.intellij.openapi.components.Service
66
import kotlinx.coroutines.*
77
import java.net.HttpURLConnection
8-
import java.net.URL
8+
import java.net.URI
99
import java.time.LocalDateTime
1010
import java.time.format.DateTimeFormatter
1111

@@ -32,7 +32,7 @@ class AnalyticsService {
3232
withContext(Dispatchers.IO) {
3333
try {
3434
val baseUrl = "https://www.google-analytics.com/mp/collect"
35-
val url = URL("$baseUrl?measurement_id=$measurementId&api_secret=$apiSecret")
35+
val url = URI("$baseUrl?measurement_id=$measurementId&api_secret=$apiSecret").toURL()
3636
val connection = url.openConnection() as HttpURLConnection
3737

3838
connection.requestMethod = "POST"

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/apitester/ApiTesterContent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import java.io.BufferedReader
3434
import java.io.InputStreamReader
3535
import java.io.OutputStreamWriter
3636
import java.net.HttpURLConnection
37-
import java.net.URL
37+
import java.net.URI
3838
import kotlin.time.measureTime
3939

4040
@Composable
@@ -484,13 +484,13 @@ private suspend fun makeApiRequest(
484484

485485
val time = measureTime {
486486
try {
487-
val url = URL(
487+
val url = URI(
488488
urlString + (if (queryParams.isNotEmpty()) {
489489
buildQueryParamsString(queryParams)
490490
} else {
491491
""
492492
})
493-
)
493+
).toURL()
494494
connection = url.openConnection() as HttpURLConnection
495495

496496
connection.apply {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<idea-plugin>
2+
<depends>com.intellij.modules.androidstudio</depends>
3+
4+
<extensions defaultExtensionNs="com.android.tools.idea.wizard.template">
5+
<wizardTemplateProvider
6+
implementation="com.github.cnrture.quickprojectwizard.projectwizard.AndroidStudioTemplateProvider"/>
7+
</extensions>
8+
</idea-plugin>

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
<vendor email="cnrture@gmail.com" url="https://canerture.com">Caner Ture</vendor>
66

77
<depends>com.intellij.modules.platform</depends>
8-
<depends>org.jetbrains.android</depends>
9-
<depends>com.intellij.modules.androidstudio</depends>
108
<depends>com.intellij.modules.java</depends>
11-
12-
<extensions defaultExtensionNs="com.android.tools.idea.wizard.template">
13-
<wizardTemplateProvider
14-
implementation="com.github.cnrture.quickprojectwizard.projectwizard.AndroidStudioTemplateProvider"/>
15-
</extensions>
9+
<depends optional="true" config-file="android-only.xml">org.jetbrains.android</depends>
1610

1711
<extensions defaultExtensionNs="com.intellij">
1812
<notificationGroup id="QPW Notification Group"

0 commit comments

Comments
 (0)