1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

[189274] provide import and export operations for profiles

https://bugs.eclipse.org/bugs/show_bug.cgi?id=189274
This commit is contained in:
David Dykstal 2008-03-29 19:34:17 +00:00
parent f47e91b3af
commit 4114889197

View file

@ -138,20 +138,68 @@ public class RSEEnvelope {
} }
/** /**
* @return a file handle to a temporary directory * Adds a host to the envelope.
* If a host of the same name is already present in the envelope the new host will
* be renamed prior to adding it.
* @param host the host to be added to the envelope
*/ */
private File getTemporaryFolder() { public void add(final IHost host) {
IPath stateLocation = RSECorePlugin.getDefault().getStateLocation(); // find and add the host-unique filter pools
File stateFolder = new File(stateLocation.toOSString()); ISubSystem[] subsystems = host.getSubSystems();
File envelopesFolder = new File(stateFolder, "envelopes"); //$NON-NLS-1$ for (int i = 0; i < subsystems.length; i++) {
envelopesFolder.mkdir(); ISubSystem subsystem = subsystems[i];
List envelopeNames = Arrays.asList(envelopesFolder.list()); ISystemFilterPool pool = subsystem.getUniqueOwningSystemFilterPool(false);
String envelopeName = generateName(envelopeNames); if (pool != null) {
File envelopeFolder = new File(envelopesFolder, envelopeName); add(pool);
envelopeFolder.mkdir(); }
return envelopeFolder; }
// add the host
String type = IRSEDOMConstants.TYPE_HOST;
String name = host.getName();
Runnable action = new Runnable() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, host, true);
}
};
addNode(type, name, action);
} }
/**
* Adds a filter pool to the envelope.
* If a filter pool of the same name is already present in the envelope the new filter pool will
* be renamed prior to adding it.
* @param pool the filter pool to be added to the envelope
*/
public void add(final ISystemFilterPool pool) {
// add the pool
String type = IRSEDOMConstants.TYPE_FILTER_POOL;
String name = pool.getName();
Runnable action = new Runnable() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, pool, true);
}
};
addNode(type, name, action);
}
/**
* Adds a property set to the envelope.
* If a property set of the same name is already present in the envelope the new property set will
* be renamed prior to adding it.
* @param propertySet the property set to be added to the envelope
*/
public void add(final IPropertySet propertySet) {
// add the property set
String type = IRSEDOMConstants.TYPE_FILTER_POOL;
String name = propertySet.getName();
Runnable action = new Runnable() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, propertySet, true);
}
};
addNode(type, name, action);
}
/** /**
* Merges the contents of the envelope into the profile. * Merges the contents of the envelope into the profile.
* @param profile the profile which is updated with the changes. The profile may be active or inactive. * @param profile the profile which is updated with the changes. The profile may be active or inactive.
@ -254,73 +302,6 @@ public class RSEEnvelope {
return filterPool; return filterPool;
} }
private interface NodeAction {
abstract void run();
}
/**
* Adds a host to the envelope.
* If a host of the same name is already present in the envelope the new host will
* be renamed prior to adding it.
* @param host the host to be added to the envelope
*/
public void add(final IHost host) {
// find and add the host-unique filter pools
ISubSystem[] subsystems = host.getSubSystems();
for (int i = 0; i < subsystems.length; i++) {
ISubSystem subsystem = subsystems[i];
ISystemFilterPool pool = subsystem.getUniqueOwningSystemFilterPool(false);
if (pool != null) {
add(pool);
}
}
// add the host
String type = IRSEDOMConstants.TYPE_HOST;
String name = host.getName();
NodeAction action = new NodeAction() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, host, true);
}
};
addNode(type, name, action);
}
/**
* Adds a filter pool to the envelope.
* If a filter pool of the same name is already present in the envelope the new filter pool will
* be renamed prior to adding it.
* @param pool the filter pool to be added to the envelope
*/
public void add(final ISystemFilterPool pool) {
// add the pool
String type = IRSEDOMConstants.TYPE_FILTER_POOL;
String name = pool.getName();
NodeAction action = new NodeAction() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, pool, true);
}
};
addNode(type, name, action);
}
/**
* Adds a property set to the envelope.
* If a property set of the same name is already present in the envelope the new property set will
* be renamed prior to adding it.
* @param propertySet the property set to be added to the envelope
*/
public void add(final IPropertySet propertySet) {
// add the property set
String type = IRSEDOMConstants.TYPE_FILTER_POOL;
String name = propertySet.getName();
NodeAction action = new NodeAction() {
public void run() {
RSEDOMExporter.getInstance().createNode(dom, propertySet, true);
}
};
addNode(type, name, action);
}
private IStatus saveProviderId(File parent, IRSEImportExportProvider provider) { private IStatus saveProviderId(File parent, IRSEImportExportProvider provider) {
IStatus status = Status.OK_STATUS; IStatus status = Status.OK_STATUS;
String providerId = provider.getId(); String providerId = provider.getId();
@ -347,7 +328,7 @@ public class RSEEnvelope {
return providerId; return providerId;
} }
private void addNode(String type, String name, NodeAction action) { private void addNode(String type, String name, Runnable action) {
ensureDOM(); ensureDOM();
RSEDOMNode existingNode = dom.getChild(type, name); RSEDOMNode existingNode = dom.getChild(type, name);
if (existingNode != null) { if (existingNode != null) {
@ -358,14 +339,10 @@ public class RSEEnvelope {
private void ensureDOM() { private void ensureDOM() {
if (dom == null) { if (dom == null) {
initialize(); dom = new RSEDOM("dom"); //$NON-NLS-1$
} }
} }
private void initialize() {
dom = new RSEDOM("dom"); //$NON-NLS-1$
}
private String generateName(List usedNames) { private String generateName(List usedNames) {
String prefix = "env_"; //$NON-NLS-1$ String prefix = "env_"; //$NON-NLS-1$
int n = 0; int n = 0;
@ -486,5 +463,20 @@ public class RSEEnvelope {
IStatus status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, "Unexpected Exception", e); //$NON-NLS-1$ IStatus status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, "Unexpected Exception", e); //$NON-NLS-1$
return status; return status;
} }
/**
* @return a file handle to a temporary directory
*/
private File getTemporaryFolder() {
IPath stateLocation = RSECorePlugin.getDefault().getStateLocation();
File stateFolder = new File(stateLocation.toOSString());
File envelopesFolder = new File(stateFolder, "envelopes"); //$NON-NLS-1$
envelopesFolder.mkdir();
List envelopeNames = Arrays.asList(envelopesFolder.list());
String envelopeName = generateName(envelopeNames);
File envelopeFolder = new File(envelopesFolder, envelopeName);
envelopeFolder.mkdir();
return envelopeFolder;
}
} }