List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.sonar.plugins.cxx.utils.CxxReportSensor_getReports_Test.java
@Test public void testAbsoluteOutsideBasedirWithGlobbingAndRelativeWithGlobbing() throws IOException { File absReportsProject = TestUtils.loadResource("/org/sonar/plugins/cxx/reports-project").getAbsoluteFile(); File absReportFile = new File(absReportsProject, "cppcheck-reports/cppcheck-result-SAMPLE-*.xml"); FileUtils.touch(new File(base.getRoot(), "report.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/supercoolreport.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/a/report.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/some/reports/1.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/some/reports/2.xml")); Settings settings = new Settings(); settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + ",**/*.xml"); List<File> reports = sensor.getReports(settings, base.getRoot(), REPORT_PATH_KEY); assertEquals(7, reports.size());/*from w w w . j a va2 s. co m*/ }
From source file:org.sonar.plugins.cxx.utils.CxxReportSensor_getReports_Test.java
@Test public void testAbsoluteOutsideBasedirWithGlobbingAndNestedRelativeWithGlobbing() throws IOException { File absReportsProject = TestUtils.loadResource("/org/sonar/plugins/cxx/reports-project").getAbsoluteFile(); File absReportFile = new File(absReportsProject, "cppcheck-reports/cppcheck-result-SAMPLE-*.xml"); FileUtils.touch(new File(base.getRoot(), "path/to/supercoolreport.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/a/report.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/some/reports/1.xml")); FileUtils.touch(new File(base.getRoot(), "path/to/some/reports/2.xml")); Settings settings = new Settings(); settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + ",path/**/*.xml"); List<File> reports = sensor.getReports(settings, base.getRoot(), REPORT_PATH_KEY); assertEquals(6, reports.size());//from w ww . j a v a2 s . c o m }
From source file:org.sonar.process.ProcessCommands.java
private void createFile(File file) { try {/* ww w.java2 s. c o m*/ FileUtils.touch(file); } catch (IOException e) { throw new IllegalStateException(String.format("Fail to create file %s", file), e); } }
From source file:org.sonar.process.ProcessCommandsTest.java
@Test public void delete_files_on_prepare() throws Exception { File dir = temp.newFolder();//from ww w. j a va2s . c om assertThat(dir).exists(); FileUtils.touch(new File(dir, "web.ready")); FileUtils.touch(new File(dir, "web.stop")); ProcessCommands commands = new ProcessCommands(dir, "web"); commands.prepare(); assertThat(commands.getReadyFile()).doesNotExist(); assertThat(commands.getStopFile()).doesNotExist(); }
From source file:org.sonar.scanner.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/*from w w w. j a v a2 s . c o 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 MapSettings(), 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.scanner.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 MapSettings(), new FileMetadata()); DefaultInputFile inputFile = builder.create(srcFile); assertThat(inputFile).isNull();/*from w w w .ja v a2s . c om*/ }
From source file:org.sonar.scanner.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 . j a va2 s .co m*/ when(langDetection.language(any(InputFile.class))).thenReturn(null); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, new MapSettings(), new FileMetadata()); DefaultInputFile inputFile = builder.create(srcFile); inputFile = builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN); assertThat(inputFile).isNull(); }
From source file:org.sonar.scanner.scan.filesystem.MetadataGeneratorTest.java
@Test public void complete_input_file() throws Exception { // file system Path baseDir = temp.newFolder().toPath(); Path srcFile = baseDir.resolve("src/main/java/foo/Bar.java"); FileUtils.touch(srcFile.toFile()); FileUtils.write(srcFile.toFile(), "single line"); // status/* www . ja v a2 s . co m*/ when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) .thenReturn(InputFile.Status.ADDED); InputFile inputFile = createInputFileWithMetadata(baseDir, "src/main/java/foo/Bar.java"); assertThat(inputFile.type()).isEqualTo(InputFile.Type.MAIN); assertThat(inputFile.file()).isEqualTo(srcFile.toFile()); assertThat(inputFile.absolutePath()).isEqualTo(PathUtils.sanitize(srcFile.toAbsolutePath().toString())); 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.server.app.TomcatContextsTest.java
@Test public void cleanup_static_directory_if_already_exists() throws Exception { File dir = temp.newFolder();//from w w w .j ava2 s . com FileUtils.touch(new File(dir, "foo.txt")); underTest.addStaticDir(tomcat, "/deploy", dir); assertThat(dir).isDirectory().exists(); assertThat(dir.listFiles()).isEmpty(); }
From source file:org.sonar.server.computation.ReportFilesTest.java
@Test public void deleteIfExists() throws IOException { File report = new File(reportDir, "TASK_1.zip"); FileUtils.touch(report); assertThat(report).exists();/*from w ww . java2 s . co m*/ underTest.deleteIfExists("TASK_1"); assertThat(report).doesNotExist(); }