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 @@ -15,7 +15,7 @@
*/
package nebula.plugin.publishing.maven

import groovy.transform.CompileDynamic

import nebula.plugin.info.scm.GitScmProvider
import nebula.plugin.info.scm.ScmInfoExtension
import nebula.plugin.info.scm.ScmInfoPlugin
Expand Down Expand Up @@ -76,17 +76,16 @@ class MavenScmPlugin implements Plugin<Project> {
}
}

static final GIT_PATTERN = /((git|ssh|https?):(\/\/))?(\w+@)?([\w\.@\\/\-~]+)([\:\\/])([\w\.@\:\/\-~]+)(\.git)(\/)?/
static final GIT_PATTERN = /^((git|ssh|https?):\/\/)?((\S+)@)?(?<host>\S+?)[:\/](?<repo>\S+?)(.git)?\/?$/

/**
* Convert git syntax of git@github.com:reactivex/rxjava-core.git to https://github.com/reactivex/rxjava-core
* @param origin
*/
@CompileDynamic
static String calculateUrlFromOrigin(String origin, Project project) {
def m = origin =~ GIT_PATTERN
if (m) {
return "https://${m[0][5]}/${m[0][7]}"
if (m.matches()) {
return "https://${m.group("host")}/${m.group("repo")}"
} else {
project.logger.warn("Unable to convert $origin to https form in MavenScmPlugin. Using original value.")
return origin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class MavenScmPluginSpec extends PluginProjectSpec {
scmOrigin | calculatedUrl
'https://fake-scm.com/foo/bar.git' | 'https://fake-scm.com/foo/bar'
'https://github.com/nebula-plugins/nebula-publishing-plugin' | 'https://github.com/nebula-plugins/nebula-publishing-plugin'
'https://github.com/nebula-plugins/nebula-publishing-plugin/' | 'https://github.com/nebula-plugins/nebula-publishing-plugin'
'https://github.com/nebula-plugins/nebula-publishing-plugin.git' | 'https://github.com/nebula-plugins/nebula-publishing-plugin'
'git@github.com:nebula-plugins/nebula-publishing-plugin.git' | 'https://github.com/nebula-plugins/nebula-publishing-plugin'
'git@github.com:username/nebula-publishing-plugin.git' | 'https://github.com/username/nebula-publishing-plugin'
'git@github.com:username/nebula-publishing-plugin.git' | 'https://github.com/username/nebula-publishing-plugin'
'git@github.com:username/nebula-publishing-plugin' | 'https://github.com/username/nebula-publishing-plugin'
}
}