VersionInfoPListManager { static String getScmPort(Dependency dep, boolean hideConfidentialInformation) { if (!hideConfidentialInformation) { return dep.getScm().getConnection(); } else { String[] parts = dep.getScm().getConnection().split(":"); String port; if (parts.length == 1) { port = parts[0]; } else { int index; if(!parts[0].equals("scm")) throw new IllegalStateException(String.format("Invalid connection string: '%s'.", dep.getScm().getConnection())); if(parts[3].startsWith(" return ""; } else if(parts[1].equals("perforce")) { index = 3; } else if(parts[1].equals("git")) { index = 4; } else { throw new IllegalStateException(String.format("Invalid scm type (%s) found in connection string (%s).", parts[1], dep.getScm().getConnection())); } port = parts[index]; if(parts.length > index + 1) { port += parts[index + 1]; } } return port; } }    }
@Test public void testScmPortForGitHubHideConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:git:git: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, true); Assert.assertEquals("", port); }
@Test public void testScmPortForGitHideConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:git:ssh: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, true); Assert.assertEquals("29418/MyProject", port); }
@Test public void testScmPortForPerforceHideConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:perforce:p4.example.com:1666: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, true); Assert.assertEquals("1666 }
@Test public void testScmPortForGitHubShowConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:git:git: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, false); Assert.assertEquals("scm:git:git: }
@Test public void testScmPortForGitShowConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:git:ssh: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, false); Assert.assertEquals("scm:git:ssh: }
@Test public void testScmPortForPerforceShowConfidentialInformation() { SCM scm = new SCM(); scm.setConnection("scm:perforce:p4.example.com:1666: Dependency dependency = new Dependency(); dependency.setScm(scm); String port = VersionInfoPListManager.getScmPort(dependency, false); Assert.assertEquals("scm:perforce:p4.example.com:1666: }