aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-11-05 03:16:02 (EST)
committerJacek Pospychala2012-11-05 12:06:35 (EST)
commitf310c37bc2fce272cf9c85452c8436eabfea1a2e (patch)
tree102adca8ab38ebf0a411d6fad8cea020cc23f8fa
parent2952e62b0f3fd182e53c3cdea34ccb62179c415a (diff)
downloadorg.eclipse.pdt-f310c37bc2fce272cf9c85452c8436eabfea1a2e.zip
org.eclipse.pdt-f310c37bc2fce272cf9c85452c8436eabfea1a2e.tar.gz
org.eclipse.pdt-f310c37bc2fce272cf9c85452c8436eabfea1a2e.tar.bz2
restore accidentally removed methods
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
index a4209e2..e2de3d1 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
@@ -11,18 +11,23 @@
*******************************************************************************/
package org.eclipse.php.internal.ui.wizards;
+import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.eclipse.dltk.core.*;
+import org.eclipse.dltk.internal.corext.util.Messages;
import org.eclipse.dltk.internal.ui.util.CoreUtility;
import org.eclipse.dltk.internal.ui.wizards.BuildpathDetector;
import org.eclipse.dltk.internal.ui.wizards.NewWizardMessages;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.util.ExceptionHandler;
import org.eclipse.dltk.ui.util.IStatusChangeListener;
import org.eclipse.dltk.ui.wizards.BuildpathsBlock;
@@ -66,6 +71,8 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
private boolean fKeepContent;
+ private File fDotProjectBackup;
+ private File fDotBuildpathBackup;
private Boolean fIsAutobuild;
/**
@@ -75,6 +82,9 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
fFirstPage = mainPage;
fCurrProjectLocation = null;
fKeepContent = false;
+
+ fDotProjectBackup = null;
+ fDotBuildpathBackup = null;
fIsAutobuild = null;
}
@@ -345,6 +355,119 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
return fFirstPage.getLocationURI();
}
+ protected void rememberExistingFiles(URI projectLocation)
+ throws CoreException {
+ fDotProjectBackup = null;
+ fDotBuildpathBackup = null;
+
+ IFileStore file = EFS.getStore(projectLocation);
+ if (file.fetchInfo().exists()) {
+ IFileStore projectFile = file.getChild(FILENAME_PROJECT);
+ if (projectFile.fetchInfo().exists()) {
+ fDotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$
+ }
+ IFileStore buildpathFile = file.getChild(FILENAME_BUILDPATH);
+ if (buildpathFile.fetchInfo().exists()) {
+ fDotBuildpathBackup = createBackup(buildpathFile,
+ "buildpath-desc"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void restoreExistingFiles(URI projectLocation,
+ IProgressMonitor monitor) throws CoreException {
+ int ticks = ((fDotProjectBackup != null ? 1 : 0) + (fDotBuildpathBackup != null ? 1
+ : 0)) * 2;
+ monitor.beginTask("", ticks); //$NON-NLS-1$
+ try {
+ if (fDotProjectBackup != null) {
+ IFileStore projectFile = EFS.getStore(projectLocation)
+ .getChild(FILENAME_PROJECT);
+ projectFile
+ .delete(EFS.NONE, new SubProgressMonitor(monitor, 1));
+ copyFile(fDotProjectBackup, projectFile,
+ new SubProgressMonitor(monitor, 1));
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_project,
+ e);
+ throw new CoreException(status);
+ }
+ try {
+ if (fDotBuildpathBackup != null) {
+ IFileStore buildpathFile = EFS.getStore(projectLocation)
+ .getChild(FILENAME_BUILDPATH);
+ buildpathFile.delete(EFS.NONE, new SubProgressMonitor(monitor,
+ 1));
+ copyFile(fDotBuildpathBackup, buildpathFile,
+ new SubProgressMonitor(monitor, 1));
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_buildpath,
+ e);
+ throw new CoreException(status);
+ }
+ }
+
+ private File createBackup(IFileStore source, String name)
+ throws CoreException {
+ try {
+ File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$
+ copyFile(source, bak);
+ return bak;
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ Messages.format(
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_backup,
+ name), e);
+ throw new CoreException(status);
+ }
+ }
+
+ private void copyFile(IFileStore source, File target) throws IOException,
+ CoreException {
+ InputStream is = source.openInputStream(EFS.NONE, null);
+ FileOutputStream os = new FileOutputStream(target);
+ copyFile(is, os);
+ }
+
+ private void copyFile(File source, IFileStore target,
+ IProgressMonitor monitor) throws IOException, CoreException {
+ FileInputStream is = new FileInputStream(source);
+ OutputStream os = target.openOutputStream(EFS.NONE, monitor);
+ copyFile(is, os);
+ }
+
+ private void copyFile(InputStream is, OutputStream os) throws IOException {
+ try {
+ byte[] buffer = new byte[8192];
+ while (true) {
+ int bytesRead = is.read(buffer);
+ if (bytesRead == -1)
+ break;
+
+ os.write(buffer, 0, bytesRead);
+ }
+ } finally {
+ try {
+ is.close();
+ } finally {
+ os.close();
+ }
+ }
+ }
+
/**
* Called from the wizard on finish.
*/