Skip to content

Commit

Permalink
Rename Host to Platform (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-gibson authored Jul 24, 2022
1 parent 8f1b335 commit 662578a
Show file tree
Hide file tree
Showing 38 changed files with 502 additions and 462 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# GitLink Changelog

## [Unreleased]
- Rename 'Host' option to 'Platform'

## [4.1.7]
- Do not disable actions during project indexing
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.6.10"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.6.0"
id("org.jetbrains.intellij") version "1.7.0"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "1.3.1"
// Gradle Qodana Plugin
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = uk.co.ben_gibson.git.link
pluginName = GitLink
# SemVer format -> https://semver.org
pluginVersion = 4.1.7
pluginVersion = 4.1.8

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/uk/co/ben_gibson/git/link/GitLinkBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object GitLinkBundle : DynamicBundle(BUNDLE) {
BrowserLauncher.instance.open("https://github.com/ben-gibson/GitLink");
}

fun openHostPoll() {
fun openPlatformPoll() {
BrowserLauncher.instance.open("https://github.com/ben-gibson/GitLink/discussions/172");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.co.ben_gibson.git.link.extensions
package uk.co.ben_gibson.git.link.extension

fun <T> List<T>.replaceAt(index: Int, value: T): List<T> {
val mutable = this.toMutableList()
Expand Down
16 changes: 0 additions & 16 deletions src/main/kotlin/uk/co/ben_gibson/git/link/git/HostLocator.kt

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/kotlin/uk/co/ben_gibson/git/link/git/Hosts.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package uk.co.ben_gibson.git.link.listener

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import uk.co.ben_gibson.git.link.GitLinkBundle
import uk.co.ben_gibson.git.link.platform.PlatformDetector
import uk.co.ben_gibson.git.link.settings.ApplicationSettings
import uk.co.ben_gibson.git.link.settings.ProjectSettings
import uk.co.ben_gibson.git.link.ui.notification.Notification
import uk.co.ben_gibson.git.link.ui.notification.sendNotification

class ApplicationStartupListener : StartupActivity.DumbAware {
override fun runActivity(project: Project) {
showVersionNotification(project)
detectPlatform(project)
}

private fun showVersionNotification(project: Project) {
val settings = service<ApplicationSettings>()
val version = GitLinkBundle.plugin()?.version

if (version == settings.lastVersion) {
return
}

settings.lastVersion = version
sendNotification(Notification.welcome(version ?: "Unknown"), project)
}

private fun detectPlatform(project: Project) {
val projectSettings = project.service<ProjectSettings>()

if (projectSettings.host != null) {
return
}

val platform = project.service<PlatformDetector>().detect()

if (platform == null) {
sendNotification(Notification.couldNotDetectPlatform(project), project)
return
}

sendNotification(Notification.platformAutoDetected(platform, project), project)

projectSettings.host = platform.id.toString()
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/Pass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.intellij.openapi.project.Project
import git4idea.repo.GitRemote
import git4idea.repo.GitRepository
import uk.co.ben_gibson.git.link.Context
import uk.co.ben_gibson.git.link.git.Host
import uk.co.ben_gibson.git.link.platform.Platform

class Pass(val project: Project, val context: Context) {
var host: Host? = null
var platform: Platform? = null
var repository: GitRepository? = null
var remote: GitRemote? = null

fun hostOrThrow() = host ?: throw IllegalStateException("Host not set")
fun platformOrThrow() = platform ?: throw IllegalStateException("Platform not set")
fun repositoryOrThrow() = repository ?: throw IllegalStateException("Repository not set")
fun remoteOrThrow() = remote ?: throw IllegalStateException("Remote not set")
}
18 changes: 10 additions & 8 deletions src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/Pipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import uk.co.ben_gibson.git.link.Context
import uk.co.ben_gibson.git.link.pipeline.middleware.*
import uk.co.ben_gibson.git.link.pipeline.middleware.Timer
import java.net.URI
import java.util.*
import kotlin.collections.Set

@Service
class Pipeline(private val project: Project) {
private val middlewares: Set<Middleware> = setOf(
project.service<GenerateUrlMiddleware>(),
project.service<TimerMiddleware>(),
project.service<RecordHitMiddleware>(),
project.service<ForceHttpsMiddleware>(),
project.service<RatePluginMiddleware>(),
project.service<HostPollMiddleware>(),
project.service<ResolveContextMiddleware>(),
project.service<GenerateUrl>(),
project.service<Timer>(),
project.service<RecordHit>(),
project.service<ForceHttps>(),
project.service<SendSupportNotification>(),
project.service<SendPollNotification>(),
project.service<ResolveContext>(),
)

fun accept(context: Context) : URI? {
if (middlewares.isEmpty()) {
throw IllegalStateException("No middleware registered")
}

val queue = PriorityQueue<Middleware>(middlewares)
val queue = PriorityQueue(middlewares)

return next(queue, Pass(project, context))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package uk.co.ben_gibson.git.link.pipeline
package uk.co.ben_gibson.git.link.pipeline.middleware

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import uk.co.ben_gibson.git.link.pipeline.Pass
import uk.co.ben_gibson.git.link.settings.ProjectSettings
import uk.co.ben_gibson.git.link.url.toHttps
import java.net.URI

@Service
class ForceHttpsMiddleware : Middleware {
class ForceHttps : Middleware {
override val priority = 30

override fun invoke(pass: Pass, next: () -> URI?) : URI? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package uk.co.ben_gibson.git.link.pipeline
package uk.co.ben_gibson.git.link.pipeline.middleware

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import git4idea.repo.GitRemote
import git4idea.repo.GitRepository
import uk.co.ben_gibson.git.link.*
import uk.co.ben_gibson.git.link.git.*
import uk.co.ben_gibson.git.link.pipeline.Pass
import uk.co.ben_gibson.git.link.settings.ProjectSettings
import uk.co.ben_gibson.git.link.url.UrlOptions
import uk.co.ben_gibson.git.link.url.UrlOptionsCommit
Expand All @@ -16,18 +17,18 @@ import java.net.URI

// Must be the last middleware in the pipeline!
@Service
class GenerateUrlMiddleware : Middleware {
class GenerateUrl : Middleware {
override val priority = 50

override fun invoke(pass: Pass, next: () -> URI?) : URI? {
// We can't reach this point unless the host, repository, and remote have been resolved
// We can't reach this point unless the platform, repository, and remote have been resolved
val baseUrl = pass.remoteOrThrow().httpUrl ?: return null

val host = pass.hostOrThrow()
val platform = pass.platformOrThrow()

val urlOptions = createUrlOptions(pass, baseUrl)

return service<UrlFactoryLocator>().locate(host).createUrl(urlOptions)
return service<UrlFactoryLocator>().locate(platform).createUrl(urlOptions)
}

private fun createUrlOptions(pass: Pass, baseUrl: URI): UrlOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.co.ben_gibson.git.link.pipeline
package uk.co.ben_gibson.git.link.pipeline.middleware

import uk.co.ben_gibson.git.link.pipeline.Pass
import java.net.URI

interface Middleware : Comparable<Middleware> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package uk.co.ben_gibson.git.link.pipeline
package uk.co.ben_gibson.git.link.pipeline.middleware

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import uk.co.ben_gibson.git.link.pipeline.Pass
import uk.co.ben_gibson.git.link.settings.ApplicationSettings
import java.net.URI

@Service
class RecordHitMiddleware : Middleware {
class RecordHit : Middleware {
override val priority = 20

override fun invoke(pass: Pass, next: () -> URI?) : URI? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
package uk.co.ben_gibson.git.link.pipeline
package uk.co.ben_gibson.git.link.pipeline.middleware

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import git4idea.repo.GitRemote
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryManager
import uk.co.ben_gibson.git.link.git.*
import uk.co.ben_gibson.git.link.pipeline.Pass
import uk.co.ben_gibson.git.link.platform.Platform
import uk.co.ben_gibson.git.link.platform.PlatformLocator
import uk.co.ben_gibson.git.link.settings.ProjectSettings
import uk.co.ben_gibson.git.link.ui.notification.Notification
import uk.co.ben_gibson.git.link.ui.notification.sendNotification
import java.net.URI

@Service
class ResolveContextMiddleware : Middleware {
class ResolveContext : Middleware {
override val priority = 5

override fun invoke(pass: Pass, next: () -> URI?): URI? {
val repository = locateRepository(pass) ?: return null
val remote = locateRemote(pass, repository) ?: return null
val host = localeHost(pass) ?: return null
val platform = localePlatform(pass) ?: return null

pass.host = host
pass.platform = platform
pass.repository = repository
pass.remote = remote

return next()
}

private fun localeHost(pass: Pass): Host? {
val host = pass.project.service<HostLocator>().locate()
private fun localePlatform(pass: Pass): Platform? {
val platform = pass.project.service<PlatformLocator>().locate()

if (host == null) {
if (platform == null) {
sendNotification(Notification.hostNotSet(pass.project), pass.project)
}

return host
return platform
}

private fun locateRepository(pass: Pass): GitRepository? {
Expand Down
Loading

0 comments on commit 662578a

Please sign in to comment.