From 72dbf59b6d1b938d88d14b09bd9b517b92b450d8 Mon Sep 17 00:00:00 2001 From: Viacheslav Kabanovich Date: Wed, 23 Mar 2016 13:21:24 -0700 Subject: [PATCH] Enhance normalize uri Normalize uri like git@github.com:errai/errai.git/errai-common into git://github.com/errai/errai.git There are 3 independent operations: 1) set git:// instead git@ 2) set github.com/ instead github: 3) remove tail after .git --- .../m2e/egit/internal/EgitScmHandler.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/org.sonatype.m2e.egit/src/org/sonatype/m2e/egit/internal/EgitScmHandler.java b/org.sonatype.m2e.egit/src/org/sonatype/m2e/egit/internal/EgitScmHandler.java index b4a6b99..a98e2de 100644 --- a/org.sonatype.m2e.egit/src/org/sonatype/m2e/egit/internal/EgitScmHandler.java +++ b/org.sonatype.m2e.egit/src/org/sonatype/m2e/egit/internal/EgitScmHandler.java @@ -101,6 +101,28 @@ protected String normalizeUri(String uri) throws URISyntaxException { throw new URISyntaxException(uri, "Invalid git URI"); } + // Normalize uri like + // git@github.com:errai/errai.git/errai-common + // into + // git://github.com/errai/errai.git + // These 3 distinctions may happen independently in other cases. + //1. Replace @ with :// + if(uri.startsWith("git@")) { + uri = "git://" + uri.substring(4); + } + //2. Replace github.com: with github.com/ + String githubDotCom = "github.com"; + int pos = uri.indexOf(githubDotCom + ":"); + if(pos > 0) { + pos += githubDotCom.length(); + uri = uri.substring(0, pos) + "/" + uri.substring(pos + 1); + } + //3. Remove tail after .git + int dotGit = uri.indexOf(".git"); + if(dotGit >= 0 && uri.length() > dotGit + 4) { + uri = uri.substring(0, dotGit + 4); + } + URIish gitUri = new URIish(uri); if(gitUri.getScheme() == null) { if(gitUri.getHost() == null || "file".equals(gitUri.getHost())) {