use of org.eclipse.wst.server.core.internal.XMLMemento in project liferay-ide by liferay.
the class LiferayServerCore method saveGlobalRuntimeSettings.
private synchronized void saveGlobalRuntimeSettings(IRuntime runtime) {
final IRuntimeType runtimeType = runtime.getRuntimeType();
if (runtimeType != null && runtimeType.getId().startsWith("com.liferay")) {
try {
LiferayCore.GLOBAL_SETTINGS_PATH.toFile().mkdirs();
final File runtimesGlobalFile = LiferayCore.GLOBAL_SETTINGS_PATH.append("runtimes.xml").toFile();
final Set<IMemento> existing = new HashSet<IMemento>();
if (runtimesGlobalFile.exists()) {
try {
try (InputStream newInputStream = Files.newInputStream(runtimesGlobalFile.toPath())) {
IMemento existingMemento = XMLMemento.loadMemento(newInputStream);
if (existingMemento != null) {
IMemento[] children = existingMemento.getChildren("runtime");
if (ListUtil.isNotEmpty(children)) {
for (IMemento child : children) {
final IPath loc = Path.fromPortableString(child.getString("location"));
if (loc != null && loc.toFile().exists()) {
boolean duplicate = ServerCore.findRuntime(child.getString("id")) != null;
if (!duplicate) {
existing.add(child);
}
}
}
}
}
}
} catch (Exception e) {
}
}
final Map<String, IMemento> mementos = new HashMap<String, IMemento>();
final XMLMemento runtimeMementos = XMLMemento.createWriteRoot("runtimes");
for (IMemento exist : existing) {
final IMemento copy = runtimeMementos.createChild("runtime");
copyMemento(exist, copy);
mementos.put(copy.getString("id"), copy);
}
for (IRuntime r : ServerCore.getRuntimes()) {
if (mementos.get(r.getId()) == null && r.getRuntimeType() != null) {
final IMemento rMemento = runtimeMementos.createChild("runtime");
if (addRuntimeToMemento(r, rMemento)) {
mementos.put(r.getId(), rMemento);
}
}
}
final OutputStream fos = Files.newOutputStream(runtimesGlobalFile.toPath());
runtimeMementos.save(fos);
} catch (Exception e) {
LiferayServerCore.logError("Unable to save global runtime settings", e);
}
}
}
use of org.eclipse.wst.server.core.internal.XMLMemento in project liferay-ide by liferay.
the class LiferayServerCore method saveGlobalServerSettings.
private synchronized void saveGlobalServerSettings(IServer server) {
final IServerType serverType = server.getServerType();
if (serverType != null && serverType.getId().startsWith("com.liferay")) {
try {
LiferayCore.GLOBAL_SETTINGS_PATH.toFile().mkdirs();
final File globalServersFile = LiferayCore.GLOBAL_SETTINGS_PATH.append("servers.xml").toFile();
final Set<IMemento> existing = new HashSet<IMemento>();
if (globalServersFile.exists()) {
try {
try (InputStream newInputStream = Files.newInputStream(globalServersFile.toPath())) {
IMemento existingMemento = XMLMemento.loadMemento(newInputStream);
if (existingMemento != null) {
IMemento[] children = existingMemento.getChildren("server");
if (ListUtil.isNotEmpty(children)) {
for (IMemento child : children) {
final boolean duplicate = ServerCore.findServer(child.getString("id")) != null;
if (!duplicate) {
existing.add(child);
}
}
}
}
}
} catch (Exception e) {
}
}
final Map<String, IMemento> mementos = new HashMap<String, IMemento>();
final XMLMemento serverMementos = XMLMemento.createWriteRoot("servers");
for (IMemento exist : existing) {
final IMemento copy = serverMementos.createChild("server");
copyMemento(exist, copy);
mementos.put(copy.getString("id"), copy);
}
for (IServer s : ServerCore.getServers()) {
if (mementos.get(s.getId()) == null && s.getServerType() != null) {
final IMemento sMemento = serverMementos.createChild("server");
if (addServerToMemento(s, sMemento)) {
mementos.put(s.getId(), sMemento);
}
}
}
if (mementos.size() > 0) {
final OutputStream fos = Files.newOutputStream(globalServersFile.toPath());
serverMementos.save(fos);
}
} catch (Exception e) {
LiferayServerCore.logError("Unable to save global server settings", e);
}
}
}
Aggregations