1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Fix for problem converting CDT 1.2 & 2.0 projects

This commit is contained in:
Leo Treggiari 2005-06-28 16:53:14 +00:00
parent 3dc2073d23
commit 03cb2a3ec9
13 changed files with 92 additions and 46 deletions

View file

@ -45,6 +45,8 @@ public class ManagedProjectUpdateTests extends TestCase {
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate12_NoUpdate")); suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate12_NoUpdate"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate20_NoUpdate")); suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate20_NoUpdate"));
suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21_NoUpdate")); suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21_NoUpdate"));
// TODO: This is affected by the TODO in UpdateManagedProjectManager
//suite.addTest(new ManagedProjectUpdateTests("testProjectUpdate21CPP_Update"));
return suite; return suite;
} }
@ -124,6 +126,14 @@ public class ManagedProjectUpdateTests extends TestCase {
//check for correct update //check for correct update
if (!updateProject) { if (!updateProject) {
//TODO: if the user has chosen not to update the project the .cdtbuild file should not change //TODO: if the user has chosen not to update the project the .cdtbuild file should not change
} else {
// Make sure that we have a valid project
if (info == null ||
info.getManagedProject() == null ||
info.getManagedProject().isValid() == false)
{
fail("the project \"" + curProject.getName() + "\" was not properly converted");
}
} }
//check whether the project builds without errors //check whether the project builds without errors
@ -192,6 +202,19 @@ public class ManagedProjectUpdateTests extends TestCase {
doTestProjectUpdate("2.1", true, true, makefiles); doTestProjectUpdate("2.1", true, true, makefiles);
} }
/* (non-Javadoc)
* tests project v2.1 update of a C++ project with C source files
*/
public void testProjectUpdate21CPP_Update(){
IPath[] makefiles = {
Path.fromOSString("makefile"),
Path.fromOSString("objects.mk"),
Path.fromOSString("sources.mk"),
Path.fromOSString("subdir.mk"),
Path.fromOSString("Functions/subdir.mk")};
doTestProjectUpdate("2.1CPP", true, true, makefiles);
}
/* (non-Javadoc) /* (non-Javadoc)
* tests project v1.2 update * tests project v1.2 update
* in case when user chooses not to update the project * in case when user chooses not to update the project

View file

@ -1514,7 +1514,10 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
buildInfo = new ManagedBuildInfo(project, (Element)node, fileVersion); buildInfo = new ManagedBuildInfo(project, (Element)node, fileVersion);
if (fileVersion != null) { if (fileVersion != null) {
buildInfo.setVersion(fileVersion); buildInfo.setVersion(fileVersion);
} PluginVersionIdentifier version = new PluginVersionIdentifier(fileVersion);
PluginVersionIdentifier version21 = new PluginVersionIdentifier("2.1"); //$NON-NLS-1$
// CDT 2.1 is the first version using the new MBS model
if (version.isGreaterOrEqualTo(version21)) {
// Check to see if all elements could be loaded correctly - for example, // Check to see if all elements could be loaded correctly - for example,
// if references in the project file could not be resolved to extension // if references in the project file could not be resolved to extension
// elements // elements
@ -1530,13 +1533,15 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
// walk through the project hierarchy and call the converters // walk through the project hierarchy and call the converters
// written for previous mbs versions // written for previous mbs versions
if ( checkForMigrationSupport(buildInfo, false) != true ) { if ( checkForMigrationSupport(buildInfo, false) != true ) {
// display an error message that the project is no loadable // display an error message that the project is not loadable
if (buildInfo.getManagedProject() == null || if (buildInfo.getManagedProject() == null ||
(!buildInfo.getManagedProject().isValid())) { (!buildInfo.getManagedProject().isValid())) {
// The load failed // The load failed
throw new Exception(ManagedMakeMessages.getFormattedString("ManagedBuildManager.error.id.nomatch", project.getName())); //$NON-NLS-1$ throw new Exception(ManagedMakeMessages.getFormattedString("ManagedBuildManager.error.id.nomatch", project.getName())); //$NON-NLS-1$
} }
} }
}
}
// Upgrade the project's CDT version if necessary // Upgrade the project's CDT version if necessary
if (!UpdateManagedProjectManager.isCompatibleProject(buildInfo)) { if (!UpdateManagedProjectManager.isCompatibleProject(buildInfo)) {

View file

@ -339,7 +339,7 @@ public class Configuration extends BuildObject implements IConfiguration {
// Hook me up // Hook me up
managedProject.addConfiguration(this); managedProject.addConfiguration(this);
setDirty(true); setDirty(true);
setRebuildState(true); rebuildNeeded = true;
} }
/* /*
@ -1096,7 +1096,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (extension == null && artifactExtension == null) return; if (extension == null && artifactExtension == null) return;
if (artifactExtension == null || extension == null || !artifactExtension.equals(extension)) { if (artifactExtension == null || extension == null || !artifactExtension.equals(extension)) {
artifactExtension = extension; artifactExtension = extension;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }
@ -1108,7 +1108,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (name == null && artifactName == null) return; if (name == null && artifactName == null) return;
if (artifactName == null || name == null || !artifactName.equals(name)) { if (artifactName == null || name == null || !artifactName.equals(name)) {
artifactName = name; artifactName = name;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }
@ -1184,7 +1184,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (step == null && prebuildStep == null) return; if (step == null && prebuildStep == null) return;
if (prebuildStep == null || step == null || !prebuildStep.equals(step)) { if (prebuildStep == null || step == null || !prebuildStep.equals(step)) {
prebuildStep = step; prebuildStep = step;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }
@ -1197,7 +1197,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (step == null && postbuildStep == null) return; if (step == null && postbuildStep == null) return;
if (postbuildStep == null || step == null || !postbuildStep.equals(step)) { if (postbuildStep == null || step == null || !postbuildStep.equals(step)) {
postbuildStep = step; postbuildStep = step;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }
@ -1209,7 +1209,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (announceStep == null && preannouncebuildStep == null) return; if (announceStep == null && preannouncebuildStep == null) return;
if (preannouncebuildStep == null || announceStep == null || !preannouncebuildStep.equals(announceStep)) { if (preannouncebuildStep == null || announceStep == null || !preannouncebuildStep.equals(announceStep)) {
preannouncebuildStep = announceStep; preannouncebuildStep = announceStep;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }
@ -1221,7 +1221,7 @@ public class Configuration extends BuildObject implements IConfiguration {
if (announceStep == null && postannouncebuildStep == null) return; if (announceStep == null && postannouncebuildStep == null) return;
if (postannouncebuildStep == null || announceStep == null || !postannouncebuildStep.equals(announceStep)) { if (postannouncebuildStep == null || announceStep == null || !postannouncebuildStep.equals(announceStep)) {
postannouncebuildStep = announceStep; postannouncebuildStep = announceStep;
setRebuildState(true); rebuildNeeded = true;
isDirty = true; isDirty = true;
} }
} }

View file

@ -73,7 +73,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
// The path container used for all managed projects // The path container used for all managed projects
public static final IContainerEntry containerEntry = CoreModel.newContainerEntry(new Path("org.eclipse.cdt.managedbuilder.MANAGED_CONTAINER")); //$NON-NLS-1$ public static final IContainerEntry containerEntry = CoreModel.newContainerEntry(new Path("org.eclipse.cdt.managedbuilder.MANAGED_CONTAINER")); //$NON-NLS-1$
private static final QualifiedName defaultConfigProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_CONFIGURATION); private static final QualifiedName defaultConfigProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_CONFIGURATION);
private static final QualifiedName defaultTargetProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_TARGET); //private static final QualifiedName defaultTargetProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_TARGET);
public static final String MAJOR_SEPERATOR = ";"; //$NON-NLS-1$ public static final String MAJOR_SEPERATOR = ";"; //$NON-NLS-1$
public static final String MINOR_SEPERATOR = "::"; //$NON-NLS-1$ public static final String MINOR_SEPERATOR = "::"; //$NON-NLS-1$
private static final String EMPTY_STRING = new String(); private static final String EMPTY_STRING = new String();
@ -791,6 +791,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* *
*/ */
public void initializePathEntries() { public void initializePathEntries() {
if (!isValid()) return;
try { try {
IPathEntryContainer container = new ManagedBuildCPathEntryContainer(getOwner().getProject()); IPathEntryContainer container = new ManagedBuildCPathEntryContainer(getOwner().getProject());
CoreModel.setPathEntryContainer(new ICProject[]{cProject}, container, new NullProgressMonitor()); CoreModel.setPathEntryContainer(new ICProject[]{cProject}, container, new NullProgressMonitor());

View file

@ -80,7 +80,7 @@ public class ProjectType extends BuildObject implements IProjectType {
// Load the configuration children // Load the configuration children
IManagedConfigElement[] configs = element.getChildren(IConfiguration.CONFIGURATION_ELEMENT_NAME); IManagedConfigElement[] configs = element.getChildren(IConfiguration.CONFIGURATION_ELEMENT_NAME);
String [] usedConfigNames = new String[0]; String [] usedConfigNames = new String[configs.length];
IConfigurationNameProvider configurationNameProvder = getConfigurationNameProvider(); IConfigurationNameProvider configurationNameProvder = getConfigurationNameProvider();
if ( configurationNameProvder != null ) { if ( configurationNameProvder != null ) {

View file

@ -734,7 +734,7 @@ class UpdateManagedProject12 {
} }
// Upgrade the version // Upgrade the version
((ManagedBuildInfo)info).setVersion(ManagedBuildManager.getBuildInfoVersion().toString()); ((ManagedBuildInfo)info).setVersion("2.1.0");
info.setValid(true); info.setValid(true);
} catch (CoreException e){ } catch (CoreException e){
throw e; throw e;

View file

@ -94,7 +94,7 @@ class UpdateManagedProject20 {
} }
} }
// Upgrade the version // Upgrade the version
((ManagedBuildInfo)info).setVersion(ManagedBuildManager.getBuildInfoVersion().toString()); ((ManagedBuildInfo)info).setVersion("2.1.0");
info.setValid(true); info.setValid(true);
}catch (CoreException e){ }catch (CoreException e){
throw e; throw e;
@ -377,7 +377,7 @@ class UpdateManagedProject20 {
for(int i = 0; i < options.length; i++){ for(int i = 0; i < options.length; i++){
IOption curOption = options[i]; IOption curOption = options[i];
IOption parent = curOption.getSuperClass(); IOption parent = curOption.getSuperClass();
String curOptionId = curOption.getId(); //String curOptionId = curOption.getId();
if(parent == null) if(parent == null)
continue; continue;

View file

@ -64,27 +64,32 @@ class UpdateManagedProject21 {
// did in CDT 2.*. Otherwise the .c files will not be compiled by default since CDT 3.0 switched to using // did in CDT 2.*. Otherwise the .c files will not be compiled by default since CDT 3.0 switched to using
// Eclipse content types. // Eclipse content types.
if (CoreModel.hasCCNature(project)) { if (CoreModel.hasCCNature(project)) {
IResource[] files = project.members(); try {
IResource[] files = project.members(IProject.EXCLUDE_DERIVED);
for (int i=0; i<files.length; i++) { for (int i=0; i<files.length; i++) {
String ext = files[i].getFileExtension(); String ext = files[i].getFileExtension();
if (ext != null && ext.equals("c")) { //$NON-NLS-1$ if (ext != null && ext.equals("c")) { //$NON-NLS-1$
/*
* What to do here is not yet decided
try {
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$ IContentType contentType = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$
IScopeContext projectScope = new ProjectScope(project); IScopeContext projectScope = new ProjectScope(project);
IContentTypeSettings settings = contentType.getSettings(projectScope); IContentTypeSettings settings = contentType.getSettings(projectScope);
// TODO: we need to add the default extensions too... // First, copy the extensions from the "global" content type
settings.addFileSpec("c", IContentType.FILE_EXTENSION_SPEC); //$NON-NLS-1$ String[] specs = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
} catch (CoreException e) { for (int j = 0; j < specs.length; j++) {
// TODO: Issue message?? settings.addFileSpec(specs[j], IContentType.FILE_EXTENSION_SPEC);
} }
*/ specs = contentType.getFileSpecs(IContentType.FILE_NAME_SPEC);
for (int j = 0; j < specs.length; j++) {
settings.addFileSpec(specs[j], IContentType.FILE_NAME_SPEC);
}
// Add the .c extension
settings.addFileSpec("c", IContentType.FILE_EXTENSION_SPEC); //$NON-NLS-1$
break; break;
} }
} }
} catch (CoreException e) {
// Ignore errors. User will need to manually add .c extension if necessary
}
} }
// Save the updated file // Save the updated file

View file

@ -25,6 +25,7 @@ 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.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.WorkspaceJob; 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;
@ -327,7 +328,18 @@ public class UpdateManagedProjectManager {
static public void updateProject(final IProject project, ManagedBuildInfo info) static public void updateProject(final IProject project, ManagedBuildInfo info)
throws CoreException{ throws CoreException{
try { try {
getUpdateManager(project).doProjectUpdate(info); // Refresh the project here since we may be called before an import operation has fully
// completed setting up the project's resources
IWorkspace workspace = project.getWorkspace();
final ManagedBuildInfo mbsInfo = info;
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
};
// TODO: This is causing a "workspace locked" error (sometimes), but I don't know why...
//workspace.run(runnable, project, IWorkspace.AVOID_UPDATE, null);
getUpdateManager(project).doProjectUpdate(mbsInfo);
} finally { } finally {
removeUpdateManager(project); removeUpdateManager(project);
// We have to this here since we use java.io.File to handle the update. // We have to this here since we use java.io.File to handle the update.