Skip to content

Commit

Permalink
MavenSupport: Add support for projects that use an SCP-like Git URL
Browse files Browse the repository at this point in the history
Add support for parsing Git URLs for Maven projects that omit the type
fragment and use an SCP-like URL, for example
"scm:git@github.com:facebook/facebook-android-sdk.git".

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
  • Loading branch information
mnonnenmacher committed Jul 31, 2019
1 parent 56a9160 commit 5648c40
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions analyzer/src/main/kotlin/MavenSupport.kt
Expand Up @@ -93,7 +93,8 @@ class MavenSupport(workspaceReader: WorkspaceReader) {
private const val MAX_DISK_CACHE_ENTRY_AGE_SECONDS = 6 * 60 * 60

// See http://maven.apache.org/pom.html#SCM.
val SCM_REGEX = Pattern.compile("scm:(?<type>[^:]+):(?<url>.+)")!!
val SCM_REGEX = Pattern.compile("scm:(?<type>[^:@]+):(?<url>.+)")!!
val USER_HOST_REGEX = Pattern.compile("scm:(?<user>[^:@]+)@(?<host>[^:]+):(?<url>.+)")!!

private val remoteArtifactCache =
DiskCache(
Expand Down Expand Up @@ -164,9 +165,18 @@ class MavenSupport(workspaceReader: WorkspaceReader) {
else -> VcsInfo(type = VcsType(type), url = url, revision = tag)
}
} else {
// It is a common mistake to omit the "scm:[provider]:" prefix. Add fall-backs for nevertheless
// clear cases.
if (connection.startsWith("git://") || connection.endsWith(".git")) {
val userHostMatcher = USER_HOST_REGEX.matcher(connection)

if (userHostMatcher.matches()) {
// Some projects omit the provider and use the SCP-like Git URL syntax, for example
// "scm:git@github.com:facebook/facebook-android-sdk.git".
val host = userHostMatcher.group("host")
val url = userHostMatcher.group("url")

VcsInfo(type = VcsType.GIT, url = "https://$host/$url", revision = tag)
} else if (connection.startsWith("git://") || connection.endsWith(".git")) {
// It is a common mistake to omit the "scm:[provider]:" prefix. Add fall-backs for nevertheless
// clear cases.
log.warn { "Maven SCM connection URL '$connection' lacks the required 'scm' prefix." }

VcsInfo(VcsType.GIT, connection, tag)
Expand Down

0 comments on commit 5648c40

Please sign in to comment.