mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-04 15:45:25 +02:00
[233876] [Persistence] Lose of Filters after restart
https://bugs.eclipse.org/bugs/show_bug.cgi?id=233876
This commit is contained in:
parent
b15c28c5fc
commit
c5774fd9f1
5 changed files with 135 additions and 29 deletions
|
@ -0,0 +1,62 @@
|
|||
/*********************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation. All rights reserved.
|
||||
* This program and the accompanying materials are made available under the terms
|
||||
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* David Dykstal (IBM) - initial contribution.
|
||||
* David Dykstal (IBM) - [233876] filters lost after restart
|
||||
*********************************************************************************/
|
||||
package org.eclipse.rse.internal.core.filters;
|
||||
|
||||
/**
|
||||
* This is a utility class used for manipulating host-owned filter pool names.
|
||||
*/
|
||||
public class HostOwnedFilterPoolPattern {
|
||||
|
||||
final private static String prefix = "CN-"; //$NON-NLS-1$
|
||||
final private static int start = prefix.length();
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* Create a pattern given a subsystem configuration id
|
||||
* @param configurationId the id from which to construct the pattern.
|
||||
*/
|
||||
public HostOwnedFilterPoolPattern(String configurationId) {
|
||||
suffix = "-" + configurationId; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a filter pool name to see if it matches this pattern
|
||||
* @param filterPoolName The filter pool name to test.
|
||||
* @return true if the pattern matches this name, false otherwise.
|
||||
*/
|
||||
public boolean matches(String filterPoolName) {
|
||||
return (filterPoolName.startsWith(prefix) && filterPoolName.endsWith(suffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the host name from the filter pool name
|
||||
* @param filterPoolName the name of the filter pool
|
||||
* @return the associated host name
|
||||
*/
|
||||
public String extract(String filterPoolName) {
|
||||
String result = null;
|
||||
if (matches(filterPoolName)) {
|
||||
int length = filterPoolName.length() - (prefix.length() + suffix.length());
|
||||
result = filterPoolName.substring(start, start + length);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a filter pool name from the host name
|
||||
* @param hostName the host name to use as a base
|
||||
* @return the associated filter pool name
|
||||
*/
|
||||
public String make(String hostName) {
|
||||
return prefix + hostName + suffix;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
* David Dykstal (IBM) - initial contribution.
|
||||
* David Dykstal (IBM) - [189274] provide import and export operations for profiles
|
||||
* David Dykstal (IBM) - [216858] Need the ability to Import/Export RSE connections for sharing
|
||||
* David Dykstal (IBM) - [233876] Filters lost after restart
|
||||
*********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.persistence;
|
||||
|
@ -49,6 +50,7 @@ import org.eclipse.rse.core.model.ISystemRegistry;
|
|||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
|
||||
import org.eclipse.rse.internal.core.RSECoreMessages;
|
||||
import org.eclipse.rse.internal.core.filters.HostOwnedFilterPoolPattern;
|
||||
import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter;
|
||||
import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter;
|
||||
import org.eclipse.rse.persistence.IRSEPersistenceManager;
|
||||
|
@ -255,9 +257,11 @@ public class RSEEnvelope {
|
|||
// create the filter pools
|
||||
for (Iterator z = filterPoolNodes.iterator(); z.hasNext();) {
|
||||
RSEDOMNode filterPoolNode = (RSEDOMNode) z.next();
|
||||
String name = filterPoolNode.getName();
|
||||
if (name.startsWith("CN-")) { //$NON-NLS-1$
|
||||
String hostName = name.substring(3);
|
||||
String filterPoolName = filterPoolNode.getName();
|
||||
String configurationId = filterPoolNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_ID).getValue();
|
||||
HostOwnedFilterPoolPattern pattern = new HostOwnedFilterPoolPattern(configurationId);
|
||||
String hostName = pattern.extract(filterPoolName);
|
||||
if (hostName != null) {
|
||||
IHost host = (IHost) hostMap.get(hostName);
|
||||
if (host != null) {
|
||||
mergeHostFilterPool(profile, host, filterPoolNode);
|
||||
|
@ -291,12 +295,16 @@ public class RSEEnvelope {
|
|||
}
|
||||
|
||||
private void mergeHostFilterPool(ISystemProfile profile, IHost host, RSEDOMNode filterPoolNode) {
|
||||
String configurationId = filterPoolNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_ID).getValue();
|
||||
HostOwnedFilterPoolPattern pattern = new HostOwnedFilterPoolPattern(configurationId);
|
||||
String hostName = host.getAliasName();
|
||||
String filterPoolName = "CN-" + hostName; //$NON-NLS-1$
|
||||
String filterPoolName = pattern.make(hostName);
|
||||
filterPoolNode.setName(filterPoolName);
|
||||
mergeFilterPool(profile, filterPoolNode);
|
||||
RSEDOMImporter importer = RSEDOMImporter.getInstance();
|
||||
ISystemFilterPool filterPool = importer.restoreFilterPool(profile, filterPoolNode);
|
||||
filterPool.setOwningParentName(hostName);
|
||||
}
|
||||
|
||||
|
||||
private ISystemFilterPool mergeFilterPool(ISystemProfile profile, RSEDOMNode filterPoolNode) {
|
||||
ISystemFilterPool filterPool = getMatchingFilterPool(profile, filterPoolNode);
|
||||
if (filterPool != null) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* David Dykstal (IBM) - [217556] remove service subsystem types
|
||||
* David Dykstal (IBM) - [225988] need API to mark persisted profiles as migrated
|
||||
* David Dykstal (IBM) - [232126] retrieve persisted filter type attribute
|
||||
* David Dykstal (IBM) - [233876] filters lost after restart
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.persistence.dom;
|
||||
|
@ -49,6 +50,7 @@ import org.eclipse.rse.core.subsystems.IConnectorService;
|
|||
import org.eclipse.rse.core.subsystems.IServerLauncherProperties;
|
||||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
|
||||
import org.eclipse.rse.internal.core.filters.HostOwnedFilterPoolPattern;
|
||||
import org.eclipse.rse.internal.core.model.SystemProfile;
|
||||
import org.eclipse.rse.internal.core.model.SystemProfileManager;
|
||||
import org.eclipse.rse.persistence.dom.IRSEDOMConstants;
|
||||
|
@ -463,17 +465,28 @@ public class RSEDOMImporter {
|
|||
public ISystemFilterPoolReference restoreFilterPoolReference(ISubSystem subsystem, RSEDOMNode node) {
|
||||
ISystemFilterPoolReference filterPoolReference = null;
|
||||
String filterPoolName = node.getName();
|
||||
ISystemProfile profile = subsystem.getSystemProfile();
|
||||
String profileName = profile.getName();
|
||||
String baseFilterPoolName = filterPoolName;
|
||||
String[] part = filterPoolName.split("___", 2); //$NON-NLS-1$
|
||||
if (part.length == 1) { // name is unqualified and refers to a filter pool in the current profile, ensure it is qualified
|
||||
ISystemProfile profile = subsystem.getSystemProfile();
|
||||
String profileName = profile.getName();
|
||||
filterPoolName = profileName + "___" + filterPoolName; //$NON-NLS-1$
|
||||
if (part.length == 2) { // name is qualified and refers to a filter pool in a specific profile
|
||||
profileName = part[0];
|
||||
baseFilterPoolName = part[1];
|
||||
}
|
||||
// special processing for host owned pool references
|
||||
String configurationId = subsystem.getConfigurationId();
|
||||
HostOwnedFilterPoolPattern pattern = new HostOwnedFilterPoolPattern(configurationId);
|
||||
if (pattern.matches(baseFilterPoolName)) { // if this is a host owned pool then fix up this reference
|
||||
String hostName = subsystem.getHostAliasName();
|
||||
baseFilterPoolName = pattern.make(hostName);
|
||||
}
|
||||
// qualify the name and construct the reference
|
||||
filterPoolName = profileName + "___" + baseFilterPoolName; //$NON-NLS-1$
|
||||
ISystemFilterPoolReferenceManager referenceManager = subsystem.getFilterPoolReferenceManager();
|
||||
filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPoolName);
|
||||
return filterPoolReference;
|
||||
}
|
||||
|
||||
|
||||
public ISystemFilterString restoreFilterString(ISystemFilter filter, RSEDOMNode node) {
|
||||
/*
|
||||
String string = node.getAttribute(IRSEDOMConstants.ATTRIBUTE_STRING).getValue();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* David Dykstal (IBM) - [216858] provide ability to import and export connections
|
||||
* David Dykstal (IBM) - [233876] filters lost after restart
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.ui.actions;
|
||||
|
@ -26,6 +27,8 @@ import org.eclipse.rse.core.model.IHost;
|
|||
import org.eclipse.rse.core.model.ISystemProfile;
|
||||
import org.eclipse.rse.core.model.ISystemProfileManager;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
import org.eclipse.rse.internal.core.model.ISystemProfileOperation;
|
||||
import org.eclipse.rse.internal.core.model.SystemProfileManager;
|
||||
import org.eclipse.rse.internal.persistence.RSEEnvelope;
|
||||
import org.eclipse.rse.internal.ui.SystemResources;
|
||||
import org.eclipse.rse.ui.ISystemContextMenuConstants;
|
||||
|
@ -56,24 +59,33 @@ public class SystemImportConnectionAction extends SystemBaseAction {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
protected IStatus run(final IProgressMonitor monitor) {
|
||||
IStatus status = Status.OK_STATUS;
|
||||
RSEEnvelope envelope = new RSEEnvelope();
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(inFile);
|
||||
envelope.get(in, monitor);
|
||||
envelope.mergeWith(profile);
|
||||
final FileInputStream in = new FileInputStream(inFile);
|
||||
// run inside an ISystemProfileOperation to ensure that the changes are committed
|
||||
status = SystemProfileManager.run(new ISystemProfileOperation() {
|
||||
public IStatus run() {
|
||||
IStatus operationStatus = Status.OK_STATUS;
|
||||
try {
|
||||
final RSEEnvelope envelope = new RSEEnvelope();
|
||||
envelope.get(in, monitor);
|
||||
envelope.mergeWith(profile);
|
||||
} catch (CoreException e) {
|
||||
// log the exception and return the status code
|
||||
operationStatus = e.getStatus();
|
||||
String message = operationStatus.getMessage();
|
||||
if (message == null) {
|
||||
message = SystemResources.SystemImportConnectionAction_CoreExceptionFound;
|
||||
}
|
||||
SystemBasePlugin.logError(message, e);
|
||||
}
|
||||
return operationStatus;
|
||||
}
|
||||
});
|
||||
} catch (FileNotFoundException e) {
|
||||
// should not happen, log as unexpected
|
||||
SystemBasePlugin.logError(SystemResources.SystemImportConnectionAction_UnexpectedException, e);
|
||||
} catch (CoreException e) {
|
||||
// log the exception and return the status code
|
||||
status = e.getStatus();
|
||||
String message = status.getMessage();
|
||||
if (message == null) {
|
||||
message = SystemResources.SystemImportConnectionAction_CoreExceptionFound;
|
||||
}
|
||||
SystemBasePlugin.logError(message, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
* Martin Oberhuber (Wind River) - [190231] Prepare API for UI/Non-UI Splitting
|
||||
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
|
||||
* David McKnight (IBM) - [233435] SubSystem.resolveFilterStrings(*) does not prompt for a connection when the subsystem is not connected
|
||||
* David Dykstal (IBM) - [233876] filters lost after restart
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.core.subsystems;
|
||||
|
@ -89,6 +90,7 @@ import org.eclipse.rse.core.model.ISystemRegistry;
|
|||
import org.eclipse.rse.core.model.RSEModelObject;
|
||||
import org.eclipse.rse.internal.core.RSECoreMessages;
|
||||
import org.eclipse.rse.internal.core.SystemResourceConstants;
|
||||
import org.eclipse.rse.internal.core.filters.HostOwnedFilterPoolPattern;
|
||||
import org.eclipse.rse.internal.core.model.ISystemProfileOperation;
|
||||
import org.eclipse.rse.internal.core.model.SystemModelChangeEvent;
|
||||
import org.eclipse.rse.internal.core.model.SystemProfileManager;
|
||||
|
@ -680,9 +682,17 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider
|
|||
String hostName = host.getAliasName();
|
||||
if (allPoolsInProfile != null) {
|
||||
for (int idx = 0; idx < allPoolsInProfile.length; idx++) {
|
||||
String poolOwnerName = allPoolsInProfile[idx].getOwningParentName();
|
||||
if ((poolOwnerName != null) && (poolOwnerName.equals(hostName))) {
|
||||
pool = allPoolsInProfile[idx];
|
||||
ISystemFilterPool currentPool = allPoolsInProfile[idx];
|
||||
String poolOwnerName = currentPool.getOwningParentName();
|
||||
if (poolOwnerName == null) {
|
||||
HostOwnedFilterPoolPattern pattern = new HostOwnedFilterPoolPattern(config.getId());
|
||||
if (pattern.matches(currentPool.getName())) {
|
||||
currentPool.setOwningParentName(hostName); // TODO these pools should have been created with the owner set properly
|
||||
poolOwnerName = hostName;
|
||||
}
|
||||
}
|
||||
if (hostName.equals(poolOwnerName)) {
|
||||
pool = currentPool;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -718,10 +728,11 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider
|
|||
* since it names a team sharable resource. Not qualified by the profile
|
||||
* name since that is implicit by being in a profile.
|
||||
*/
|
||||
String name = "CN-" + connectionName; //$NON-NLS-1$
|
||||
HostOwnedFilterPoolPattern pattern = new HostOwnedFilterPoolPattern(getConfigurationId());
|
||||
String name = pattern.make(connectionName);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------
|
||||
// Filter Testing Methods...
|
||||
// -------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue