List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.sonar.batch.scan.filesystem.FileMetadataTest.java
@Test public void empty_file() throws Exception { File tempFile = temp.newFile(); FileUtils.touch(tempFile); FileMetadata.Metadata metadata = FileMetadata.INSTANCE.read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(0); assertThat(metadata.hash).isNotEmpty(); }
From source file:org.sonar.batch.scan.filesystem.InputFileBuilderTest.java
@Test public void complete_input_file() throws Exception { // file system File basedir = temp.newFolder(); File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); FileUtils.touch(srcFile); FileUtils.write(srcFile, "single line"); when(fs.baseDir()).thenReturn(basedir); when(fs.encoding()).thenReturn(StandardCharsets.UTF_8); // lang// www . j a v a2 s .co m when(langDetection.language(any(InputFile.class))).thenReturn("java"); // status when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) .thenReturn(InputFile.Status.ADDED); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, new Settings(), new FileMetadata()); DefaultInputFile inputFile = builder.create(srcFile); builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN); assertThat(inputFile.type()).isEqualTo(InputFile.Type.MAIN); assertThat(inputFile.file()).isEqualTo(srcFile.getAbsoluteFile()); assertThat(inputFile.absolutePath()).isEqualTo(PathUtils.sanitize(srcFile.getAbsolutePath())); assertThat(inputFile.language()).isEqualTo("java"); assertThat(inputFile.key()).isEqualTo("struts:src/main/java/foo/Bar.java"); assertThat(inputFile.relativePath()).isEqualTo("src/main/java/foo/Bar.java"); assertThat(inputFile.lines()).isEqualTo(1); }
From source file:org.sonar.batch.scan.filesystem.InputFileBuilderTest.java
@Test public void return_null_if_file_outside_basedir() throws Exception { // file system File basedir = temp.newFolder(); File otherDir = temp.newFolder(); File srcFile = new File(otherDir, "src/main/java/foo/Bar.java"); FileUtils.touch(srcFile); when(fs.baseDir()).thenReturn(basedir); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, new Settings(), new FileMetadata()); DefaultInputFile inputFile = builder.create(srcFile); assertThat(inputFile).isNull();/*from www. j av a2 s. c o m*/ }
From source file:org.sonar.batch.scan.filesystem.InputFileBuilderTest.java
@Test public void return_null_if_language_not_detected() throws Exception { // file system File basedir = temp.newFolder(); File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); FileUtils.touch(srcFile); FileUtils.write(srcFile, "single line"); when(fs.baseDir()).thenReturn(basedir); when(fs.encoding()).thenReturn(StandardCharsets.UTF_8); // lang/* ww w.java 2s . c o m*/ when(langDetection.language(any(InputFile.class))).thenReturn(null); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, new Settings(), new FileMetadata()); DefaultInputFile inputFile = builder.create(srcFile); inputFile = builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN); assertThat(inputFile).isNull(); }
From source file:org.sonar.ce.log.CeLoggingTest.java
@Test public void getFile() throws IOException { Settings settings = newSettings(dataDir, 10); CeLogging underTest = new CeLogging(settings); LogFileRef ref = new LogFileRef("TYPE1", "TASK1", "COMPONENT1"); // file does not exist Optional<File> file = underTest.getFile(ref); assertThat(file.isPresent()).isFalse(); File logFile = new File(dataDir, "ce/logs/" + ref.getRelativePath()); FileUtils.touch(logFile); file = underTest.getFile(ref);/*from w w w . j a va2 s.co m*/ assertThat(file.isPresent()).isTrue(); assertThat(file.get()).isEqualTo(logFile); }
From source file:org.sonar.ce.log.CeLoggingTest.java
@Test public void delete_oldest_files_of_same_directory_to_keep_only_max_allowed_files() throws IOException { for (int i = 1; i <= 5; i++) { File file = new File(dataDir, format("U%d.log", i)); FileUtils.touch(file); // see javadoc: "all platforms support file-modification times to the nearest second, // but some provide more precision" --> increment by second, not by millisecond file.setLastModified(1_450_000_000_000L + i * 1000); }//from w ww . j a va 2 s . co m assertThat(dataDir.listFiles()).hasSize(5); // keep 3 files in each dir CeLogging underTest = new CeLogging(newSettings(dataDir, 3)); underTest.purgeDir(dataDir); assertThat(dataDir.listFiles()).hasSize(3); assertThat(dataDir.listFiles()).extracting("name").containsOnly("U3.log", "U4.log", "U5.log"); }
From source file:org.sonar.ce.log.CeLoggingTest.java
@Test public void do_not_delete_files_if_dir_has_less_files_than_max_allowed() throws IOException { FileUtils.touch(new File(dataDir, "U1.log")); CeLogging underTest = new CeLogging(newSettings(dataDir, 5)); underTest.purgeDir(dataDir);/* w ww . j a va 2 s . c o m*/ assertThat(dataDir.listFiles()).extracting("name").containsOnly("U1.log"); }
From source file:org.sonar.ce.log.CeLoggingTest.java
@Test public void do_not_keep_any_logs() throws IOException { FileUtils.touch(new File(dataDir, "U1.log")); CeLogging underTest = new CeLogging(newSettings(dataDir, 0)); underTest.purgeDir(dataDir);//from w w w. j av a2 s . c om assertThat(dataDir.listFiles()).isEmpty(); }
From source file:org.sonar.cxx.sensors.utils.CxxReportPatternMatchingTest.java
private void setupExample(String pathes) throws java.io.IOException { String[] parsedPaths = pathes.split(","); for (String path : parsedPaths) { path = path.trim();//w w w . j a v a 2s.c o m if (!path.isEmpty()) { FileUtils.touch(new File(base.getRoot(), path)); } } }
From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java
@Test public void testAbsoluteInsideBasedir() throws IOException { File absReportFile = new File(base.getRoot(), "path/to/report.xml").getAbsoluteFile(); FileUtils.touch(absReportFile); settings.setProperty(REPORT_PATH_KEY, absReportFile.toString()); List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY); assertThat(reports.size()).isEqualTo(1); }