ScannerForMSBuildInstaller { public File install(@Nullable Version scannerVersion, @Nullable Location location, File toDir, boolean useDotNetCore) { if (location != null) { return installFromLocation(location, toDir, useDotNetCore); } else if (scannerVersion != null) { return install(scannerVersion, toDir, useDotNetCore); } else { return install(Version.create(DEFAULT_SCANNER_VERSION), toDir, useDotNetCore); } } ScannerForMSBuildInstaller(Locators locators); File install(@Nullable Version scannerVersion, @Nullable Location location, File toDir, boolean useDotNetCore); static final String DEFAULT_SCANNER_VERSION; static final String NETCOREAPP_2_0; static final String NET_46; }
@Test public void install_zip_after_dot_net_core_support_by_providing_version_dot_net_core() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstallerTest.class.getResource("/com/sonar/orchestrator/build/ScannerForMSBuildInstallerTest/sonar-scanner-msbuild-4.2.0.1214-netcoreapp2.0.zip"); when(locators.locate(any())).thenReturn(new File(zip.toURI())); File script = installer.install(Version.create("4.2.0.1214"), null, toDir, true); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.dll"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild-4.2.0.1214" + "-" + ScannerForMSBuildInstaller.NETCOREAPP_2_0); }
@Test public void install_without_version_nor_location_should_install_default() throws IOException { File toDir = temp.newFolder(); File script = installer.install(null, null, toDir, true); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.dll"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild-" + ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION + "-" + ScannerForMSBuildInstaller.NETCOREAPP_2_0); }
@Test public void do_not_install_twice_with_version() throws Exception { File toDir = temp.newFolder(); File script = installer.install(Version.create(ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION), null, toDir, false); File txt = new File(script.getParentFile(), "text.txt"); txt.createNewFile(); assertThat(txt).exists(); installer.install(Version.create(ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION), null, toDir, false); assertThat(txt).exists(); }
@Test public void do_install_twice_with_location() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstaller.class.getResource("/com/sonar/orchestrator/build/sonar-scanner-msbuild-" + ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION + "-net46.zip"); FileLocation zipLocation = FileLocation.of(new File(zip.toURI())); when(locators.locate(zipLocation)).thenReturn(new File(zip.toURI())); File script = installer.install(null, zipLocation, toDir, false); File txt = new File(script.getParentFile(), "text.txt"); txt.createNewFile(); assertThat(txt).exists(); installer.install(null, zipLocation, toDir, false); assertThat(txt).doesNotExist(); }
@Test public void fail_if_file_doesnt_exist() throws Exception { File toDir = temp.newFolder(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("File doesn't exist"); installer.install(null, FileLocation.of(new File("unknown")), toDir, false); }
@Test public void install_embedded_version() throws Exception { File toDir = temp.newFolder(); File script = installer.install(Version.create(ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION), null, toDir, false); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.exe"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild-" + ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION + "-" + ScannerForMSBuildInstaller.NET_46); verify(locators, never()).locate(any(MavenLocation.class)); }
@Test public void install_zip() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstaller.class.getResource("/com/sonar/orchestrator/build/sonar-scanner-msbuild-" + ScannerForMSBuildInstaller.DEFAULT_SCANNER_VERSION + "-net46.zip"); FileLocation zipLocation = FileLocation.of(new File(zip.toURI())); when(locators.locate(zipLocation)).thenReturn(new File(zip.toURI())); File script = installer.install(null, zipLocation, toDir, false); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.exe"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild"); }
@Test public void install_zip_after_dot_net_core_support() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstallerTest.class.getResource("/com/sonar/orchestrator/build/ScannerForMSBuildInstallerTest/sonar-scanner-msbuild-4.2.0.1214-net46.zip"); FileLocation zipLocation = FileLocation.of(new File(zip.toURI())); when(locators.locate(zipLocation)).thenReturn(new File(zip.toURI())); File script = installer.install(null, zipLocation, toDir, false); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.exe"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild"); }
@Test public void install_zip_after_dot_net_core_support_with_dot_net_core() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstallerTest.class.getResource("/com/sonar/orchestrator/build/ScannerForMSBuildInstallerTest/sonar-scanner-msbuild-4.2.0.1214-netcoreapp2.0.zip"); FileLocation zipLocation = FileLocation.of(new File(zip.toURI())); when(locators.locate(zipLocation)).thenReturn(new File(zip.toURI())); File script = installer.install(null, zipLocation, toDir, true); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.dll"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild"); }
@Test public void install_zip_after_dot_net_core_support_by_providing_version() throws Exception { File toDir = temp.newFolder(); URL zip = ScannerForMSBuildInstallerTest.class.getResource("/com/sonar/orchestrator/build/ScannerForMSBuildInstallerTest/sonar-scanner-msbuild-4.2.0.1214-net46.zip"); when(locators.locate(any())).thenReturn(new File(zip.toURI())); File script = installer.install(Version.create("4.2.0.1214"), null, toDir, false); assertThat(script).isFile().exists(); assertThat(script.getName()).contains("SonarScanner.MSBuild.exe"); assertThat(script.getParentFile()).hasName("sonar-scanner-msbuild-4.2.0.1214" + "-" + ScannerForMSBuildInstaller.NET_46); }