MavenBuildExecutor extends AbstractBuildExecutor<MavenBuild> { String buildMvnPath(Configuration config) throws IOException { Optional<String> binary = Optional.ofNullable(config.getStringByKeys("maven.binary", "MAVEN_BINARY")); File home = config.fileSystem().mavenHome(); if (home == null) { return binary.orElse(os.isWindows() ? "mvn.cmd" : "mvn"); } if (binary.isPresent()) { return new File(home, "bin/" + binary.get()).getCanonicalPath(); } if (os.isWindows()) { File bin = new File(home, "bin/mvn.bat"); if (bin.exists()) { return bin.getCanonicalPath(); } return new File(home, "bin/mvn.cmd").getCanonicalPath(); } return new File(home, "bin/mvn").getCanonicalPath(); } MavenBuildExecutor(Os os);  MavenBuildExecutor();   }
@Test public void configure_command_in_PATH_on_linux() throws Exception { emulateLinux(); Configuration configuration = Configuration.builder().setProperty("maven.binary", "mvnDebug").build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo("mvnDebug"); }
@Test public void configure_command_in_PATH_on_windows() throws Exception { emulateWindows(); Configuration configuration = Configuration.builder().setProperty("maven.binary", "mvnDebug.cmd").build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo("mvnDebug.cmd"); }
@Test public void configure_path_to_command_on_linux() throws Exception { emulateLinux(); File home = temp.newFolder(); String binPath = new File(home, "bin/maven").getCanonicalPath(); Configuration configuration = Configuration.builder().setProperty("maven.binary", binPath).build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo(binPath); }
@Test public void configure_path_to_command_on_windows() throws Exception { emulateWindows(); File home = temp.newFolder(); String binPath = new File(home, "bin/maven.bat").getCanonicalPath(); Configuration configuration = Configuration.builder().setProperty("maven.binary", binPath).build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo(binPath); }
@Test public void default_command_on_linux_is_in_PATH() throws Exception { emulateLinux(); Configuration configuration = Configuration.builder().build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo("mvn"); }
@Test public void default_command_on_windows_is_in_PATH() throws Exception { emulateWindows(); Configuration configuration = Configuration.builder().build(); assertThat(underTest.buildMvnPath(configuration)).isEqualTo("mvn.cmd"); }
@Test public void configure_MAVEN_HOME_on_linux() throws Exception { emulateLinux(); File home = temp.newFolder(); Configuration configuration = Configuration.builder().setProperty("MAVEN_HOME", home.getCanonicalPath()).build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvn").getCanonicalPath()); }
@Test public void configure_maven_home_on_windows() throws Exception { emulateWindows(); File home = temp.newFolder(); Configuration configuration = Configuration.builder().setProperty("MAVEN_HOME", home.getCanonicalPath()).build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvn.cmd").getCanonicalPath()); }
@Test public void configure_maven_home_and_binary_on_windows() throws Exception { emulateWindows(); File home = temp.newFolder(); Configuration configuration = Configuration.builder() .setProperty("MAVEN_HOME", home.getCanonicalPath()) .setProperty("MAVEN_BINARY", "mvnDebug.cmd") .build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvnDebug.cmd").getCanonicalPath()); }
@Test public void configure_maven_home_on_linux() throws Exception { emulateLinux(); File home = temp.newFolder(); Configuration configuration = Configuration.builder().setProperty("MAVEN_HOME", home.getCanonicalPath()).build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvn").getCanonicalPath()); }
@Test public void configure_maven_home_and_binary_on_linux() throws Exception { emulateLinux(); File home = temp.newFolder(); Configuration configuration = Configuration.builder() .setProperty("MAVEN_HOME", home.getCanonicalPath()) .setProperty("MAVEN_BINARY", "mvnDebug") .build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvnDebug").getCanonicalPath()); }
@Test public void support_maven_3_2_binary_on_windows() throws Exception { emulateWindows(); File home = temp.newFolder(); FileUtils.touch(new File(home, "bin/mvn.bat")); Configuration configuration = Configuration.builder().setProperty("MAVEN_HOME", home.getCanonicalPath()).build(); String result = underTest.buildMvnPath(configuration); assertThat(result).isEqualTo(new File(home, "bin/mvn.bat").getCanonicalPath()); }