mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-02 22:55:26 +02:00
[301075] Host copy doesn't copy contained property sets
This commit is contained in:
parent
d19bcd042c
commit
8317fc23f9
4 changed files with 132 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2002, 2011 IBM Corporation and others. All rights reserved.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others. 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
|
||||
|
@ -21,8 +21,8 @@
|
|||
* David Dykstal (IBM) - [176577] wrong enablement of "Move up/down" in connection context menu
|
||||
* Martin Oberhuber (Wind River) - [206742] Make SystemHostPool thread-safe
|
||||
* David Dykstal (IBM) - [210537] removed exception signaling from this class to match the interface
|
||||
* Tom Hochstein (freescale) - [325923] Host copy doesn't copy contained property sets
|
||||
********************************************************************************/
|
||||
* Tom Hochstein (Freescale) - [301075] Host copy doesn't copy contained property sets
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.core.model;
|
||||
import java.util.ArrayList;
|
||||
|
@ -40,6 +40,7 @@ import org.eclipse.rse.core.model.Host;
|
|||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.core.model.IProperty;
|
||||
import org.eclipse.rse.core.model.IPropertySet;
|
||||
import org.eclipse.rse.core.model.IPropertySetContainer;
|
||||
import org.eclipse.rse.core.model.IRSEPersistableContainer;
|
||||
import org.eclipse.rse.core.model.ISystemHostPool;
|
||||
import org.eclipse.rse.core.model.ISystemProfile;
|
||||
|
@ -398,7 +399,6 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.rse.core.model.ISystemHostPool#cloneHost(org.eclipse.rse.core.model.ISystemHostPool, org.eclipse.rse.core.model.IHost, java.lang.String)
|
||||
|
@ -408,35 +408,34 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool
|
|||
IHost copy =
|
||||
targetPool.createHost(conn.getSystemType(), aliasName,
|
||||
conn.getHostName(), conn.getDescription(), conn.getLocalDefaultUserId(), IRSEUserIdConstants.USERID_LOCATION_HOST);
|
||||
|
||||
|
||||
// Copy all properties as well.
|
||||
clonePropertySets(copy, conn.getPropertySets());
|
||||
clonePropertySets(copy, conn.getPropertySets());
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make copies of a list of property sets and add them to the specified host.
|
||||
* Make copies of a list of property sets and add them to the specified container.
|
||||
* Each property set may contain its own list of property sets, so the
|
||||
* method is recursive.
|
||||
* @param copy
|
||||
* @param fromSets
|
||||
* @param container
|
||||
* @param propertySets
|
||||
*/
|
||||
private static void clonePropertySets(IHost copy, IPropertySet[] fromSets) {
|
||||
if (fromSets == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0, n = fromSets.length; i < n; ++i) {
|
||||
IPropertySet fromSet = fromSets[i];
|
||||
IPropertySet copySet = copy.createPropertySet(fromSet.getName(), fromSet.getDescription());
|
||||
String[] fromKeys = fromSet.getPropertyKeys();
|
||||
for (int i2 = 0, n2 = fromKeys.length; i2 < n2; ++i2) {
|
||||
IProperty fromProperty = fromSet.getProperty(fromKeys[i2]);
|
||||
copySet.addProperty(fromProperty.getKey(), fromProperty.getValue(), fromProperty.getType());
|
||||
}
|
||||
clonePropertySets(copy, fromSet.getPropertySets());
|
||||
}
|
||||
}
|
||||
|
||||
private static void clonePropertySets(IPropertySetContainer container, IPropertySet[] propertySets) {
|
||||
if (propertySets == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0, n = propertySets.length; i < n; ++i) {
|
||||
IPropertySet fromSet = propertySets[i];
|
||||
IPropertySet copySet = container.createPropertySet(fromSet.getName(), fromSet.getDescription());
|
||||
String[] fromKeys = fromSet.getPropertyKeys();
|
||||
for (int i2 = 0, n2 = fromKeys.length; i2 < n2; ++i2) {
|
||||
IProperty fromProperty = fromSet.getProperty(fromKeys[i2]);
|
||||
copySet.addProperty(fromProperty.getKey(), fromProperty.getValue(), fromProperty.getType());
|
||||
}
|
||||
clonePropertySets(copySet, fromSet.getPropertySets());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Uwe Stieber (Wind River) - initial API and implementation
|
||||
* Tom Hochstein (Freescale) - [301075] Host copy doesn't copy contained property sets
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.tests.core.connection;
|
||||
|
||||
|
@ -60,6 +61,26 @@ public interface IRSEConnectionManager {
|
|||
*/
|
||||
public IRSEConnectionProperties loadConnectionProperties(Properties properties, boolean allowDefaults);
|
||||
|
||||
/**
|
||||
* Finds the connection given by the specified name/label from the specified
|
||||
* system profile. The method will do nothing if either the system profile or
|
||||
* the connection does not exist.
|
||||
*
|
||||
* @param profileName The system profile to look for the connection. Must be not <code>null</code>.
|
||||
* @param name The name of the connection to find. Must be not <code>null</code>.
|
||||
* @return The found connection, or null if failed.
|
||||
*/
|
||||
public IHost findConnection(String profileName, String name);
|
||||
|
||||
/**
|
||||
* Copies the connection.
|
||||
*
|
||||
* @param connection The connection to copy. Must be not <code>null</code>.
|
||||
* @param copyName The name of the new connection. Must be not <code>null</code>.
|
||||
* @return The copied connection, or null if failed.
|
||||
*/
|
||||
public IHost copyConnection(IHost connection, String copyName);
|
||||
|
||||
/**
|
||||
* Removes the connection given by the specified name/label from the specified
|
||||
* system profile. The method will do nothing if either the system profile or
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* David McKnight (IBM) - [186363] get rid of obsolete calls to SubSystem.connect()
|
||||
* Martin Oberhuber (Wind River) - organize, enable and tag test cases
|
||||
* Martin Oberhuber (Wind River) - [247908] extract testBug255023
|
||||
* Tom Hochstein (Freescale) - [301075] Host copy doesn't copy contained property sets
|
||||
********************************************************************************/
|
||||
package org.eclipse.rse.tests.core.connection;
|
||||
|
||||
|
@ -20,6 +21,8 @@ import java.util.Properties;
|
|||
import org.eclipse.rse.core.IRSESystemType;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.core.model.IProperty;
|
||||
import org.eclipse.rse.core.model.IPropertySet;
|
||||
import org.eclipse.rse.core.model.ISystemProfile;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
|
@ -103,6 +106,55 @@ public class RSEConnectionTestCase extends RSEBaseConnectionTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test copy of connections
|
||||
*/
|
||||
public void testConnectionCopy() {
|
||||
//-test-author-:DavidDykstal
|
||||
if (isTestDisabled())
|
||||
return;
|
||||
|
||||
String profileName = "TestProfile"; //$NON-NLS-1$
|
||||
|
||||
String name = "TestHost1"; //$NON-NLS-1$
|
||||
String copyName = "TestHost1Copy"; //$NON-NLS-1$
|
||||
IHost connection = getConnectionManager().findConnection(profileName, name);
|
||||
assertNotNull("Failed to find source connection " + name, connection); //$NON-NLS-1$
|
||||
|
||||
String setName = "Test Property Set Level 1"; //$NON-NLS-1$
|
||||
String propertyName = "Test Property Level 1"; //$NON-NLS-1$
|
||||
String propertyValue = "Level 1"; //$NON-NLS-1$
|
||||
IPropertySet ps = connection.createPropertySet(setName);
|
||||
assertNotNull("Failed to create property set " + setName, ps); //$NON-NLS-1$
|
||||
IProperty p = ps.addProperty(propertyName, propertyValue);
|
||||
assertNotNull("Failed to create property " + propertyName, p); //$NON-NLS-1$
|
||||
assertEquals("Failed to set value for property " + propertyName, propertyValue, p.getValue()); //$NON-NLS-1$
|
||||
|
||||
String setName2 = "Test Property Set Level 2"; //$NON-NLS-1$
|
||||
String propertyName2 = "Test Property Level 2"; //$NON-NLS-1$
|
||||
String propertyValue2 = "Level 2"; //$NON-NLS-1$
|
||||
ps = ps.createPropertySet(setName2);
|
||||
assertNotNull("Failed to create property set " + setName2, ps); //$NON-NLS-1$
|
||||
p = ps.addProperty(propertyName2, propertyValue2);
|
||||
assertNotNull("Failed to create property " + propertyName2, p); //$NON-NLS-1$
|
||||
assertEquals("Failed to set value for property " + propertyName2, propertyValue2, p.getValue()); //$NON-NLS-1$
|
||||
|
||||
IHost copy = getConnectionManager().copyConnection(connection, copyName);
|
||||
assertNotNull("Failed to copy connection " + name, copy); //$NON-NLS-1$
|
||||
|
||||
ps = copy.getPropertySet(setName);
|
||||
assertNotNull("Failed to copy property set " + setName, ps); //$NON-NLS-1$
|
||||
p = ps.getProperty(propertyName);
|
||||
assertNotNull("Failed to copy property " + propertyName, p); //$NON-NLS-1$
|
||||
assertEquals("Failed to copy value for property " + propertyName, propertyValue, p.getValue()); //$NON-NLS-1$
|
||||
|
||||
ps = ps.getPropertySet(setName2);
|
||||
assertNotNull("Failed to copy property set " + setName2, ps); //$NON-NLS-1$
|
||||
p = ps.getProperty(propertyName2);
|
||||
assertNotNull("Failed to copy property " + propertyName2, p); //$NON-NLS-1$
|
||||
assertEquals("Failed to copy value for property " + propertyName2, propertyValue2, p.getValue()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removal of connections
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Martin Oberhuber (Wind River) - [219086] flush event queue to shield tests from each other
|
||||
* David Dykstal (IBM) - [210474] Deny save password function missing
|
||||
* Martin Oberhuber (Wind River) - Support REXEC launch type for dstore
|
||||
* Tom Hochstein (Freescale) - [301075] Host copy doesn't copy contained property sets
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.tests.internal;
|
||||
|
||||
|
@ -168,6 +169,40 @@ public class RSEConnectionManager implements IRSEConnectionManager {
|
|||
return resultProperties != null ? new RSEConnectionProperties(resultProperties) : (IRSEConnectionProperties)null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.rse.tests.core.connection.IRSEConnectionManager#copyConnection(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public IHost findConnection(String profileName, String name) {
|
||||
assert profileName != null && name != null;
|
||||
|
||||
ISystemRegistry systemRegistry = RSECorePlugin.getTheSystemRegistry();
|
||||
Assert.assertNotNull("FAILED(findConnection): RSE system registry unavailable!", systemRegistry); //$NON-NLS-1$
|
||||
|
||||
ISystemProfile profile = systemRegistry.getSystemProfile(profileName);
|
||||
if (profile != null) {
|
||||
return systemRegistry.getHost(profile, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.rse.tests.core.connection.IRSEConnectionManager#copyConnection(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public IHost copyConnection(IHost connection, String copyName) {
|
||||
assert connection != null;
|
||||
|
||||
ISystemRegistry systemRegistry = RSECorePlugin.getTheSystemRegistry();
|
||||
Assert.assertNotNull("FAILED(copyConnection): RSE system registry unavailable!", systemRegistry); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
return systemRegistry.copyHost(connection, connection.getSystemProfile(), copyName, null);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a host given its name and the name of its profile. If the host is not found then
|
||||
* do nothing.
|
||||
|
|
Loading…
Add table
Reference in a new issue