1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 19:25:38 +02:00

1. follow-up to fix for [Bug 196048] Updating .cproject from CVS does not cause reload of settings

2. initial fix for [Bug 196284] ConcurrentModificationException during getProjectDescription
This commit is contained in:
Mikhail Sennikovsky 2007-07-26 16:33:29 +00:00
parent c61a0ca618
commit fcf6db2881
4 changed files with 108 additions and 57 deletions

View file

@ -50,6 +50,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@ -402,6 +403,7 @@ public class ProjectModelTests extends TestCase implements IElementChangedListen
for(int i = 0; i < settings.length; i++){
ICLanguageSetting setting = settings[i];
ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
BuildSystemTestHelper.checkDiff(entries, updatedEntries);
if(entries.length > 0){
// ICLanguageSettingEntry updated[] = new ICLanguageSettingEntry[entries.length + 1];
// System.arraycopy(entries, 0, updated, 1, entries.length);

View file

@ -161,9 +161,16 @@ public class CfgDiscoveredPathManager implements IResourceChangeListener {
PathInfo info = getCachedPathInfo(cInfo);
if (info == null) {
synchronized (this) {
info = getCachedPathInfo(cInfo);
if(info == null){
IDiscoveredPathManager.IDiscoveredPathInfo baseInfo = loadPathInfo(project, context.getConfiguration(), cInfo);
info = resolveCacheBaseDiscoveredInfo(cInfo, baseInfo);
}
}
// setCachedPathInfo(context, info);
// if(info instanceof DiscoveredPathInfo && !((DiscoveredPathInfo)info).isLoadded()){
// info = createPathInfo(project, context);

View file

@ -448,6 +448,10 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
return fRootStorageElement;
}
ICStorageElement doGetCachedRootStorageElement(){
return fRootStorageElement;
}
private ICSettingsStorage getStorageBase() throws CoreException{
if(fStorage == null)
fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement());

View file

@ -442,6 +442,21 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
// }
}
private boolean streamsMatch(InputStream stream1, InputStream stream2) throws IOException{
do{
int i1 = stream1.read();
int i2 = stream2.read();
if(i1 != i2){
return false;
} else if (i1 == -1){
break;
}
}while(true);
return true;
}
CProjectDescription checkExternalProjectFileModification(IResource rc) throws CoreException{
Map map = getProjectFileSerializationMap(false);
IProject project = rc.getProject();
@ -454,7 +469,24 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
if(des == null || des.isLoadding())
return null;
//TODO: .cproject file is modified externally
//check whether contents differ
try {
ICStorageElement oldEl = des.doGetCachedRootStorageElement();
if(oldEl != null){
InputStream newContents = getSharedProperty(project, STORAGE_FILE_NAME);
ByteArrayOutputStream oldOut = write(oldEl);
InputStream oldContents = new ByteArrayInputStream(oldOut.toByteArray());
if(streamsMatch(newContents, oldContents))
return null;
}
} catch (CoreException e){
CCorePlugin.log(e);
//continue
} catch (IOException e) {
CCorePlugin.log(e);
//continue
}
des = (CProjectDescription)loadProjectDescription(project);
des = createWritableDescription(des);
des.touch();
@ -1425,11 +1457,9 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
}
}
private void serialize(IProject project, String file, ICStorageElement element) throws CoreException{
private ByteArrayOutputStream write(ICStorageElement element) throws CoreException {
Document doc = getDocument(element);
// Transform the document to something we can save in a file
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@ -1440,12 +1470,23 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
StreamResult result = new StreamResult(stream);
transformer.transform(source, result);
// Save the document
IFile projectFile = project.getFile(file);
String utfString = stream.toString("UTF-8"); //$NON-NLS-1$
return stream;
} catch (TransformerConfigurationException e){
throw ExceptionFactory.createCoreException(e);
} catch (TransformerException e) {
throw ExceptionFactory.createCoreException(e);
}
}
private void serialize(IProject project, String file, ICStorageElement element) throws CoreException{
try {
IFile projectFile = project.getFile(file);
ByteArrayOutputStream stream = write(element); //$NON-NLS-1$
String utfString = stream.toString("UTF-8"); //$NON-NLS-1$
aboutToSaveProjectFile(project);
try {
if (projectFile.exists()) {
if (projectFile.isReadOnly()) {
// Inform Eclipse that we are intending to modify this file
@ -1485,13 +1526,10 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} else {
projectFile.create(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor()); //$NON-NLS-1$
}
}finally{
doneSaveProjectFile(project);
// Close the streams
stream.close();
} catch (TransformerConfigurationException e){
throw ExceptionFactory.createCoreException(e);
} catch (TransformerException e) {
throw ExceptionFactory.createCoreException(e);
}
} catch (IOException e) {
throw ExceptionFactory.createCoreException(e);
}