@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 SourceLinesHashCache(TempFolder tempFolder) { this.cacheDirectoryPath = tempFolder.newDir().toPath(); }
public IssueCache(TempFolder tempFolder, System2 system2) { super(tempFolder.newFile("issues", ".dat"), system2); }
private void initPersistit() { try { tempDir = tempFolder.newDir("caches"); persistit = new Persistit(); persistit.setPersistitLogger(new Slf4jAdapter(LoggerFactory.getLogger("PERSISTIT"))); Properties props = new Properties(); props.setProperty("datapath", tempDir.getAbsolutePath()); props.setProperty("logpath", "${datapath}/log"); props.setProperty("logfile", "${logpath}/persistit_${timestamp}.log"); props.setProperty("buffer.count.8192", "10"); props.setProperty("journalpath", "${datapath}/journal"); props.setProperty("tmpvoldir", "${datapath}"); props.setProperty("volume.1", "${datapath}/persistit,create,pageSize:8192,initialPages:10,extensionPages:100,maximumPages:25000"); props.setProperty("jmx", "false"); persistit.setProperties(props); persistit.initialize(); } catch (Exception e) { throw new IllegalStateException("Fail to start caches", 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); } }
@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 create_temp_dir_if_missing() throws Exception { ServerFileSystem fs = mock(ServerFileSystem.class); File tmpDir = temp.newFolder(); when(fs.getTempDir()).thenReturn(tmpDir); FileUtils.forceDelete(tmpDir); TempFolder folder = underTest.provide(fs); assertThat(folder).isNotNull(); File newDir = folder.newDir(); assertThat(newDir).exists().isDirectory(); assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath()); } }
@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_"); }
@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 existing_temp_dir() throws Exception { ServerFileSystem fs = mock(ServerFileSystem.class); File tmpDir = temp.newFolder(); when(fs.getTempDir()).thenReturn(tmpDir); TempFolder folder = underTest.provide(fs); assertThat(folder).isNotNull(); File newDir = folder.newDir(); assertThat(newDir).exists().isDirectory(); assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath()); }
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 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); } }
@Override public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Optional<CeTaskInputDao.DataStream> opt = dbClient.ceTaskInputDao().selectData(dbSession, task.getUuid()); if (opt.isPresent()) { File unzippedDir = tempFolder.newDir(); try (CeTaskInputDao.DataStream reportStream = opt.get(); InputStream zipStream = new BufferedInputStream(reportStream.getInputStream())) { ZipUtils.unzip(zipStream, unzippedDir); } catch (IOException e) { throw new IllegalStateException("Fail to extract report " + task.getUuid() + " from database", e); } reportDirectoryHolder.setDirectory(unzippedDir); if (LOGGER.isDebugEnabled()) { // size is not added to context statistics because computation // can take time. It's enabled only if log level is DEBUG. try { String dirSize = FileUtils.byteCountToDisplaySize(FileUtils2.sizeOf(unzippedDir.toPath())); LOGGER.debug("Analysis report is {} uncompressed", dirSize); } catch (IOException e) { LOGGER.warn("Fail to compute size of directory " + unzippedDir, e); } } } else { throw MessageException.of("Analysis report " + task.getUuid() + " is missing in database"); } } }
@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_"); }
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); } }
public SourceLinesHashCache(TempFolder tempFolder) { this.cacheDirectoryPath = tempFolder.newDir().toPath(); }
public IssueCache(TempFolder tempFolder, System2 system2) { super(tempFolder.newFile("issues", ".dat"), system2); }
EslintBridgeServerImpl(NodeCommandBuilder nodeCommandBuilder, TempFolder tempFolder, int timeoutSeconds, String startServerScript, String bundleLocation) { this.nodeCommandBuilder = nodeCommandBuilder; this.timeoutSeconds = timeoutSeconds; this.startServerScript = startServerScript; this.client = new OkHttpClient.Builder() .readTimeout(timeoutSeconds, TimeUnit.SECONDS) .build(); this.deployLocation = tempFolder.newDir(DEPLOY_LOCATION).toPath(); this.bundleLocation = bundleLocation; }
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'"); } }
EslintBridgeServerImpl(NodeCommandBuilder nodeCommandBuilder, TempFolder tempFolder, int timeoutSeconds, String startServerScript, String bundleLocation) { this.nodeCommandBuilder = nodeCommandBuilder; this.timeoutSeconds = timeoutSeconds; this.startServerScript = startServerScript; this.client = new OkHttpClient.Builder() .readTimeout(timeoutSeconds, TimeUnit.SECONDS) .build(); this.deployLocation = tempFolder.newDir(DEPLOY_LOCATION).toPath(); this.bundleLocation = bundleLocation; }