public IssueCache(TempFolder tempFolder, System2 system2) { super(tempFolder.newFile("issues", ".dat"), system2); }
private File generateReportFile() { try { long startTime = System.currentTimeMillis(); for (ReportPublisherStep publisher : publishers) { publisher.publish(writer); } long stopTime = System.currentTimeMillis(); LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir.toFile()))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("scanner-report", ".zip"); ZipUtils.zipDir(reportDir.toFile(), reportZip); stopTime = System.currentTimeMillis(); LOG.info("Analysis report compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip))); return reportZip; } catch (IOException e) { throw new IllegalStateException("Unable to prepare analysis report", e); } }
@Test public void dotWorkingDir() throws IOException { File sonarHome = temp.getRoot(); String globalWorkDir = "."; ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath(), CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir)); TempFolder tempFolder = tempFolderProvider.provide(globalProperties); File newFile = tempFolder.newFile(); assertThat(newFile.getParentFile().getParentFile().getAbsolutePath()).isEqualTo(sonarHome.getAbsolutePath()); assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_"); }
public QProfileDto copyToName(DbSession dbSession, QProfileDto sourceProfile, String toName) { OrganizationDto organization = db.organizationDao().selectByUuid(dbSession, sourceProfile.getOrganizationUuid()) .orElseThrow(() -> new IllegalStateException("Organization with UUID [" + sourceProfile.getOrganizationUuid() + "] does not exist")); QProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName); File backupFile = temp.newFile(); try { backup(dbSession, sourceProfile, backupFile); restore(dbSession, backupFile, to); return to; } finally { org.sonar.core.util.FileUtils.deleteQuietly(backupFile); } }
@Test public void homeIsSymbolicLink() throws IOException { assumeTrue(!System2.INSTANCE.isOsWindows()); File realSonarHome = temp.newFolder(); File symlink = temp.newFolder(); symlink.delete(); Files.createSymbolicLink(symlink.toPath(), realSonarHome.toPath()); ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath())); TempFolder tempFolder = tempFolderProvider.provide(globalProperties); File newFile = tempFolder.newFile(); assertThat(newFile.getParentFile().getParentFile().getAbsolutePath()).isEqualTo(symlink.getAbsolutePath()); assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_"); }
@Test public void createTempFolderProps() throws Exception { File workingDir = temp.newFolder(); workingDir.delete(); TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath()))); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); FileUtils.deleteQuietly(workingDir); }
@Test public void createTempFolderSonarHome() throws Exception { // with sonar home, it will be in {sonar.home}/.sonartmp File sonarHome = temp.newFolder(); File workingDir = new File(sonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile(); TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath()))); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); FileUtils.deleteQuietly(sonarHome); }
@Test public void createTempFolderDefault() throws Exception { System2 system = mock(System2.class); tempFolderProvider = new GlobalTempFolderProvider(system); File userHome = temp.newFolder(); when(system.envVariable("SONAR_USER_HOME")).thenReturn(null); when(system.property("user.home")).thenReturn(userHome.getAbsolutePath().toString()); // if nothing is defined, it will be in {user.home}/.sonar/.sonartmp File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar"); File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile(); try { TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(Collections.<String, String>emptyMap())); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); } finally { FileUtils.deleteQuietly(workingDir); } }
@Test public void createTempFolder() throws IOException { File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME); TempFolder tempFolder = tempFolderProvider.provide(project); tempFolder.newDir(); tempFolder.newFile(); assertThat(defaultDir).exists(); assertThat(defaultDir.list()).hasSize(2); } }
public IssueCache(TempFolder tempFolder, System2 system2) { super(tempFolder.newFile("issues", ".dat"), system2); }
private File extractSlf4jAdapterJar() { InputStream jarInputStream = PluginLoader.class.getResourceAsStream("/" + SLF4J_ADAPTER_JAR_NAME + ".jar"); try { File extractedJar = tempFolder.newFile(SLF4J_ADAPTER_JAR_NAME, ".jar"); FileUtils.copyInputStreamToFile(jarInputStream, extractedJar); return extractedJar; } catch (Exception e) { throw new IllegalStateException("Failed to extract the jar '" + SLF4J_ADAPTER_JAR_NAME + ".jar'"); } }
private File prepareReport() { try { long startTime = System.currentTimeMillis(); File reportDir = temp.newDir("batch-report"); BatchReportWriter writer = new BatchReportWriter(reportDir); for (ReportPublisher publisher : publishers) { publisher.publish(writer); } long stopTime = System.currentTimeMillis(); LOG.info("Analysis reports generated in " + (stopTime - startTime) + "ms, dir size=" + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("batch-report", ".zip"); ZipUtils.zipDir(reportDir, reportZip); FileUtils.deleteDirectory(reportDir); stopTime = System.currentTimeMillis(); LOG.info("Analysis reports compressed in " + (stopTime - startTime) + "ms, zip size=" + FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip))); return reportZip; } catch (IOException e) { throw new IllegalStateException("Unable to prepare batch report", e); } }
private File generateReportFile() { try { long startTime = System.currentTimeMillis(); for (ReportPublisherStep publisher : publishers) { publisher.publish(writer); } long stopTime = System.currentTimeMillis(); LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir.toFile()))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("scanner-report", ".zip"); ZipUtils.zipDir(reportDir.toFile(), reportZip); stopTime = System.currentTimeMillis(); LOG.info("Analysis report compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip))); return reportZip; } catch (IOException e) { throw new IllegalStateException("Unable to prepare analysis report", e); } }
File tslintOutputFile = this.tempFolder.newFile(); String tslintOutputFilePath = tslintOutputFile.getAbsolutePath(); Command baseCommand = getBaseCommand(config, tslintOutputFilePath);
private File generateReportFile() { try { long startTime = System.currentTimeMillis(); for (ReportPublisherStep publisher : publishers) { publisher.publish(writer); } long stopTime = System.currentTimeMillis(); LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("batch-report", ".zip"); ZipUtils.zipDir(reportDir, reportZip); stopTime = System.currentTimeMillis(); LOG.info("Analysis reports compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip))); return reportZip; } catch (IOException e) { throw new IllegalStateException("Unable to prepare analysis report", e); } }
public QProfileDto copyToName(DbSession dbSession, QProfileDto sourceProfile, String toName) { OrganizationDto organization = db.organizationDao().selectByUuid(dbSession, sourceProfile.getOrganizationUuid()) .orElseThrow(() -> new IllegalStateException("Organization with UUID [" + sourceProfile.getOrganizationUuid() + "] does not exist")); QProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName); File backupFile = temp.newFile(); try { backup(dbSession, sourceProfile, backupFile); restore(dbSession, backupFile, to); return to; } finally { org.sonar.core.util.FileUtils.deleteQuietly(backupFile); } }