Search in sources :

Example 1 with ConnectionPersistency

use of org.jboss.tools.openshift.core.connection.ConnectionPersistency in project jbosstools-openshift by jbosstools.

the class ConnectionPersistencyTest method shouldLoadUsernamesAsDefaultHostConnection.

@Ignore("no default server for OpenShift 3 yet")
@Test
public void shouldLoadUsernamesAsDefaultHostConnection() {
    // pre-condition
    ConnectionPersistency persistency = new ConnectionPersistency() {

        @Override
        protected String[] loadPersisted() {
            return new String[] { "bingobongo@redhat.com" };
        }
    };
    // operations
    Collection<Connection> connections = persistency.load();
    // verification
    assertEquals(1, connections.size());
    Connection connection = connections.iterator().next();
    assertTrue(connection.isDefaultHost());
    assertEquals("bingobongo@redhat.com", connection.getUsername());
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) ConnectionPersistency(org.jboss.tools.openshift.core.connection.ConnectionPersistency) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ConnectionPersistency

use of org.jboss.tools.openshift.core.connection.ConnectionPersistency in project jbosstools-openshift by jbosstools.

the class OpenShiftCoreActivator method saveAllConnections.

protected void saveAllConnections() {
    Collection<Connection> connections = ConnectionsRegistrySingleton.getInstance().getAll(Connection.class);
    new ConnectionPersistency().save(connections);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionPersistency(org.jboss.tools.openshift.core.connection.ConnectionPersistency)

Example 3 with ConnectionPersistency

use of org.jboss.tools.openshift.core.connection.ConnectionPersistency in project jbosstools-openshift by jbosstools.

the class OpenShiftCoreActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    registerDebugOptionsListener(PLUGIN_ID, new Trace(this), context);
    Collection<Connection> connections = new ConnectionPersistency().load();
    ConnectionsRegistrySingleton.getInstance().addAll(connections);
    ConnectionsRegistrySingleton.getInstance().addListener(new ConnectionsRegistryAdapter() {

        // @TODO I think we need to handle the cleanup case where a connection
        // username changes since username is what makes up part of the
        // the key that is saved which seems to apply to secure values
        // and preference values
        @Override
        public void connectionRemoved(IConnection connection) {
            if (!(connection instanceof Connection)) {
                return;
            }
            ((Connection) connection).removeSecureStoreData();
            ConnectionURL url = ConnectionURL.safeForConnection(connection);
            if (url != null) {
                OpenShiftCorePreferences.INSTANCE.removeAuthScheme(url.toString());
            }
            saveAllConnections();
        }

        @Override
        public void connectionAdded(IConnection connection) {
            if (connection instanceof Connection) {
                saveAllConnections();
            }
        }

        @Override
        public void connectionChanged(IConnection connection, String property, Object oldValue, Object newValue) {
            if (connection instanceof Connection && (oldValue instanceof Connection || newValue instanceof Connection)) {
                saveAllConnections();
            }
        }
    });
    ServerCore.addServerLifecycleListener(getServerListener());
    // A clone of the auto-publish thread implementation
    resourceChangeListener = new ResourceChangePublisher();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) ConnectionPersistency(org.jboss.tools.openshift.core.connection.ConnectionPersistency) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionsRegistryAdapter(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter) ResourceChangePublisher(org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)3 ConnectionPersistency (org.jboss.tools.openshift.core.connection.ConnectionPersistency)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)2 ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)1 ConnectionsRegistryAdapter (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter)1 ResourceChangePublisher (org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1