Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] MBS Fix for bugzilla #80075

Title: MBS Fix for bugzilla #80075


    <<80075a_ui.txt>> <<80075a_core.txt>>
    Attached are patches which resolve bugzilla #80075.
    The patches address issues that arise when the MBS .cdtbuild file is
    non-writeable and a write operation is attempted.


    Bob Monteleone
    Intel Corporation 

Index: src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java,v
retrieving revision 1.33
diff -u -r1.33 BuildPropertyPage.java
--- src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java	5 Oct 2005 12:23:59 -0000	1.33
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java	6 Oct 2005 18:24:10 -0000
@@ -309,12 +309,12 @@
 	 */
 	protected boolean writeBuildInfo() {
 		// Write out the build model info
-		ManagedBuildManager.saveBuildInfo(getProject(), false);
+		boolean saveBuildStatus = ManagedBuildManager.saveBuildInfo(getProject(), false);
 		IManagedBuildInfo bi = ManagedBuildManager.getBuildInfo(getProject());
 		if (bi != null & bi instanceof ManagedBuildInfo) {
 			((ManagedBuildInfo)bi).initializePathEntries();
 		}
-		return true;
+		return saveBuildStatus;
 	}
 	
 	/*
Index: src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java,v
retrieving revision 1.10
diff -u -r1.10 ResourceBuildPropertyPage.java
--- src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java	5 Oct 2005 12:23:57 -0000	1.10
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/ResourceBuildPropertyPage.java	6 Oct 2005 18:24:10 -0000
@@ -452,6 +452,8 @@
 	 */
 	public boolean performOk() {
 		
+		boolean retStatus = true;
+		
 		//	If there is no content on the page, then there is nothing to do
 		if (noContentOnPage) return true;
 
@@ -484,12 +486,12 @@
 			// Write out the build model info
 		ManagedBuildManager.setDefaultConfiguration(getProject(), getSelectedConfiguration());
 		
-		if(getCurrentResourceConfigClone().isDirty()){
+		if (getCurrentResourceConfigClone().isDirty()) {
 			selectedConfiguration.setRebuildState(true);
 			getCurrentResourceConfigClone().setDirty(false);
 		}
 
-		ManagedBuildManager.saveBuildInfo(getProject(), false);
+		retStatus = ManagedBuildManager.saveBuildInfo(getProject(), false);
 		
 		IManagedBuildInfo bi = ManagedBuildManager.getBuildInfo(getProject());
 		if (bi != null & bi instanceof ManagedBuildInfo) {
@@ -498,7 +500,7 @@
 		
 		EnvironmentVariableProvider.fUserSupplier.checkInexistentConfigurations(clonedConfiguration.getManagedProject());
 
-		return true;
+		return retStatus;
 	}
 	
 	public boolean containsDefaults(){
Index: src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java,v
retrieving revision 1.59
diff -u -r1.59 ManagedBuildManager.java
--- src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	30 Sep 2005 19:09:15 -0000	1.59
+++ src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	6 Oct 2005 18:25:38 -0000
@@ -75,6 +75,8 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.ResourceAttributes;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtension;
@@ -125,6 +127,9 @@
 	private static final String MANIFEST_ERROR_OPTION_CATEGORY = "ManagedBuildManager.error.manifest.option.category";	//$NON-NLS-1$
 	private static final String MANIFEST_ERROR_OPTION_FILTER = "ManagedBuildManager.error.manifest.option.filter";	//$NON-NLS-1$
 	private static final String MANIFEST_ERROR_OPTION_VALUEHANDLER = "ManagedBuildManager.error.manifest.option.valuehandler";	//$NON-NLS-1$
+	private static final String MANIFEST_ERROR_READ_ONLY = "ManagedBuildManager.error.read_only";	//$NON-NLS-1$
+	private static final String MANIFEST_ERROR_WRITE_FAILED = "ManagedBuildManager.error.write_failed";	//$NON-NLS-1$
+	
 	// Error ID's for OptionValidError()
 	public static final int ERROR_CATEGORY = 0;
 	public static final int ERROR_FILTER = 1;
@@ -1032,8 +1037,9 @@
 	 * @param project
 	 * @param force 
 	 */
-	public static void saveBuildInfo(IProject project, boolean force) {
+	public static boolean saveBuildInfo(IProject project, boolean force) {
 		// Create document
+		Exception err = null;
 		try {
 			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
 			Document doc = builder.newDocument();
@@ -1071,6 +1077,34 @@
 				String utfString = stream.toString("UTF-8");	//$NON-NLS-1$
 
 				if (projectFile.exists()) {
+					if (projectFile.isReadOnly()) {						
+						// If we are not running headless, and there is a UI Window around, grab it
+						// and the associated shell
+						IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+						if (window == null) {
+							IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
+							window = windows[0];
+						}
+						Shell shell = null; 
+						if (window != null) {							
+							shell = window.getShell();
+						}						
+	                    // Inform Eclipse that we are intending to modify this file
+						// This will provide the user the opportunity, via UI prompts, to fetch the file from source code control
+						// reset a read-only file protection to write etc.
+						// If there is no shell, i.e. shell is null, then there will be no user UI interaction
+						IStatus status = projectFile.getWorkspace().validateEdit(new IFile[]{projectFile}, shell);
+						// If the file is still read-only, then we should not attempt the write, since it will
+						// just fail - just throw an exception, to be caught below, and inform the user
+						// For other non-successful status, we take our chances, attempt the write, and pass
+						// along any exception thrown
+						if (!status.isOK()) {
+						    if (status.getCode() == IResourceStatus.READ_ONLY_LOCAL) {
+						    	stream.close();
+		    	                throw new IOException(ManagedMakeMessages.getFormattedString(MANIFEST_ERROR_READ_ONLY, projectFile.getFullPath().toString())); //$NON-NLS-1$						
+						    }
+						}
+					}
 					projectFile.setContents(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor());	//$NON-NLS-1$
 				} else {
 					projectFile.create(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor());	//$NON-NLS-1$
@@ -1080,27 +1114,53 @@
 				stream.close();
 			}
 		} catch (ParserConfigurationException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			err = e;
 		} catch (FactoryConfigurationError e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		} catch (TransformerConfigurationException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		} catch (TransformerFactoryConfigurationError e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
+			err = e.getException();
+		} catch (TransformerConfigurationException e) {
+			err = e;
+		} catch (TransformerFactoryConfigurationError e) {
+			err = e.getException();
 		} catch (TransformerException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			err = e;
 		} catch (IOException e) {
 			// The save failed
-			e.printStackTrace();
-		} catch (CoreException e) {
-			// Save to IFile failed
-			e.printStackTrace();
-		}
+			err = e;
+    	} catch (CoreException e) {
+	    	// Save to IFile failed
+		    err = e;
+	    }
+
+		if (err != null) {			
+			// Put out an error message indicating that the attempted write to the .cdtbuild project file failed					
+			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+			if (window == null) {
+				IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
+				window = windows[0];
+			}
+
+			final Shell shell = window.getShell();
+			if (shell != null) {
+				final String exceptionMsg = err.getMessage(); 
+				shell.getDisplay().syncExec( new Runnable() {
+					public void run() {
+						MessageDialog.openError(shell, 
+								ManagedMakeMessages.getResourceString("ManagedBuildManager.error.write_failed_title"),	//$NON-NLS-1$
+								ManagedMakeMessages.getFormattedString(MANIFEST_ERROR_WRITE_FAILED,		//$NON-NLS-1$
+										exceptionMsg));
+					}
+			    } );
+			}
+		}
+		// If we return an honest status when the operation fails, there are instances when the UI behavior
+		// is not very good
+		// Specifically, if "OK" is clicked by the user from the property page UI, and the return status 
+		// from this routine is false, the property page UI will not be closed (note: this is Eclispe code) and
+		// the OK button will simply be grayed out
+		// At this point, the only way out is to click "Cancel" to get the UI to go away; note however that any
+		// property page changes will be sticky, in the UI, which is nonintuitive and confusing
+		// Therefore, just always return success, i.e. true, from this routine
+		return true;
 	}
 
 	/**
Index: src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties,v
retrieving revision 1.32
diff -u -r1.32 PluginResources.properties
--- src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties	14 Jul 2005 09:23:10 -0000	1.32
+++ src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties	6 Oct 2005 18:25:38 -0000
@@ -49,6 +49,9 @@
 ManagedBuildManager.error.manifest.option.valuehandler=Could not load value handler {0} in option {1}.
 ManagedBuildManager.error.open_failed_title=Managed Make Project File Error
 ManagedBuildManager.error.open_failed=The Managed Make project file could not be read because of the following error:\n\n{0}\n\nManaged Make functionality will not be available for this project.
+ManagedBuildManager.error.write_failed_title=Managed Make Project File Write Error
+ManagedBuildManager.error.write_failed=The Managed Make project file could not be written because of the following error:\n\n{0}\n
+ManagedBuildManager.error.read_only=File {0} is read-only.
 ManagedBuildManager.error.project.version.error=The version number of the project {0} is greater than the Managed Build System version number.
 ManagedBuildManager.error.id.nomatch=Error loading Managed Make project information for project {0}.  The tool definitions used to create the project are not available.
 ManagedBuildManager.error.project.file.missing=The Managed Make project file for project {0} is missing.

Back to the top