Search in sources :

Example 1 with ResourceManager

use of org.eclipse.wst.server.core.internal.ResourceManager 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 ResourceManager

use of org.eclipse.wst.server.core.internal.ResourceManager in project liferay-ide by liferay.

the class ServerStartup method importGlobalRuntimes.

private void importGlobalRuntimes(File runtimesFile) {
    try {
        final IMemento runtimesMemento = XMLMemento.loadMemento(new FileInputStream(runtimesFile));
        if (runtimesMemento != null) {
            final ResourceManager resourceManager = ResourceManager.getInstance();
            final IMemento[] mementos = runtimesMemento.getChildren("runtime");
            if (ListUtil.isNotEmpty(mementos)) {
                for (IMemento memento : mementos) {
                    final Runtime runtime = new Runtime(null);
                    try {
                        final Method loadFromMemento = Base.class.getDeclaredMethod("loadFromMemento", IMemento.class, IProgressMonitor.class);
                        if (loadFromMemento != null) {
                            loadFromMemento.setAccessible(true);
                            loadFromMemento.invoke(runtime, memento, null);
                            if (ServerCore.findRuntime(runtime.getId()) == null) {
                                final Method addRuntime = ResourceManager.class.getDeclaredMethod("addRuntime", IRuntime.class);
                                if (addRuntime != null) {
                                    addRuntime.setAccessible(true);
                                    addRuntime.invoke(resourceManager, runtime);
                                }
                            }
                        }
                    } catch (Exception e) {
                        LiferayServerUI.logError("Unable to load runtime from memento", e);
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
    }
}
Also used : Runtime(org.eclipse.wst.server.core.internal.Runtime) IRuntime(org.eclipse.wst.server.core.IRuntime) FileNotFoundException(java.io.FileNotFoundException) ResourceManager(org.eclipse.wst.server.core.internal.ResourceManager) Method(java.lang.reflect.Method) IMemento(org.eclipse.wst.server.core.internal.IMemento) FileInputStream(java.io.FileInputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Method (java.lang.reflect.Method)2 IMemento (org.eclipse.wst.server.core.internal.IMemento)2 ResourceManager (org.eclipse.wst.server.core.internal.ResourceManager)2 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2 IRuntime (org.eclipse.wst.server.core.IRuntime)1 IServer (org.eclipse.wst.server.core.IServer)1 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)1 Runtime (org.eclipse.wst.server.core.internal.Runtime)1 Server (org.eclipse.wst.server.core.internal.Server)1 ServerDelegate (org.eclipse.wst.server.core.model.ServerDelegate)1