1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for [Bug 195160] Import hangs when importing project of version 3

This commit is contained in:
Mikhail Sennikovsky 2007-08-15 14:51:55 +00:00
parent 9329353166
commit 2c81d31199
3 changed files with 109 additions and 76 deletions

View file

@ -2026,7 +2026,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
* 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(final IProject project) throws Exception { private static ManagedBuildInfo loadOldStyleBuildInfo(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);
File cdtbuild = file.getLocation().toFile(); File cdtbuild = file.getLocation().toFile();
@ -2644,7 +2644,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
// try { // try {
// mngr.beginRule(rule, null); // mngr.beginRule(rule, null);
doSetLoaddedInfo(project, info); doSetLoaddedInfo(project, info, true);
// } catch (IllegalArgumentException e) { // } catch (IllegalArgumentException e) {
// // TODO: set anyway for now // // TODO: set anyway for now
// doSetLoaddedInfo(project, info); // doSetLoaddedInfo(project, info);
@ -2653,7 +2653,10 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
// } // }
} }
private synchronized static void doSetLoaddedInfo(IProject project, IManagedBuildInfo info){ private synchronized static void doSetLoaddedInfo(IProject project, IManagedBuildInfo info, boolean overwrite){
if(!overwrite && fInfoMap.get(project) != null)
return;
if(info != null){ if(info != null){
fInfoMap.put(project, info); fInfoMap.put(project, info);
if(BuildDbgUtil.DEBUG) if(BuildDbgUtil.DEBUG)
@ -2743,6 +2746,15 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
ManagedBuildInfo buildInfo = null; ManagedBuildInfo buildInfo = null;
IProject proj = rc.getProject(); IProject proj = rc.getProject();
if(buildInfo == null){
if(BuildDbgUtil.DEBUG)
BuildDbgUtil.getInstance().traceln(BuildDbgUtil.BUILD_INFO_LOAD, "build info load: info is null, querying the update mngr"); //$NON-NLS-1$
buildInfo = UpdateManagedProjectManager.getConvertedManagedBuildInfo(proj);
}
if(buildInfo != null)
return buildInfo;
// Check if there is any build info associated with this project for this session // Check if there is any build info associated with this project for this session
try { try {
buildInfo = getLoaddedBuildInfo(proj); buildInfo = getLoaddedBuildInfo(proj);
@ -2793,11 +2805,11 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
} }
if(buildInfo == null){ // if(buildInfo == null){
if(BuildDbgUtil.DEBUG) // if(BuildDbgUtil.DEBUG)
BuildDbgUtil.getInstance().traceln(BuildDbgUtil.BUILD_INFO_LOAD, "build info load: info is null, querying the update mngr"); //$NON-NLS-1$ // BuildDbgUtil.getInstance().traceln(BuildDbgUtil.BUILD_INFO_LOAD, "build info load: info is null, querying the update mngr"); //$NON-NLS-1$
buildInfo = UpdateManagedProjectManager.getConvertedManagedBuildInfo(proj); // buildInfo = UpdateManagedProjectManager.getConvertedManagedBuildInfo(proj);
} // }
} }
// if (buildInfo == null && resource instanceof IProject) // if (buildInfo == null && resource instanceof IProject)
// buildInfo = findBuildInfoSynchronized((IProject)resource, forceLoad); // buildInfo = findBuildInfoSynchronized((IProject)resource, forceLoad);
@ -2983,7 +2995,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return getBuildInfo(resource, true); return getBuildInfo(resource, true);
} }
public static synchronized IManagedBuildInfo getOldStyleBuildInfo(IProject project) throws CoreException { public static IManagedBuildInfo getOldStyleBuildInfo(IProject project) throws CoreException {
IManagedBuildInfo info = null; IManagedBuildInfo info = null;
try { try {
info = getLoaddedBuildInfo(project); info = getLoaddedBuildInfo(project);
@ -2992,10 +3004,10 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
if(info == null){ if(info == null){
try { try {
info = loadBuildInfo(project); info = loadOldStyleBuildInfo(project);
if(info != null) if(info != null)
setLoaddedBuildInfo(project, info); doSetLoaddedInfo(project, info, false);
} catch (Exception e) { } catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e)); throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e));
} }

View file

@ -46,7 +46,6 @@ import org.eclipse.cdt.managedbuilder.internal.core.BuilderFactory;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration; import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -63,6 +62,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IOverwriteQuery;
public class ProjectConverter implements ICProjectConverter { public class ProjectConverter implements ICProjectConverter {
private final static String OLD_MAKE_BUILDER_ID = "org.eclipse.cdt.make.core.makeBuilder"; //$NON-NLS-1$ private final static String OLD_MAKE_BUILDER_ID = "org.eclipse.cdt.make.core.makeBuilder"; //$NON-NLS-1$
@ -78,7 +82,6 @@ public class ProjectConverter implements ICProjectConverter {
private final static String OLD_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.make.MakeTargetBuilder"; //$NON-NLS-1$ private final static String OLD_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.make.MakeTargetBuilder"; //$NON-NLS-1$
private final static String NEW_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.build.MakeTargetBuilder"; //$NON-NLS-1$ private final static String NEW_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.build.MakeTargetBuilder"; //$NON-NLS-1$
private static final Object LOCK = new Object();
private static ResourcePropertyHolder PROPS = new ResourcePropertyHolder(true); private static ResourcePropertyHolder PROPS = new ResourcePropertyHolder(true);
private static String CONVERSION_FAILED_MSG_ID = "conversionFailed"; //$NON-NLS-1$ private static String CONVERSION_FAILED_MSG_ID = "conversionFailed"; //$NON-NLS-1$
@ -133,17 +136,13 @@ public class ProjectConverter implements ICProjectConverter {
des.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData()); des.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
} else if(natureSet.contains(OLD_MNG_NATURE_ID)){ } else if(natureSet.contains(OLD_MNG_NATURE_ID)){
try { try {
synchronized (LOCK) { if(PROPS.getProperty(project, CONVERSION_FAILED_MSG_ID) != null)
if(PROPS.getProperty(project, CONVERSION_FAILED_MSG_ID) != null) throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), DataProviderMessages.getString("ProjectConverter.0"))); //$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), DataProviderMessages.getString("ProjectConverter.0"))); //$NON-NLS-1$
}
newDes = model.createProjectDescription(project, false); newDes = model.createProjectDescription(project, false);
info = convertManagedBuildInfo(project, newDes); info = convertManagedBuildInfo(project, newDes);
} catch (CoreException e) { } catch (CoreException e) {
synchronized (LOCK) { displayInfo(project, CONVERSION_FAILED_MSG_ID, DataProviderMessages.getString("ProjectConverter.10"), DataProviderMessages.getFormattedString("ProjectConverter.11", new String[]{project.getName(), e.getLocalizedMessage()})); //$NON-NLS-1$ //$NON-NLS-2$
displayInfo(project, CONVERSION_FAILED_MSG_ID, DataProviderMessages.getString("ProjectConverter.10"), DataProviderMessages.getFormattedString("ProjectConverter.11", new String[]{project.getName(), e.getLocalizedMessage()})); //$NON-NLS-1$ //$NON-NLS-2$
}
throw e; throw e;
} }
} }
@ -235,11 +234,59 @@ public class ProjectConverter implements ICProjectConverter {
static void displayInfo(IProject proj, String id, String title, String message){ static void displayInfo(IProject proj, String id, String title, String message){
if(PROPS.getProperty(proj, id) == null){ if(PROPS.getProperty(proj, id) == null){
UpdateManagedProjectManager.openInformation(title, message); openInformation(proj, id, title, message, false);
PROPS.setProperty(proj, id, Boolean.TRUE); PROPS.setProperty(proj, id, Boolean.TRUE);
} }
} }
public static boolean getBooleanFromQueryAnswer(String answer){
if(IOverwriteQuery.ALL.equalsIgnoreCase(answer) ||
IOverwriteQuery.YES.equalsIgnoreCase(answer))
return true;
return false;
}
static public boolean openQuestion(final IResource rc, final String id, final String title, final String message, IOverwriteQuery query, final boolean multiple){
if(query != null)
return getBooleanFromQueryAnswer(query.queryOverwrite(message));
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window == null){
IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
window = windows[0];
}
final Shell shell = window.getShell();
final boolean [] answer = new boolean[1];
shell.getDisplay().syncExec(new Runnable() {
public void run() {
if(multiple || PROPS.getProperty(rc, id) == null){
PROPS.setProperty(rc, id, Boolean.TRUE);
answer[0] = MessageDialog.openQuestion(shell,title,message);
}
}
});
return answer[0];
}
static private void openInformation(final IResource rc, final String id, final String title, final String message, final boolean multiple){
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window == null){
IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
window = windows[0];
}
final Shell shell = window.getShell();
shell.getDisplay().syncExec(new Runnable() {
public void run() {
if(multiple || PROPS.getProperty(rc, id) == null){
PROPS.setProperty(rc, id, Boolean.TRUE);
MessageDialog.openInformation(shell,title,message);
}
}
});
}
private static void convertMakeTargetInfo(final IProject project, ICProjectDescription des, IProgressMonitor monitor) throws CoreException{ private static void convertMakeTargetInfo(final IProject project, ICProjectDescription des, IProgressMonitor monitor) throws CoreException{
if(monitor == null) if(monitor == null)
monitor = new NullProgressMonitor(); monitor = new NullProgressMonitor();
@ -527,7 +574,7 @@ public class ProjectConverter implements ICProjectConverter {
private IManagedBuildInfo convertManagedBuildInfo(IProject project, ICProjectDescription newDes) throws CoreException { private IManagedBuildInfo convertManagedBuildInfo(IProject project, ICProjectDescription newDes) throws CoreException {
IManagedBuildInfo info = ManagedBuildManager.getOldStyleBuildInfo(project); IManagedBuildInfo info = ManagedBuildManager.getOldStyleBuildInfo(project);
synchronized(LOCK){ synchronized(PROPS){
if(info != null && info.isValid()){ if(info != null && info.isValid()){
IManagedProject mProj = info.getManagedProject(); IManagedProject mProj = info.getManagedProject();
IConfiguration cfgs[] = mProj.getConfigurations(); IConfiguration cfgs[] = mProj.getConfigurations();

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; 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.cdt.managedbuilder.internal.dataprovider.ProjectConverter;
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;
@ -36,10 +37,6 @@ 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.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IOverwriteQuery; import org.eclipse.ui.dialogs.IOverwriteQuery;
public class UpdateManagedProjectManager { public class UpdateManagedProjectManager {
@ -68,13 +65,6 @@ public class UpdateManagedProjectManager {
fUpdateProjectQuery = updateProjectQuery; fUpdateProjectQuery = updateProjectQuery;
} }
private static boolean getBooleanFromQueryAnswer(String answer){
if(IOverwriteQuery.ALL.equalsIgnoreCase(answer) ||
IOverwriteQuery.YES.equalsIgnoreCase(answer))
return true;
return false;
}
synchronized static private UpdateManagedProjectManager getUpdateManager(IProject project){ synchronized static private UpdateManagedProjectManager getUpdateManager(IProject project){
UpdateManagedProjectManager mngr = getExistingUpdateManager(project); UpdateManagedProjectManager mngr = getExistingUpdateManager(project);
if(mngr == null) if(mngr == null)
@ -184,10 +174,10 @@ public class UpdateManagedProjectManager {
if (dstFile.exists()) { if (dstFile.exists()) {
boolean shouldUpdate; boolean shouldUpdate;
if(query != null) if(query != null)
shouldUpdate = getBooleanFromQueryAnswer(query.queryOverwrite(dstFile.getName())); shouldUpdate = ProjectConverter.getBooleanFromQueryAnswer(query.queryOverwrite(dstFile.getName()));
else else
shouldUpdate = openQuestion(ConverterMessages.getResourceString("UpdateManagedProjectManager.0"), //$NON-NLS-1$ shouldUpdate = ProjectConverter.openQuestion(fProject, "UpdateManagedProjectManager.0", ConverterMessages.getResourceString("UpdateManagedProjectManager.0"), //$NON-NLS-1$ //$NON-NLS-2$
ConverterMessages.getFormattedString("UpdateManagedProjectManager.1", new String[] {dstFile.getName(),project.getName()})); //$NON-NLS-1$ ConverterMessages.getFormattedString("UpdateManagedProjectManager.1", new String[] {dstFile.getName(),project.getName()}), fOpenQuestionQuery, false); //$NON-NLS-1$
if (shouldUpdate) { if (shouldUpdate) {
dstFile.delete(); dstFile.delete();
@ -241,43 +231,27 @@ public class UpdateManagedProjectManager {
} }
} }
static private boolean openQuestion(final String title, final String message){ // static private boolean openQuestion(IResource rc, final String title, final String message){
if(fOpenQuestionQuery != null) // return ProjectConverter.openQuestion(rc, message, title, message, fOpenQuestionQuery, false);
return getBooleanFromQueryAnswer(fOpenQuestionQuery.queryOverwrite(message)); // }
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); // static public void openInformation(final String title, final String message){
if(window == null){ // if(fOpenQuestionQuery != null)
IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows(); // return;// getBooleanFromQueryAnswer(fOpenQuestionQuery.queryOverwrite(message));
window = windows[0]; //
} // IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
// if(window == null){
final Shell shell = window.getShell(); // IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
final boolean [] answer = new boolean[1]; // window = windows[0];
shell.getDisplay().syncExec(new Runnable() { // }
public void run() { //
answer[0] = MessageDialog.openQuestion(shell,title,message); // final Shell shell = window.getShell();
} // shell.getDisplay().syncExec(new Runnable() {
}); // public void run() {
return answer[0]; // MessageDialog.openInformation(shell,title,message);
} // }
// });
static public void openInformation(final String title, final String message){ // }
if(fOpenQuestionQuery != null)
return;// getBooleanFromQueryAnswer(fOpenQuestionQuery.queryOverwrite(message));
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window == null){
IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
window = windows[0];
}
final Shell shell = window.getShell();
shell.getDisplay().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell,title,message);
}
});
}
/** /**
* returns ManagedBuildInfo for the current project * returns ManagedBuildInfo for the current project
@ -322,11 +296,11 @@ public class UpdateManagedProjectManager {
boolean shouldUpdate; boolean shouldUpdate;
if(fUpdateProjectQuery != null) if(fUpdateProjectQuery != null)
shouldUpdate = getBooleanFromQueryAnswer(fUpdateProjectQuery.queryOverwrite(fProject.getFullPath().toString())); shouldUpdate = ProjectConverter.getBooleanFromQueryAnswer(fUpdateProjectQuery.queryOverwrite(fProject.getFullPath().toString()));
else else
shouldUpdate = openQuestion(ConverterMessages.getResourceString("UpdateManagedProjectManager.3"), //$NON-NLS-1$ shouldUpdate = ProjectConverter.openQuestion(fProject, "UpdateManagedProjectManager.3", ConverterMessages.getResourceString("UpdateManagedProjectManager.3"), //$NON-NLS-1$ //$NON-NLS-2$
ConverterMessages.getFormattedString("UpdateManagedProjectManager.4", new String[]{fProject.getName(),version.toString(),ManagedBuildManager.getBuildInfoVersion().toString()}) //$NON-NLS-1$ ConverterMessages.getFormattedString("UpdateManagedProjectManager.4", new String[]{fProject.getName(),version.toString(),ManagedBuildManager.getBuildInfoVersion().toString()}), //$NON-NLS-1$
); fOpenQuestionQuery, false);
if (!shouldUpdate){ if (!shouldUpdate){
fIsInfoReadOnly = true; fIsInfoReadOnly = true;