1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 15:35:24 +02:00
This commit is contained in:
David Inglis 2004-10-27 16:55:47 +00:00
parent 61b7feb54d
commit e875aee948
2 changed files with 23 additions and 32 deletions

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.make.internal.core; package org.eclipse.cdt.make.internal.core;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -74,7 +73,12 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
} }
((MakeTarget) target).setContainer(container); ((MakeTarget) target).setContainer(container);
projectTargets.add((MakeTarget) target); projectTargets.add((MakeTarget) target);
try {
writeTargets(projectTargets); writeTargets(projectTargets);
} catch (CoreException e) {
projectTargets.remove((MakeTarget) target);
throw e;
}
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target)); notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target));
} }
@ -84,8 +88,13 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(project); projectTargets = readTargets(project);
} }
if (projectTargets.remove(target)) { if (projectTargets.remove((MakeTarget) target)) {
try {
writeTargets(projectTargets); writeTargets(projectTargets);
} catch (CoreException e) {
projectTargets.add((MakeTarget) target);
throw e;
}
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target)); 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 { protected void writeTargets(ProjectTargets projectTargets) throws CoreException {
try {
projectTargets.saveTargets(); 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$
}
} }
protected ProjectTargets readTargets(IProject project) throws CoreException { protected ProjectTargets readTargets(IProject project) throws CoreException {

View file

@ -13,8 +13,6 @@ package org.eclipse.cdt.make.internal.core;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -166,7 +164,7 @@ public class ProjectTargets {
return false; return false;
} }
public boolean remove(IMakeTarget target) { public boolean remove(MakeTarget target) {
ArrayList list = (ArrayList) targetMap.get(target.getContainer()); ArrayList list = (ArrayList) targetMap.get(target.getContainer());
if (list == null || !list.contains(target)) { if (list == null || !list.contains(target)) {
return false; return false;
@ -182,13 +180,14 @@ public class ProjectTargets {
return project; return project;
} }
protected Document getAsXML() throws IOException { protected Document getAsXML() throws CoreException {
Document doc; Document doc;
try { try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException ex) { } catch (ParserConfigurationException ex) {
//This should never happen. //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); Element targetsRootElement = doc.createElement(BUILD_TARGET_ELEMENT);
doc.appendChild(targetsRootElement); doc.appendChild(targetsRootElement);
@ -234,26 +233,14 @@ public class ProjectTargets {
return targetElem; return targetElem;
} }
public void saveTargets() throws IOException { public void saveTargets() throws CoreException {
Document doc = getAsXML(); Document doc = getAsXML();
//Historical method would save the output to the stream specified //Historical method would save the output to the stream specified
//translateDocumentToOutputStream(doc, output); //translateDocumentToOutputStream(doc, output);
try {
translateDocumentToCDTProject(doc); 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) {
}
}
} }
protected void saveTargets(Document doc, OutputStream output) throws IOException, TransformerException { protected void saveTargets(Document doc, OutputStream output) throws TransformerException {
TransformerFactory factory = TransformerFactory.newInstance(); TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer; Transformer transformer;
transformer = factory.newTransformer(); transformer = factory.newTransformer();
@ -268,9 +255,9 @@ public class ProjectTargets {
* This output method saves the information into the .cdtproject metadata file. * This output method saves the information into the .cdtproject metadata file.
* *
* @param doc * @param doc
* @throws IOException * @throws CoreException
*/ */
protected void translateDocumentToCDTProject(Document doc) throws CoreException, IOException { protected void translateDocumentToCDTProject(Document doc) throws CoreException {
ICDescriptor descriptor; ICDescriptor descriptor;
descriptor = CCorePlugin.getDefault().getCProjectDescription(getProject(), true); descriptor = CCorePlugin.getDefault().getCProjectDescription(getProject(), true);