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

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

Introduction

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

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:com.jslsolucoes.tagria.lib.compressor.Compressor.java

private void copyFileToDirectory(String resource) throws IOException {

    File root = new File(new File(source, resource), THEME);

    for (String theme : themes) {
        File themeFolder = new File(root, theme);
        if (!themeFolder.exists()) {
            themeFolder.mkdir();//from   www .  ja  v a2s  . c om
        }
        Stream.concat(Arrays.asList(new File(root, "base").listFiles()).stream(),
                Arrays.asList(themeFolder.listFiles()).stream()).forEach(file -> {
                    try {
                        FileUtils.copyFileToDirectory(file,
                                new File(new File(new File(destination, resource), THEME), theme));
                    } catch (Exception exception) {
                        throw new TagriaRuntimeException(exception);
                    }
                });
    }

}

From source file:com.xebialabs.deployit.maven.packager.ManifestPackager.java

public void addDeployableArtifact(DeployableArtifactItem item) {
    if ("Dar".equals(item.getType()))
        return;/*from   w ww  .  j a v  a2 s.  co  m*/

    if ("Pom".equals(item.getType()))
        return;

    final Map<String, Attributes> entries = manifest.getEntries();
    final Attributes attributes = new Attributes();
    final String type = item.getType();
    final File location = new File(item.getLocation());

    attributes.putValue("CI-Type", type);
    if (item.hasName())
        attributes.putValue("CI-Name", item.getName());

    String darLocation = (item.getDarLocation() == null ? type : item.getDarLocation());

    if (item.isFolder()) {
        entries.put(darLocation, attributes);
    } else {
        if (location.isAbsolute())
            entries.put(darLocation + "/" + location.getName(), attributes);
        else
            entries.put(darLocation + "/" + item.getLocation(), attributes);
    }

    final File targetDir = new File(targetDirectory, darLocation);
    if (generateManifestOnly) {
        System.out.println("Skip copying artifact " + item.getName() + " to " + targetDir);
        return;
    }
    targetDir.mkdirs();

    File locationTargetDirs;
    //do not create missing directories is there are no parents or if the file is absolute
    if (location.isAbsolute() || location.getParent() == null) {
        locationTargetDirs = targetDir;
    } else {
        locationTargetDirs = new File(targetDir, location.getParent());
        locationTargetDirs.mkdirs();
    }

    try {
        if (location.isDirectory()) {
            FileUtils.copyDirectoryToDirectory(location, locationTargetDirs);
        } else {
            FileUtils.copyFileToDirectory(location, locationTargetDirs);
        }
    } catch (IOException e) {
        throw new RuntimeException("Fail to copy of " + location + " to " + targetDir, e);

    }

}

From source file:net.sf.taverna.t2.maven.plugins.TavernaProfileGenerateMojo.java

private void copyDependencies() throws MojoExecutionException {
    File libDirectory = new File(tempDirectory, "lib");
    libDirectory.mkdirs();//from  w w w. ja v a  2 s .c  om

    try {
        for (Artifact artifact : project.getArtifacts()) {
            FileUtils.copyFileToDirectory(artifact.getFile(), new File(libDirectory, artifact.getGroupId()));
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying dependecies to lib directory", e);
    }

}

From source file:com.thruzero.test.support.AbstractCoreTestCase.java

/**
 * Copy the given file to a temporary directory, so that a test can be run multiple times without requiring a maven
 * clean.//www  .  jav a  2 s  . co m
 */
protected File copyFileToTemp(final String sourceFileName) {
    File result = null;

    try {
        File templateFile = getTestFile(sourceFileName);
        assertTrue("Source file named '" + sourceFileName + "' does not exist", templateFile.exists());

        File tempDir = new File(templateFile.getParentFile(), DEFAULT_TEMP_DIR_NAME);
        FileUtils.copyFileToDirectory(templateFile, tempDir);
        result = new File(tempDir, sourceFileName);
    } catch (IOException e) {
        fail("could not copy substitution test file to temp directory: " + e);
    }

    return result;
}

From source file:io.fabric8.vertx.maven.plugin.mojos.InitializeMojo.java

private void copyJSDependencies(Set<Artifact> dependencies) throws MojoExecutionException {
    for (Artifact artifact : dependencies) {
        if (artifact.getType().equalsIgnoreCase("js")) {
            Optional<File> file = getArtifactFile(artifact);
            if (file.isPresent()) {
                try {
                    if (stripJavaScriptDependencyVersion) {
                        String name = artifact.getArtifactId();
                        if (artifact.getClassifier() != null) {
                            name += "-" + artifact.getClassifier();
                        }//w w  w .  ja v a2  s.  c om
                        name += ".js";
                        File output = new File(createWebRootDirIfNeeded(), name);
                        FileUtils.copyFile(file.get(), output);
                    } else {
                        FileUtils.copyFileToDirectory(file.get(), createWebRootDirIfNeeded());
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to copy '" + artifact.toString() + "'", e);
                }
            } else {
                getLog().warn(
                        "Skipped the copy of '" + artifact.toString() + "' - The artifact file does not exist");
            }
        }
    }
}

From source file:com.us.util.FileHelper.java

/**
 * ?//* w  w w .j  av  a  2s  .c o  m*/
 * 
 * @param source /
 * @param target /
 */
public static void copy(File source, File target) {
    try {
        if (source.isDirectory() && target.isDirectory()) {
            FileUtils.copyDirectory(source, target);
        } else if (source.isFile() && target.isDirectory()) {
            FileUtils.copyFileToDirectory(source, target);
        } else if (source.isFile()) {
            FileUtils.copyFile(source, target);
        }
    } catch (IOException e) {
        log.error("?", e);
    }
}

From source file:fm.last.commons.io.LastFileUtilsTest.java

@Test
public void testMoveFileSafely() throws IOException {
    // first copy file from data folder to temp folder so it can be moved safely
    String filename = "3805bytes.log";
    File originalFile = dataFolder.getFile(filename);
    FileUtils.copyFileToDirectory(originalFile, tempFolder.getRoot());
    File inputFile = new File(tempFolder.getRoot(), filename);
    assertTrue(inputFile.getAbsolutePath() + " not found", inputFile.exists());

    // now do the actual moving
    File movedFile = new File(tempFolder.getRoot(), "copy.log");
    LastFileUtils.moveFileSafely(inputFile, movedFile);
    assertFalse(inputFile.getAbsolutePath() + " exists", inputFile.exists());
    assertTrue(movedFile.getAbsolutePath() + " doesn't exist", movedFile.exists());
    assertEquals(FileUtils.readFileToString(originalFile), FileUtils.readFileToString(movedFile));
}

From source file:com.athena.meerkat.controller.web.provisioning.TomcatProvisioningControllerTest.java

@Test
public void testInstall() {

    File workingDir = new File(commanderDir);
    String serverIp = "192.168.0.157";
    MDC.put("serverIp", serverIp);
    String userId = "centos";

    Properties prop = new Properties(); //build-ssh.properties
    prop.setProperty("server.ip", serverIp);
    prop.setProperty("server.id", "6");
    prop.setProperty("server.port", "22");
    prop.setProperty("user.id", userId);
    prop.setProperty("user.passwd", userId);
    prop.setProperty("key.file", commanderDir + "/ssh/svn_key.pem");

    Properties targetProps = new Properties(); //build.properties
    targetProps.setProperty("agent.deploy.dir", "/home/" + userId + "/athena-meerkat-agent");
    targetProps.setProperty("agent.name", "athena-meerkat-agent-1.0.0-SNAPSHOT");
    targetProps.setProperty("tomcat.unzip.pah", "/home/" + userId + "/app");
    targetProps.setProperty("catalina.base", "/home/" + userId + "/app/instance1");

    OutputStream output = null;/*  w  w w.  jav a  2 s  .com*/

    try {
        int jobNum = ProvisioningUtil.getJobNum(
                new File(workingDir.getAbsolutePath() + File.separator + "jobs" + File.separator + serverIp));
        targetProps.setProperty("job.number", String.valueOf(jobNum));

        /*
         * 1. make job dir & copy build.xml.
         */
        File jobDir = new File(workingDir.getAbsolutePath() + File.separator + "jobs" + File.separator
                + serverIp + File.separator + String.valueOf(jobNum));
        if (jobDir.exists() == false) {
            jobDir.mkdirs();
        }
        LOGGER.debug("JOB_DIR : " + jobDir.getAbsolutePath());

        FileUtils.copyFileToDirectory(new File(workingDir.getAbsolutePath() + File.separator + "build.xml"),
                jobDir);

        /*
         * 2. generate agentenv.sh
         */
        createAgentEnvSHFile(jobDir, targetProps.getProperty("agent.deploy.dir"),
                targetProps.getProperty("agent.name"));
        generateTomcatEnvFile(jobDir, createTomcatConfig(userId));

        /*
         * 3. generate build properties
         */
        output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build-ssh.properties");
        prop.store(output, "desc");
        LOGGER.debug("generated build-ssh.properties");

        IOUtils.closeQuietly(output);

        output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build.properties");
        targetProps.store(output, "desc");
        LOGGER.debug("generated build.properties");

        /*
         * 4. deploy agent
         */
        ProvisioningUtil.runDefaultTarget(workingDir, jobDir, "deploy-agent");

        /*
         * 5. send cmd.
         */
        ProvisioningUtil.sendCommand(workingDir, jobDir);

    } catch (Exception e) {
        //fail(e.toString());
        e.printStackTrace();
    } finally {
        MDC.remove("serverIp");
        IOUtils.closeQuietly(output);
    }

}

From source file:com.mc.printer.model.panel.task.BuildModelTask.java

@Override
public Object doBackgrounp() {
    javax.swing.JTabbedPane tabs = AutoPrinterApp.getMainView().getMainWorkPanel();
    if (tabs != null) {
        if (tabs.getSelectedIndex() >= 0) {
            Component selectedcom = tabs.getSelectedComponent();
            if (selectedcom instanceof CanvasWork) {
                CanvasWork selectPanel = (CanvasWork) selectedcom;
                FormBeans beansForm = selectPanel.getBeansForm();

                /**/
                if (beansForm.getHeightcm() == 0 || beansForm.getWidthcm() == 0) {
                    int res = BaseMessage.CONFIRM(
                            "?\r\nA4.");
                    if (res != JOptionPane.OK_OPTION) {
                        return null;
                    }/*  ww w .  ja v a 2s  .c om*/
                }

                String imagePath = beansForm.getImgpath();
                HashMap<String, ComponentBean> parameterMap = selectPanel.getSavedForms();
                if (parameterMap.size() > 0) {
                    Set set = parameterMap.keySet();
                    boolean foundKey = false;
                    //???
                    List<ComponentBean> beans = new ArrayList();
                    Iterator it = set.iterator();
                    while (it.hasNext()) {
                        ComponentBean com = parameterMap.get(it.next().toString());
                        beans.add(com);
                        if (com.isIskey()) {
                            foundKey = true;
                        }
                    }
                    beansForm.setElements(beans);
                    //
                    //                        if (!foundKey) {
                    //                            BaseMessage.ERROR("PRIMARY KEY.");
                    //                            return null;
                    //                        }

                    BaseFileChoose fileChoose = new BaseFileChoose("?",
                            new String[] { Constants.MODEL_SUFFIX }, AutoPrinterApp.getMainFrame());
                    String selectedPath = fileChoose.showSaveDialog();
                    if (!selectedPath.trim().equals("")) {

                        //get formname
                        selectedPath = selectedPath + File.separator + beansForm.getFormname();
                        //String time=DateHelper.format(new Date(), "yyyyMMddHHmmss");
                        String finalZip = selectedPath;
                        if (!selectedPath.endsWith("." + Constants.MODEL_SUFFIX)) {
                            finalZip = selectedPath + "." + Constants.MODEL_SUFFIX;
                        }

                        String tempDir = selectedPath + File.separator + Constants.MODEL_TEMP_DIR;

                        File imageFile = new File(imagePath);

                        String xmlPath = tempDir + File.separator + imageFile.getName() + ".xml";
                        XMLHelper helper = new XMLHelper(xmlPath, beansForm);
                        try {
                            helper.write();
                        } catch (JAXBException ex) {
                            ex.printStackTrace();
                            logger.error(ex.getMessage());
                            return ex;
                        }

                        File paramFile = new File(xmlPath);
                        if (paramFile.isFile() && paramFile.exists()) {
                            try {
                                FileUtils.copyFileToDirectory(imageFile, new File(tempDir));
                                ZipHelper.createZip(tempDir, finalZip);
                                return "??.\r\n" + finalZip;
                            } catch (IOException ex) {
                                ex.printStackTrace();
                                logger.error(ex.getMessage());
                                return ex;
                            } finally {
                                try {
                                    FileUtils.deleteDirectory(new File(selectedPath));
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                    logger.error(ex.getMessage());
                                    return ex;
                                }
                            }
                        }
                    }
                } else {
                    return "??.";
                }
            } else {
                return "??????.";
            }
        } else {
            return ".";
        }
    } else {
        return ".";
    }
    return null;
}

From source file:ch.unibas.fittingwizard.presentation.addmolecule.CoordinatesPage.java

private File copyXyzToCurrentSession(File input) {
    logger.info("Copying XYZ file to current session directory.");
    try {//from  w  w w .  j a v a  2s . c  o  m
        // this overwrites existing files.
        FileUtils.copyFileToDirectory(input, moleculesDir.getDirectory());
    } catch (IOException e) {
        throw new RuntimeException("Could not copy file.", e);
    }
    return new File(moleculesDir.getDirectory(), input.getName());
}