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:org.h819.commons.file.MyFileUtils.java

/**
 * ?,????//from w ww  . j a  va 2 s. co m
 * ?
 *
 * @param srcPdf
 * @param descDirectory
 */
public static void copyFileToDirectory(File srcPdf, File descDirectory) {
    try {
        if (descDirectory != null && (!descDirectory.exists() || !descDirectory.isDirectory()))
            FileUtils.forceMkdir(descDirectory);
        FileUtils.copyFileToDirectory(srcPdf, descDirectory);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.jahia.configuration.deployers.AbstractServerDeploymentImpl.java

@Override
public boolean deploySharedLibraries(File... pathToLibraries) throws IOException {
    File targetDirectory = getSharedLibraryDirectory();
    for (File currentLibraryPath : pathToLibraries) {
        FileUtils.copyFileToDirectory(currentLibraryPath, targetDirectory);
    }/*from w  w w  .  j a v a  2 s  . c  o m*/
    return true;
}

From source file:org.jahia.configuration.deployers.jboss.DriverDeploymentHelper.java

public static boolean deploy(File targetServerDirectory, File driverJar) throws IOException {
    String driverKey = getDriverKey(driverJar.getName());
    String driverType = getDriverType(driverKey, driverJar.getName());
    File targetDir = new File(targetServerDirectory, "/modules/org/jahia/jdbc/" + driverType + "/main");
    boolean inPlace = targetDir.equals(driverJar.getParentFile());
    if (targetDir.isDirectory()) {
        // special case for the second JAR of the Oracle driver
        // second test is for the case driver JAR is already in-place (used only in configurators to configure module.xml)
        if (!"oracle".equals(driverType) && !inPlace) {
            FileUtils.cleanDirectory(targetDir);
        }/*from  w w  w.j ava2s . com*/
    } else {
        if (!targetDir.mkdirs()) {
            throw new IOException("Unable to create target directory: " + targetDir);
        }
    }

    if (!inPlace) {
        FileUtils.copyFileToDirectory(driverJar, targetDir);
    }

    File moduleXml = new File(targetDir, "module.xml");
    String existingContent = moduleXml.isFile() ? FileUtils.readFileToString(moduleXml, FILE_CONTENT_ENCODING)
            : null;
    FileUtils.writeStringToFile(moduleXml,
            generateModuleXmlContent(existingContent, driverJar.getName(), driverType), FILE_CONTENT_ENCODING);

    return Boolean.TRUE;
}

From source file:org.jahia.configuration.modules.ModuleDeployer.java

public void deployModule(File file) throws IOException {
    FileUtils.copyFileToDirectory(file, output);
    logger.info("Copied " + file + " to " + output);
    File targetDir = new File(output, "../");
    copyDbScripts(file, targetDir);/* w  w w .  j  ava  2s  .  c  om*/
}

From source file:org.jahia.services.content.impl.jackrabbit.RepositoryMigrator.java

private File createTempRepoHome() throws IOException {
    File repoHomeCopy = new File(repoHome.getParentFile(), "repository-migration");
    repoHomeCopy.mkdir();/*  ww  w .j  ava2s. co  m*/

    File toCopy = new File(repoHome, "indexing_configuration.xml");
    if (toCopy.exists()) {
        FileUtils.copyFileToDirectory(toCopy, repoHomeCopy);
    }

    toCopy = new File(repoHome, "indexing_configuration_version.xml");
    if (toCopy.exists()) {
        FileUtils.copyFileToDirectory(toCopy, repoHomeCopy);
    }

    logger.info("Using folder {} for migrated repository", repoHomeCopy);

    return repoHomeCopy;
}

From source file:org.jahia.test.services.templates.ModuleDeploymentTest.java

@Test
public void testJarAutoDeploy() throws RepositoryException {
    SettingsBean settingsBean = SettingsBean.getInstance();

    File f = null;/* w  w  w  . j  av  a2 s .c o m*/
    try {
        File tmpFile = File.createTempFile("module", ".jar");
        InputStream stream = managerService.getTemplatePackageById("jahia-test-module")
                .getResource("dummy1-" + "1.0" + ".jar").getInputStream();
        FileUtils.copyInputStreamToFile(stream, tmpFile);
        FileUtils.copyFileToDirectory(tmpFile, new File(settingsBean.getJahiaModulesDiskPath()));
        tmpFile.delete();
        f = new File(settingsBean.getJahiaModulesDiskPath(), tmpFile.getName());

        with().pollInterval(Duration.ONE_SECOND).await().atMost(20, SECONDS)
                .until(isPackageDeployedAndServiceInstalled("dummy1"));

        JahiaTemplatesPackage pack = managerService.getTemplatePackageById("dummy1");

        assertNotNull(pack);
        assertEquals("Module is not started", ModuleState.State.STARTED, pack.getState().getState());
        assertNotNull("Spring context is null", pack.getContext());
        assertTrue("No action defined", !pack.getContext().getBeansOfType(Action.class).isEmpty());
        assertTrue("Action not registered", managerService.getActions().containsKey("my-post-action"));

        try {
            NodeTypeRegistry.getInstance().getNodeType("jnt:testComponent1");
        } catch (NoSuchNodeTypeException e) {
            fail("Definition not registered");
        }
        assertTrue("Module view is not correctly registered",
                managerService.getModulesWithViewsForComponent("jnt:testComponent1").contains(pack));

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        fail(e.toString());
    } finally {
        FileUtils.deleteQuietly(f);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
    }

}

From source file:org.jahia.utils.maven.plugin.contentgenerator.FileService.java

/**
 * /*  w w w .  j a v a2 s  .  co m*/
 * @param filesToCopy
 * @param destDir
 * @returns List of new files (copies)
 * @throws IOException
 *             if source or destination is invalid
 * @throws IOException
 *             if an IO error occurs during copying
 */
public List<File> copyFilesForAttachment(List<File> filesToCopy, File destDir) throws IOException {
    List<File> newFiles = new ArrayList<File>();
    File oldFile;
    File newFile;
    for (Iterator<File> iterator = filesToCopy.iterator(); iterator.hasNext();) {
        oldFile = iterator.next();

        // creates a new directory for each file, with the same name
        File newDirForFile = new File(destDir + sep + oldFile.getName());
        newDirForFile.mkdir();

        FileUtils.copyFileToDirectory(oldFile, newDirForFile);
        newFile = new File(destDir, oldFile.getName());
        newFiles.add(newFile);
    }
    return newFiles;
}

From source file:org.jahia.utils.maven.plugin.contentgenerator.SiteService.java

/**
 * Copies the XML file generated into a temporary dir and renames it to
 * "repository.xml" (or other name defined in the constant)
 * //from  www.  jav a2s . co m
 * @param pagesFile
 * @return new File created
 * @throws IOException
 */
public File copyPagesFile(File pagesFile, File tempOutputDir) throws IOException {
    FileUtils.copyFileToDirectory(pagesFile, tempOutputDir);
    File copy = new File(tempOutputDir, pagesFile.getName());
    File renamedCopy = new File(tempOutputDir, ContentGeneratorCst.REPOSITORY_FILENAME);
    copy.renameTo(renamedCopy);
    logger.debug("new file containing pages: " + renamedCopy);
    return renamedCopy;
}

From source file:org.jahia.utils.maven.plugin.ContextServerDeployMojo.java

@SuppressWarnings("deprecation")
private void doDeploy(File deployDir) {
    Artifact artifact = project.getArtifact();
    try {/*from  www . j  a v  a 2 s  . c om*/
        artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository);
        getLog().info("Deploying jar file " + artifact.getFile().getName() + " to " + deployDir);
        FileUtils.copyFileToDirectory(artifact.getFile(), deployDir);
    } catch (Exception e) {
        getLog().error("Error while deploying JAR project", e);
    }
}

From source file:org.jahia.utils.maven.plugin.DeployMojo.java

private void deployProject() throws Exception {
    if (skipDeploy()) {
        getLog().info("jahia.deploy.skip is set to 'true' for the current project. Skip deploying it.");
        return;/*from w w w  .  ja v  a2  s .  c  o m*/
    }
    if (project.getPackaging().equals("ear")) {
        deployEarProject();
    } else if (project.getPackaging().equals("war")) {
        if (project.getGroupId().equals("org.jahia.server")
                || project.getGroupId().equals("org.jahia.extensions")) {
            deployWarProject();
        } else if (project.getGroupId().equals("org.jahia.modules")
                || (deployTests && project.getGroupId().equals("org.jahia.test"))
                || project.getGroupId().endsWith(".jahia.modules")) {
            deployModuleProject();
        } else if (project.getGroupId().equals("org.jahia.test") && !deployTests) {
            getLog().info(
                    "Deployment of test projects " + "(with groupId 'org.jahia.test') is disabled by default. "
                            + "You can enable it by specifying -Djahia.deploy.deployTests"
                            + " option for the 'mvn jahia:deploy' command");
        } else {
            getLog().warn("Unrecognized type of the WAR project. Skipping deployment");
        }
    } else if (project.getPackaging().equals("jar")) {
        if (project.getGroupId().equals("org.jahia.test") && !deployTests) {
            getLog().info(
                    "Deployment of test projects " + "(with groupId 'org.jahia.test') is disabled by default. "
                            + "You can enable it by specifying -Djahia.deploy.deployTests"
                            + " option for the 'mvn jahia:deploy' command");
        } else {
            deployJarProject();
        }
    } else if (project.getPackaging().equals("pom")) {
        deployPomProject();
    } else if (project.getPackaging().equals("bundle")) {
        boolean isJahiaTaglib = project.getArtifactId().equals("jahia-taglib");
        if (isJahiaTaglib) {
            deployJarProject();
        }
        if (project.getGroupId().equals("org.jahia.bundles")
                && JAHIA_SYSTEM_BUNDLES.contains(project.getArtifactId()) || isJahiaTaglib) {
            String fileName = project.getArtifactId() + "-" + project.getVersion() + "." + "jar";
            File srcFile = new File(output, fileName);
            File destDir = null;
            File karafDir = new File(getWebappDeploymentDir(), "WEB-INF/karaf/system");
            boolean karafDeployment = karafDir.isDirectory();
            if (karafDeployment) {
                destDir = new File(
                        new File(karafDir,
                                StringUtils.join(StringUtils.split(project.getGroupId(), '.'),
                                        File.separatorChar)),
                        project.getArtifactId() + File.separatorChar + project.getVersion());
            } else {
                destDir = new File(getWebappDeploymentDir(), "WEB-INF/bundles");
            }
            FileUtils.copyFileToDirectory(srcFile, destDir);
            getLog().info("Copied " + srcFile + " to " + destDir);
            if (karafDeployment) {
                copyToKarafDeploy(srcFile);
            } else {
                removeCachedBundle(fileName, new File(getDataDir(), "bundles-deployed"));
            }
        } else {
            boolean isStandardModule = project.getGroupId().equals("org.jahia.module")
                    || project.getGroupId().endsWith(".jahia.modules");
            if (isStandardModule || isJahiaModuleBundle(
                    new File(output, project.getArtifactId() + "-" + project.getVersion() + "." + "jar"))) {
                deployModuleProject();
            } else {
                File srcFile = new File(output,
                        project.getArtifactId() + "-" + project.getVersion() + "." + "jar");
                File destDir = null;
                File karafDir = new File(getWebappDeploymentDir(), "WEB-INF/karaf/system");
                boolean karafDeployment = karafDir.isDirectory();
                if (karafDeployment) {
                    destDir = new File(getDataDir(), "karaf/deploy");
                } else {
                    destDir = new File(getDataDir(), "bundles");
                }
                FileUtils.copyFileToDirectory(srcFile, destDir);
                getLog().info("Copied " + srcFile + " to " + destDir);
            }
        }
    }
}