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

1. Fix for [Bug 192838] Fix for MBS old project conversion logic

2.follow up for the fix for [Bug 192423] Project conversion should NOT occur in case the tool-chain definition is not installed
This commit is contained in:
Mikhail Sennikovsky 2007-06-15 10:49:55 +00:00
parent 3aace937cf
commit e30e3da19e
7 changed files with 205 additions and 13 deletions

View file

@ -1105,10 +1105,12 @@ public class BuildDescriptionModelTests extends TestCase {
//the refresh is scheduled as a job, so in case we do not wait here the job may not be completed by the time
//the test is run
try {
Thread.sleep(10000);
Thread.sleep(5000);
} catch (InterruptedException e) {
}
CCorePlugin.getIndexManager().joinIndexer(-1, new NullProgressMonitor());
CCorePlugin.getIndexManager().reindex(cProject);
CCorePlugin.getIndexManager().joinIndexer(-1, new NullProgressMonitor());
IBuildDescription des = null;

View file

@ -51,9 +51,9 @@ public class ManagedProjectUpdateTests extends TestCase {
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate12_Update"));
// suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate20_Update"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21_Update"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate12_NoUpdate"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate20_NoUpdate"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21_NoUpdate"));
// suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate12_NoUpdate"));
// suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate20_NoUpdate"));
// suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21_NoUpdate"));
// TODO: This is affected by the TODO in UpdateManagedProjectManager
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21CPP_Update"));

View file

@ -2982,7 +2982,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return getBuildInfo(resource, true);
}
public static synchronized IManagedBuildInfo getBuildInfoLegacy(IProject project){
public static synchronized IManagedBuildInfo getOldStyleBuildInfo(IProject project) throws CoreException {
IManagedBuildInfo info = null;
try {
info = getLoaddedBuildInfo(project);
@ -2996,10 +2996,21 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
if(info != null)
setLoaddedBuildInfo(project, info);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e));
}
}
return info;
}
public static synchronized IManagedBuildInfo getBuildInfoLegacy(IProject project){
try {
return getOldStyleBuildInfo(project);
} catch (CoreException e) {
ManagedBuilderCorePlugin.log(e);
return null;
}
}
/**
* Finds, but does not create, the managed build information for the

View file

@ -46,6 +46,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.BuilderFactory;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
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.IContainer;
import org.eclipse.core.resources.IProject;
@ -78,6 +79,9 @@ public class ProjectConverter implements ICProjectConverter {
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 String CONVERSION_FAILED_MSG_ID = "conversionFailed";
public boolean canConvertProject(IProject project, String oldOwnerId, ICProjectDescription oldDes) {
try {
@ -128,8 +132,20 @@ public class ProjectConverter implements ICProjectConverter {
des.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
} else if(natureSet.contains(OLD_MNG_NATURE_ID)){
newDes = model.createProjectDescription(project, false);
info = convertManagedBuildInfo(project, newDes);
try {
synchronized (LOCK) {
if(PROPS.getProperty(project, CONVERSION_FAILED_MSG_ID) != null)
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), "failed to load the build info for the old-style project"));
}
newDes = model.createProjectDescription(project, false);
info = convertManagedBuildInfo(project, newDes);
} catch (CoreException e) {
synchronized (LOCK) {
displayInfo(project, CONVERSION_FAILED_MSG_ID, "project conversion failed", "project conversion failed for project " + project.getName() + " with the following error:\n" + e.getLocalizedMessage());
}
throw e;
}
}
if(newDes == null || !newDes.isValid() || newDes.getConfigurations().length == 0){
@ -217,6 +233,13 @@ public class ProjectConverter implements ICProjectConverter {
return newDes;
}
static void displayInfo(IProject proj, String id, String title, String message){
if(PROPS.getProperty(proj, id) == null){
UpdateManagedProjectManager.openInformation(title, message);
PROPS.setProperty(proj, id, Boolean.TRUE);
}
}
private static void convertMakeTargetInfo(final IProject project, ICProjectDescription des, IProgressMonitor monitor) throws CoreException{
if(monitor == null)
monitor = new NullProgressMonitor();
@ -502,7 +525,7 @@ public class ProjectConverter implements ICProjectConverter {
}
private IManagedBuildInfo convertManagedBuildInfo(IProject project, ICProjectDescription newDes) throws CoreException {
IManagedBuildInfo info = ManagedBuildManager.getBuildInfoLegacy(project);
IManagedBuildInfo info = ManagedBuildManager.getOldStyleBuildInfo(project);
synchronized(LOCK){
if(info != null && info.isValid()){

View file

@ -0,0 +1,132 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.dataprovider;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.settings.model.util.ResourceChangeHandlerBase;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
class ResourcePropertyHolder extends ResourceChangeHandlerBase {
private Map fRcMap = new HashMap();
private boolean fProjectOnly;
public ResourcePropertyHolder(boolean projectOnly){
fProjectOnly = projectOnly;
}
private class ResourceMoveHandler implements IResourceMoveHandler {
public void done() {
}
public void handleProjectClose(IProject project) {
removeResourcePropertyMap(project);
}
public boolean handleResourceMove(IResource fromRc, IResource toRc) {
if(isValidResource(fromRc)){
moveResourcePropertyMap(fromRc, toRc);
return !fProjectOnly;
}
return false;
}
public boolean handleResourceRemove(IResource rc) {
if(isValidResource(rc)){
removeResourcePropertyMap(rc);
return !fProjectOnly;
}
return false;
}
}
private boolean isValidResource(IResource rc){
return !fProjectOnly || rc.getType() == IResource.PROJECT;
}
protected IResourceMoveHandler createResourceMoveHandler(
IResourceChangeEvent event) {
return new ResourceMoveHandler();
}
protected Object keyForResource(IResource rc){
return rc.getFullPath().toString();
}
public synchronized Object getProperty(IResource rc, Object propKey) throws IllegalArgumentException {
if(!isValidResource(rc))
throw new IllegalArgumentException();
Map map = getResourcePropertyMap(rc, false);
if(map == null)
return null;
return map.get(propKey);
}
private Map getResourcePropertyMap(IResource rc, boolean create){
Object key = keyForResource(rc);
Map map = (Map)fRcMap.get(key);
if(map == null && create){
map = new HashMap();
fRcMap.put(key, map);
}
return map;
}
private synchronized void removeResourcePropertyMap(IResource rc){
Object key = keyForResource(rc);
fRcMap.remove(key);
}
private synchronized void moveResourcePropertyMap(IResource fromRc, IResource toRc){
Object fromKey = keyForResource(fromRc);
Object toKey = keyForResource(toRc);
Map fromMap = (Map)fRcMap.remove(fromKey);
if(fromMap != null){
fRcMap.put(toKey, fromMap);
} else {
fRcMap.remove(toKey);
}
}
public synchronized Object setProperty(IResource rc, Object propKey, Object value) throws IllegalArgumentException {
if(!isValidResource(rc))
throw new IllegalArgumentException();
if(value == null)
return removeProperty(rc, propKey);
Map map = getResourcePropertyMap(rc, true);
return map.put(propKey, value);
}
private synchronized Object removeProperty(IResource rc, Object propKey){
Map map = getResourcePropertyMap(rc, false);
if(map == null)
return null;
Object old = map.remove(propKey);
if(map.size() == 0)
removeResourcePropertyMap(rc);
return old;
}
}

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2004, 2005 Intel Corporation and others.
# Copyright (c) 2004, 2007 Intel Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@ -39,7 +39,7 @@ UpdateManagedProject12.invalid_build_info=The Managed Make information for the p
UpdateManagedProjectManager.0=Backup File Already Exists
UpdateManagedProjectManager.1=A backup file {0} already exists for the project {1}.\n Do you want to convert the project anyway?
UpdateManagedProjectManager.2=The update operation has been cancelled.\n The build system will not be able to read the project settings until you update the project.
UpdateManagedProjectManager.3=Update Managed Make Project
UpdateManagedProjectManager.4=The project {0} build settings are stored in a format that is no longer supported (version {1}).\n\nWould you like to convert it to the newer version ({2})?\n\nNOTE: Converted projects can no longer be loaded by previous versions of the Managed Build System.\nIf you select "No", project settings will be available in readonly mode.
UpdateManagedProjectManager.3=Update Managed Build Project
UpdateManagedProjectManager.4=The project {0} build settings are stored in a format that is no longer supported (version {1}).\n\nWould you like to convert it to the newer version ({2})?\n\nNOTE: Converted projects can no longer be loaded by previous versions of the Managed Build System.\nIf you select "No", project settings will NOT be available.
UpdateManagedProjectManager.5=Managed Make project conversion failed: \n Managed Build System version {0} is not equivalent to the Managed Make project version {1} (project ID = {2})
UpdateManagedProjectManager.6=the project .cdtbuild file does not exist

View file

@ -261,6 +261,24 @@ public class UpdateManagedProjectManager {
return answer[0];
}
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
* if converter is currently running
@ -310,9 +328,15 @@ public class UpdateManagedProjectManager {
ConverterMessages.getFormattedString("UpdateManagedProjectManager.4", new String[]{fProject.getName(),version.toString(),ManagedBuildManager.getBuildInfoVersion().toString()}) //$NON-NLS-1$
);
if (!shouldUpdate)
if (!shouldUpdate){
fIsInfoReadOnly = true;
throw new CoreException(new Status(IStatus.CANCEL, ManagedBuilderCorePlugin.getUniqueIdentifier(), "project conversion was cancelled"));
}
IFile projectFile = fProject.getFile(".project"); //$NON-NLS-1$
if(projectFile.exists())
backupFile(projectFile, "_initial", monitor, fProject); //$NON-NLS-1$
if(version.isEquivalentTo(new PluginVersionIdentifier(1,2,0))){
UpdateManagedProject12.doProjectUpdate(monitor, fProject);
version = getManagedBuildInfoVersion(info.getVersion());