From e875aee9487f594ee373eb98dcb9a25ae490e83c Mon Sep 17 00:00:00 2001 From: David Inglis Date: Wed, 27 Oct 2004 16:55:47 +0000 Subject: [PATCH] fixed bug #77135 --- .../make/internal/core/MakeTargetManager.java | 24 ++++++++------ .../make/internal/core/ProjectTargets.java | 31 ++++++------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java index a0cf46c2bf9..05eff7b1128 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.make.internal.core; import java.io.File; -import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -74,7 +73,12 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis } ((MakeTarget) target).setContainer(container); projectTargets.add((MakeTarget) target); - writeTargets(projectTargets); + try { + writeTargets(projectTargets); + } catch (CoreException e) { + projectTargets.remove((MakeTarget) target); + throw e; + } notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target)); } @@ -84,8 +88,13 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis if (projectTargets == null) { projectTargets = readTargets(project); } - if (projectTargets.remove(target)) { - writeTargets(projectTargets); + if (projectTargets.remove((MakeTarget) target)) { + try { + writeTargets(projectTargets); + } catch (CoreException e) { + projectTargets.add((MakeTarget) target); + throw e; + } notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target)); } } @@ -252,12 +261,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis } protected void writeTargets(ProjectTargets projectTargets) throws CoreException { - try { - projectTargets.saveTargets(); - } catch (IOException e) { - throw new CoreException( - new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.error_writing_file"), e)); //$NON-NLS-1$ - } + projectTargets.saveTargets(); } protected ProjectTargets readTargets(IProject project) throws CoreException { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java index a2d28b0ba3e..8f60ac7ba1e 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java @@ -13,8 +13,6 @@ package org.eclipse.cdt.make.internal.core; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; @@ -166,7 +164,7 @@ public class ProjectTargets { return false; } - public boolean remove(IMakeTarget target) { + public boolean remove(MakeTarget target) { ArrayList list = (ArrayList) targetMap.get(target.getContainer()); if (list == null || !list.contains(target)) { return false; @@ -182,13 +180,14 @@ public class ProjectTargets { return project; } - protected Document getAsXML() throws IOException { + protected Document getAsXML() throws CoreException { Document doc; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException ex) { //This should never happen. - throw new IOException("Error creating new XML storage document"); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, + "Error creating new XML storage document", ex)); //$NON-NLS-1$ } Element targetsRootElement = doc.createElement(BUILD_TARGET_ELEMENT); doc.appendChild(targetsRootElement); @@ -234,26 +233,14 @@ public class ProjectTargets { return targetElem; } - public void saveTargets() throws IOException { + public void saveTargets() throws CoreException { Document doc = getAsXML(); //Historical method would save the output to the stream specified //translateDocumentToOutputStream(doc, output); - try { - translateDocumentToCDTProject(doc); - } catch (Exception e) { - IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(project.getName()).addFileExtension( - TARGETS_EXT); - File targetFile = targetFilePath.toFile(); - try { - saveTargets(doc, new FileOutputStream(targetFile)); - } catch (FileNotFoundException e1) { - } catch (IOException e1) { - } catch (TransformerException e1) { - } - } + translateDocumentToCDTProject(doc); } - protected void saveTargets(Document doc, OutputStream output) throws IOException, TransformerException { + protected void saveTargets(Document doc, OutputStream output) throws TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; transformer = factory.newTransformer(); @@ -268,9 +255,9 @@ public class ProjectTargets { * This output method saves the information into the .cdtproject metadata file. * * @param doc - * @throws IOException + * @throws CoreException */ - protected void translateDocumentToCDTProject(Document doc) throws CoreException, IOException { + protected void translateDocumentToCDTProject(Document doc) throws CoreException { ICDescriptor descriptor; descriptor = CCorePlugin.getDefault().getCProjectDescription(getProject(), true);