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.apache.solr.schema.TestSchemalessBufferedUpdates.java

@BeforeClass
public static void beforeClass() throws Exception {
    File tmpSolrHome = createTempDir().toFile();
    File tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-schemaless.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-add-schema-fields-update-processor.xml"),
            tmpConfDir);/* ww w . j a v  a2 s. c om*/
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);
    initCore("solrconfig-schemaless.xml", "schema-add-schema-fields-update-processor.xml",
            tmpSolrHome.getPath());
}

From source file:org.apache.solr.schema.TestUseDocValuesAsStored.java

@Before
private void initManagedSchemaCore() throws Exception {
    tmpSolrHome = createTempDir().toFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);/*from  ww w .j a v  a  2 s .  c  o  m*/
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "enumsConfig.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-non-stored-docvalues.xml"), tmpConfDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    System.setProperty("enable.update.log", "false");
    System.setProperty("managed.schema.mutable", "true");
    initCore("solrconfig-managed-schema.xml", "schema-non-stored-docvalues.xml", tmpSolrHome.getPath());
}

From source file:org.apache.solr.search.TestAddFieldRealTimeGet.java

@Before
private void initManagedSchemaCore() throws Exception {
    final String tmpSolrHomePath = createTempDir().toFile().getAbsolutePath();
    tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    final String configFileName = "solrconfig-managed-schema.xml";
    final String schemaFileName = "schema-id-and-version-fields-only.xml";
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, configFileName), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, schemaFileName), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);//from  www .ja  v a  2s .  c  o  m

    // initCore will trigger an upgrade to managed schema, since the solrconfig has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    System.setProperty("managed.schema.mutable", "true");
    System.setProperty("enable.update.log", "true");
    initCore(configFileName, schemaFileName, tmpSolrHome.getPath());
}

From source file:org.apache.solr.search.TestSearcherReuse.java

/**
 * We're using a Managed schema so we can confirm that opening a new searcher 
 * after a schema modification results in getting a new searcher with the new 
 * schema linked to it.//from   w  ww  .  j  a v  a  2 s  .co m
 */
@BeforeClass
private static void setupTempDirAndCoreWithManagedSchema() throws Exception {
    solrHome = createTempDir().toFile();
    solrHome = solrHome.getAbsoluteFile();

    File confDir = new File(solrHome, confPath);
    File testHomeConfDir = new File(TEST_HOME(), confPath);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-id-and-version-fields-only.xml"), confDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    System.setProperty("managed.schema.mutable", "true");
    initCore("solrconfig-managed-schema.xml", "schema-id-and-version-fields-only.xml", solrHome.getPath());
}

From source file:org.apache.solr.update.DataDrivenBlockJoinTest.java

@Before
public void before() throws Exception {
    tmpSolrHome = createTempDir().toFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-schemaless.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-add-schema-fields-update-processor.xml"),
            tmpConfDir);/* www.j a v  a2s . com*/
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);

    System.setProperty("managed.schema.mutable", "true");
    System.setProperty("enable.update.log", "false");
    initCore("solrconfig-schemaless.xml", "schema-add-schema-fields-update-processor.xml",
            tmpSolrHome.getPath());
}

From source file:org.apache.solr.update.processor.AddSchemaFieldsUpdateProcessorFactoryTest.java

@Before
private void initManagedSchemaCore() throws Exception {
    tmpSolrHome = createTempDir().toFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, SOLRCONFIG_XML), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, SCHEMA_XML), tmpConfDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig*.xml has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    initCore(SOLRCONFIG_XML, SCHEMA_XML, tmpSolrHome.getPath());
}

From source file:org.appfuse.mojo.exporter.ModelGeneratorMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getComponentProperties().put("implementation", "jdbcconfiguration");
    getComponentProperties().put("outputDirectory",
            (sourceDirectory != null) ? sourceDirectory : "${basedir}/target/appfuse/generated-sources");

    // default location for reveng file is src/test/resources
    File revengFile = new File("src/test/resources/hibernate.reveng.xml");
    if (revengFile.exists() && getComponentProperty("revengfile") == null) {
        getComponentProperties().put("revengfile", "src/test/resources/hibernate.reveng.xml");
    }/* ww  w . ja v a  2  s. c o m*/

    // Check for existence of hibernate.reveng.xml and if there isn't one, create it
    // Specifying the file explicitly in pom.xml overrides default location
    if (getComponentProperty("revengfile") == null) {
        getComponentProperties().put("revengfile", "target/test-classes/hibernate.reveng.xml");
    }

    File existingConfig = new File(getComponentProperty("revengfile"));
    if (!existingConfig.exists()) {
        InputStream in = this.getClass().getResourceAsStream("/appfuse/model/hibernate.reveng.ftl");
        StringBuffer configFile = new StringBuffer();
        try {
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader reader = new BufferedReader(isr);
            String line;
            while ((line = reader.readLine()) != null) {
                configFile.append(line).append("\n");
            }
            reader.close();

            getLog().info("Writing 'hibernate.reveng.xml' to " + existingConfig.getPath());
            FileUtils.writeStringToFile(existingConfig, configFile.toString());
        } catch (IOException io) {
            throw new MojoFailureException(io.getMessage());
        }
    }

    // if package name is not configured, default to project's groupId
    if (getComponentProperty("packagename") == null) {
        getComponentProperties().put("packagename", getProject().getGroupId() + ".model");
    }

    if (getComponentProperty("configurationfile") == null) {
        // look for jdbc.properties and set "propertyfile" to its path
        File jdbcProperties = new File("target/classes/jdbc.properties");
        if (!jdbcProperties.exists()) {
            jdbcProperties = new File("target/test-classes/jdbc.properties");
        }
        if (jdbcProperties.exists()) {
            if (getComponentProperty("propertyfile") == null) {
                getComponentProperties().put("propertyfile", jdbcProperties.getPath());
                getLog().debug("Set propertyfile to '" + jdbcProperties.getPath() + "'");
            }
        } else {
            throw new MojoFailureException("Failed to find jdbc.properties in classpath.");
        }
    }

    // For some reason, the classloader created in HibernateExporterMojo does not work
    // when using jdbcconfiguration - it can't find the JDBC Driver (no suitable driver).
    // Skipping the resetting of the classloader and manually adding the dependency (with XML) works.
    // It's ugly, but it works. I wish there was a way to get get this plugin to recognize the jdbc driver
    // from the project.

    super.doExecute();

    if (System.getProperty("disableInstallation") != null) {
        disableInstallation = Boolean.valueOf(System.getProperty("disableInstallation"));
    }

    // allow installation to be supressed when testing
    if (!disableInstallation) {
        // copy the generated file to the model directory of the project
        try {
            String packageName = getComponentProperties().get("packagename");
            String packageAsDir = packageName.replaceAll("\\.", "/");
            File dir = new File(sourceDirectory + "/" + packageAsDir);
            if (dir.exists()) {
                Iterator filesIterator = FileUtils.iterateFiles(dir, new String[] { "java" }, false);
                while (filesIterator.hasNext()) {
                    File f = (File) filesIterator.next();
                    getLog().info("Copying generated '" + f.getName() + "' to project...");
                    FileUtils.copyFileToDirectory(f,
                            new File(destinationDirectory + "/src/main/java/" + packageAsDir));
                }
            } else {
                throw new MojoFailureException("No tables found in database to generate code from.");
            }
            FileUtils.forceDelete(dir);
        } catch (IOException io) {
            throw new MojoFailureException(io.getMessage());
        }
    }
}

From source file:org.archive.spring.ConfigPathConfigurer.java

public void snapshotToLaunchDir(File readFile) throws IOException {
    if (appCtx.getCurrentLaunchDir() == null || !appCtx.getCurrentLaunchDir().exists()) {
        logger.log(Level.WARNING, "launch directory unavailable to snapshot " + readFile);
        return;/*from   ww w  .  j  av a 2  s  . c o m*/
    }
    FileUtils.copyFileToDirectory(readFile, appCtx.getCurrentLaunchDir());
}

From source file:org.archive.spring.PathSharingContext.java

protected void initLaunchDir() {
    initLaunchId();// w  ww.j av a 2  s .  c  o m
    try {
        currentLaunchDir = new File(getConfigurationFile().getParentFile(), getCurrentLaunchId());
        if (!currentLaunchDir.mkdir()) {
            throw new IOException("failed to create directory " + currentLaunchDir);
        }

        // copy cxml to launch dir
        FileUtils.copyFileToDirectory(getConfigurationFile(), currentLaunchDir);

        // attempt to symlink "latest" to launch dir
        File latestSymlink = new File(getConfigurationFile().getParentFile(), "latest");
        latestSymlink.delete();
        boolean success = FilesystemLinkMaker.makeSymbolicLink(currentLaunchDir.getName(),
                latestSymlink.getPath());
        if (!success) {
            LOGGER.warning("failed to create symlink from " + latestSymlink + " to " + currentLaunchDir);
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "failed to initialize launch directory: " + e);
        currentLaunchDir = null;
    }
}

From source file:org.arquillian.droidium.container.utils.DroidiumFileUtils.java

/**
 * Copies {@code src} file to {@code dest} directory.
 *
 * @param src source file to copy/*from   w w w  .  j a  va  2s  . co  m*/
 * @param dest destination directory where file is copied
 */
public static File copyFileToDirectory(File src, File dest) {
    try {
        FileUtils.copyFileToDirectory(src, dest);
        return new File(dest, src.getName());
    } catch (IOException ex) {
        throw new RuntimeException("Unable to copy " + src.getAbsolutePath() + " to " + dest.getAbsolutePath());
    }
}