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:com.athomas.androidkickstartr.util.ResourcesUtils.java

public static void copyResourcesTo(File resourcesDir, String filepathMarker) throws IOException {

    if (resourcesDir == null) {
        throw new IllegalArgumentException("The resources dir must not be null");
    }/*  w ww .j  a  v  a2 s .  c  o  m*/

    ClassLoader classLoader = ResourcesUtils.class.getClassLoader();
    URL url = classLoader.getResource(filepathMarker);
    String protocol = url.getProtocol();

    if (protocol.equals("file")) {
        File src = new File("src/main/resources");
        FileUtils.copyDirectory(src, resourcesDir);
    } else if (protocol.equals("jar")) {
        copyResourcesToFromJar(resourcesDir, url);
    }
}

From source file:msi.gama.doc.util.PrepareEnv.java

private static void copyPythonTemplate() throws IOException {
    File pythonTemplate = new File(Constants.PYTHON_TEMPLATE_FOLDER);
    FileUtils.copyDirectory(pythonTemplate, new File(Constants.WIKI2WIKI_FOLDER));
}

From source file:com.stratio.crossdata.connector.plugin.installer.InstallerGoalLauncher.java

public static void launchInstallerGoal(InstallerGoalConfig config, Log log) throws IOException {

    log.info("Create TARGET directory.");
    File targetDirectory = new File(
            FilenameUtils.concat(config.getOutputDirectory(), config.getConnectorName()));
    if (targetDirectory.exists()) {
        log.info("Remove previous TARGET directory");
        FileUtils.forceDelete(targetDirectory);
    }/*from w  ww  .j  a v a  2 s.  co m*/
    File includeConfigDirectory = new File(config.getIncludeDirectory());
    FileUtils.copyDirectory(includeConfigDirectory, targetDirectory);

    log.info("Create LIB directory.");
    File libDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "lib"));
    FileUtils.copyFileToDirectory(config.getMainJarRepo(), libDirectory);
    for (File jarFile : config.getDependenciesJarRepo()) {
        FileUtils.copyFileToDirectory(jarFile, libDirectory);
    }

    log.info("Create CONF directory.");
    File confDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "conf"));
    File confConfigDirectory = new File(config.getConfigDirectory());
    FileUtils.copyDirectory(confConfigDirectory, confDirectory);

    log.info("Create BIN Directory");
    File binDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "bin"));
    FileUtils.forceMkdir(binDirectory);

    log.info("Launch template");
    String outputString = (config.getUnixScriptTemplate());
    outputString = outputString.replaceAll("<name>", config.getConnectorName());
    outputString = outputString.replaceAll("<desc>", config.getDescription());
    String user = config.getUserService();
    if (config.isUseCallingUserAsService()) {
        user = System.getProperty("user.name");
    }
    outputString = outputString.replaceAll("<user>", user);
    outputString = outputString.replaceAll("<mainClass>", config.getMainClass());
    int index = config.getMainClass().lastIndexOf('.');
    String className = config.getMainClass();
    if (index != -1) {
        className = config.getMainClass().substring(index + 1);
    }
    outputString = outputString.replaceAll("<mainClassName>", className);

    outputString = outputString.replaceAll("<jmxPort>", config.getJmxPort());
    String pidFileName = "";
    if (config.getPidFileName() != null) {
        pidFileName = config.getPidFileName();
    }
    outputString = outputString.replaceAll("<pidFileName>", pidFileName);

    File binFile = new File(FilenameUtils.concat(binDirectory.toString(), config.getConnectorName()));
    FileUtils.writeStringToFile(binFile, outputString);
    if (!binFile.setExecutable(true)) {
        throw new IOException("Can't change executable option.");
    }

    log.info("Process complete: " + targetDirectory);
}

From source file:de.akquinet.innovation.play.maven.Helper.java

public static void copyScalaApp(File out) throws IOException {
    if (out.exists()) {
        FileUtils.deleteQuietly(out);//  w  ww .  j  ava2  s.co m
    }
    out.mkdirs();

    FileUtils.copyDirectory(SCALA_APP_ROOT, out);
}

From source file:com.jr2016.copynonemptydirectory.CopyNonEmptyDirectoryUsingApache.java

public static void copyDirectoryUsingApache(String from, String to) throws IOException {
    File source = new File(from);
    File target = new File(to);
    FileUtils.copyDirectory(source, target);
}

From source file:io.spikex.core.integration.MainTest.java

@BeforeClass
public static void init() throws IOException {
    Path nodeRepoPath1 = Paths.get("build/resources/test/node1/repo");
    Path nodeRepoPath2 = Paths.get("build/resources/test/node2/repo");
    Files.createDirectories(nodeRepoPath1);
    Files.createDirectories(nodeRepoPath2);

    // Copy repo to node home directories
    // The repos are defined in repos.txt that is found on the classpath
    Path repoPath = Paths.get("build/resources/test/repo");
    FileUtils.copyDirectory(repoPath.toFile(), nodeRepoPath1.toFile());
    FileUtils.copyDirectory(repoPath.toFile(), nodeRepoPath2.toFile());

    //        System.out.println(ClassLoader.getSystemClassLoader().getResource(".").getPath());
}

From source file:com.batchiq.nifi.executescript.samples.BaseScriptTest.java

/**
 * Copies all scripts to the target directory because when they are compiled they can leave unwanted .class files.
 *
 * @throws Exception Any error encountered while testing
 *///from ww  w.j av a  2 s. c om
@BeforeClass
public static void setupBeforeClass() throws Exception {
    FileUtils.copyDirectory(new File("src/test/resources"), new File("target/test/resources"));
}

From source file:ch.elexis.importer.div.Helpers.java

static Path copyRscToTempDirectory() {
    Path path = null;/*from  ww  w .  j a v a  2  s .c  om*/
    try {
        path = Files.createTempDirectory("HL7_Test");
        File src = new File(PlatformHelper.getBasePath("ch.elexis.core.ui.importer.div.tests"), "rsc");
        System.out.println("src: " + src.toString());
        FileUtils.copyDirectory(src, path.toFile());
    } catch (IOException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    return path;
}

From source file:com.streamsets.pipeline.cluster.ClusterFunctionImpl.java

private static synchronized void initialize(Properties properties, Integer id, String rootDataDir)
        throws Exception {
    if (initialized) {
        return;//from  w w w  . ja  va2 s.c om
    }
    File dataDir = new File(System.getProperty("user.dir"), "data");
    FileUtils.copyDirectory(new File(rootDataDir), dataDir);
    System.setProperty("sdc.data.dir", dataDir.getAbsolutePath());
    // must occur before creating the EmbeddedSDCPool as
    // the hdfs target validation evaluates the sdc:id EL
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMinimumIntegerDigits(6);
    numberFormat.setGroupingUsed(false);
    final String sdcId = numberFormat.format(id);
    Utils.setSdcIdCallable(new Callable<String>() {
        @Override
        public String call() {
            return sdcId;
        }
    });
    sdcPool = new EmbeddedSDCPool(properties);
    initialized = true;
}

From source file:mx.itesm.imb.ImbBusController.java

@SuppressWarnings("unchecked")
public static void generateImbBusController(final File rooProject, final File busProject) {
    Writer writer;//from   w ww.ja v  a2  s.c  o m
    File typeReference;
    File controllerFile;
    int basePackageIndex;
    String imbTypePackage;
    String webConfiguration;
    VelocityContext context;
    Collection<String> types;
    String controllerPackage;
    Iterator<File> typesIterator;

    try {
        // Copy imb types
        FileUtils.copyDirectory(new File(rooProject, "/src/main/java/imb"),
                new File(busProject, "/src/main/java/imb"));
        FileUtils.copyFile(new File(rooProject, "/src/main/resources/schema.xsd"),
                new File(busProject, "/src/main/resources/schema.xsd"));

        imbTypePackage = null;
        types = new ArrayList<String>();
        typesIterator = FileUtils.iterateFiles(new File(busProject, "/src/main/java/imb"),
                new String[] { "java" }, true);
        while (typesIterator.hasNext()) {
            typeReference = typesIterator.next();
            if ((!typeReference.getName().equals("ObjectFactory.java"))
                    && (!typeReference.getName().equals("package-info.java"))) {
                if (FileUtils.readFileToString(typeReference).contains("public class")) {
                    types.add(typeReference.getName().replace(".java", ""));
                    if (imbTypePackage == null) {
                        imbTypePackage = typeReference.getPath()
                                .substring(
                                        typeReference.getPath().indexOf("src/main/java")
                                                + "src/main/java".length() + 1,
                                        typeReference.getPath().indexOf(typeReference.getName()) - 1)
                                .replace(File.separatorChar, '.');
                    }
                }
            }
        }

        // Add rest configuration
        FileUtils.copyFile(
                new File(rooProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"),
                new File(busProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"));

        context = new VelocityContext();
        context.put("types", types);
        context.put("imbTypePackage", imbTypePackage);

        webConfiguration = FileUtils
                .readFileToString(new File(busProject, "src/main/webapp/WEB-INF/spring/webmvc-config.xml"));
        basePackageIndex = webConfiguration.indexOf("base-package=\"") + "base-package=\"".length();
        controllerPackage = webConfiguration.substring(basePackageIndex,
                webConfiguration.indexOf('"', basePackageIndex)) + ".web";
        context.put("controllerPackage", controllerPackage);
        context.put("typePackage", controllerPackage.replace(".web", ".domain"));
        controllerFile = new File(busProject,
                "/src/main/java/" + controllerPackage.replace('.', '/') + "/ImbBusController.java");
        writer = new FileWriter(controllerFile);
        ImbBusController.controllerTemplate.merge(context, writer);
        writer.close();
    } catch (Exception e) {
        System.out.println("Error while configuring IMB Bus: " + e.getMessage());
    }
}