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:io.apigee.buildTools.enterprise4g.mavenplugin.ConfigureMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {

    if (super.isSkip()) {
        getLog().info("Skipping");
        return;/*w  ww .  ja  v  a 2 s.c o m*/
    }

    Logger logger = LoggerFactory.getLogger(ConfigureMojo.class);
    File configFile = findConfigFile(logger);

    if (configFile != null) {
        configurePackage(logger, configFile);
    }

    logger.info("\n\n=============Checking for node.js app================\n\n");
    //sometimes node.js source lives outside the apiproxy/ in node/ within the base project directory
    String externalNodeDirPath = super.getBaseDirectoryPath() + "/node/";
    File externalNodeDir = new File(externalNodeDirPath);

    //if node.js source is inside apiproxy/ directory, it will be in the build directory
    String nodeDirPath = super.getBuildDirectory() + "/apiproxy/resources/node/";
    File nodeDir = new File(nodeDirPath);

    //if we find files in the node/ directory outside apiproxy/, move into apiproxy/resources/node
    //this takes precedence and we will overwrite potentially stale node.js code in  apiproxy/resources/node
    if (externalNodeDir.isDirectory()) {
        String[] filesInExternalNodeDir = externalNodeDir.list();
        if (filesInExternalNodeDir.length > 0) {
            logger.info(
                    "Node.js app code found outside apiproxy/ directory. Moving to target/apiproxy/resources/node (will overwrite).");
            try {
                FileUtils.deleteDirectory(nodeDir);
                FileUtils.copyDirectory(externalNodeDir, nodeDir);
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage());
            }
        }
    }

    //always handle zipping of any directories in apiproxy/resources/node
    if (nodeDir.isDirectory()) {
        logger.info("\n\n=============Now zipping node modules================\n\n");

        String[] filesInNodeDir = nodeDir.list();

        for (String fileName : filesInNodeDir) {
            String filePath = nodeDirPath + fileName;
            File dirFile = new File(filePath);
            if (dirFile.isDirectory() && fileName.contains("node_modules")) {
                logger.info("Zipping " + fileName + " (it is a directory).");
                try {
                    ZipUtils zu = new ZipUtils();
                    zu.zipDir(new File(filePath + ".zip"), dirFile, fileName);
                    FileUtils.deleteDirectory(dirFile);
                } catch (Exception e) {
                    throw new MojoExecutionException(e.getMessage());
                }
            }
        }

    }

    logger.info("\n\n=============Now zipping the App Bundle================\n\n");

    try {
        ZipUtils zu = new ZipUtils();
        zu.zipDir(new File(super.getApplicationBundlePath()), new File(super.getBuildDirectory() + "/apiproxy"),
                "apiproxy");
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage());
    }
}

From source file:com.diffplug.gradle.CmdLine.java

/** Removes the given file or directory. */
public void copy(File src, File dst) {
    run(() -> {//w w  w  .  j av  a 2  s.  c o m
        if (!src.exists()) {
            throw new IllegalArgumentException("copy failed: " + src.getAbsolutePath() + " does not exist.");
        }

        if (src.isDirectory()) {
            FileUtils.copyDirectory(src, dst);
        } else {
            FileUtils.copyFile(src, dst);
        }
    });
}

From source file:gov.usgs.cida.coastalhazards.rest.data.util.MetadataUtilTest.java

@Before
public void setUp() throws IOException, URISyntaxException {
    String packagePath = "/";
    FileUtils.copyDirectory(new File(getClass().getResource(packagePath).toURI()), workDir);

}

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

@Before
public void setUp() throws FileNotFoundException, RepositoryException, IOException {
    n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH);
    o.setPackage_type(CB_PACKAGETYPE_EAD);
    action.setWorkArea(new WorkArea(n, o));
    Map<String, String> edmMappings = new HashMap<String, String>();
    edmMappings.put(CB_PACKAGETYPE_EAD, EAD_TO_EDM_XSL);
    edmMappings.put(CB_PACKAGETYPE_METS, METS_MODS_TO_EDM_XSL);
    action.setEdmMappings(edmMappings);/*  w w w . ja va  2 s.  co m*/
    action.setRepositoryFacade(mock(Fedora3RepositoryFacade.class));

    FileUtils.copyDirectory(Path.makeFile(WORK_AREA_ROOT_PATH, "_" + WorkArea.PIPS),
            Path.makeFile(WORK_AREA_ROOT_PATH, WorkArea.PIPS));

}

From source file:net.sourceforge.lept4j.util.LoadLibs.java

/**
 * Extracts Leptonica resources to temp folder.
 *
 * @param dirname resource location//  w  w w  .  j a  v  a  2 s . c o m
 * @return target location
 */
public static File extractNativeResources(String dirname) {
    File targetTempDir = null;

    try {
        targetTempDir = new File(LEPT4J_TEMP_DIR, dirname);

        URL leptResourceUrl = LoadLibs.class.getResource(dirname.startsWith("/") ? dirname : "/" + dirname);
        if (leptResourceUrl == null) {
            return null;
        }

        URLConnection urlConnection = leptResourceUrl.openConnection();

        /**
         * Either load from resources from jar or project resource folder.
         */
        if (urlConnection instanceof JarURLConnection) {
            copyJarResourceToDirectory((JarURLConnection) urlConnection, targetTempDir);
        } else {
            FileUtils.copyDirectory(new File(leptResourceUrl.getPath()), targetTempDir);
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, e.getMessage(), e);
    }

    return targetTempDir;
}

From source file:com.linkedin.pinot.tools.admin.command.StarTreeOnHeapToOffHeapConverter.java

@Override
public boolean execute() throws Exception {
    File indexDir = new File(_segmentDir);
    long start = System.currentTimeMillis();

    LOGGER.info("Loading segment {}", indexDir.getName());
    IndexSegment segment = Loaders.IndexSegment.load(indexDir, ReadMode.heap);

    long end = System.currentTimeMillis();
    LOGGER.info("Loaded segment {} in {} ms ", indexDir.getName(), (end - start));

    start = end;//from w w w  .  j a va2  s  . c  o  m
    StarTreeInterf starTreeOnHeap = segment.getStarTree();
    File starTreeOffHeapFile = new File(TMP_DIR,
            (V1Constants.STAR_TREE_INDEX_FILE + System.currentTimeMillis()));

    // Convert the star tree on-heap to off-heap format.
    StarTreeSerDe.writeTreeOffHeapFormat(starTreeOnHeap, starTreeOffHeapFile);

    // Copy all the indexes into output directory.
    File outputDir = new File(_outputDir);
    FileUtils.deleteQuietly(outputDir);
    FileUtils.copyDirectory(indexDir, outputDir);

    // Delete the existing star tree on-heap file from the output directory.
    FileUtils.deleteQuietly(new File(_outputDir, V1Constants.STAR_TREE_INDEX_FILE));

    // Move the temp star tree off-heap file into the output directory.
    FileUtils.moveFile(starTreeOffHeapFile, new File(_outputDir, V1Constants.STAR_TREE_INDEX_FILE));
    end = System.currentTimeMillis();

    LOGGER.info("Converted segment: {} ms", (end - start));
    return true;
}

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

@SuppressWarnings("unchecked")
@Before/* w ww.ja  v a2  s  . com*/
public void setUp() throws IOException, FileFormatException {
    HibernateUtil.init("src/main/xml/hibernateCentralDB.cfg.xml.inmem");

    FileUtils.copyDirectory(Path.makeFile(TEST_CONTRACTOR_WORK_FOLDER, IDENTIFIER + "_"),
            Path.makeFile(TEST_CONTRACTOR_WORK_FOLDER, IDENTIFIER));

    n.setWorkAreaRootPath(WORK_AREA_ROOT_PATH);

    action.setLocalNode(n);
    grid = new FakeGridFacade();
    grid.setGridCacheAreaRootPath("/tmp/");
    action.setGridRoot(grid);

    gate = mock(IngestGate.class);
    when(gate.canHandle((Long) anyObject())).thenReturn(true);
    JmsMessageServiceHandler jms = mock(JmsMessageServiceHandler.class);
    action.setJmsMessageServiceHandler(jms);
    action.setIngestGate(gate);

    FileFormatFacade ffs = mock(ConfigurableFileFormatFacade.class);

    DAFile file = new DAFile("rep+a", "140849.tif");
    file.setFormatPUID("fmt/353");
    List<FileWithFileFormat> files = new ArrayList<FileWithFileFormat>();
    files.add(file);
    when(ffs.identify((Path) anyObject(), (List<FileWithFileFormat>) anyObject(), anyBoolean()))
            .thenReturn(files);
    action.setFileFormatFacade(ffs);
}

From source file:com.truven.report.reporter.Reporter.java

/**
 * Copy report helper files.//from w  w  w  .  j  a v  a 2  s  . c om
 *
 * @param reportFolderStr the report folder str
 */
private void copyReportHelperFiles(final String reportFolderStr) {
    /*File reportTemplateHtml =
        new File(new File("src" + File.separator + "main"
                + File.separator + "resources" + File.separator
                + "ReportTemplate").getAbsolutePath());*/
    File reportTemplateHtml = new File(new File("ReportTemplate").getAbsolutePath());

    /*File reportTemplateHtml =
        new File(new File("ReportTemplate").getAbsolutePath());*/
    File reportFolder = new File(reportFolderStr);
    try {
        FileUtils.copyDirectory(reportTemplateHtml, reportFolder);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.dragovorn.dragonbot.api.bot.file.FileManager.java

public static void setDirectory(String directory) {
    File file = new File(directory, "Dragon Bot");

    if (FileManager.directory.exists() && !file.exists()) {
        if (file.mkdirs()) {
            try {
                FileUtils.copyDirectory(FileManager.directory, file);
            } catch (IOException exception) {
                exception.printStackTrace();
            }//from  www  .  ja v  a 2 s .c  o m
        } else {
            throw new RuntimeException("Unable to create file: " + file.getName()); // FIXME: 11/23/16 make custom exception
        }

        try {
            FileUtils.deleteDirectory(FileManager.directory);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    FileManager.directory = file;

    File path = new File(FileManager.dir, "path");

    try {
        FileWriter fileWriter = new FileWriter(path);

        BufferedWriter writer = new BufferedWriter(fileWriter);

        writer.write(directory);

        writer.close();
        fileWriter.close();
    } catch (IOException exception) {
        exception.printStackTrace();
    }

    reloadFiles();
}

From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetCompilationHandler.java

public void run() {
    File tmpDir = null;/* w  w  w.jav  a  2 s.  c om*/
    try {
        tmpDir = WidgetsetUtil.createTempDir();

        WidgetsetUtil.createWidgetset(tmpDir, widgetset, getIncludeWidgetsets());

        compiler = new WidgetsetCompiler(outputLog, widgetset, tmpDir.getAbsolutePath(),
                getClasspathEntries(tmpDir));

        try {
            compiler.compileWidgetset();
        } catch (InterruptedException e1) {
            Thread.currentThread().interrupt();
        }

        File compiledWidgetset = new File(tmpDir, widgetset);
        if (compiledWidgetset.exists() && compiledWidgetset.isDirectory()) {
            String ws = ControlPanelPortletUtil.getWidgetsetDir() + widgetset;
            WidgetsetUtil.rotateWidgetsetBackups(ws);
            WidgetsetUtil.backupOldWidgetset(ws);
            File destDir = new File(ws);

            outputLog.log("Copying widgetset from " + compiledWidgetset + " to " + destDir);

            System.out.println("Copying widgetset from " + compiledWidgetset + " to " + destDir);

            FileUtils.copyDirectory(compiledWidgetset, destDir);

            outputLog.log("Copying done");
            System.out.println("Copying done");
        }

    } catch (IOException e) {
        log.warn("Could not compile widgetsets.", e);
        System.out.println("Could not compile widgetsets. " + e.getMessage());
    } finally {
        try {
            System.out.println("Remove temp directory");
            FileUtils.deleteDirectory(tmpDir);
            System.out.println("Removing done...");
        } catch (IOException e) {
            log.warn("Could not delete temporary directory: " + tmpDir, e);
            System.out.println("Could not delete temporary directory: " + tmpDir + "  " + e);
        }

        compilationFinished();
    }
}