List of usage examples for org.apache.commons.io FileUtils copyDirectoryToDirectory
public static void copyDirectoryToDirectory(File srcDir, File destDir) throws IOException
From source file:org.eclipse.thym.ui.wizard.export.NativeBinaryExportOperation.java
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { SubMonitor sm = SubMonitor.convert(monitor); sm.setWorkRemaining(delegates.size() * 10); for (AbstractNativeBinaryBuildDelegate delegate : delegates) { if (monitor.isCanceled()) { break; }// w w w. j av a 2 s.com delegate.setRelease(true); delegate.buildNow(sm.newChild(10)); try { File buildArtifact = delegate.getBuildArtifact(); File destinationFile = new File(destinationDir, buildArtifact.getName()); if (destinationFile.exists()) { String callback = overwriteQuery.queryOverwrite(destinationFile.toString()); if (IOverwriteQuery.NO.equals(callback)) { continue; } if (IOverwriteQuery.CANCEL.equals(callback)) { break; } } File artifact = delegate.getBuildArtifact(); if (artifact.isDirectory()) { FileUtils.copyDirectoryToDirectory(artifact, destinationDir); } else { FileUtils.copyFileToDirectory(artifact, destinationDir); } sm.done(); } catch (IOException e) { HybridCore.log(IStatus.ERROR, "Error on NativeBinaryExportOperation", e); } } monitor.done(); }
From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentUninstaller.java
@Override public boolean uninstallComponent(Component component) throws ApsSystemException { ServletContext servletContext = ((ConfigurableWebApplicationContext) _applicationContext) .getServletContext();//from www . j a va 2 s.c om ClassLoader cl = (ClassLoader) servletContext.getAttribute("componentInstallerClassLoader"); List<ClassPathXmlApplicationContext> ctxList = (List<ClassPathXmlApplicationContext>) servletContext .getAttribute("pluginsContextsList"); ClassPathXmlApplicationContext appCtx = null; if (ctxList != null) { for (ClassPathXmlApplicationContext ctx : ctxList) { if (component.getCode().equals(ctx.getDisplayName())) { appCtx = ctx; } } } String appRootPath = servletContext.getRealPath("/"); String backupDirPath = appRootPath + "componentinstaller" + File.separator + component.getArtifactId() + "-backup"; Map<File, File> resourcesMap = new HashMap<File, File>(); try { ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { if (cl != null) { Thread.currentThread().setContextClassLoader(cl); } if (null == component || null == component.getUninstallerInfo()) { return false; } this.getDatabaseManager().createBackup();//backup database SystemInstallationReport report = super.extractReport(); ComponentUninstallerInfo ui = component.getUninstallerInfo(); //remove records from db String[] dataSourceNames = this.extractBeanNames(DataSource.class); for (int j = 0; j < dataSourceNames.length; j++) { String dataSourceName = dataSourceNames[j]; Resource resource = (null != ui) ? ui.getSqlResources(dataSourceName) : null; String script = (null != resource) ? this.readFile(resource) : null; if (null != script && script.trim().length() > 0) { DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName); String[] queries = QueryExtractor.extractDeleteQueries(script); TableDataUtils.executeQueries(dataSource, queries, true); } } this.executePostProcesses(ui.getPostProcesses()); //drop tables Map<String, List<String>> tableMapping = component.getTableMapping(); if (tableMapping != null) { for (int j = 0; j < dataSourceNames.length; j++) { String dataSourceName = dataSourceNames[j]; List<String> tableClasses = tableMapping.get(dataSourceName); if (null != tableClasses && tableClasses.size() > 0) { List<String> newList = new ArrayList<String>(); newList.addAll(tableClasses); Collections.reverse(newList); DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName); IDatabaseManager.DatabaseType type = this.getDatabaseManager() .getDatabaseType(dataSource); TableFactory tableFactory = new TableFactory(dataSourceName, dataSource, type); tableFactory.dropTables(newList); } } } //move resources (jar, files and folders) on temp folder List<String> resourcesPaths = ui.getResourcesPaths(); if (resourcesPaths != null) { for (String resourcePath : resourcesPaths) { try { String fullResourcePath = servletContext.getRealPath(resourcePath); File resFile = new File(fullResourcePath); String relResPath = FilenameUtils.getPath(resFile.getAbsolutePath()); File newResFile = new File( backupDirPath + File.separator + relResPath + resFile.getName()); if (resFile.isDirectory()) { FileUtils.copyDirectory(resFile, newResFile); resourcesMap.put(resFile, newResFile); FileUtils.deleteDirectory(resFile); } else { FileUtils.copyFile(resFile, newResFile); resourcesMap.put(resFile, newResFile); FileUtils.forceDelete(resFile); } } catch (Exception e) { } } } //upgrade report ComponentInstallationReport cir = report.getComponentReport(component.getCode(), true); cir.getDataSourceReport().upgradeDatabaseStatus(SystemInstallationReport.Status.UNINSTALLED); cir.getDataReport().upgradeDatabaseStatus(SystemInstallationReport.Status.UNINSTALLED); this.saveReport(report); //remove plugin's xmlapplicationcontext if present if (appCtx != null) { appCtx.close(); ctxList.remove(appCtx); } InitializerManager initializerManager = (InitializerManager) _applicationContext .getBean("InitializerManager"); initializerManager.reloadCurrentReport(); ComponentManager componentManager = (ComponentManager) _applicationContext .getBean("ComponentManager"); componentManager.refresh(); } catch (Exception e) { _logger.error("Unexpected error in component uninstallation process", e); throw new ApsSystemException("Unexpected error in component uninstallation process.", e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); ApsWebApplicationUtils.executeSystemRefresh(servletContext); } } catch (Throwable t) { //restore files on temp folder try { for (Object object : resourcesMap.entrySet()) { File resFile = ((Map.Entry<File, File>) object).getKey(); File newResFile = ((Map.Entry<File, File>) object).getValue(); if (newResFile.isDirectory()) { FileUtils.copyDirectoryToDirectory(newResFile, resFile.getParentFile()); } else { FileUtils.copyFile(newResFile, resFile.getParentFile()); } } } catch (Exception e) { } _logger.error("Unexpected error in component uninstallation process", t); throw new ApsSystemException("Unexpected error in component uninstallation process.", t); } finally { //clean temp folder } return true; }
From source file:org.exist.replication.jms.obsolete.FileSystemListener.java
private void handleCollection(eXistMessage em) { File src = new File(baseDir, em.getResourcePath()); switch (em.getResourceOperation()) { case CREATE:/* w w w. java 2 s .c om*/ case UPDATE: try { // Create dirs if not existent FileUtils.forceMkdir(src); } catch (IOException ex) { LOG.error(ex); } break; case DELETE: FileUtils.deleteQuietly(src); break; case MOVE: File mvDest = new File(baseDir, em.getDestinationPath()); try { FileUtils.moveDirectoryToDirectory(src, mvDest, true); } catch (IOException ex) { LOG.error(ex); } break; case COPY: File cpDest = new File(baseDir, em.getDestinationPath()); try { FileUtils.copyDirectoryToDirectory(src, cpDest); } catch (IOException ex) { LOG.error(ex); } break; default: LOG.error("Unknown change type"); } }
From source file:org.iobserve.mobile.instrument.core.APKInstrumenter.java
/** * Builds the agent with all class files and libraries. * /* ww w . j av a 2s. co m*/ * @param instrConfig * the configuration of the instrumentation * @throws IOException * if not all files could be resolved * @throws ZipException * if zipping to agent build fails */ private void buildAgentInner(final InstrumentationConfiguration instrConfig) throws IOException, ZipException { LOG.info("Bundling current agent version."); final File agentZipOld = AGENT_BUILD; agentZipOld.delete(); FileUtils.deleteDirectory(AGENT_LIB_BUILD_TEMP); final ZipFile agentZipNew = new ZipFile(AGENT_BUILD); // TO NOT ADD INCONSISTENT FOLDERS FileUtils.copyDirectory(AGENT_SHARED, AGENT_CURRENT); FileUtils.copyDirectory(AGENT_RECORDS_COMMON, AGENT_CURRENT); final File[] libs = AGENT_LIB_CURRENT.listFiles(); for (File lib : libs) { if (lib.isFile() && !lib.getName().contains("org.iobserve.mobile.agent")) { final ZipFile zipF = new ZipFile(lib); zipF.extractAll(AGENT_LIB_BUILD_TEMP.getAbsolutePath()); } } final File toAdd = AGENT_LIB_BUILD_TEMP; final List<String> includedFolders = instrConfig.getXmlConfiguration().getAgentBuildConfiguration() .getLibraryFolders(); for (String includedFolder : includedFolders) { final File[] toAddArray = new File(toAdd.getAbsolutePath() + "/" + includedFolder).listFiles(); if (toAddArray != null) { final File containingFolder = new File(AGENT_CURRENT.getAbsolutePath() + "/" + includedFolder); if (!containingFolder.exists()) { containingFolder.mkdir(); } for (File ff : toAddArray) { if (ff.isDirectory()) { FileUtils.copyDirectoryToDirectory(ff, containingFolder); } else { FileUtils.copyFile(ff, new File(containingFolder.getAbsolutePath() + "/" + ff.getName())); } } } } addFolderToZipNoParent(agentZipNew, AGENT_CURRENT); LOG.info("Bundled agent with an actual size of " + round(agentZipNew.getFile().length() / MB_FACTOR) + "MB."); }
From source file:org.jahia.configuration.configurators.JahiaGlobalConfigurator.java
private void copyExternalizedConfig() throws IOException, ArchiverException { if (jahiaConfig.isExternalizedConfigExploded()) { // we copy configuration to folder without archiving it File target = new File(jahiaConfig.getExternalizedConfigTargetPath()); final File targetCfgDir = new File(target, "jahia"); final File srcDir = new File(jahiaConfigDir, "jahia"); if (targetCfgDir.isDirectory()) { File jahiaPropsFile = new File(targetCfgDir, "jahia.properties"); if (jahiaPropsFile.exists()) { Properties p = PropertyUtils.loadProperties(jahiaPropsFile); if (p.containsKey("db_script") && !jahiaConfig.getDatabaseType().equals(p.getProperty("db_script")) || !p.containsKey("db_script") && !jahiaConfig.getDatabaseType().equals("derby_embedded")) { getLogger().info("Deleting existing " + jahiaPropsFile + " file as the target database type has changed"); jahiaPropsFile.delete(); }//from w w w. j a va 2 s . co m } // we won't overwrite existing files FileUtils.copyDirectory(srcDir, targetCfgDir, new FileFilter() { @Override public boolean accept(File pathname) { if (!pathname.isFile()) { return true; } return !new File(targetCfgDir, pathname.getAbsolutePath().substring(srcDir.getAbsolutePath().length())).exists(); } }); } else { FileUtils.copyDirectoryToDirectory(srcDir, target); } } else { boolean verbose = true; JarArchiver archiver = new JarArchiver(); if (verbose) { archiver.enableLogging( new org.codehaus.plexus.logging.console.ConsoleLogger(Logger.LEVEL_DEBUG, "console")); } String jarFileName = "jahia-config.jar"; if (!StringUtils.isBlank(jahiaConfig.getExternalizedConfigFinalName())) { jarFileName = jahiaConfig.getExternalizedConfigFinalName(); if (!StringUtils.isBlank(jahiaConfig.getExternalizedConfigClassifier())) { jarFileName += "-" + jahiaConfig.getExternalizedConfigClassifier(); } jarFileName += ".jar"; } // let's generate the WAR file File targetFile = new File(jahiaConfig.getExternalizedConfigTargetPath(), jarFileName); // archiver.setManifest(targetManifestFile); archiver.setDestFile(targetFile); String excludes = null; archiver.addDirectory(jahiaConfigDir, null, excludes != null ? excludes.split(",") : null); archiver.createArchive(); } FileUtils.deleteDirectory(jahiaConfigDir); }
From source file:org.jboss.tools.aerogear.hybrid.ui.wizard.export.NativeBinaryExportOperation.java
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Build native binaries", delegates.size() * 2); for (AbstractNativeBinaryBuildDelegate delegate : delegates) { if (monitor.isCanceled()) { break; }/* ww w . j ava2 s . c o m*/ SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); subMonitor.setTaskName("Building " + delegate.getProject().getName()); delegate.setRelease(true); delegate.buildNow(subMonitor); try { File buildArtifact = delegate.getBuildArtifact(); File destinationFile = new File(destinationDir, buildArtifact.getName()); if (destinationFile.exists()) { String callback = overwriteQuery.queryOverwrite(destinationFile.toString()); if (IOverwriteQuery.NO.equals(callback)) { continue; } if (IOverwriteQuery.CANCEL.equals(callback)) { break; } } File artifact = delegate.getBuildArtifact(); if (artifact.isDirectory()) { FileUtils.copyDirectoryToDirectory(artifact, destinationDir); } else { FileUtils.copyFileToDirectory(artifact, destinationDir); } monitor.worked(1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } monitor.done(); }
From source file:org.jwebsocket.plugins.reporting.service.JasperReportService.java
/** * Save the report in the desire format. Generate an array of bytes to * transform the report in a base64 String. * * @param aUserHome/*from w w w.java 2 s . c o m*/ * @param aReportName * @param aParams * @param aFields * @param aConnection * @param aFormat * @return * @throws Exception */ @Override public String generateReport(String aUserHome, String aReportName, Map<String, Object> aParams, List<Map<String, Object>> aFields, Connection aConnection, String aFormat) throws Exception { // getting the report template path to compile String lTemplatePath = getReportTemplatePath(aReportName); // a JasperReport object JasperReport lJasperReport; // searching for JasperReport object in cache to improve performance if (mCache.containsKey(lTemplatePath)) { // initializing the JasperReport object from cache lJasperReport = mCache.get(lTemplatePath); } else { // compiling the JasperReport object using the report template path lJasperReport = JasperCompileManager.compileReport(lTemplatePath); mCache.put(lTemplatePath, lJasperReport); } // JasperPrint Object JasperPrint lJasperPrint; if (null != aConnection) { lJasperPrint = JasperFillManager.fillReport(lJasperReport, aParams, aConnection); } else { Assert.notNull(aFields, "The 'fields' arguments cannot be null!"); JRBeanCollectionDataSource lReportDataSource = new JRBeanCollectionDataSource(aFields); lJasperPrint = JasperFillManager.fillReport(lJasperReport, aParams, lReportDataSource); } // getting the directory for the report String lOutputDir = mSettings.getOutputFolder().replace("${USER_HOME}", aUserHome); FileUtils.forceMkdir(new File(lOutputDir)); // the final zip file path String lFinalPath = ""; String lDestFile = lOutputDir + File.separator + aReportName; // generating the report if (ReportFormats.PDF.equals(aFormat)) { lDestFile = lDestFile + ".pdf"; JasperExportManager.exportReportToPdfFile(lJasperPrint, lDestFile); lFinalPath = lDestFile; } else if (ReportFormats.HTML.equals(aFormat)) { lDestFile = lDestFile + ".html"; JasperExportManager.exportReportToHtmlFile(lJasperPrint, lDestFile); // getting the 'report_name'.html page and the report_name_folder_files File lFilesDirectory = new File(lDestFile + "_files"); File lFilePage = new File(lDestFile); // moving resulting files to a unique directory to get zip File lReportZipFolder = new File(lOutputDir + File.separator + aReportName); FileUtils.forceMkdir(lReportZipFolder); FileUtils.copyDirectoryToDirectory(lFilesDirectory, lReportZipFolder); FileUtils.copyFileToDirectory(lFilePage, lReportZipFolder, true); // deleting the resulting files of reporting FileUtils.forceDelete(lFilesDirectory); FileUtils.forceDelete(lFilePage); // using the zip method of FileUtils String[] lFiles = new String[] { lReportZipFolder.getPath() }; Tools.zip(lFiles, lOutputDir + File.separator + aReportName + ".zip"); FileUtils.deleteDirectory(lReportZipFolder); lFinalPath = lOutputDir + aReportName + ".zip"; } else { throw new Exception("The given format is not supported!"); } return lFinalPath.replace(aUserHome, ""); }
From source file:org.kalypso.calculation.plc.postprocessing.PLCPreprocessingSimulation.java
private void doWspmModel(final ISimulationDataProvider inputProvider, final File statusQuoFolder) throws SimulationException, IOException { if (!inputProvider.hasID(INPUT_WSPM_MODEL)) return;// w w w . j a v a2s. co m final File actualWspmModel = FileUtils.toFile((URL) inputProvider.getInputForID(INPUT_WSPM_MODEL)); FileUtils.copyDirectoryToDirectory(actualWspmModel, statusQuoFolder); }
From source file:org.keycloak.testsuite.adapter.servlet.cluster.AbstractSAMLAdapterClusterTest.java
protected static void prepareServerDirectory(String targetSubdirectory) throws IOException { Path path = Paths.get(System.getProperty("app.server.home"), targetSubdirectory); File targetSubdirFile = path.toFile(); FileUtils.deleteDirectory(targetSubdirFile); FileUtils.forceMkdir(targetSubdirFile); FileUtils.copyDirectoryToDirectory( Paths.get(System.getProperty("app.server.home"), "standalone", "deployments").toFile(), targetSubdirFile);// w w w . j a v a 2 s . c o m }
From source file:org.kuali.ole.docstore.utility.DocStoreSettingsUtil.java
/** * Method to copyResources/*from ww w . j a va 2 s . c o m*/ */ public void copyResources() { try { File targetFolder = new File(DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH + File.separator + DocStoreConstants.RESOURCES_DIR_NAME); if (!targetFolder.exists() || (targetFolder.exists() && targetFolder.list().length <= 0)) { Enumeration<URL> resources = this.getClass().getClassLoader() .getResources(DocStoreConstants.RESOURCES_DIR_NAME); boolean canItBeTaken = false; while (resources.hasMoreElements()) { URL url = resources.nextElement(); try { url.toURI(); canItBeTaken = true; } catch (Exception e) { e.printStackTrace(); } if (canItBeTaken) { logger.debug("Copying Settings from source @:" + url.getFile()); File sourceDir = new File(url.toURI()); FileUtils.copyDirectoryToDirectory(sourceDir, targetFolder.getParentFile()); } } logger.debug("Copied Settings @: " + DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH); } else logger.info("Using Existing Settings @: " + DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH); } catch (Exception e) { e.printStackTrace(); } }