Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RunTasksListAdapter
TooltipManager.showIdeCategoryTooltip(
context = binding.root.context,
anchorView = binding.root,
tag = TooltipTag.PROJECT_GRADLE_TASKS,
tag = TooltipTag.gradleTaskTooltipTag(task.path),
)
true
}
Expand Down
2 changes: 2 additions & 0 deletions idetooltips/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ dependencies {

implementation(projects.resources)
implementation(projects.common)

testImplementation(libs.tests.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,20 @@ object TooltipManager {
dbPath = debugDatabaseFile.absolutePath
}

var lastChange = "n/a"
var rowId = -1
var tooltipId = -1
var summary = "n/a"
var detail = "n/a"
var buttons: ArrayList<Pair<String, String>> = ArrayList<Pair<String, String>>()

try {
val db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY)

db.use { database ->
try {
lastChange = DatabaseVersionResolver.resolveDatabaseVersion(database)
SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY).use { database ->
val lastChange = try {
DatabaseVersionResolver.resolveDatabaseVersion(database)
} catch (e: Exception) {
Log.e(TAG, "Version resolution failed: ${e.message}")
"n/a"
}

Log.d(TAG, "last change is '${lastChange}'.")

database.rawQuery(QUERY_TOOLTIP, arrayOf(tag, category)).use { c ->
when (c.count) {
// A missing tag is a normal outcome (e.g. a Gradle task with no
// authored tooltip). Honor the nullable contract so the caller
// shows nothing rather than an "n/a" popup.
0 -> throw NoTooltipFoundException(category, tag)
1 -> { /* Expected case, continue processing */
}
Expand All @@ -115,38 +108,36 @@ object TooltipManager {
}

c.moveToFirst()

rowId = c.getInt(0)
tooltipId = c.getInt(1)
summary = c.getString(2)
detail = c.getString(3)
}

database.rawQuery(QUERY_TOOLTIP_BUTTONS, arrayOf(tooltipId.toString())).use { c ->
while (c.moveToNext()) {
buttons.add(
Pair(
c.getString(0),
"http://localhost:6174/" + c.getString(1)
val rowId = c.getInt(0)
val tooltipId = c.getInt(1)
val summary = c.getString(2)
val detail = c.getString(3)

val buttons = ArrayList<Pair<String, String>>()
database.rawQuery(QUERY_TOOLTIP_BUTTONS, arrayOf(tooltipId.toString())).use { bc ->
while (bc.moveToNext()) {
buttons.add(
Pair(
bc.getString(0),
"http://localhost:6174/" + bc.getString(1)
)
)
)
}
}
}

Log.d(
TAG,
"For tooltip ${tooltipId}, retrieved ${buttons.size} buttons. They are $buttons."
)
IDETooltipItem(rowId, tooltipId, category, tag, summary, detail, buttons, lastChange)
}
}

} catch (e: NoTooltipFoundException) {
Log.d(TAG, "No tooltip found for category='$category', tag='$tag'")
null
} catch (e: Exception) {
Log.e(
TAG,
"Error getting tooltip for category='$category', tag='$tag': ${e.message}"
)
null
}

IDETooltipItem(rowId, tooltipId, category, tag, summary, detail, buttons, lastChange)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ object TooltipTag {
const val PROJECT_GRADLE_TASKS = "project.gradle.tasks"
const val PROJECT_RUN_GRADLE_TASKS = "project.run.gradle.tasks"

/**
* Tooltip tag for an individual Gradle task, derived from its task path.
* ":app:assembleDebug" -> "gradle.app:assembleDebug"; ":clean" -> "gradle.clean".
*/
fun gradleTaskTooltipTag(taskPath: String): String = "gradle." + taskPath.removePrefix(":")

// General Preferences
const val PREFS_TOP = "prefs.top"
const val PREFS_EDITOR = "prefs.editor"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.idetooltips

import org.junit.Assert.assertEquals
import org.junit.Test

/** Verifies the Gradle task path -> tooltip tag mapping used by RunTasksListAdapter. */
class GradleTaskTooltipTagTest {

@Test
fun `project-qualified task path maps to colon tag`() {
assertEquals("gradle.app:assembleDebug", TooltipTag.gradleTaskTooltipTag(":app:assembleDebug"))
}

@Test
fun `root task path maps to dotted tag`() {
assertEquals("gradle.clean", TooltipTag.gradleTaskTooltipTag(":clean"))
}

@Test
fun `merge task path is preserved verbatim`() {
assertEquals(
"gradle.app:mergeReleaseResources",
TooltipTag.gradleTaskTooltipTag(":app:mergeReleaseResources"),
)
}

@Test
fun `plugin-builder task maps to gradle-prefixed tag`() {
assertEquals("gradle.assemblePlugin", TooltipTag.gradleTaskTooltipTag(":assemblePlugin"))
}
}
Loading