-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve module updates by backing up files
- Loading branch information
1 parent
098479e
commit cc9f188
Showing
16 changed files
with
652 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
src/main/kotlin/fi/aalto/cs/apluscourses/model/component/ScalaSdk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/fi/aalto/cs/apluscourses/notifications/ModuleUpdatedNotification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fi.aalto.cs.apluscourses.notifications | ||
|
||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.util.io.isFile | ||
import fi.aalto.cs.apluscourses.model.component.Module | ||
import fi.aalto.cs.apluscourses.services.PluginSettings | ||
import java.nio.file.Path | ||
import kotlin.io.path.isRegularFile | ||
|
||
class ModuleUpdatedNotification(module: Module, addedFiles: List<Path>, removedFiles: List<Path>) : Notification( | ||
PluginSettings.A_PLUS, | ||
"Module Updated", | ||
notificationContent(module, addedFiles, removedFiles), | ||
NotificationType.INFORMATION | ||
) { | ||
companion object { | ||
private fun pathsToHtmlList(paths: List<Path>, module: Module): String { | ||
fun relativePath(path: Path): String { | ||
return module.fullPath.relativize(path).toString() | ||
} | ||
return paths.filter { | ||
it.toString().contains('.') | ||
} // Filter out directories, while keeping removed files | ||
.joinToString(separator = "") { "<li>${relativePath(it)}</li>" } | ||
} | ||
|
||
private fun notificationContent(module: Module, addedFiles: List<Path>, removedFiles: List<Path>): String { | ||
val baseText = "${module.name} has been updated to version ${module.latestVersion}.<vr>" | ||
val addedFilesText = | ||
if (addedFiles.isNotEmpty()) "Added files: <ul>${pathsToHtmlList(addedFiles, module)}</ul>" else null | ||
val removedFilesText = | ||
if (removedFiles.isNotEmpty()) | ||
"<br>Removed files: <ul>${pathsToHtmlList(removedFiles, module)}</ul>" else null | ||
return listOfNotNull(baseText, addedFilesText, removedFilesText).joinToString(separator = "<br>") | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/fi/aalto/cs/apluscourses/services/Background.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package fi.aalto.cs.apluscourses.services | ||
|
||
import com.intellij.openapi.components.Service | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@Service(Service.Level.PROJECT) | ||
class Background( | ||
val cs: CoroutineScope | ||
) { | ||
fun runInBackground(action: suspend () -> Unit) { | ||
cs.launch { | ||
action() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.