List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.java
/** * Prepares the input files for the polynome process * /* w w w .j ava 2 s . c o m*/ * @param tmpDir * any tmp dir, must be empty before start, may be deleted after end * @param dathDir * Directory containing the laengsschnitt.txt and the beiwerte.aus files. * @return The polynom input dir (01Eingang), if preparation was succesful, else <code>null</code>. */ private File preparePolynomes() { /* The files needed from the 1D-calculation */ final File lsQFile = new File(m_dathDir, QLANG_FILE_NAME); final File weirFile = new File(m_dathDir, WEIR_FILE_NAME); final File bridgeFile = new File(m_dathDir, BRIDGE_FILE_NAME); final File[] dathFiles = new File[] { lsQFile, weirFile, bridgeFile }; /* Check input data */ for (final File file : dathFiles) { if (!file.exists()) { m_log.log(false, Messages.getString("org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.0"), //$NON-NLS-1$ file); return null; } } /* Copy input data to exe dir */ try { final File eingangDir = new File(m_tmpDir, "01Eingang"); //$NON-NLS-1$ for (final File file : dathFiles) FileUtils.copyFileToDirectory(file, eingangDir); return eingangDir; } catch (final IOException e) { m_log.log(e, Messages.getString("org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.2")); //$NON-NLS-1$ return null; } }
From source file:org.kalypso.model.wspm.tuhh.schema.simulation.WspmTuhhCalcJob.java
public final static File getExecuteable(final TuhhCalculation calculation, final File tmpDir, final String exeFormat, final String exePattern, final ISimulationMonitor monitor) { try {/*from ww w . ja v a 2s .c o m*/ final String version = calculation.getVersion(); final File exeFile = CalcCoreUtils.findExecutable(version, exeFormat, exePattern); if (exeFile == null) return null; // BUGFIX #491: we copy the executable to the tmpDir, as it is not clear if it can be executed where it is stored FileUtils.copyFileToDirectory(exeFile, tmpDir); return new File(tmpDir, exeFile.getName()); } catch (final CoreException e) { final IStatus status = e.getStatus(); monitor.setFinishInfo(status.getSeverity(), status.getMessage()); return null; } catch (final IOException e) { final String errorMsg = String.format(Messages.getString("WspmTuhhCalcJob.1"), e.getLocalizedMessage()); //$NON-NLS-1$ monitor.setFinishInfo(IStatus.ERROR, errorMsg); return null; } }
From source file:org.kiji.maven.plugins.BentoCluster.java
/** * Copy a site file generated by the bento script to the location specified by the plugin * specification./*from w ww . j a v a2s.co m*/ * * @param generatedSiteFile is the path to the site file generated by bento to copy. * @param pluginConfigDir to copy the site file to. * @throws MojoExecutionException if copying the site file or writing to the index file fails. */ private void copySiteFile(final File generatedSiteFile, final File pluginConfigDir) throws MojoExecutionException { try { FileUtils.copyFileToDirectory(generatedSiteFile, pluginConfigDir); } catch (final IOException ioe) { throw new MojoExecutionException(String.format("Copying site file %s to location %s failed.", generatedSiteFile.getAbsolutePath(), pluginConfigDir.getAbsolutePath()), ioe); } final File writtenFile = new File(pluginConfigDir, generatedSiteFile.getName()); Preconditions.checkArgument(writtenFile.exists()); mMavenLog.info("Wrote config site file: " + writtenFile.getAbsolutePath()); // We will also append the "conf-index.conf" file with the path to the newly written config // site file. final File confIndexFile = new File(pluginConfigDir, "conf-index.conf"); try { FileUtils.write(confIndexFile, writtenFile.getAbsolutePath() + "\n", true); } catch (final IOException ioe) { throw new MojoExecutionException( String.format("Unable to write to configuration index file: %s", writtenFile.getAbsolutePath()), ioe); } mMavenLog.info("Appended site file path to conf index: " + confIndexFile.getAbsolutePath()); }
From source file:org.kitodo.filemanagement.FileManagement.java
private void copyFileToDirectory(File sourceFile, File targetDirectory) throws IOException { FileUtils.copyFileToDirectory(sourceFile, targetDirectory); }
From source file:org.ktc.soapui.maven.extension.MockAsWarMojo.java
private void copySoapuiJar(File sourceDirectory, File destinationDirectory) throws IOException { getLog().info("Copying soapui jar to " + destinationDirectory); File[] mainJars = sourceDirectory.listFiles(new FilenameFilter() { @Override/*w w w . ja v a 2 s .com*/ public boolean accept(File dir, String name) { if (name.toLowerCase().startsWith("soapui") && name.toLowerCase().endsWith(".jar")) return true; return false; } }); if (mainJars.length == 0) { throw new RuntimeException("Unable to found a soapui jar in " + sourceDirectory); } File soapuiSourceJar = mainJars[0]; FileUtils.copyFileToDirectory(soapuiSourceJar, destinationDirectory); getLog().info("Copy done"); }
From source file:org.kuali.ole.docstore.common.client.DocstoreRestClient.java
private File createBagItfile(Licenses licenses) throws IOException { File bagitFolder = new File(FileUtils.getTempDirectoryPath() + File.separator + "bagit"); String licensesXml = licenses.serialize(licenses); File licensesXmlFile = new File(bagitFolder + File.separator + "licenses.xml"); FileUtils.writeStringToFile(licensesXmlFile, licensesXml); for (License license : licenses.getLicenses()) { if (license instanceof LicenseAttachment) { LicenseAttachment licenseAttachment = (LicenseAttachment) license; File contentFile = new File( licenseAttachment.getFilePath() + File.separator + licenseAttachment.getFileName()); FileUtils.copyFileToDirectory(contentFile, bagitFolder); }/*from www .ja v a 2 s . co m*/ } File bagitFile = createZipFile(bagitFolder); deleteFiles(bagitFile.listFiles()); bagitFolder.delete(); return bagitFile; }
From source file:org.kuali.rice.kew.plugin.ExtraClassPathTest.java
@Override public void setUp() throws Exception { // we want to copy the ziptest plugin into the plugin directories before the // test harness starts up. That way the plugin will be loaded at startup time. super.setUp(); TestUtilities.initializePluginDirectories(); String pluginZipFileLocation = new ClasspathOrFileResourceLoader() .getResource("classpath:org/kuali/rice/kew/plugin/extraclasspathtest.zip").getURL().getPath(); File pluginZipFile = new File(pluginZipFileLocation); assertTrue("File " + pluginZipFileLocation + " should exist", pluginZipFile.exists()); assertTrue("File " + pluginZipFileLocation + " should be a file", pluginZipFile.isFile()); FileUtils.copyFileToDirectory(pluginZipFile, TestUtilities.getPluginsDirectory()); pluginZipFile = new File(TestUtilities.getPluginsDirectory(), pluginZipFile.getName()); FileUtils.forceDeleteOnExit(pluginZipFile); registry = new PluginRegistryFactory().createPluginRegistry(); registry.start();/*from w w w. jav a 2s.c o m*/ }
From source file:org.kuali.rice.kew.plugin.HotDeployTest.java
@Test public void testHotDeploy() throws Exception { // Grab the ServerPluginRegistry PluginRegistry theRegistry = PluginUtils.getPluginRegistry(); assertNotNull("PluginRegistry should exist.", theRegistry); assertTrue(theRegistry instanceof ServerPluginRegistry); ServerPluginRegistry registry = (ServerPluginRegistry) theRegistry; // Let's shut down the asynchronous reloader and hot deployer because we want to do this synchronously. HotDeployer hotDeployer = registry.getHotDeployer(); Reloader reloader = registry.getReloader(); registry.stopHotDeployer();/*w w w .j av a 2 s . co m*/ registry.stopReloader(); // Assert that there are currently no plugins assertEquals("There should be no plugins.", 0, registry.getPluginEnvironments().size()); assertEquals("Resource loader should have no children.", 0, registry.getResourceLoaders().size()); // query the hot deployer directly about it's added and removed plugins assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); assertEquals("There should still be no plugins.", 0, registry.getPluginEnvironments().size()); // now let's copy a plugin over and run the hot deployer String pluginZipFileLocation = new ClasspathOrFileResourceLoader() .getResource("classpath:org/kuali/rice/kew/plugin/ziptest.zip").getURL().getPath(); File pluginZipFile = new File(pluginZipFileLocation); assertTrue("Plugin file '" + pluginZipFileLocation + "' should exist", pluginZipFile.exists()); assertTrue("Plugin file '" + pluginZipFileLocation + "' should be a file", pluginZipFile.isFile()); FileUtils.copyFileToDirectory(pluginZipFile, pluginDir); assertEquals("There should be one plugin added.", 1, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); // the plugin should have been hot deployed assertEquals("Plugin should have been hot deployed.", 1, registry.getPluginEnvironments().size()); // check added plugins again, it should now indicate no new added plugins assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be no plugins removed.", 0, hotDeployer.getRemovedPlugins().size()); // verify that the resource loading and the registry are sane and properly set up with the new plugin assertEquals("Resource loader should have 1 plugin child.", 1, registry.getResourceLoaders().size()); Plugin plugin = (Plugin) registry.getResourceLoaders().get(0); assertEquals("Plugin has wrong name.", new QName(CoreConfigHelper.getApplicationId(), "ziptest"), plugin.getName()); assertTrue("Plugin should be started.", plugin.isStarted()); assertEquals("Plugin in resource loader and environment should be the same.", plugin, registry.getPluginEnvironment(plugin.getName().getLocalPart()).getPlugin()); // The reloader should have a reference to the environment assertEquals("Reloader should have a reference to environment.", 1, reloader.getReloadables().size()); // now remove the plugin and ensure that it goes away FileUtils.forceDelete(new File(pluginDir, "ziptest.zip")); assertEquals("There should be no plugins added.", 0, hotDeployer.getAddedPlugins().size()); assertEquals("There should be one plugin removed.", 1, hotDeployer.getRemovedPlugins().size()); hotDeployer.run(); // verify that the resource loading and the registry no longer contain the plugin assertEquals("No plugins should be deployed.", 0, registry.getPluginEnvironments().size()); assertEquals("Resource loader should have 0 plugin children.", 0, registry.getResourceLoaders().size()); // also assert that the reloader no longer has a reference to the environment assertEquals("Reloader should no longer have reference to environment.", 0, reloader.getReloadables().size()); }
From source file:org.kuali.rice.kew.plugin.HotDeployTest.java
@Test public void testReloader() throws Exception { // Grab the ServerPluginRegistry PluginRegistry theRegistry = PluginUtils.getPluginRegistry(); assertNotNull("PluginRegistry should exist.", theRegistry); assertTrue(theRegistry instanceof ServerPluginRegistry); ServerPluginRegistry registry = (ServerPluginRegistry) theRegistry; // Let's shut down the asynchronous reloader and hot deployer because we want to do this synchronously. HotDeployer hotDeployer = registry.getHotDeployer(); Reloader reloader = registry.getReloader(); registry.stopHotDeployer();/*from w w w. j av a 2 s.co m*/ registry.stopReloader(); // Assert that there are currently no plugins assertEquals("There should be no plugins.", 0, registry.getPluginEnvironments().size()); assertEquals("Resource loader should have no children.", 0, registry.getResourceLoaders().size()); // now let's copy a plugin over and run the hot deployer String pluginZipFileLocation = new ClasspathOrFileResourceLoader() .getResource("classpath:org/kuali/rice/kew/plugin/ziptest.zip").getURL().getPath(); File pluginZipFile = new File(pluginZipFileLocation); assertTrue("Plugin file '" + pluginZipFileLocation + "' should exist", pluginZipFile.exists()); assertTrue("Plugin file '" + pluginZipFileLocation + "' should be a file", pluginZipFile.isFile()); FileUtils.copyFileToDirectory(pluginZipFile, pluginDir); // update pluginZipFile to point to the copy pluginZipFile = new File(pluginDir, pluginZipFile.getName()); assertTrue(pluginZipFile.exists()); // execute a hot deploy hotDeployer.run(); // the plugin should have been hot deployed assertEquals("Plugin should have been hot deployed.", 1, registry.getPluginEnvironments().size()); assertEquals("Resource loader should have 1 plugin child.", 1, registry.getResourceLoaders().size()); PluginEnvironment environment = registry.getPluginEnvironments().get(0); Plugin plugin = environment.getPlugin(); assertTrue(environment.isReloadable()); assertFalse(environment.isReloadNeeded()); // let's attempt to execute a Reload reloader.run(); // a reload should not have occurred here since nothing was updated assertTrue("Original plugin should still be running.", plugin.isStarted()); assertEquals("Plugin should not have changed.", plugin, registry.getPluginEnvironments().get(0).getPlugin()); // touch the plugin file and then reload FileUtils.touch(pluginZipFile); assertTrue("A reload should be needed now.", environment.isReloadNeeded()); reloader.run(); // the original plugin should now be stopped assertTrue("original plugin should be stopped.", !plugin.isStarted()); assertEquals("There should only be one Plugin.", 1, registry.getResourceLoaders().size()); PluginEnvironment newPluginEnvironment = registry.getPluginEnvironments().get(0); Plugin newPlugin = newPluginEnvironment.getPlugin(); assertEquals("There should still only be one environment.", 1, registry.getPluginEnvironments().size()); assertEquals("The plugin environments should still be the same.", environment, registry.getPluginEnvironments().get(0)); assertFalse("The old and new plugins should be different.", newPlugin.equals(plugin)); // verify that the resource loader was updated assertEquals("The resource loaders should have been updated with the new plugin.", newPlugin, registry.getResourceLoaders().get(0)); }
From source file:org.kuali.rice.kew.plugin.ZipFilePluginLoaderTest.java
@Before // public void setUp() throws Exception { // super.setUp(); // Config config = ConfigContext.getCurrentContextConfig(); // if (config == null) { // // because of previously running tests, the config might already be initialized // config = new SimpleConfig(); // config.getProperties().put(Config.SERVICE_NAMESPACE, "KEW"); // ConfigContext.init(config); // }/*from ww w. j a va 2 s . c o m*/ // // from RiceTestCase if this ever get put into that hierarchy // // } // // @After // public void tearDown() throws Exception { // super.setUp(); // try { // plugin.stop(); // } catch (Exception e) { // e.printStackTrace(); // } // try { // FileUtils.deleteDirectory(pluginDir); // } catch (Exception e) { // // } // } @Test public void testLoad() throws Exception { Config config = ConfigContext.getCurrentContextConfig(); if (config == null) { // because of previously running tests, the config might already be initialized config = new JAXBConfigImpl(); config.putProperty(CoreConstants.Config.APPLICATION_ID, "KEW"); ConfigContext.init(config); } File pluginZipFile = new ClasspathOrFileResourceLoader() .getResource("classpath:org/kuali/rice/kew/plugin/ziptest.zip").getFile(); assertTrue(pluginZipFile.exists()); assertTrue(pluginZipFile.isFile()); // create a temp directory to copy the zip file into pluginDir = TestUtilities.createTempDir(); // copy the zip file FileUtils.copyFileToDirectory(pluginZipFile, pluginDir); pluginZipFile = new File(pluginDir, pluginZipFile.getName()); assertTrue(pluginZipFile.exists()); pluginZipFile.deleteOnExit(); // create the ZipFilePluginLoader and load the plugin ZipFilePluginLoader loader = new ZipFilePluginLoader(pluginZipFile, null, ClassLoaderUtils.getDefaultClassLoader(), ConfigContext.getCurrentContextConfig()); this.plugin = loader.load(); assertNotNull("Plugin should have been successfully loaded.", plugin); // check the plugin name, it's QName should be '{KUALI}ziptest', it's plugin name should be 'ziptest' assertEquals("Plugin QName should be '{KUALI}ziptest'", new QName("KUALI", "ziptest"), plugin.getName()); // start the plugin this.plugin.start(); // verify that the plugin was extracted, should be in a directory named the same as the local part of the // QName File extractedDirectory = new File(pluginDir, plugin.getName().getLocalPart()); assertTrue("Plugin should have been extracted.", extractedDirectory.exists()); assertTrue(extractedDirectory.isDirectory()); File[] files = extractedDirectory.listFiles(); assertEquals("Should be 3 files", 3, files.length); // try loading some classes and checking that things got loaded properly assertNotNull("Resource should exist.", plugin.getClassLoader().getResource("lib-test.txt")); assertNotNull("Resource should exist.", plugin.getClassLoader().getResource("classes-test.txt")); // check the config values assertEquals(plugin.getConfig().getProperty("test.param.1"), "test.value.1"); assertEquals(plugin.getConfig().getProperty("test.param.2"), "test.value.2"); assertEquals(plugin.getConfig().getProperty("test.param.3"), "test.value.3"); // verify the modification checks on the plugin which drive hot deployment assertFalse("Plugin should not be modifed at this point.", loader.isModified()); // record the last modified date of the extracted directory long lastModified = pluginDir.lastModified(); // sleep for a milliseconds before touching the file, this will help our last modified check so we don't // get the same value Thread.sleep(1000); // touch the zip file FileUtils.touch(pluginZipFile); assertTrue("Plugin should be modifed after zip file is touched.", loader.isModified()); plugin.stop(); // reload the plugin this.plugin = loader.load(); this.plugin.start(); assertFalse("After reload, plugin should no longer be modifed.", loader.isModified()); // check the last modified date of the extracted directory assertTrue("The extracted directory should have been modified.", pluginDir.lastModified() > lastModified); try { plugin.stop(); } catch (Exception e) { e.printStackTrace(); } try { FileUtils.deleteDirectory(pluginDir); } catch (Exception e) { } }