Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java

@Test
public void testAbsoluteOutsideBasedirAndRelative() throws IOException {
    File absReportsProject = TestUtils.loadResource("/org/sonar/cxx/sensors/reports-project").getAbsoluteFile();
    File absReportFile = new File(absReportsProject, "cppcheck-reports/cppcheck-result-SAMPLE-V2.xml");

    String relativeReport = "path/to/report.xml";
    FileUtils.touch(new File(base.getRoot(), relativeReport));

    settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + "," + relativeReport);

    List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY);
    assertThat(reports.size()).isEqualTo(2);
}

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java

@Test
public void testAbsoluteOutsideBasedirWithGlobbingAndRelativeWithGlobbing() throws IOException {
    File absReportsProject = TestUtils.loadResource("/org/sonar/cxx/sensors/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"));
    FileUtils.touch(new File(base.getRoot(), "some/reports/a"));
    FileUtils.touch(new File(base.getRoot(), "some/reports/b"));

    settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + ",**/*.xml");

    List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY);
    assertThat(reports.size()).isEqualTo(7);
}

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java

@Test
public void testAbsoluteOutsideBasedirWithGlobbingAndNestedRelativeWithGlobbing() throws IOException {
    File absReportsProject = TestUtils.loadResource("/org/sonar/cxx/sensors/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"));
    FileUtils.touch(new File(base.getRoot(), "some/reports/a.xml"));
    FileUtils.touch(new File(base.getRoot(), "some/reports/b.xml"));

    settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + ",path/**/*.xml");

    List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY);
    assertThat(reports.size()).isEqualTo(6);
}

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java

@Test
public void testRelativeBackticksOutsideBasedirThenBackInside() throws IOException {
    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.setProperty(REPORT_PATH_KEY, "../" + base.getRoot().getName() + "/path/**/*.xml");

    List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY);
    assertThat(reports.size()).isEqualTo(4);
}

From source file:org.sonar.cxx.sensors.utils.CxxReportSensor_getReports_Test.java

@Test
public void testRelativeExcessiveBackticks() throws IOException {
    FileUtils.touch(new File(base.getRoot(), "path/to/supercoolreport.xml"));

    // Might be valid if java.io.tmpdir is nested excessively deep -- not likely    
    settings.setProperty(REPORT_PATH_KEY,
            "../../../../../../../../../../../../../../../../../../../../../../../../"
                    + "../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../"
                    + "../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../"
                    + "../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../*.xml");

    List<File> reports = CxxReportSensor.getReports(settings.asConfig(), base.getRoot(), REPORT_PATH_KEY);
    assertThat(reports.size()).isEqualTo(0);
}

From source file:org.sonar.oracleforms.plsql.SettingsTest.java

@Test
public void default_forms_files() throws Exception {
    File input = temp.newFolder("forms-sources");
    File forms1 = new File(input, "foo.fmb");
    FileUtils.touch(forms1);
    File forms2 = new File(input, "bar.pll");
    FileUtils.touch(forms2);//www  .  j  av  a2s  .com
    File other = new File(input, "other.forms");
    FileUtils.touch(other);

    File output = temp.newFolder("plsql-sources");
    Properties props = new Properties();
    props.setProperty("inputDir", input.getAbsolutePath());
    props.setProperty("outputDir", output.getAbsolutePath());

    Settings settings = new Settings(props);

    assertThat(settings.formsFiles()).containsOnly(forms1, forms2);
}

From source file:org.sonar.oracleforms.plsql.SettingsTest.java

@Test
public void customized_forms_files() throws Exception {
    File input = temp.newFolder("forms-sources");
    File forms1 = new File(input, "foo.fmb");
    FileUtils.touch(forms1);
    File forms2 = new File(input, "bar.forms");
    FileUtils.touch(forms2);//w w  w.j  av a2 s  .  c  o  m
    File other = new File(input, "other.txt");
    FileUtils.touch(other);

    File output = temp.newFolder("plsql-sources");
    Properties props = new Properties();
    props.setProperty("inputDir", input.getAbsolutePath());
    props.setProperty("outputDir", output.getAbsolutePath());
    props.setProperty("formsExtensions", "fmb,pll,forms");

    Settings settings = new Settings(props);

    assertThat(settings.formsFiles()).containsOnly(forms1, forms2);
}

From source file:org.sonar.plugins.cxx.utils.CxxReportSensor_getReports_Test.java

private void setupExample(String pathes) throws java.io.IOException {
    String[] parsedPaths = StringUtils.split(pathes, ",");
    for (String path : parsedPaths) {
        FileUtils.touch(new File(base.getRoot(), path.trim()));
    }/*from  w  w  w. j  ava  2  s  . c  o  m*/
}

From source file:org.sonar.plugins.cxx.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 settings = new Settings();
    settings.setProperty(REPORT_PATH_KEY, absReportFile.toString());

    List<File> reports = sensor.getReports(settings, base.getRoot(), REPORT_PATH_KEY);
    assertEquals(1, 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 testAbsoluteOutsideBasedirAndRelative() throws IOException {
    File absReportsProject = TestUtils.loadResource("/org/sonar/plugins/cxx/reports-project").getAbsoluteFile();
    File absReportFile = new File(absReportsProject, "cppcheck-reports/cppcheck-result-SAMPLE-V2.xml");

    String relativeReport = "path/to/report.xml";
    FileUtils.touch(new File(base.getRoot(), relativeReport));

    Settings settings = new Settings();
    settings.setProperty(REPORT_PATH_KEY, absReportFile.toString() + "," + relativeReport);

    List<File> reports = sensor.getReports(settings, base.getRoot(), REPORT_PATH_KEY);
    assertEquals(2, reports.size());/*  w  ww .  j  a v a 2s  .c  om*/
}