public SourceLinesHashCache(TempFolder tempFolder) { this.cacheDirectoryPath = tempFolder.newDir().toPath(); }
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); } }
@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()); }
@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 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 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); } }
@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 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"); } } }
public SourceLinesHashCache(TempFolder tempFolder) { this.cacheDirectoryPath = tempFolder.newDir().toPath(); }
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; }
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 void initWorkingDir(ProjectDefinition module, TempFolder tempUtils) { workingDir = module.getWorkDir(); if (workingDir == null) { workingDir = tempUtils.newDir("work"); } else { try { FileUtils.forceMkdir(workingDir); } catch (Exception e) { throw new IllegalStateException("Fail to create working dir: " + workingDir.getAbsolutePath(), e); } } }
private void initWorkingDir(ProjectDefinition module, TempFolder tempUtils) { workingDir = module.getWorkDir(); if (workingDir == null) { workingDir = tempUtils.newDir("work"); } else { try { FileUtils.forceMkdir(workingDir); } catch (Exception e) { throw new IllegalStateException("Fail to create working dir: " + workingDir.getAbsolutePath(), e); } } }
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 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); } }
public void update(String projectKey, Sonarlint.ProjectConfiguration projectConfiguration) { Path work = tempFolder.newDir().toPath(); Path target = storagePaths.getServerIssuesPath(projectKey); FileUtils.replaceDir(path -> updateServerIssues(projectKey, projectConfiguration, path), target, work); }
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"); persistit.setProperties(props); persistit.initialize(); volume = persistit.createTemporaryVolume(); } catch (Exception e) { throw new IllegalStateException("Fail to start caches", e); } }
@Override public void execute() { 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); } else { throw MessageException.of("Analysis report " + task.getUuid() + " is missing in database"); } } }
public void update(String projectKey, ProgressWrapper progress) { GlobalProperties globalProps = storageReader.readGlobalProperties(); Version serverVersion = Version.create(storageReader.readServerInfos().getVersion()); FileUtils.replaceDir(temp -> { ProjectConfiguration projectConfiguration = updateConfiguration(projectKey, globalProps, temp, progress); updateServerIssues(projectKey, temp, projectConfiguration); updateComponents(serverVersion, projectKey, temp, projectConfiguration, progress); updateStatus(temp); }, storagePaths.getProjectStorageRoot(projectKey), tempFolder.newDir().toPath()); }