public void moveConsoleArtifacts(LocatableEntity locatableEntity) { try { File from = chooser.temporaryConsoleFile(locatableEntity); // Job cancellation skips temporary file creation. Force create one if it does not exist. FileUtils.touch(from); File to = consoleLogArtifact(locatableEntity); FileUtils.moveFile(from, to); } catch (IOException | IllegalArtifactLocationException e) { throw new RuntimeException(e); } } }
/** * Snooze the upgrade wizard notice. */ @RequirePOST public HttpResponse doSnooze() throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); File f = SetupWizard.getUpdateStateFile(); FileUtils.touch(f); f.setLastModified(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)); LOGGER.log(FINE, "Snoozed the upgrade wizard notice"); return HttpResponses.redirectToContextRoot(); }
private void addLockTo(File hgRepoRootDir) throws IOException { File lock = new File(hgRepoRootDir, ".hg/store/lock"); FileUtils.touch(lock); }
@Override public Void answer(InvocationOnMock inv) throws Throwable { File toFile = (File) inv.getArguments()[1]; touch(toFile); return null; } }).when(httpDownloader).download(any(URI.class), any(File.class));
@SuppressWarnings("ResultOfMethodCallIgnored") @Before public void setUp() throws Exception { top = temporaryFolder.getRoot(); directory1 = new File(top, "directory1"); directory2 = new File(top, "directory2"); directory3 = new File(directory2, "directory3"); directory1.mkdir(); directory2.mkdir(); directory3.mkdir(); file1 = new File(directory1, "file1"); file2 = new File(directory2, "file2"); file3 = new File(top, "file3"); // Tests case with relative path file1ByRelativeDirectory2 = new File(top, "directory2/../directory1/file1"); file2ByRelativeDirectory1 = new File(top, "directory1/../directory2/file2"); FileUtils.touch(file1); FileUtils.touch(file2); FileUtils.touch(file3); }
@Test public void testDeletesNested() throws Exception { final File nested = new File(top, "nested"); assertTrue(nested.mkdirs()); FileUtils.touch(new File(nested, "file")); assertEquals(1, top.list().length); FileUtils.cleanDirectory(top); assertEquals(0, top.list().length); }
@Test public void testStillClearsIfGivenDirectoryIsASymlink() throws Exception { if (System.getProperty("os.name").startsWith("Win")) { // cant create symlinks in windows. return; } final File randomDirectory = new File(top, "randomDir"); assertTrue(randomDirectory.mkdirs()); FileUtils.touch(new File(randomDirectory, "randomfile")); assertEquals(1, randomDirectory.list().length); final File symlinkDirectory = new File(top, "fakeDir"); setupSymlink(randomDirectory, symlinkDirectory); FileUtils.cleanDirectory(symlinkDirectory); assertEquals(0, symlinkDirectory.list().length); assertEquals(0, randomDirectory.list().length); }
@Test public void testThrowsOnCannotDeleteFile() throws Exception { final File file = new File(top, "restricted"); FileUtils.touch(file); if (System.getProperty("os.name").startsWith("Win") || !chmod(top, 500, false)) { // test wont work if we can't restrict permissions on the // directory, so skip it. return; } try { FileUtils.cleanDirectory(top); fail("expected IOException"); } catch (final IOException e) { assertEquals("Unable to delete file: " + file.getAbsolutePath(), e.getMessage()); } }
@Test public void too_many_files_in_driver_dir() throws Exception { FileUtils.touch(new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc5.jar")); FileUtils.touch(new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar")); expectedException.expect(MessageException.class); expectedException.expectMessage("Directory must contain only one JAR file: extensions/jdbc-driver/oracle"); underTest.driverPath(homeDir, Provider.ORACLE); }
@Test public void testIdentifiesSymlinkFile() throws Exception { if (System.getProperty("os.name").startsWith("Win")) { // cant create symlinks in windows. return; } final File randomFile = new File(top, "randomfile"); FileUtils.touch(randomFile); final File symlinkFile = new File(top, "fakeinner"); setupSymlink(randomFile, symlinkFile); assertTrue(FileUtils.isSymlink(symlinkFile)); assertFalse(FileUtils.isSymlink(randomFile)); }
@Test public void fail_if_required_directory_is_a_file() throws Exception { // <home>/data is missing FileUtils.forceMkdir(webDir); FileUtils.forceMkdir(logsDir); FileUtils.touch(dataDir); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Property 'sonar.path.data' is not valid, not a directory: " + dataDir.getAbsolutePath()); underTest.reset(); }
@Test public void cleanup_static_directory_if_already_exists() throws Exception { File dir = temp.newFolder(); FileUtils.touch(new File(dir, "foo.txt")); underTest.addStaticDir(tomcat, "/deploy", dir); assertThat(dir).isDirectory().exists(); assertThat(dir.listFiles()).isEmpty(); }
@Test public void shouldNotDeleteLockFileIfTryLockHasFailed() throws IOException { FileUtils.touch(LOCK_FILE); Lockfile lockfile = new Lockfile(LOCK_FILE); assertThat(lockfile.tryLock(), is(false)); lockfile.delete(); assertThat(LOCK_FILE.exists(), is(true)); }
@Test public void empty_file() throws Exception { File tempFile = temp.newFile(); FileUtils.touch(tempFile); Metadata metadata = new FileMetadata().readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName()); assertThat(metadata.lines()).isEqualTo(1); assertThat(metadata.nonBlankLines()).isEqualTo(0); assertThat(metadata.hash()).isNotEmpty(); assertThat(metadata.originalLineStartOffsets()).containsOnly(0); assertThat(metadata.originalLineEndOffsets()).containsOnly(0); assertThat(metadata.isEmpty()).isTrue(); }
@Test public void clean_deletes_non_empty_directory() throws Exception { File dir = temp.newFolder(); FileUtils.touch(new File(dir, "foo.txt")); DefaultTempFolder underTest = new DefaultTempFolder(dir); underTest.clean(); assertThat(dir).doesNotExist(); }
@Test public void sets_driver_path_for_h2() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/h2/h2.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:h2:tcp://localhost:9092/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_postgresql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/postgresql/pg.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:postgresql://localhost/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_mssql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/mssql/sqljdbc4.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_oracle() throws Exception { File driverFile = new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:oracle:thin:@localhost/XE"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }