Java Code Examples for org.apache.commons.io.FileUtils#moveDirectoryToDirectory()

The following examples show how to use org.apache.commons.io.FileUtils#moveDirectoryToDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileController.java    From opscenter with Apache License 2.0 5 votes vote down vote up
/**
 * 文件粘贴
 * 
 * @param fileBean
 * @param session
 * @return
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/filepaste")
public FileBean filePaste(FileBean fileBean, HttpSession session) {
	try {
		String sourcePath = (String) session.getAttribute("sourcePath");
		String command = (String) session.getAttribute("command");
		List<String> names = (List<String>) session.getAttribute("names");
		if (names == null) {
			fileBean.setCode("400");
			fileBean.setMessage("没有需要粘贴的文件");
			return fileBean;
		}
		fileBean.setCode("200");
		fileBean.setMessage("文件已粘贴");
		for (String name : names) {
			File sourceFile = new File(sourcePath + SEPARATOR + name);
			if (sourceFile.isFile()) {
				File targetFile = new File(fileBean.getFilePath() + SEPARATOR + name);
				if ("copy".equals(command))
					FileUtils.copyFile(sourceFile, targetFile);
				else if ("move".equals(command))
					FileUtils.moveFile(sourceFile, targetFile);
			} else {
				File targetPath = new File(fileBean.getFilePath());
				if ("copy".equals(command))
					FileUtils.copyDirectoryToDirectory(sourceFile, targetPath);
				else if ("move".equals(command))
					FileUtils.moveDirectoryToDirectory(sourceFile, targetPath, true);
			}
		}
	} catch (IOException e) {
		fileBean.setCode("500");
		fileBean.setMessage("文件粘贴失败: " + e.getMessage());
	}
	return fileBean;
}
 
Example 2
Source File: ModelArchive.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private static void moveToTopLevel(File from, File to) throws IOException {
    File[] list = from.listFiles();
    if (list != null) {
        for (File file : list) {
            if (file.isDirectory()) {
                FileUtils.moveDirectoryToDirectory(file, to, false);
            } else {
                FileUtils.moveFileToDirectory(file, to, false);
            }
        }
    }
}
 
Example 3
Source File: Updater.java    From PYX-Reloaded with Apache License 2.0 5 votes vote down vote up
private void moveUpdatedFiles(File updateFiles) throws IOException {
    File[] files = updateFiles.listFiles();
    if (files == null) throw new IllegalStateException("Cannot read update files.");

    for (File file : files) {
        File destFile = new File(currentFiles, file.getName());
        if (destFile.exists()) FileUtils.forceDelete(destFile);

        if (file.isDirectory()) FileUtils.moveDirectoryToDirectory(file, currentFiles, true);
        else FileUtils.moveFileToDirectory(file, currentFiles, true);
    }
}
 
Example 4
Source File: WindupUpdateRulesetTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testUpdateRuleset() throws Exception
{
    // Extract the rulesets to a temp dir and move the rules/ to target/rules/ .
    File tempDir = OperatingSystemUtils.createTempDir();

    ZipUtil.unzipFromClassResource(WindupUpdateRulesetTest.class, TEST_OLD_WINDUP, tempDir);
    final File targetDir = PathUtil.getWindupHome().resolve("target").toAbsolutePath().toFile();
    final File rulesetsDir = new File(targetDir, "rules");
    FileUtils.deleteDirectory(rulesetsDir);
    FileUtils.moveDirectoryToDirectory(new File(tempDir, "windup-old-ruleset/rules"), targetDir, false);
    System.setProperty(PathUtil.WINDUP_RULESETS_DIR_SYSPROP, rulesetsDir.getAbsolutePath());
    FileUtils.deleteDirectory(tempDir);

    try
    {
        boolean rulesetNeedUpdate = this.updater.rulesetsNeedUpdate(true);
        Assert.assertTrue("Rulesets should need an update.", rulesetNeedUpdate);
        updater.replaceRulesetsDirectoryWithLatestReleaseIfAny();
        Assert.assertFalse("Rulesets should not need an update.", this.updater.rulesetsNeedUpdate(true));
    }
    catch (Throwable ex)
    {
        if (ex.getClass().getSimpleName().equals("InvocationTargetException"))
        {
            final Throwable wrappedEx = ((InvocationTargetException) ex).getTargetException();
            throw new RuntimeException(wrappedEx.getClass().getSimpleName() + " " + wrappedEx.getMessage(), wrappedEx);
        }
        else
            throw ex;
    }
    finally
    {
        System.getProperties().remove("windup.home");
    }
}
 
Example 5
Source File: MSF4JDependencyResolverJob.java    From msf4j with Apache License 2.0 4 votes vote down vote up
private IWorkspaceRoot resourceAlteration() throws IOException, CoreException, JavaModelException {
	// Renaming generated folder structure to match with WSO2
	// conventional directory structure
	IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = workspace.getProject(msf4jArtifactModel.getProjectName());
	msf4jArtifactModel.setProject(project);
	IFolder resourceFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY,
			MAIN_DIRECTORY);
	File resourcePhysicalFolder = resourceFolder.getRawLocation().makeAbsolute().toFile();
	File newResourcePhysicalFolder = new File(
			resourcePhysicalFolder.getParent() + File.separator + RESOURCES_DIRECTORY);
	resourcePhysicalFolder.renameTo(newResourcePhysicalFolder);

	IFolder sourceFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY,
			GEN_DIRECTORY);
	File sourcePhysicalFolder = sourceFolder.getRawLocation().makeAbsolute().toFile();
	File newSourcePhysicalFolder = new File(sourcePhysicalFolder.getParent() + File.separator + MAIN_DIRECTORY);
	sourcePhysicalFolder.renameTo(newSourcePhysicalFolder);

	// Moving src/resources to src/main
	resourceFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY,
			RESOURCES_DIRECTORY);
	resourcePhysicalFolder = resourceFolder.getRawLocation().makeAbsolute().toFile();
	sourceFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY, MAIN_DIRECTORY);
	sourcePhysicalFolder = sourceFolder.getRawLocation().makeAbsolute().toFile();
	FileUtils.moveDirectoryToDirectory(resourcePhysicalFolder, sourcePhysicalFolder, true);

	// Adding Java support to the source folder src/main/java
	// delete the project target folder
	IFolder targetFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(),
			MSF4JArtifactConstants.TRGET_DIRECTORY);
	targetFolder.delete(true, new NullProgressMonitor());
	IFolder mainFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY,
			MAIN_DIRECTORY, JAVA_DIRECTORY);
	JavaUtils.addJavaSupportAndSourceFolder(msf4jArtifactModel.getProject(), mainFolder);

	// removing the webapps folder generated by the tool
	IFolder webAppFolder = ProjectUtils.getWorkspaceFolder(msf4jArtifactModel.getProject(), SRC_DIRECTORY,
			MAIN_DIRECTORY, RESOURCES_DIRECTORY, WEBAPP_DIRECTORY);
	File webAppPhysicalFolder = webAppFolder.getRawLocation().makeAbsolute().toFile();
	if (webAppPhysicalFolder.exists()) {
		FileUtils.forceDelete(webAppPhysicalFolder);
	}

	// removing unnecessary classes generated by the tool
	IProject newMSF4JProject = workspace.getProject(msf4jArtifactModel.getProject().getName());
	String[] filesToBeDeleted = { NOT_FOUND_EXCEPTION_JAVA, API_ORIGIN_FILTER_JAVA, API_RESPONSE_MESSAGE_JAVA,
			API_EXCEPTION_JAVA };

	for (String fileToBeDeleted : filesToBeDeleted) {
		IResource originFilterFile = newMSF4JProject
				.getFile(SRC_DIRECTORY + File.separator + MAIN_DIRECTORY + File.separator + JAVA_DIRECTORY
						+ File.separator + msf4jArtifactModel.getPackageName().replace(".", File.separator)
						+ File.separator + API + File.separator + fileToBeDeleted);
		File fileToDelete = originFilterFile.getRawLocation().makeAbsolute().toFile();
		if (fileToDelete.exists()) {
			FileUtils.forceDelete(fileToDelete);
		}
	}
	ProjectUtils.addNatureToProject(project, false, MAVEN2_PROJECT_NATURE);
	ProjectUtils.addNatureToProject(project, false, MSF4J_PROJECT_NATURE);
	project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
	return workspace;
}
 
Example 6
Source File: SettingsForm.java    From Plugin with MIT License 4 votes vote down vote up
private void setSpecsRepoDirectory(File specsDirectory){
    //Make sure the directory exists
    if (specsDirectory.exists()){
        //Double check that it is a directory
        if (specsDirectory.isDirectory()){

            if (Utils.androidGearsDirectory().exists()){
                //Make local copy of old specs directory
                File oldSpecsDirectory = Utils.androidGearsDirectory();

                Boolean failure = false;
                for (File file : oldSpecsDirectory.listFiles()){
                    try {
                        if (file.isDirectory()){
                            FileUtils.moveDirectoryToDirectory(file, new File(specsDirectory.getAbsolutePath()+Utils.pathSeparator()+"repos"), true);
                        }
                    } catch (IOException e) {

                        failure = true;
                        e.printStackTrace();
                        break;
                    }
                }

                if (!failure){
                    //Save new setting!
                    SettingsManager.getInstance().setSpecsPath(specsDirectory.getAbsolutePath());

                    //Delete previous path, if it exists
                    FileUtils.deleteQuietly(oldSpecsDirectory);

                    //Set specs directory in UI
                    SpecUrlTextField.setText(specsDirectory.getAbsolutePath());
                }
            }
            else {
                //Set new directory
                SettingsManager.getInstance().setSpecsPath(specsDirectory.getAbsolutePath());

                //Clone specs repo in new path
                showResyncLoadingMessage();
                resyncSpecs();
            }
        }
    }
}
 
Example 7
Source File: ExtensionUtils.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Moves extension directory to the given directory
 * 
 * @param destination
 *            destination directory
 * @param extensionName
 *            name of extension
 * @throws IOException
 */
public static void moveExtension(File destination, String extensionName) throws IOException {
	File srcFile = new File(PathUtils.getDefaultExtensionPath(extensionName));
	FileUtils.moveDirectoryToDirectory(srcFile, destination, true);
}