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.streamsets.datacollector.util.ClusterUtil.java

public static File createSparkHome(File dataTestDir) throws IOException {
    File sparkDir = new File(new File(System.getProperty("user.dir"), "target"), "spark");
    if (!sparkDir.exists()) {
        throw new RuntimeException("'Cannot find spark assembly dir at location " + sparkDir.getAbsolutePath());
    }//from   ww  w .j a  v  a  2s. co m
    File sparkHome = new File(dataTestDir, "spark");
    System.setProperty(SPARK_TEST_HOME, sparkHome.getAbsolutePath());
    FileUtils.copyDirectory(sparkDir, sparkHome);
    return sparkHome;
}

From source file:edu.isi.wings.portal.classes.domains.Domain.java

public static Domain importLegacyDomain(String domName, Config config, String legacyDomDir) {
    // Get Legacy apis
    PropertiesHelper.resetProperties();/*w w  w.  jav  a 2  s  .c om*/
    PropertiesHelper.loadWingsProperties(legacyDomDir + fsep + "wings.properties");
    Properties legacyprops = TemplateFactory.createLegacyConfiguration();
    legacyprops.putAll(DataFactory.createLegacyConfiguration());
    legacyprops.putAll(ComponentFactory.createLegacyConfiguration());
    DataCreationAPI ldc = DataFactory.getCreationAPI(legacyprops);
    ComponentCreationAPI lacc = ComponentFactory.getCreationAPI(legacyprops, false);
    ComponentCreationAPI lccc = ComponentFactory.getCreationAPI(legacyprops, true);
    TemplateCreationAPI ltc = TemplateFactory.getCreationAPI(legacyprops);

    // Get new apis
    Domain domain = Domain.createDefaultDomain(domName, config.getUserDir(), config.getExportUserUrl());
    Properties props = config.getProperties(domain);
    DataCreationAPI dc = DataFactory.getCreationAPI(props);
    ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false);
    ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true);
    TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props);

    // Copy from legacy apis to new apis
    dc.copyFrom(ldc);
    acc.copyFrom(lacc);
    ccc.copyFrom(lccc);
    tc.copyFrom(ltc);

    // Copy legacy data/code directories to new data/code storage directory
    File srcDataDir = new File(PropertiesHelper.getDataDirectory());
    File destDataDir = new File(
            domain.getDomainDirectory() + fsep + domain.getDataLibrary().getStorageDirectory());
    File srcCodeDir = new File(PropertiesHelper.getCodeDirectory());
    File destCodeDir = new File(
            domain.getDomainDirectory() + fsep + domain.getConcreteComponentLibrary().getStorageDirectory());
    File srcBeamerDir = new File(PropertiesHelper.getOntologyDir() + fsep + "beamer");
    File destBeamerDir = new File(domain.getDomainDirectory() + fsep + "beamer");
    try {
        if (srcDataDir.isDirectory())
            FileUtils.copyDirectory(srcDataDir, destDataDir);
        if (srcCodeDir.isDirectory()) {
            FileUtils.copyDirectory(srcCodeDir, destCodeDir);
            // FIXME: Setting executable permissions on all files for now
            for (File f : FileUtils.listFiles(destCodeDir, null, true)) {
                f.setExecutable(true);
            }
        }
        if (srcBeamerDir.isDirectory())
            FileUtils.copyDirectory(srcBeamerDir, destBeamerDir);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return domain;
}

From source file:eu.qualimaster.dataManagement.storage.hdfs.HdfsUtils.java

/**
 * Transparently copies <code>source</code> to <code>target</code> in HDFS or DFS.
 * /*from www.  j ava  2 s  . c o  m*/
 * @param source the source file
 * @param target the target file
 * @param targetBase shell target be considered as the base path in HDFS or shall the Dfs path be prefixed
 * @return the target path used 
 * @throws IOException in case that copying fails
 */
public static String copy(File source, File target, boolean absolute) throws IOException {
    String result;
    if (!DataManagementConfiguration.isEmpty(DataManagementConfiguration.getHdfsUrl())) {
        String basePath = absolute ? target + "/"
                : DataManagementConfiguration.getDfsPath() + "/" + target + "/";
        FileSystem fs = HdfsUtils.getFilesystem();
        copy(fs, basePath, source);
        result = basePath;
    } else if (!DataManagementConfiguration.isEmpty(DataManagementConfiguration.getDfsPath())) {
        File tgt = new File(DataManagementConfiguration.getDfsPath(), target.toString());
        FileUtils.copyDirectory(source, tgt);
        result = tgt.getAbsolutePath();
    } else {
        throw new IOException("Cannot copy directory. Check HDFS/DFS configuration.");
    }
    return result;
}

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

private void prepareWorkArea() throws IOException {
    FileUtils.copyDirectory(Path.makeFile(WORKAREAROOTPATH, WorkArea.PIPS + UNDERSCORE),
            Path.makeFile(WORKAREAROOTPATH, WorkArea.PIPS));
}

From source file:eu.asterics.ape.main.APE.java

/**
 * Initializes and starts APE.//  w w w  .j a  v a 2 s.com
 * @throws ParseException 
 * @throws IOException 
 * @throws TransformerException 
 * @throws SAXException 
 * @throws ParserConfigurationException 
 * @throws URISyntaxException 
 * @throws BundleManagementException 
 * @throws APEConfigurationException 
 */
public void start() throws IOException, ParseException, URISyntaxException, ParserConfigurationException,
        SAXException, TransformerException, BundleManagementException, APEConfigurationException {
    ResourceRegistry.getInstance().setOSGIMode(false);

    projectDir = ResourceRegistry.resolveRelativeFilePath(getAPEBaseURI(), DEFAULT_PROJECT_DIR);

    String customProjectDir = System.getProperty(P_APE_PROJECT_DIR);
    if (customProjectDir != null && !"".equals(customProjectDir)) {
        projectDir = new File(resolveURIsToCWD(customProjectDir));
    }
    //APEProperties.APE_PROJECT_DIR_URI=projectDir.toURI();
    Notifier.info("ApeProp[" + APEProperties.P_APE_PROJECT_DIR + "]=" + projectDir);

    if (!projectDir.exists()) {
        Notifier.info("Project folder does not exist, copying template to: " + projectDir);
        //If the projectDir does not exist, we should copy the template dir to the projectDir      
        FileUtils.copyDirectory(
                ResourceRegistry.resolveRelativeFilePath(getAPEBaseURI(), Packager.TEMPLATE_FOLDER),
                projectDir);
    }

    initProperties();

    String newAreBaseURIString = apeProperties.getProperty(APEProperties.P_ARE_BASE_URI,
            ResourceRegistry.resolveRelativeFilePath(getAPEBaseURI(), "../ARE/").getPath());

    if (newAreBaseURIString != null) {
        URI newAREBaseURI = ResourceRegistry.resolveRelativeFilePath(projectDir, newAreBaseURIString).toURI();
        Notifier.debug("ApeProp[" + APEProperties.P_ARE_BASE_URI + "]=" + newAREBaseURI, null);
        ResourceRegistry.getInstance().setAREBaseURI(newAREBaseURI);
    }

    modelInspector = new ModelInspector(apeProperties);
    packager = new Packager(apeProperties, modelInspector);
    packager.makeAll();
}

From source file:com.collective.celos.CelosClientServerTest.java

@Test
public void testGetWorkflowStatusCorrectOrder() throws Exception {
    File src = new File(Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/client/wf-list").toURI());
    FileUtils.copyDirectory(src, workflowsDir);

    List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-2")).getSlotStates();
    Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW);

    for (int i = 0; i < slotStates.size() - 1; i++) {
        SlotState slotState = slotStates.get(i);
        SlotState nextSlotState = slotStates.get(i + 1);
        Assert.assertTrue(!slotState.getScheduledTime().getDateTime()
                .isBefore(nextSlotState.getScheduledTime().getDateTime()));
    }// w  w w.ja v  a  2s . c o  m
}

From source file:ch.bender.evacuate.Runner.java

/**
 * run//from   w  ww.  j  ava 2s  .c o m
 * <p>
 * @throws Exception 
 */
public void run() throws Exception {
    checkDirectories();
    initExcludeMatchers();

    myEvacuateCandidates = new TreeMap<>();
    myFailedChainPreparations = Collections.synchronizedMap(new HashMap<>());
    myFutures = new HashSet<>();
    myExclusionDirCount = 0;
    myEvacuationDirCount = 0;
    myExclusionFileCount = 0;
    myEvacuationFileCount = 0;

    Files.walkFileTree(myBackupDir, new SimpleFileVisitor<Path>() {
        /**
         * @see java.nio.file.SimpleFileVisitor#visitFileFailed(java.lang.Object, java.io.IOException)
         */
        @Override
        public FileVisitResult visitFileFailed(Path aFile, IOException aExc) throws IOException {
            if ("System Volume Information".equals((aFile.getFileName().toString()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            throw aExc;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            return Runner.this.visitFile(file, attrs);
        }

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            if ("System Volume Information".equals((dir.getFileName()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            return Runner.this.preVisitDirectory(dir, attrs);
        }

    });

    if (myEvacuateCandidates.size() == 0) {
        myLog.info("No candidates for evacuation found");
    } else {
        StringBuilder sb = new StringBuilder("\nFound candidates for evacuation:");
        myEvacuateCandidates.keySet().forEach(p -> sb.append("\n    " + p.toString()));
        myLog.info(sb.toString());
    }

    if (myDryRun) {
        myLog.debug("DryRun flag is set. Doing nothing");
        return;
    }

    if (myFutures.size() > 0) {
        myLog.debug("Waiting for all async tasks to complete");
        CompletableFuture.allOf(myFutures.toArray(new CompletableFuture[myFutures.size()])).get();
    }

    if (myFailedChainPreparations.size() > 0) {
        for (Path path : myFailedChainPreparations.keySet()) {
            myLog.error("exception occured", myFailedChainPreparations.get(path));
        }

        throw new Exception("chain preparation failed. See above error messages");
    }

    for (Path src : myEvacuateCandidates.keySet()) {
        Path dst = myEvacuateCandidates.get(src);
        Path dstParent = dst.getParent();

        if (Files.notExists(dstParent)) {
            Files.createDirectories(dstParent); // FUTURE: overtake file attributes from src
        }

        if (myMove) {
            try {
                myLog.debug(
                        "Moving file system object \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE);
            } catch (AtomicMoveNotSupportedException e) {
                myLog.warn("Atomic move not supported. Try copy and then delete");

                if (Files.isDirectory(src)) {
                    myLog.debug("Copying folder \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                    FileUtils.copyDirectory(src.toFile(), dst.toFile());
                    myLog.debug("Delete folder \"" + src.toString() + "\"");
                    FileUtils.deleteDirectory(src.toFile());
                } else {
                    myLog.debug("Copy file \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                    FileUtils.copyFile(src.toFile(), dst.toFile());
                    myLog.debug("Delete file \"" + src.toString() + "\"");
                    Files.delete(src);
                }
            }

        } else {
            if (Files.isDirectory(src)) {
                myLog.debug("Copying folder \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                FileUtils.copyDirectory(src.toFile(), dst.toFile());
            } else {
                myLog.debug("Copy file \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                FileUtils.copyFile(src.toFile(), dst.toFile());
            }
        }
    }

    myLog.info("\nSuccessfully terminated." + "\n             Evacuated  Skipped" + "\n    Files  : "
            + StringUtils.leftPad("" + myEvacuationDirCount, 9)
            + StringUtils.leftPad("" + myExclusionDirCount, 9) + "\n    Folders: "
            + StringUtils.leftPad("" + myEvacuationFileCount, 9)
            + StringUtils.leftPad("" + myExclusionFileCount, 9));
}

From source file:com.c4om.autoconf.ulysses.configanalyzer.configurationextractor.LocalCopyConfigurationsExtractor.java

/**
 * This method performs the extraction. 
 * The context must contain: //from w  w w .  java 2s.c o  m
 * <ul>
 * <li>One or more {@link ConfigureAppsTarget} returned by {@link ConfigurationAnalysisContext#getInputTargets()}. 
 * All the referenced {@link Application} must return "file://" URIs at {@link Application#getConfigurationURIs()}.</li>
 * <li>An {@link Environment} object returned by {@link ConfigurationAnalysisContext#getInputEnvironment()}, from which 
 * the configuration of the runtime where all the referenced applications are run.</li>
 * </ul>
 * @see com.c4om.autoconf.ulysses.interfaces.configanalyzer.configurationextractor.ConfigurationsExtractor#extractConfigurations(com.c4om.autoconf.ulysses.interfaces.configanalyzer.core.datastructures.ConfigurationAnalysisContext)
 */
@Override
public void extractConfigurations(ConfigurationAnalysisContext context)
        throws ConfigurationExtractionException {
    try {
        Path tempFolderPath = Files.createTempDirectory("ConfigurationAnalyzer");
        for (Target currentTarget : context.getInputTargets().values()) {
            if (!(currentTarget instanceof ConfigureAppsTarget)) {
                continue;
            }
            Properties configurationAnalyzerSettings = context.getConfigurationAnalyzerSettings();
            String runtimeConfigurationDirName = configurationAnalyzerSettings
                    .getProperty(PROPERTY_KEY_RUNTIME_CONFIGURATION_FILENAME);
            if (runtimeConfigurationDirName == null) {
                throw new ConfigurationExtractionException(
                        "Property '" + PROPERTY_KEY_RUNTIME_CONFIGURATION_FILENAME + "' not found");
            }
            ConfigureAppsTarget currentConfigureAppsTarget = (ConfigureAppsTarget) currentTarget;
            for (String appId : currentConfigureAppsTarget.getParameters().keySet()) {
                Path subfolderForApp = tempFolderPath.resolve(Paths.get(appId));
                List<File> copiedFiles = new ArrayList<>();
                Files.createDirectory(subfolderForApp);
                //We copy the application configuration files to the root of the directory.
                //We also copy the runtime configuration.
                Application currentApplication = (Application) currentConfigureAppsTarget.getParameters()
                        .get(appId);
                for (URI configurationURI : currentApplication.getConfigurationURIs()) {
                    //TODO: Let other configuration URIs live, specially, SVN-based ones, which should be extracted by other extractors. This would require some refactoring. 
                    if (!configurationURI.getScheme().equalsIgnoreCase("file")) {
                        throw new ConfigurationExtractionException(
                                "URI '" + configurationURI.toString() + "' does not have a 'file' scheme");
                    }
                    Path configurationPath = Paths.get(configurationURI);
                    Path configurationPathName = configurationPath.getFileName();
                    if (configurationPathName.toString().equals(runtimeConfigurationDirName)) {
                        throw new ConfigurationExtractionException(
                                "One of the application configuration files has the same name than the runtime configuration folder ('"
                                        + runtimeConfigurationDirName + "')");
                    }

                    Path destinationConfigurationPath = Files.copy(configurationPath,
                            subfolderForApp.resolve(configurationPathName), REPLACE_EXISTING);
                    File destinationConfigurationFile = destinationConfigurationPath.toFile();
                    copiedFiles.add(destinationConfigurationFile);

                }

                File runtimeConfigurationDirectory = new File(
                        context.getInputEnvironment().getApplicationConfigurations().get(appId));
                File destinationRuntimeConfigurationDirectory = subfolderForApp
                        .resolve(runtimeConfigurationDirName).toFile();
                FileUtils.copyDirectory(runtimeConfigurationDirectory,
                        destinationRuntimeConfigurationDirectory);
                copiedFiles.add(destinationRuntimeConfigurationDirectory);

                ExtractedConfiguration<File> extractedConfiguration = new FileExtractedConfiguration(appId,
                        currentTarget, copiedFiles);
                context.getExtractedConfigurations().add(extractedConfiguration);
            }
        }
    } catch (IOException e) {
        throw new ConfigurationExtractionException(e);
    }

}

From source file:com.kylinolap.job.hadoop.cube.MergeCuboidMapperTest.java

@Test
public void test() throws IOException, ParseException, CubeIntegrityException {

    String cubeName = "test_kylin_cube_without_slr_left_join_ready_2_segments";

    List<CubeSegment> newSegments = cubeManager.allocateSegments(cube, CubeBuildTypeEnum.MERGE, 1384240200000L,
            1386835200000L);// www. ja v  a 2 s  .co m

    logger.info("Size of new segments: " + newSegments.size());

    CubeSegment newSeg = newSegments.get(0);
    String segmentName = newSeg.getName();

    ((TrieDictionary) cubeManager.getDictionary(newSeg, lfn)).dump(System.out);

    // hack for distributed cache
    File metaDir = new File("../job/meta");
    FileUtils.copyDirectory(new File(this.getTestConfig().getMetadataUrl()), metaDir);

    mapDriver.getConfiguration().set(BatchConstants.CFG_CUBE_NAME, cubeName);
    mapDriver.getConfiguration().set(BatchConstants.CFG_CUBE_SEGMENT_NAME, segmentName);
    // mapDriver.getConfiguration().set(KylinConfig.KYLIN_METADATA_URL,
    // "../job/meta");

    byte[] key = new byte[] { 0, 0, 0, 0, 0, 0, 0, -92, 1, 1, 1 };
    byte[] value = new byte[] { 1, 2, 3 };
    byte[] newkey = new byte[] { 0, 0, 0, 0, 0, 0, 0, -92, 1, 1, 2 };
    byte[] newvalue = new byte[] { 1, 2, 3 };

    mapDriver.withInput(new Text(key), new Text(value));
    mapDriver.withOutput(new Text(newkey), new Text(newvalue));
    mapDriver.setMapInputPath(new Path(
            "/apps/hdmi-prod/b_kylin/prod/kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa/vac_sw_cube_v4/cuboid/15d_cuboid"));

    mapDriver.runTest();
}

From source file:com.photon.phresco.service.util.DependencyUtils.java

public static void copyFilesTo(File[] files, File destPath) throws IOException {
    if (isDebugEnabled) {
        LOGGER.debug("DependencyUtils.copyFilesTo:Entry");
        LOGGER.info("DependencyUtils.copyFilesTo", "destPath=\"" + destPath + "\"");
    }/*from w  w w.  j  a  v a 2  s .  co m*/
    if (files == null || destPath == null) {
        //nothing to copy
        return;
    }
    for (File file : files) {
        if (file.isDirectory()) {
            FileUtils.copyDirectory(file, destPath);
        } else {
            FileUtils.copyFileToDirectory(file, destPath);
        }
    }
    if (isDebugEnabled) {
        LOGGER.debug("DependencyUtils.copyFilesTo:Exit");
    }

}