Search in sources :

Example 1 with ServerDelegate

use of org.eclipse.wst.server.core.model.ServerDelegate in project liferay-ide by liferay.

the class ServerStartup method importGlobalServers.

private void importGlobalServers(File serversFile) {
    try {
        final IMemento serversMemento = XMLMemento.loadMemento(new FileInputStream(serversFile));
        if (serversMemento != null) {
            final ResourceManager resourceManager = ResourceManager.getInstance();
            final IMemento[] mementos = serversMemento.getChildren("server");
            if (ListUtil.isNotEmpty(mementos)) {
                for (IMemento memento : mementos) {
                    final Server server = new Server(null);
                    try {
                        final Method loadFromMemento = Base.class.getDeclaredMethod("loadFromMemento", IMemento.class, IProgressMonitor.class);
                        if (loadFromMemento != null) {
                            loadFromMemento.setAccessible(true);
                            loadFromMemento.invoke(server, memento, null);
                            if (ServerCore.findServer(server.getId()) == null) {
                                final Method addServer = ResourceManager.class.getDeclaredMethod("addServer", IServer.class);
                                if (addServer != null) {
                                    addServer.setAccessible(true);
                                    addServer.invoke(resourceManager, server);
                                    final IServerWorkingCopy wc = server.createWorkingCopy();
                                    ServerDelegate delegate = (ServerDelegate) wc.loadAdapter(ServerDelegate.class, null);
                                    delegate.importRuntimeConfiguration(wc.getRuntime(), null);
                                    wc.save(true, null);
                                }
                            }
                        }
                    } catch (Exception e) {
                        LiferayServerUI.logError("Unable to load server from memento", e);
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
    }
}
Also used : Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) FileNotFoundException(java.io.FileNotFoundException) ResourceManager(org.eclipse.wst.server.core.internal.ResourceManager) Method(java.lang.reflect.Method) ServerDelegate(org.eclipse.wst.server.core.model.ServerDelegate) IMemento(org.eclipse.wst.server.core.internal.IMemento) FileInputStream(java.io.FileInputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ServerDelegate

use of org.eclipse.wst.server.core.model.ServerDelegate in project liferay-ide by liferay.

the class PortalBundleTests method testPortalServerDelegateName.

@Test
@Ignore
public void testPortalServerDelegateName() throws Exception {
    if (shouldSkipBundleTests())
        return;
    IServerType portalServerType = ServerCore.findServerType(PortalServer.ID);
    assertNotNull(portalServerType);
    IProgressMonitor monitor = new NullProgressMonitor();
    IServerWorkingCopy newServer = portalServerType.createServer(null, null, monitor);
    assertNotNull(newServer);
    assertEquals("Liferay 7.x at localhost", newServer.getName());
    newServer.setHost("127.0.0.1");
    ServerDelegate delegate = (ServerDelegate) newServer.loadAdapter(ServerDelegate.class, monitor);
    delegate.newServerDetailsChanged(monitor);
    assertEquals("Liferay 7.x at 127.0.0.1", newServer.getName());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IServerType(org.eclipse.wst.server.core.IServerType) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) ServerDelegate(org.eclipse.wst.server.core.model.ServerDelegate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ServerDelegate

use of org.eclipse.wst.server.core.model.ServerDelegate in project liferay-ide by liferay.

the class ServerCoreBase method setupServer.

protected void setupServer() throws Exception {
    final NullProgressMonitor npm = new NullProgressMonitor();
    final IServerWorkingCopy serverWC = createServerForRuntime("6.2.0", runtime);
    ServerDelegate delegate = (ServerDelegate) serverWC.loadAdapter(ServerDelegate.class, null);
    delegate.importRuntimeConfiguration(serverWC.getRuntime(), null);
    server = serverWC.save(true, npm);
    assertNotNull(server);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) ServerDelegate(org.eclipse.wst.server.core.model.ServerDelegate)

Aggregations

IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)3 ServerDelegate (org.eclipse.wst.server.core.model.ServerDelegate)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Method (java.lang.reflect.Method)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IServer (org.eclipse.wst.server.core.IServer)1 IServerType (org.eclipse.wst.server.core.IServerType)1 IMemento (org.eclipse.wst.server.core.internal.IMemento)1 ResourceManager (org.eclipse.wst.server.core.internal.ResourceManager)1 Server (org.eclipse.wst.server.core.internal.Server)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1