private void cleanAllWorkingDirs(DefaultInputModule module) { for (DefaultInputModule sub : moduleHierarchy.children(module)) { cleanAllWorkingDirs(sub); } if (Files.exists(module.getWorkDir())) { deleteAllRecursivelyExceptLockFile(module.getWorkDir()); } }
private static void deleteAllRecursivelyExceptLockFile(Path dirToDelete) { try (DirectoryStream<Path> stream = list(dirToDelete)) { Iterator<Path> it = stream.iterator(); while (it.hasNext()) { FileUtils.deleteQuietly(it.next().toFile()); } } catch (IOException e) { throw new IllegalStateException("Failed to clean working directory: " + dirToDelete.toString(), e); } }
public void execute() { cleanAllWorkingDirs(moduleHierarchy.root()); mkdirsAllWorkingDirs(moduleHierarchy.root()); }
@Test public void cleaningRootModuleShouldNotDeleteChildrenWorkDir() throws IOException { DefaultInputModule moduleA = mock(DefaultInputModule.class); when(hierarchy.children(root)).thenReturn(Arrays.asList(moduleA)); File moduleAWorkdir = new File(rootWorkDir, "moduleA"); when(moduleA.getWorkDir()).thenReturn(moduleAWorkdir.toPath()); moduleAWorkdir.mkdir(); new File(moduleAWorkdir, "fooA.txt").createNewFile(); initializer.execute(); assertThat(rootWorkDir).exists(); assertThat(lock).exists(); assertThat(rootWorkDir.list()).containsOnly(DirectoryLock.LOCK_FILE_NAME, "moduleA"); assertThat(moduleAWorkdir).exists(); }
private void mkdirsAllWorkingDirs(DefaultInputModule module) { for (DefaultInputModule sub : moduleHierarchy.children(module)) { mkdirsAllWorkingDirs(sub); } try { Files.createDirectories(module.getWorkDir()); } catch (Exception e) { throw new IllegalStateException("Fail to create working dir: " + module.getWorkDir(), e); } }
@Before public void setUp() throws IOException { rootWorkDir = temp.newFolder(); // create files to clean new File(rootWorkDir, "foo.txt").createNewFile(); File newFolder = new File(rootWorkDir, "foo"); newFolder.mkdir(); File fileInFolder = new File(newFolder, "test"); fileInFolder.createNewFile(); lock = new File(rootWorkDir, DirectoryLock.LOCK_FILE_NAME); lock.createNewFile(); hierarchy = mock(InputModuleHierarchy.class); root = mock(DefaultInputModule.class); when(hierarchy.root()).thenReturn(root); when(root.getWorkDir()).thenReturn(rootWorkDir.toPath()); assertThat(rootWorkDir.list().length).isGreaterThan(1); initializer = new WorkDirectoriesInitializer(hierarchy); }
@Test public void testNonExisting() { temp.delete(); initializer.execute(); }
private void mkdirsAllWorkingDirs(DefaultInputModule module) { for (DefaultInputModule sub : moduleHierarchy.children(module)) { mkdirsAllWorkingDirs(sub); } try { Files.createDirectories(module.getWorkDir()); } catch (Exception e) { throw new IllegalStateException("Fail to create working dir: " + module.getWorkDir(), e); } }
@Test public void testClean() { initializer.execute(); assertThat(rootWorkDir).exists(); assertThat(lock).exists(); assertThat(rootWorkDir.list()).containsOnly(DirectoryLock.LOCK_FILE_NAME); }
private void cleanAllWorkingDirs(DefaultInputModule module) { for (DefaultInputModule sub : moduleHierarchy.children(module)) { cleanAllWorkingDirs(sub); } if (Files.exists(module.getWorkDir())) { deleteAllRecursivelyExceptLockFile(module.getWorkDir()); } }
public void execute() { cleanAllWorkingDirs(moduleHierarchy.root()); mkdirsAllWorkingDirs(moduleHierarchy.root()); }
private static void deleteAllRecursivelyExceptLockFile(Path dirToDelete) { try (DirectoryStream<Path> stream = list(dirToDelete)) { Iterator<Path> it = stream.iterator(); while (it.hasNext()) { FileUtils.deleteQuietly(it.next().toFile()); } } catch (IOException e) { throw new IllegalStateException("Failed to clean working directory: " + dirToDelete.toString(), e); } }
@Override protected void doBeforeStart() { addScannerComponents(); addScannerExtensions(); ProjectLock lock = getComponentByType(ProjectLock.class); lock.tryLock(); getComponentByType(WorkDirectoriesInitializer.class).execute(); if (!isIssuesMode()) { addReportPublishSteps(); } else if (isTherePreviousAnalysis()) { addIssueTrackingComponents(); } }
@Override protected void doBeforeStart() { addScannerComponents(); addScannerExtensions(); ProjectLock lock = getComponentByType(ProjectLock.class); lock.tryLock(); getComponentByType(WorkDirectoriesInitializer.class).execute(); if (!isIssuesMode()) { addReportPublishSteps(); } else if (isTherePreviousAnalysis()) { addIssueTrackingComponents(); } }