MavenSettings { static String interpolateVariables(String in) { StringBuilder out = new StringBuilder(); int cur = 0; int startLoc = -1; while ((startLoc = in.indexOf("${", cur)) >= 0) { out.append(in.substring(cur, startLoc)); int endLoc = in.indexOf("}", startLoc); if (endLoc > 0) { String name = in.substring(startLoc + 2, endLoc); String value = null; if (name.startsWith("env.")) { value = System.getenv(name.substring(4)); } else { value = System.getProperty(name); } if (value == null) { value = ""; } out.append(value); } else { out.append(in.substring(startLoc)); cur = in.length(); break; } cur = endLoc + 1; } out.append(in.substring(cur)); return out.toString(); } MavenSettings(); void setLocalRepository(Path localRepository); Path getLocalRepository(); List<String> getRemoteRepositories(); void addProfile(Profile profile); void addActiveProfile(String profileName); void addProxy(Proxy proxy); List<Proxy> getProxies(); Proxy getProxyFor(URL url); URLConnection openConnection(URL url);  }
@Test public void testInterpolateVariablesInvalidExpression2() throws Exception { try { System.setProperty( "test.user.home", "/home/bob" ); Assert.assertEquals("/home/bob/.m2/${repoName", MavenSettings.interpolateVariables("${test.user.home}/.m2/${repoName")); } finally { System.clearProperty("test.user.home"); } }
@Test public void testInterpolateVariablesNoVariables() throws Exception { Assert.assertEquals("/home/bob/.m2/repository", MavenSettings.interpolateVariables( "/home/bob/.m2/repository" ) ); }
@Test public void testInterpolateVariablesOneVariable() throws Exception { try { System.setProperty( "test.user.home", "/home/bob" ); Assert.assertEquals("/home/bob/.m2/repository", MavenSettings.interpolateVariables("${test.user.home}/.m2/repository")); } finally { System.clearProperty("test.user.home"); } }
@Test public void testInterpolateVariablesTwoVariables() throws Exception { try { System.setProperty( "test.user.home", "/home/bob" ); System.setProperty( "test.repo.dir", "repository" ); Assert.assertEquals("/home/bob/.m2/repository", MavenSettings.interpolateVariables("${test.user.home}/.m2/${test.repo.dir}")); } finally { System.clearProperty("test.user.home"); } }
@Test public void testInterpolateVariablesInvalidExpression() throws Exception { try { System.setProperty( "test.user.home", "/home/bob" ); Assert.assertEquals("${test.user.home/.m2/repository", MavenSettings.interpolateVariables("${test.user.home/.m2/repository")); } finally { System.clearProperty("test.user.home"); } }