diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/GitUtilities.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/GitUtilities.java index bd61dd842..bf9db8da7 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/GitUtilities.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/GitUtilities.java @@ -1,7 +1,5 @@ package org.hl7.fhir.igtools.publisher; -import org.jetbrains.annotations.NotNull; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -58,7 +56,7 @@ public static String getGitSource(File gitDir) { try { final String[] cmd = { "git", "remote", "get-url", "origin" }; final String url = execAndReturnString(cmd, new String[]{}, gitDir); - final String noUserInfoUrl = getURLIfNoUserInfo(url, "git remote origin url"); + final String noUserInfoUrl = getURLWithNoUserInfo(url, "git remote origin url"); return noUserInfoUrl == null ? "" : noUserInfoUrl; } catch (Exception e) { System.out.println("Warning @ Unable to read the git source: " + e.getMessage().replace("fatal: ", "") ); @@ -75,13 +73,12 @@ public static String getGitSource(File gitDir) { * @param urlSource A string representing the source of the URL to be output * @return A valid URL that does not contain user information, or null. */ - protected static String getURLIfNoUserInfo(final String url, final String urlSource) { + protected static String getURLWithNoUserInfo(final String url, final String urlSource) { try { URL newUrl = new URL(url); - boolean result = newUrl.getUserInfo() != null; - if (result) { - System.out.println("Warning @ Git URL contains user information. Source: " + urlSource); - return null; + if (newUrl.getUserInfo() != null) { + System.out.println("Info @ Removing user info from GIT URL. Source: " + urlSource); + return new URL(newUrl.getProtocol(), newUrl.getHost(), newUrl.getPort(), newUrl.getFile()).toString(); } } catch (MalformedURLException e) { diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 5474629c8..d1e509a2e 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -34,7 +34,6 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; @@ -850,7 +849,7 @@ private void setRepoSource(final String repoSource) { if (repoSource == null) { return; } - this.repoSource = GitUtilities.getURLIfNoUserInfo(repoSource, "-repo CLI parameter"); + this.repoSource = GitUtilities.getURLWithNoUserInfo(repoSource, "-repo CLI parameter"); } private String targetOutputNested; diff --git a/org.hl7.fhir.publisher.core/src/test/java/org/hl7/fhir/igtools/publisher/GitUtilitiesTests.java b/org.hl7.fhir.publisher.core/src/test/java/org/hl7/fhir/igtools/publisher/GitUtilitiesTests.java index 20169bc5d..7dc9b8bc3 100644 --- a/org.hl7.fhir.publisher.core/src/test/java/org/hl7/fhir/igtools/publisher/GitUtilitiesTests.java +++ b/org.hl7.fhir.publisher.core/src/test/java/org/hl7/fhir/igtools/publisher/GitUtilitiesTests.java @@ -98,7 +98,7 @@ public void testGitStatusWhenNotGitDirectory() throws IOException { @CsvSource(value= { VALID_URL+","+VALID_URL, "whwehwhasdlksdjsdf,''", - USERNAME_AND_TOKEN_URL+",''"}) + USERNAME_AND_TOKEN_URL+","+ VALID_URL}) void testGetGitSource(String url, String expected) throws IOException, InterruptedException { File gitRoot = initiateGitDirectory(); createOriginURL(gitRoot, url); @@ -110,9 +110,9 @@ void testGetGitSource(String url, String expected) throws IOException, Interrupt @CsvSource(value= { VALID_URL+","+VALID_URL, "whwehwhasdlksdjsdf,NULL", - USERNAME_AND_TOKEN_URL+",NULL"}, nullValues={"NULL"}) + USERNAME_AND_TOKEN_URL+","+VALID_URL}, nullValues={"NULL"}) public void getURLIfNoUserInfo(String url, String expected) { - String result = GitUtilities.getURLIfNoUserInfo(url, "test"); + String result = GitUtilities.getURLWithNoUserInfo(url, "test"); assertThat(result).isEqualTo(expected); } }