Skip to content

Commit

Permalink
Download target data only on first setup, not plugin init (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbrilRBS authored Aug 31, 2023
1 parent 9af4466 commit 7dbed7f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
12 changes: 0 additions & 12 deletions src/main/kotlin/com/jfrog/conan/clion/services/ConanPluginInit.kt

This file was deleted.

11 changes: 7 additions & 4 deletions src/main/kotlin/com/jfrog/conan/clion/services/ConanService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConanService(val project: Project) {

fun onWindowReady() {
fireOnConfiguredListeners(isPluginConfigured())
fireOnLibraryDataChanged(getRemoteData())
fireOnLibraryDataChanged(getTargetData())
}

fun fireOnConfiguredListeners(isConfigured: Boolean) {
Expand Down Expand Up @@ -161,6 +161,9 @@ class ConanService(val project: Project) {
if (!targetFile.exists() || update && ConanPluginUtils.fileHasOverwriteComment(targetFile)) {
targetFile.parentFile.mkdirs()
targetFile.downloadFromUrl(cmakeProviderURL)
// TODO: Check if cmakeProviderURL was downloaded correctly,
// else save the copy from the plugin into the project

// Re-write it, but adding the overwrite header
ConanPluginUtils.writeToFileWithOverwriteComment(targetFile, targetFile.readText())
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile)
Expand Down Expand Up @@ -196,17 +199,17 @@ class ConanService(val project: Project) {
}
}

fun getRemoteData(): LibraryData {
fun getTargetData(): LibraryData {
return try {
val targetData = getRemoteDataText()
val targetData = getTargetDataText()
Json { ignoreUnknownKeys = true }.decodeFromString<LibraryData>(targetData)
} catch (e: SerializationException) {
thisLogger().error(e)
LibraryData(hashMapOf())
}
}

fun getRemoteDataText(): String {
fun getTargetDataText(): String {
val userHomeFile = getRemoteDataFile()
if (!userHomeFile.exists()) {
val defaultFile = ConanService::class.java.classLoader.getResource("conan/targets-data.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class ReadmePanel(val project: Project) {
}
}

private val targetsData = project.service<ConanService>().getRemoteDataText()
private val libraryData = project.service<ConanService>().getRemoteData()
private val targetsDataAsText = project.service<ConanService>().getTargetDataText()
private val libraryData = project.service<ConanService>().getTargetData()

fun getTitleHtml(name: String): String {
val description = libraryData.libraries[name]?.description
Expand All @@ -43,7 +43,7 @@ class ReadmePanel(val project: Project) {
private fun getScript(name: String): String {
return """
function fillExtraData() {
const data = $targetsData;
const data = $targetsDataAsText;
const libraries = data["libraries"]
const infoDiv = document.getElementById("info");
const selected_lib = "$name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UsedPackagesPanel(val project: Project) {
setOpenLinksInExternalBrowser(true)
}

private val libraryData = project.service<ConanService>().getRemoteData()
private val libraryData = project.service<ConanService>().getTargetData()

private fun getScript(names: List<String>): String {
val filteredLibraryData = LibraryData(libraries = HashMap())
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<notificationGroup id="com.jfrog.conan.clion.notifications.general"
displayType="BALLOON"
key="generalNotificationKey"/>
<postStartupActivity implementation="com.jfrog.conan.clion.services.ConanPluginInit"/>
</extensions>

<projectListeners>
Expand Down

0 comments on commit 7dbed7f

Please sign in to comment.