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.cloudifysource.quality.iTests.test.cli.cloudify.events.CLILifecycleEventsTest.java
/** * Case 6/*from w w w .j a v a 2 s.c o m*/ * ====== * * 1. Install an application with 2 services. * 2. One service will be installed much faster than the other one. * 3. Assert that events from the slow service are displayed as well. */ @Test public void testDelayedServiceLifeCycleEvents() throws IOException, DSLException, InterruptedException, PackagingException { String slowgsc; if (ScriptUtils.isWindows()) { slowgsc = Resources.getResource("slowgsc/slowgsc.bat").getPath(); } else { slowgsc = Resources.getResource("slowgsc/slowgsc.sh").getPath(); } FileUtils.copyFileToDirectory(new File(slowgsc), new File(ScriptUtils.getBuildBinPath())); // before we install the service manipulate gsc.xml File gscXml = new File(ScriptUtils.getBuildPath() + "/config/gsa/gsc.xml"); try { IOUtils.replaceTextInFile(gscXml.getAbsolutePath(), "/bin/gsc.", "/bin/slowgsc."); testApplicationInstallLifecycleLogs(); } finally { IOUtils.replaceTextInFile(gscXml.getAbsolutePath(), "/bin/slowgsc.", "/bin/gsc."); } }
From source file:org.codehaus.mojo.gwt.eclipse.EclipseMojo.java
protected void setupExplodedWar() throws MojoExecutionException { try {//from www . j a va 2 s . c o m File classes = new File(hostedWebapp, "WEB-INF/classes"); if (!buildOutputDirectory.getAbsolutePath().equals(classes.getAbsolutePath())) { getLog().warn("Your POM <build><outputdirectory> must match your " + "hosted webapp WEB-INF/classes folder for GWT Hosted browser to see your classes."); } File lib = new File(hostedWebapp, "WEB-INF/lib"); getLog().info("create exploded Jetty webapp in " + hostedWebapp); lib.mkdirs(); Collection<Artifact> artifacts = getProject().getRuntimeArtifacts(); for (Artifact artifact : artifacts) { if (!artifact.getFile().isDirectory()) { FileUtils.copyFileToDirectory(artifact.getFile(), lib); } else { // TODO automatically add this one to GWT warnings exlusions } } } catch (IOException ioe) { throw new MojoExecutionException("Failed to create Jetty exploded webapp", ioe); } }
From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
/** * @param rootFileEntry files and directories seperated by semicolons, the syntax is: * <ul>//from w w w.ja v a 2 s. c om * <li>for a relative file: file:license.html,...</li> * <li>for a absolute file: absolute:file:/eclipse/about.html,...</li> * <li>for a relative folder: rootfiles,...</li> * <li>for a absolute folder: absolute:/eclipse/rootfiles,...</li> * </ul> * @param subFolder the sub folder to which the root file entries are copied to */ private void handleRootEntry(File target, String rootFileEntries, String subFolder) { StringTokenizer t = new StringTokenizer(rootFileEntries, ","); File destination = target; if (subFolder != null) { destination = new File(target, subFolder); } while (t.hasMoreTokens()) { String rootFileEntry = t.nextToken(); String fileName = rootFileEntry.trim(); boolean isAbsolute = false; if (fileName.startsWith("absolute:")) { isAbsolute = true; fileName = fileName.substring("absolute:".length()); } if (fileName.startsWith("file")) { fileName = fileName.substring("file:".length()); } File source = null; if (!isAbsolute) { source = new File(project.getBasedir(), fileName); } else { source = new File(fileName); } if (source.isFile()) { try { FileUtils.copyFileToDirectory(source, destination); } catch (IOException e) { e.printStackTrace(); } } else if (source.isDirectory()) { try { FileUtils.copyDirectoryToDirectory(source, destination); } catch (IOException e) { e.printStackTrace(); } } else { getLog().warn("Skipping root entry " + rootFileEntry); } } }
From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
private void copyToDirectory(File source, File targetFolder) throws MojoExecutionException { try {/*from ww w. j a v a 2s. c o m*/ if (source.isFile()) { FileUtils.copyFileToDirectory(source, targetFolder); } else if (source.isDirectory()) { FileUtils.copyDirectoryToDirectory(source, targetFolder); } else { getLog().warn("Skipping bundle " + source.getAbsolutePath()); } } catch (IOException e) { throw new MojoExecutionException("Unable to copy " + source.getName(), e); } }
From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
private void copyExecutable(TargetEnvironment environment, File target) throws MojoExecutionException, MojoFailureException { getLog().debug("Creating launcher"); FeatureDescription feature;/*from w w w . j ava 2 s. c om*/ // eclipse 3.2 if (isEclipse32Platform()) { feature = featureResolutionState.getFeature("org.eclipse.platform.launchers", null); } else { feature = featureResolutionState.getFeature("org.eclipse.equinox.executable", null); } if (feature == null) { throw new MojoExecutionException("RPC delta feature not found!"); } File location = feature.getLocation(); String os = environment.getOs(); String ws = environment.getWs(); String arch = environment.getArch(); File osLauncher = new File(location, "bin/" + ws + "/" + os + "/" + arch); try { // Don't copy eclipsec file IOFileFilter eclipsecFilter = FileFilterUtils .notFileFilter(FileFilterUtils.prefixFileFilter("eclipsec")); FileUtils.copyDirectory(osLauncher, target, eclipsecFilter); } catch (IOException e) { throw new MojoExecutionException("Unable to copy launcher executable", e); } File launcher = getLauncher(environment, target); // make launcher executable try { getLog().debug("running chmod"); ArchiveEntryUtils.chmod(launcher, 0755, null); } catch (ArchiverException e) { throw new MojoExecutionException("Unable to make launcher being executable", e); } File osxEclipseApp = null; // Rename launcher if (productConfiguration.getLauncher() != null && productConfiguration.getLauncher().getName() != null) { String launcherName = productConfiguration.getLauncher().getName(); String newName = launcherName; // win32 has extensions if (PlatformPropertiesUtils.OS_WIN32.equals(os)) { String extension = FilenameUtils.getExtension(launcher.getAbsolutePath()); newName = launcherName + "." + extension; } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { // the launcher is renamed to "eclipse", because // this is the value of the CFBundleExecutable // property within the Info.plist file. // see http://jira.codehaus.org/browse/MNGECLIPSE-1087 newName = "eclipse"; } getLog().debug("Renaming launcher to " + newName); File newLauncher = new File(launcher.getParentFile(), newName); if (!launcher.renameTo(newLauncher)) { throw new MojoExecutionException("Could not rename native launcher to " + newName); } launcher = newLauncher; // macosx: the *.app directory is renamed to the // product configuration launcher name // see http://jira.codehaus.org/browse/MNGECLIPSE-1087 if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { newName = launcherName + ".app"; getLog().debug("Renaming Eclipse.app to " + newName); File eclipseApp = new File(target, "Eclipse.app"); osxEclipseApp = new File(eclipseApp.getParentFile(), newName); eclipseApp.renameTo(osxEclipseApp); // ToDo: the "Info.plist" file must be patched, so that the // property "CFBundleName" has the value of the // launcherName variable } } // icons if (productConfiguration.getLauncher() != null) { if (PlatformPropertiesUtils.OS_WIN32.equals(os)) { getLog().debug("win32 icons"); List<String> icons = productConfiguration.getW32Icons(); if (icons != null) { getLog().debug(icons.toString()); try { String[] args = new String[icons.size() + 1]; args[0] = launcher.getAbsolutePath(); int pos = 1; for (String string : icons) { args[pos] = string; pos++; } IconExe.main(args); } catch (Exception e) { throw new MojoExecutionException("Unable to replace icons", e); } } else { getLog().debug("icons is null"); } } else if (PlatformPropertiesUtils.OS_LINUX.equals(os)) { String icon = productConfiguration.getLinuxIcon(); if (icon != null) { try { File sourceXPM = new File(project.getBasedir(), removeFirstSegment(icon)); File targetXPM = new File(launcher.getParentFile(), "icon.xpm"); FileUtils.copyFile(sourceXPM, targetXPM); } catch (IOException e) { throw new MojoExecutionException("Unable to create ico.xpm", e); } } } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { String icon = productConfiguration.getMacIcon(); if (icon != null) { try { if (osxEclipseApp == null) { osxEclipseApp = new File(target, "Eclipse.app"); } File source = new File(project.getBasedir(), removeFirstSegment(icon)); File targetFolder = new File(osxEclipseApp, "/Resources/" + source.getName()); FileUtils.copyFile(source, targetFolder); // Modify eclipse.ini File iniFile = new File(osxEclipseApp + "/Contents/MacOS/eclipse.ini"); if (iniFile.exists() && iniFile.canWrite()) { StringBuffer buf = new StringBuffer(FileUtils.readFileToString(iniFile)); int pos = buf.indexOf("Eclipse.icns"); buf.replace(pos, pos + 12, source.getName()); FileUtils.writeStringToFile(iniFile, buf.toString()); } } catch (Exception e) { throw new MojoExecutionException("Unable to create macosx icon", e); } } } } // eclipse 3.2 if (isEclipse32Platform()) { File startUpJar = new File(location, "bin/startup.jar"); try { FileUtils.copyFileToDirectory(startUpJar, target); } catch (IOException e) { throw new MojoExecutionException("Unable to copy startup.jar executable", e); } } }
From source file:org.craftercms.studio.impl.v1.repository.disk.DiskContentRepository.java
@Override public boolean copyContent(String fromPath, String toPath) { boolean success = true; try {/*from w ww . jav a 2s . co m*/ Path source = constructRepoPath(fromPath); Path target = constructRepoPath(toPath); File sourceFile = source.toFile(); if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, target.toFile()); } else { FileUtils.copyFileToDirectory(sourceFile, target.toFile()); } } catch (Exception err) { // log this error logger.error("Error while copping content from {0} to {1}", err, fromPath, toPath); success = false; } return success; }
From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepository.java
@Override public boolean copyContent(String site, String fromPath, String toPath) { boolean success = true; try {/*from w ww .j a va 2 s. c om*/ Repository repo; if (StringUtils.isEmpty(site)) { repo = getGlobalConfigurationRepositoryInstance(); } else { repo = getSiteRepositoryInstance(site); } String gitFromPath = getGitPath(fromPath); RevTree fromTree = getTree(repo); TreeWalk fromTw = TreeWalk.forPath(repo, gitFromPath, fromTree); String gitToPath = getGitPath(toPath); RevTree toTree = getTree(repo); TreeWalk toTw = TreeWalk.forPath(repo, gitToPath, toTree); FS fs = FS.detect(); File repoRoot = repo.getWorkTree(); Path sourcePath = null; if (fromTw == null) { sourcePath = Paths.get(fs.normalize(repoRoot.getPath()), gitFromPath); } else { sourcePath = Paths.get(fs.normalize(repoRoot.getPath()), fromTw.getPathString()); } Path targetPath = null; if (toTw == null) { targetPath = Paths.get(fs.normalize(repoRoot.getPath()), gitToPath); } else { targetPath = Paths.get(fs.normalize(repoRoot.getPath()), toTw.getPathString()); } File sourceFile = sourcePath.toFile(); if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, targetPath.toFile()); } else { FileUtils.copyFileToDirectory(sourceFile, targetPath.toFile()); } Git git = new Git(repo); git.add().addFilepattern(gitToPath).call(); } catch (IOException | GitAPIException err) { // log this error logger.error("Error while copping content from {0} to {1}", err, fromPath, toPath); success = false; } return success; }
From source file:org.crudgenerator.mojo.exporter.ModelGeneratorMojo.java
@SuppressWarnings("rawtypes") @Override//from w ww .j a v a 2 s. com public void execute() throws MojoExecutionException, MojoFailureException { commonCorePackage = System.getProperty("commonPackage"); 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"); } // 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.dashbuilder.dataprovider.backend.elasticsearch.ElasticSearchDataSetTestBase.java
@BeforeClass public static void runELServer() throws Exception { if (runServer) { // Build a temporary EL home folder. Copy config files to it. File elHome = elHomeFolder.newFolder("dashbuilder-elasticsearch"); File elHomeConfig = new File(elHome, EL_CONFIG_DIR); URL configFileUrl = Thread.currentThread().getContextClassLoader().getResource(EL_CONFIG_ELASTICSEARCH); URL loggingFileUrl = Thread.currentThread().getContextClassLoader().getResource(EL_CONFIG_LOGGING); File configFile = new File(configFileUrl.getFile()); File loggingFile = new File(loggingFileUrl.getFile()); // Create the configuration files and copy config files. if (!elHomeConfig.mkdirs()) throw new RuntimeException( "Cannot create config directory at [" + elHomeConfig.getAbsolutePath() + "]."); FileUtils.copyFileToDirectory(configFile, elHomeConfig); FileUtils.copyFileToDirectory(loggingFile, elHomeConfig); // Set the system properties for running the EL server. System.setProperty(EL_PROPERTY_ELASTICSEARCH, ""); System.setProperty(EL_PROPERTY_FOREGROUND, "yes"); System.setProperty(EL_PROPERTY_HOME, elHome.getAbsolutePath()); // Run the EL server. new Thread("test_ELserver") { @Override//w w w .ja v a 2 s.c o m public void run() { super.run(); Bootstrap.main(new String[] {}); } }.run(); } if (populateServer) { // Create the expensereports example index. createIndexELServer(); // Populate the server with some test content. populateELServer(EL_EXAMPLE_DATA); // Test mappings and document count. testMappingCreated(); testDocumentsCount(); } }
From source file:org.domainmath.gui.update.UpdateFrame.java
/** * Back up contents to a folder.// w w w. j av a 2 s . c om * @return backup folder */ private File backup() { // make an unique folder to store backup files. Long n = new Random().nextLong(); File backupDir = new File(System.getProperty("user.dir") + File.separator + "backup_" + n.toString()); backupDir.mkdir(); // get files list. List<File> fileList = getFileList( new File(System.getProperty("user.dir") + File.separator + "files_backup.ini")); // backup. for (File file : fileList) { // copy folders. if (file.isDirectory()) { try { FileUtils.copyDirectoryToDirectory(file, backupDir); FileUtils.deleteDirectory(file); } catch (IOException ex) { } } else if (file.isFile()) { try { FileUtils.copyFileToDirectory(file, backupDir); FileUtils.forceDelete(file); } catch (IOException ex) { } } } return backupDir; }