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

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

Introduction

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

Prototype

public static void copyDirectory(File srcDir, File destDir) throws IOException 

Source Link

Document

Copies a whole directory to a new location preserving the file dates.

Usage

From source file:me.neatmonster.spacertk.actions.FileActions.java

/**
 * Copy's a directory to another directory
 * @param oldDirectory Directory to copy
 * @param newDirectory Directory to copy to
 * @return If successful/*from w w w.  j  a  va 2s. c o m*/
 */
@Action(aliases = { "copyDirectory", "copyDir" })
public boolean copyDirectory(final String oldDirectory, final String newDirectory) {
    try {
        FileUtils.copyDirectory(new File(oldDirectory), new File(newDirectory));
        return true;
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java

protected Server createServer(int port, String displayName) throws Exception {
    FileUtils.deleteDirectory(new File("target/repo" + displayName));
    System.setProperty("simplerepo.root", "target/repo" + displayName);
    File repoRoot = new File("target/repo" + displayName);
    repoRoot.mkdirs();//w w w  .ja va  2  s  .c o  m
    Files.write(new File(repoRoot, "config.properties").toPath(), Arrays.asList("plugins="),
            StandardCharsets.UTF_8);
    Server server = new Server(port);
    FileUtils.copyDirectory(new File("src/main/webapp"), new File("target/server"));
    WebAppContext app = new WebAppContext("target/server", "/simple-repo");
    app.setAttribute("contextName", displayName);
    app.setExtractWAR(true);
    app.getSecurityHandler()
            .setLoginService(new HashLoginService("Test realm", "src/test/resources/realm.properties"));
    app.setDisplayName(displayName);
    server.setHandler(app);
    server.start();
    return server;
}

From source file:azkaban.utils.FileIOUtilsTest.java

@Before
public void setUp() throws Exception {
    // setup base dir
    baseDir = temp.newFolder("base");
    File file1 = new File(baseDir.getAbsolutePath() + "/a.out");
    File file2 = new File(baseDir.getAbsolutePath() + "/testdir");
    File file3 = new File(file2.getAbsolutePath() + "/b.out");
    file1.createNewFile();//from ww  w .j a  v  a2s  . c  om
    file2.mkdir();
    file3.createNewFile();

    byte[] fileData = new byte[] { 1, 2, 3 };
    FileOutputStream out = new FileOutputStream(file1);
    out.write(fileData);
    out.close();

    fileData = new byte[] { 2, 3, 4 };
    out = new FileOutputStream(file3);
    out.write(fileData);
    out.close();

    sourceDir = temp.newFolder("src");
    FileUtils.copyDirectory(baseDir, sourceDir);

    // setup target dir
    destDir = temp.newFolder("dest");
}

From source file:gov.nih.nci.cabig.caaers.web.admin.CTEPESYSDataIntegrationLogDownloadControllerTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    controller = new CTEPDataIntegrationLogDownloadController();
    configuration = registerMockFor(Configuration.class);
    controller.setConfiguration(configuration);
    errors = registerMockFor(Errors.class);
    ESB_LOCATION = curDir.getCanonicalPath()
            + "\\web\\src\\test\\resources\\gov\\nih\\nci\\cabig\\caaers\\web\\admin\\testdata";
    String dirPath = ESB_LOCATION + File.separator + YEAR + File.separator + MONTH + File.separator
            + DAY_OF_MONTH + File.separator + ENTITY + File.separator + CORRELATION_ID;

    try {/*from w  w w  . j  a  va2  s. com*/
        Boolean dirCreated = new File(dirPath).mkdirs();
        File source = new File(ESB_LOCATION);
        File dest = new File(dirPath);
        FileUtils.copyDirectory(source, dest);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:de.uzk.hki.da.cb.RestartIngestWorkflowActionTests.java

@Before
public void setUp() throws IOException {
    FileUtils.copyDirectory(Path.makeFile(WORK_AREA_ROOT_PATH, WorkArea.WORK + UNDERSCORE),
            Path.makeFile(WORK_AREA_ROOT_PATH, WorkArea.WORK));

    FileUtils.copyDirectory(Path.makeFile(WORK_AREA_ROOT_PATH, UNDERSCORE + WorkArea.PIPS),
            pipsFolder.toFile());/*from w  w  w  .ja  v  a  2  s.co  m*/

    n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH);
    j.setRep_name(REP_NAME);
}

From source file:com.bealearts.livecycle.AppInfoMojo.java

/**
 * Execute the Mojo/*from w w  w.j av a2  s. c o m*/
 */
public void execute() throws MojoExecutionException {
    if (!this.buildDirectory.exists()) {
        if (!this.buildDirectory.mkdirs())
            throw new MojoExecutionException(
                    "Error creating output directory: " + this.buildDirectory.getAbsolutePath());
    }

    File classesFolder = new File(this.buildDirectory, "classes");

    try {
        FileUtils.copyDirectory(this.sourceDirectory, classesFolder);
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying source files", e);
    }

    LCAUtils lcaUtils = new LCAUtils(this.getLog());

    LCADefinition lcaDef;
    try {
        lcaDef = lcaUtils.parseSourceFiles(classesFolder);
    } catch (Exception e) {
        throw new MojoExecutionException("Error parsing source files", e);
    }
    lcaDef.setCreatedBy(this.createdBy);
    lcaDef.setDescription(this.description);

    InputStream lcaTemplate = this.getClass().getClassLoader().getResourceAsStream("app.info.template");

    String content;
    try {
        content = lcaUtils.renderAppInfo(lcaTemplate, lcaDef);
    } catch (IOException e) {
        throw new MojoExecutionException("Error loading template", e);
    }

    try {
        lcaUtils.writeAppInfo(classesFolder, content);
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing app.info file to: " + classesFolder.getAbsolutePath(),
                e);
    }
}

From source file:BuildIntegrationTest.java

@After
public void tearDown() {
    try {//  w  w  w .j  a  va  2 s.  c om
        System.out.println(
                ">>>>>>>>>>> Build Integration Test Complete, see results at \"build/reports/gnag-test-runs/"
                        + testProjectDir.getRoot().getName() + "\"");
        FileUtils.copyDirectory(testProjectDir.getRoot(),
                new File("build/reports/gnag-test-runs/", testProjectDir.getRoot().getName()));
    } catch (IOException ignored) {
    }
}

From source file:net.ftb.workers.RetiredPacksLoaderTest.java

@Test
public void fullMock() throws Exception {
    temporaryFolder = tf.newFolder();//ww w.  ja  va  2s . c  om
    FileUtils.copyDirectory(sourceFolder, temporaryFolder);
    loader = new RetiredPacksLoader(json.toURL(), temporaryFolder.getAbsolutePath(),
            temporaryFolder.getAbsolutePath());

    //*******************************************
    // fully mock Settings and ModPack classes with failing default answers
    //*******************************************
    Settings mockedSettings = Mockito.mock(Settings.class, new RuntimeExceptionAnswer());
    PowerMockito.mockStatic(Settings.class, new RuntimeExceptionAnswer());
    //not needed (yet) ModPack mockedModPack = Mockito.mock(ModPack.class, new RuntimeExceptionAnswer());
    PowerMockito.mockStatic(ModPack.class, new RuntimeExceptionAnswer());

    // mock singleton getter to return mocked instance of the Settings class
    // doReturn/doNothing/... is required instead of when() because we are re-stubbing methods
    PowerMockito.doReturn(mockedSettings).when(Settings.class, "getSettings");

    // *******************************************
    // mock functions which are called from CUT...
    //
    // TODO: * Write external classes for default mocking of Settings/Modpack/CommandLineArguments default mocking with sane default values
    //       * Move common stubs in @Setup
    //       * Add tests: e.g. return some pack code for Settings.getSettings().getPrivatePacks()
    // *******************************************
    //Mockito.doReturn(new ArrayList<String>()).when(mockedSettings).getPrivatePacks();
    PowerMockito.doNothing().when(ModPack.class, "loadXml", anyString());
    Mockito.doNothing().when(mockedSettings).addPrivatePack(anyString());
    Mockito.doNothing().when(mockedSettings).save();
    Mockito.doReturn(new ArrayList<String>()).when(mockedSettings).getPrivatePacks();
    //Mockito.doCallRealMethod().when(mockedSettings).finalize();

    // run the "thread"
    loader.run();

    // check if stubbed methods were called
    // TODO: check that functions are not called with other arguments
    PowerMockito.verifyStatic();
    ModPack.loadXml("RPGImmersion.xml");
    Mockito.verify(mockedSettings).addPrivatePack("RPGImmersion");
    Mockito.verify(mockedSettings).save();
}

From source file:ml.shifu.shifu.core.pmml.PMMLTranslatorTest.java

@Test
public void testAllNumericVariablePmmlCase() throws Exception {
    // Step 1. Eval the scores using SHIFU
    File originModel = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json");
    File tmpModel = new File("ModelConfig.json");

    File originColumn = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json");
    File tmpColumn = new File("ColumnConfig.json");

    File modelsDir = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models");
    File tmpModelsDir = new File("models");

    FileUtils.copyFile(originModel, tmpModel);
    FileUtils.copyFile(originColumn, tmpColumn);
    FileUtils.copyDirectory(modelsDir, tmpModelsDir);

    // run evaluation set
    ShifuCLI.runEvalScore("EvalA");
    File evalScore = new File("evals/EvalA/EvalScore");

    ShifuCLI.exportModel(null);//w w w  . jav a2  s .  c  om

    // Step 2. Eval the scores using PMML and compare it with SHIFU output

    String DataPath = "./src/test/resources/example/cancer-judgement/DataStore/Full_data/data.dat";
    String OutPath = "./pmml_out.dat";
    for (int index = 0; index < 5; index++) {
        String num = Integer.toString(index);
        String pmmlPath = "pmmls/cancer-judgement" + num + ".pmml";
        evalPmml(pmmlPath, DataPath, OutPath, "\\|", "model" + num);
        compareScore(evalScore, new File(OutPath), "model" + num, "\\|", 1.0);
        FileUtils.deleteQuietly(new File(OutPath));
    }

    FileUtils.deleteQuietly(tmpModel);
    FileUtils.deleteQuietly(tmpColumn);
    FileUtils.deleteDirectory(tmpModelsDir);

    FileUtils.deleteQuietly(new File("./pmmls"));
    FileUtils.deleteQuietly(new File("evals"));
}

From source file:de.uzk.hki.da.cb.FetchPIPsActionTest.java

@Before
public void setUp() throws IOException {
    n.setWorkAreaRootPath(TESTDIR);/*  ww  w.java 2 s  .c  o m*/

    distributedConversionAdapter = mock(FakeDistributedConversionAdapter.class);
    FileUtils.copyDirectory(Path.makeFile(TESTDIR, WorkArea.PIPS + UNDERSCORE),
            Path.makeFile(TESTDIR, WorkArea.PIPS));

    action.setDistributedConversionAdapter(distributedConversionAdapter);
}