mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
2005-03-18 Alain Magloire
Fix for PR 88110: Importing project that need converting would create NPE and ResouceException failures. * src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java * src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject12.java * src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java * src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject.java
This commit is contained in:
parent
011cd84a92
commit
cab81eb6a0
5 changed files with 145 additions and 69 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2005-03-18 Alain Magloire
|
||||||
|
Fix for PR 88110: Importing project that need converting would
|
||||||
|
create NPE and ResouceException failures.
|
||||||
|
* src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
|
||||||
|
* src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject12.java
|
||||||
|
* src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject20.java
|
||||||
|
* src/org/eclipse/cdt/managedbuilder/projectconverter/UpdateManagedProject.java
|
||||||
|
|
||||||
2005-01-24 Vladimir Hirsl
|
2005-01-24 Vladimir Hirsl
|
||||||
Updated managed build scanner info collector to use new interfaces introduced
|
Updated managed build scanner info collector to use new interfaces introduced
|
||||||
for CDT 3.0.
|
for CDT 3.0.
|
||||||
|
|
|
@ -12,6 +12,8 @@ package org.eclipse.cdt.managedbuilder.core;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -60,11 +62,9 @@ import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
|
||||||
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
|
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
|
||||||
import org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator;
|
import org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator;
|
||||||
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
|
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
|
||||||
import org.eclipse.core.internal.resources.ResourceException;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceStatus;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
|
@ -355,9 +355,8 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
||||||
if (buildInfo != null) {
|
if (buildInfo != null) {
|
||||||
List targets = buildInfo.getTargets();
|
List targets = buildInfo.getTargets();
|
||||||
return (ITarget[])targets.toArray(new ITarget[targets.size()]);
|
return (ITarget[])targets.toArray(new ITarget[targets.size()]);
|
||||||
} else {
|
|
||||||
return emptyTargets;
|
|
||||||
}
|
}
|
||||||
|
return emptyTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1187,44 +1186,27 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
// This is a 1.2 manifest and we are compatible for now
|
// This is a 1.2 manifest and we are compatible for now
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
// isCompatibleWith will return FALSE, if:
|
// isCompatibleWith will return FALSE, if:
|
||||||
// o The major versions are not equal
|
// o The major versions are not equal
|
||||||
// o The major versions are equal, but the remainder of the manifest version # is
|
// o The major versions are equal, but the remainder of the manifest version # is
|
||||||
// greater than the MBS version #
|
// greater than the MBS version #
|
||||||
return(buildInfoVersion.isCompatibleWith(version));
|
return(buildInfoVersion.isCompatibleWith(version));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* Load the build information for the specified resource from its project
|
* Load the build information for the specified resource from its project
|
||||||
* file. Pay attention to the version number too.
|
* file. Pay attention to the version number too.
|
||||||
*/
|
*/
|
||||||
private static ManagedBuildInfo loadBuildInfo(IProject project) throws Exception {
|
private static ManagedBuildInfo loadBuildInfo(final IProject project) throws Exception {
|
||||||
ManagedBuildInfo buildInfo = null;
|
ManagedBuildInfo buildInfo = null;
|
||||||
IFile file = project.getFile(SETTINGS_FILE_NAME);
|
IFile file = project.getFile(SETTINGS_FILE_NAME);
|
||||||
if (!file.exists())
|
File cdtbuild = file.getLocation().toFile();
|
||||||
|
if (!cdtbuild.exists())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// So there is a project file, load the information there
|
// So there is a project file, load the information there
|
||||||
InputStream stream = null;
|
InputStream stream = new FileInputStream(cdtbuild);
|
||||||
try {
|
|
||||||
stream = file.getContents();
|
|
||||||
} catch (ResourceException e) {
|
|
||||||
// TODO: Why couldn't the file be read?
|
|
||||||
if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
|
|
||||||
// TODO: Issue a warning?
|
|
||||||
// Read it anyway...
|
|
||||||
try {
|
|
||||||
stream = file.getContents(true);
|
|
||||||
} catch (Exception fe) {
|
|
||||||
throw fe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = parser.parse(stream);
|
Document document = parser.parse(stream);
|
||||||
|
@ -1262,11 +1244,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
||||||
buildInfo.setVersion(fileVersion);
|
buildInfo.setVersion(fileVersion);
|
||||||
}
|
}
|
||||||
if(!UpdateManagedProjectManager.isCompatibleProject(buildInfo)){
|
if(!UpdateManagedProjectManager.isCompatibleProject(buildInfo)){
|
||||||
try{
|
UpdateManagedProjectManager.updateProject(project, buildInfo);
|
||||||
UpdateManagedProjectManager.updateProject(project,buildInfo);
|
|
||||||
} catch(CoreException e){
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (buildInfo.getManagedProject() == null ||
|
if (buildInfo.getManagedProject() == null ||
|
||||||
(!buildInfo.getManagedProject().isValid())) {
|
(!buildInfo.getManagedProject().isValid())) {
|
||||||
|
@ -1832,7 +1810,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
||||||
* @return IManagedBuildInfo The build information object for the resource.
|
* @return IManagedBuildInfo The build information object for the resource.
|
||||||
*/
|
*/
|
||||||
public static IManagedBuildInfo getBuildInfo(IResource resource) {
|
public static IManagedBuildInfo getBuildInfo(IResource resource) {
|
||||||
return (IManagedBuildInfo) findBuildInfo(resource.getProject());
|
return findBuildInfo(resource.getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.projectconverter;
|
package org.eclipse.cdt.managedbuilder.projectconverter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -38,10 +40,13 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.WorkspaceJob;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -372,12 +377,12 @@ class UpdateManagedProject12 {
|
||||||
configuration.setOption(tool, newOpt, bool.booleanValue());
|
configuration.setOption(tool, newOpt, bool.booleanValue());
|
||||||
break;
|
break;
|
||||||
case IOption.STRING:
|
case IOption.STRING:
|
||||||
String strVal = (String) optRef.getAttribute(IOption.DEFAULT_VALUE);
|
String strVal = optRef.getAttribute(IOption.DEFAULT_VALUE);
|
||||||
configuration.setOption(tool, newOpt, strVal);
|
configuration.setOption(tool, newOpt, strVal);
|
||||||
break;
|
break;
|
||||||
case IOption.ENUMERATED:
|
case IOption.ENUMERATED:
|
||||||
// This is going to be the human readable form of the enumerated value
|
// This is going to be the human readable form of the enumerated value
|
||||||
String name = (String) optRef.getAttribute(IOption.DEFAULT_VALUE);
|
String name = optRef.getAttribute(IOption.DEFAULT_VALUE);
|
||||||
// Convert it to the ID
|
// Convert it to the ID
|
||||||
String idValue = newOpt.getEnumeratedId(name);
|
String idValue = newOpt.getEnumeratedId(name);
|
||||||
configuration.setOption(tool, newOpt, idValue != null ? idValue : name);
|
configuration.setOption(tool, newOpt, idValue != null ? idValue : name);
|
||||||
|
@ -665,9 +670,11 @@ class UpdateManagedProject12 {
|
||||||
* @param project the <code>IProject</code> that needs to be upgraded
|
* @param project the <code>IProject</code> that needs to be upgraded
|
||||||
* @throws CoreException if the update fails
|
* @throws CoreException if the update fails
|
||||||
*/
|
*/
|
||||||
public static void doProjectUpdate(IProgressMonitor monitor, IProject project) throws CoreException {
|
public static void doProjectUpdate(IProgressMonitor monitor, final IProject project) throws CoreException {
|
||||||
String[] projectName = new String[]{project.getName()};
|
String[] projectName = new String[]{project.getName()};
|
||||||
IFile settingsFile = project.getFile(ManagedBuildManager.SETTINGS_FILE_NAME);
|
IFile file = project.getFile(ManagedBuildManager.SETTINGS_FILE_NAME);
|
||||||
|
File settingsFile = file.getLocation().toFile();
|
||||||
|
|
||||||
if (!settingsFile.exists()) {
|
if (!settingsFile.exists()) {
|
||||||
monitor.done();
|
monitor.done();
|
||||||
return;
|
return;
|
||||||
|
@ -676,14 +683,14 @@ class UpdateManagedProject12 {
|
||||||
// Backup the file
|
// Backup the file
|
||||||
monitor.beginTask(ConverterMessages.getFormattedString("UpdateManagedProject12.0", projectName), 1); //$NON-NLS-1$
|
monitor.beginTask(ConverterMessages.getFormattedString("UpdateManagedProject12.0", projectName), 1); //$NON-NLS-1$
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||||
UpdateManagedProjectManager.backupFile(settingsFile, "_12backup", monitor, project); ; //$NON-NLS-1$
|
UpdateManagedProjectManager.backupFile(file, "_12backup", monitor, project); ; //$NON-NLS-1$
|
||||||
|
|
||||||
IManagedProject newProject = null;
|
IManagedProject newProject = null;
|
||||||
|
|
||||||
//Now convert each target to the new format
|
//Now convert each target to the new format
|
||||||
try {
|
try {
|
||||||
// Load the old build file
|
// Load the old build file
|
||||||
InputStream stream = settingsFile.getContents();
|
InputStream stream = new FileInputStream(settingsFile);
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = parser.parse(stream);
|
Document document = parser.parse(stream);
|
||||||
|
|
||||||
|
@ -735,7 +742,22 @@ class UpdateManagedProject12 {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
||||||
e.getMessage(), e));
|
e.getMessage(), e));
|
||||||
} finally {
|
} finally {
|
||||||
|
// If the tree is locked spawn a job to this.
|
||||||
|
IWorkspace workspace = project.getWorkspace();
|
||||||
|
boolean treeLock = workspace.isTreeLocked();
|
||||||
|
ISchedulingRule rule = workspace.getRuleFactory().createRule(project);
|
||||||
|
if (treeLock) {
|
||||||
|
WorkspaceJob job = new WorkspaceJob("Updating managed Project") {
|
||||||
|
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
|
||||||
ManagedBuildManager.saveBuildInfo(project, false);
|
ManagedBuildManager.saveBuildInfo(project, false);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.setRule(rule);
|
||||||
|
job.schedule();
|
||||||
|
} else {
|
||||||
|
ManagedBuildManager.saveBuildInfo(project, false);
|
||||||
|
}
|
||||||
monitor.done();
|
monitor.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package org.eclipse.cdt.managedbuilder.projectconverter;
|
package org.eclipse.cdt.managedbuilder.projectconverter;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
@ -35,10 +37,13 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.WorkspaceJob;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -52,9 +57,10 @@ class UpdateManagedProject20 {
|
||||||
* @param project the <code>IProject</code> that needs to be upgraded
|
* @param project the <code>IProject</code> that needs to be upgraded
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
static void doProjectUpdate(IProgressMonitor monitor, IProject project) throws CoreException {
|
static void doProjectUpdate(IProgressMonitor monitor, final IProject project) throws CoreException {
|
||||||
String[] projectName = new String[]{project.getName()};
|
String[] projectName = new String[]{project.getName()};
|
||||||
IFile settingsFile = project.getFile(ManagedBuildManager.SETTINGS_FILE_NAME);
|
IFile file = project.getFile(ManagedBuildManager.SETTINGS_FILE_NAME);
|
||||||
|
File settingsFile = file.getLocation().toFile();
|
||||||
if (!settingsFile.exists()) {
|
if (!settingsFile.exists()) {
|
||||||
monitor.done();
|
monitor.done();
|
||||||
return;
|
return;
|
||||||
|
@ -63,11 +69,11 @@ class UpdateManagedProject20 {
|
||||||
// Backup the file
|
// Backup the file
|
||||||
monitor.beginTask(ConverterMessages.getFormattedString("UpdateManagedProject20.0", projectName), 1); //$NON-NLS-1$
|
monitor.beginTask(ConverterMessages.getFormattedString("UpdateManagedProject20.0", projectName), 1); //$NON-NLS-1$
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||||
UpdateManagedProjectManager.backupFile(settingsFile, "_20backup", monitor, project); //$NON-NLS-1$
|
UpdateManagedProjectManager.backupFile(file, "_20backup", monitor, project); //$NON-NLS-1$
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Load the old build file
|
// Load the old build file
|
||||||
InputStream stream = settingsFile.getContents();
|
InputStream stream = new FileInputStream(settingsFile);
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = parser.parse(stream);
|
Document document = parser.parse(stream);
|
||||||
|
|
||||||
|
@ -96,7 +102,22 @@ class UpdateManagedProject20 {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
||||||
e.getMessage(), e));
|
e.getMessage(), e));
|
||||||
} finally {
|
} finally {
|
||||||
|
// If the tree is locked spawn a job to this.
|
||||||
|
IWorkspace workspace = project.getWorkspace();
|
||||||
|
boolean treeLock = workspace.isTreeLocked();
|
||||||
|
ISchedulingRule rule = workspace.getRuleFactory().createRule(project);
|
||||||
|
if (treeLock) {
|
||||||
|
WorkspaceJob job = new WorkspaceJob("Updating managed Project") {
|
||||||
|
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
|
||||||
ManagedBuildManager.saveBuildInfo(project, false);
|
ManagedBuildManager.saveBuildInfo(project, false);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.setRule(rule);
|
||||||
|
job.schedule();
|
||||||
|
} else {
|
||||||
|
ManagedBuildManager.saveBuildInfo(project, false);
|
||||||
|
}
|
||||||
monitor.done();
|
monitor.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.projectconverter;
|
package org.eclipse.cdt.managedbuilder.projectconverter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||||
|
@ -19,6 +23,9 @@ import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.WorkspaceJob;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
@ -27,6 +34,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.PluginVersionIdentifier;
|
import org.eclipse.core.runtime.PluginVersionIdentifier;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
@ -63,7 +71,6 @@ public class UpdateManagedProjectManager {
|
||||||
if(IOverwriteQuery.ALL.equalsIgnoreCase(answer) ||
|
if(IOverwriteQuery.ALL.equalsIgnoreCase(answer) ||
|
||||||
IOverwriteQuery.YES.equalsIgnoreCase(answer))
|
IOverwriteQuery.YES.equalsIgnoreCase(answer))
|
||||||
return true;
|
return true;
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +129,7 @@ public class UpdateManagedProjectManager {
|
||||||
UpdateManagedProjectManager mngr = getExistingUpdateManager(project);
|
UpdateManagedProjectManager mngr = getExistingUpdateManager(project);
|
||||||
if(mngr == null || mngr.fIsInfoReadOnly)
|
if(mngr == null || mngr.fIsInfoReadOnly)
|
||||||
return;
|
return;
|
||||||
IContainer destFolder = (IContainer)project;
|
IContainer destFolder = project;
|
||||||
IFile dstFile = destFolder.getFile(new Path(settingsFile.getName()+suffix));
|
IFile dstFile = destFolder.getFile(new Path(settingsFile.getName()+suffix));
|
||||||
mngr.backupFile(settingsFile, dstFile, monitor, project, fBackupFileOverwriteQuery);
|
mngr.backupFile(settingsFile, dstFile, monitor, project, fBackupFileOverwriteQuery);
|
||||||
}
|
}
|
||||||
|
@ -137,40 +144,69 @@ public class UpdateManagedProjectManager {
|
||||||
* @param query
|
* @param query
|
||||||
*/
|
*/
|
||||||
private void backupFile(IFile srcFile, IFile dstFile, IProgressMonitor monitor, IProject project, IOverwriteQuery query){
|
private void backupFile(IFile srcFile, IFile dstFile, IProgressMonitor monitor, IProject project, IOverwriteQuery query){
|
||||||
try{
|
File src = srcFile.getLocation().toFile();
|
||||||
|
File dst = dstFile.getLocation().toFile();
|
||||||
|
backupFile(src, dst, monitor, project, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void backupFile(File srcFile, File dstFile, IProgressMonitor monitor, IProject project, IOverwriteQuery query){
|
||||||
|
try {
|
||||||
if (dstFile.exists()) {
|
if (dstFile.exists()) {
|
||||||
boolean shouldUpdate;
|
boolean shouldUpdate;
|
||||||
if(query != null)
|
if(query != null)
|
||||||
shouldUpdate = getBooleanFromQueryAnswer(query.queryOverwrite(dstFile.getFullPath().toString()));
|
shouldUpdate = getBooleanFromQueryAnswer(query.queryOverwrite(dstFile.getName()));
|
||||||
else
|
else
|
||||||
shouldUpdate = openQuestion(ConverterMessages.getResourceString("UpdateManagedProjectManager.0"), //$NON-NLS-1$
|
shouldUpdate = openQuestion(ConverterMessages.getResourceString("UpdateManagedProjectManager.0"), //$NON-NLS-1$
|
||||||
ConverterMessages.getFormattedString("UpdateManagedProjectManager.1", new String[] {dstFile.getName(),project.getName()})); //$NON-NLS-1$
|
ConverterMessages.getFormattedString("UpdateManagedProjectManager.1", new String[] {dstFile.getName(),project.getName()})); //$NON-NLS-1$
|
||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
dstFile.delete(true, monitor);
|
dstFile.delete();
|
||||||
} else {
|
} else {
|
||||||
// monitor.setCanceled(true);
|
|
||||||
throw new OperationCanceledException(ConverterMessages.getFormattedString("UpdateManagedProjectManager.2", project.getName())); //$NON-NLS-1$
|
throw new OperationCanceledException(ConverterMessages.getFormattedString("UpdateManagedProjectManager.2", project.getName())); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
srcFile.copy(dstFile.getFullPath(), true, monitor);
|
copyFile(srcFile, dstFile);
|
||||||
}
|
} catch(Exception e){
|
||||||
catch(Exception e){
|
|
||||||
fIsInfoReadOnly = true;
|
fIsInfoReadOnly = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copyFile(File src, File dst) throws IOException {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
FileOutputStream fos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(src);
|
||||||
|
fos = new FileOutputStream(dst);
|
||||||
|
|
||||||
|
final int BUFSIZ = 1024;
|
||||||
|
byte buf[] = new byte[BUFSIZ];
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
while ((len = fis.read(buf)) > 0) {
|
||||||
|
fos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (fis != null) {
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
if (fos != null) {
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void restoreFile(String backupFileName, String restoreFileName, IProgressMonitor monitor, IProject project){
|
private void restoreFile(String backupFileName, String restoreFileName, IProgressMonitor monitor, IProject project){
|
||||||
IContainer destFolder = (IContainer)project;
|
IContainer destFolder = project;
|
||||||
IFile restoreFile = destFolder.getFile(new Path(restoreFileName));
|
File restoreFile = destFolder.getFile(new Path(restoreFileName)).getLocation().toFile();
|
||||||
IFile backupFile = destFolder.getFile(new Path(backupFileName));
|
File backupFile = destFolder.getFile(new Path(backupFileName)).getLocation().toFile();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if (restoreFile.exists())
|
if (restoreFile.exists()) {
|
||||||
restoreFile.delete(true, monitor);
|
restoreFile.delete();
|
||||||
backupFile.copy(restoreFile.getFullPath(), true, monitor);
|
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
copyFile(backupFile, restoreFile);
|
||||||
|
} catch(Exception e){
|
||||||
fIsInfoReadOnly = true;
|
fIsInfoReadOnly = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +259,7 @@ public class UpdateManagedProjectManager {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!settingsFile.exists())
|
if (!settingsFile.getLocation().toFile().exists())
|
||||||
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), -1,
|
||||||
ConverterMessages.getResourceString("UpdateManagedProjectManager.6"),null)); //$NON-NLS-1$
|
ConverterMessages.getResourceString("UpdateManagedProjectManager.6"),null)); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -284,12 +320,23 @@ public class UpdateManagedProjectManager {
|
||||||
* @param info the ManagedBuildInfo for the current project
|
* @param info the ManagedBuildInfo for the current project
|
||||||
* @throws CoreException if conversion failed
|
* @throws CoreException if conversion failed
|
||||||
*/
|
*/
|
||||||
static public void updateProject(IProject project, ManagedBuildInfo info)
|
static public void updateProject(final IProject project, ManagedBuildInfo info)
|
||||||
throws CoreException{
|
throws CoreException{
|
||||||
try{
|
try{
|
||||||
getUpdateManager(project).doProjectUpdate(info);
|
getUpdateManager(project).doProjectUpdate(info);
|
||||||
} finally {
|
} finally {
|
||||||
removeUpdateManager(project);
|
removeUpdateManager(project);
|
||||||
|
// We have to this here since we use java.io.File to handle the update.
|
||||||
|
IWorkspace workspace = project.getWorkspace();
|
||||||
|
ISchedulingRule rule = workspace.getRuleFactory().refreshRule(project);
|
||||||
|
WorkspaceJob job = new WorkspaceJob("Refresh Project") { //$NON-NLS-1$
|
||||||
|
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
|
||||||
|
project.refreshLocal(IResource.DEPTH_ONE, null);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.setRule(rule);
|
||||||
|
job.schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue