Search in sources :

Example 1 with Runtime

use of org.eclipse.wst.server.core.internal.Runtime 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)1 FileNotFoundException (java.io.FileNotFoundException)1 Method (java.lang.reflect.Method)1 IRuntime (org.eclipse.wst.server.core.IRuntime)1 IMemento (org.eclipse.wst.server.core.internal.IMemento)1 ResourceManager (org.eclipse.wst.server.core.internal.ResourceManager)1 Runtime (org.eclipse.wst.server.core.internal.Runtime)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1