-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1236 Refactoring of the file download service
- Loading branch information
1 parent
54880eb
commit 15af154
Showing
34 changed files
with
318 additions
and
115 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
ontrack-extension-api/src/main/java/net/nemerosa/ontrack/extension/api/FileRefExtension.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,25 @@ | ||
package net.nemerosa.ontrack.extension.api | ||
|
||
import net.nemerosa.ontrack.common.Document | ||
import net.nemerosa.ontrack.model.extension.Extension | ||
|
||
/** | ||
* Extension used to support a protocol to download a file. | ||
*/ | ||
interface FileRefExtension : Extension { | ||
|
||
/** | ||
* Supported protocol | ||
*/ | ||
val protocol: String | ||
|
||
/** | ||
* Downloading a document using its path | ||
* | ||
* @param path Path extracted from the file ref URI | ||
* @param type Expected MIME type of the document | ||
* @return Document or null if not found | ||
*/ | ||
fun download(path: String, type: String): Document? | ||
|
||
} |
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
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
15 changes: 0 additions & 15 deletions
15
...k-extension-scm/src/main/java/net/nemerosa/ontrack/extension/scm/service/SCMRefService.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...n-scm/src/main/java/net/nemerosa/ontrack/extension/scm/service/SCMRefServiceExtensions.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...tension-scm/src/main/java/net/nemerosa/ontrack/extension/scm/service/SCMRefServiceImpl.kt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...scm/src/main/java/net/nemerosa/ontrack/extension/scm/service/SCMRefURIParsingException.kt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...src/main/java/net/nemerosa/ontrack/extension/scm/service/SCMRefUnknownSCMTypeException.kt
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...tension-scm/src/test/java/net/nemerosa/ontrack/extension/scm/files/SCMFileRefExtension.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,39 @@ | ||
package net.nemerosa.ontrack.extension.scm.files | ||
|
||
import net.nemerosa.ontrack.common.Document | ||
import net.nemerosa.ontrack.extension.api.ExtensionManager | ||
import net.nemerosa.ontrack.extension.api.FileRefExtension | ||
import net.nemerosa.ontrack.extension.scm.SCMExtensionFeature | ||
import net.nemerosa.ontrack.extension.scm.service.SCMExtension | ||
import net.nemerosa.ontrack.extension.support.AbstractExtension | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SCMFileRefExtension( | ||
extensionFeature: SCMExtensionFeature, | ||
private val extensionManager: ExtensionManager, | ||
) : AbstractExtension(extensionFeature), FileRefExtension { | ||
|
||
override val protocol: String = "scm" | ||
|
||
private val scmExtensions: Map<String, SCMExtension> by lazy { | ||
extensionManager.getExtensions(SCMExtension::class.java) | ||
.associateBy { it.type } | ||
} | ||
|
||
override fun download(path: String, type: String): Document? { | ||
val ref = SCMRef.parseUri(path) ?: throw SCMRefParsingException(path) | ||
val extension = scmExtensions[ref.type] | ||
?: throw SCMRefUnknownSCMTypeException(ref.type) | ||
|
||
val (scm, scmPath) = extension.getSCMPath(ref.config, ref.ref) ?: return null | ||
|
||
val bytes = scm.download( | ||
scmBranch = null, // Using the default branch | ||
path = scmPath, | ||
retryOnNotFound = false, | ||
) ?: return null | ||
|
||
return Document(type, bytes) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...sion-scm/src/test/java/net/nemerosa/ontrack/extension/scm/files/SCMRefParsingException.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,7 @@ | ||
package net.nemerosa.ontrack.extension.scm.files | ||
|
||
import net.nemerosa.ontrack.common.BaseException | ||
|
||
class SCMRefParsingException(path: String): BaseException( | ||
"""Cannot parse SCM path: $path""" | ||
) |
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
7 changes: 7 additions & 0 deletions
7
...m/src/test/java/net/nemerosa/ontrack/extension/scm/files/SCMRefUnknownSCMTypeException.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,7 @@ | ||
package net.nemerosa.ontrack.extension.scm.files | ||
|
||
import net.nemerosa.ontrack.common.BaseException | ||
|
||
class SCMRefUnknownSCMTypeException(type: String): BaseException( | ||
"""SCM type is not supported: $type.""" | ||
) |
Oops, something went wrong.