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) {
}
}
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) {
}
}
Aggregations