use of org.eclipse.wst.server.core.internal.IMemento in project webtools.servertools by eclipse.
the class ServerTransfer method javaToNative.
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.Transfer#javaToNative(java.lang.Object, org.eclipse.swt.dnd.TransferData)
*/
protected void javaToNative(Object data, TransferData transferData) {
if (!(data instanceof IServer[]))
return;
IServer[] servers = (IServer[]) data;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLMemento memento = XMLMemento.createWriteRoot("servers");
// write each element
for (int i = 0; i < servers.length; i++) {
IMemento child = memento.createChild("server");
((Server) servers[i]).serialize(child);
}
memento.save(out);
// cleanup
out.close();
byte[] bytes = out.toByteArray();
super.javaToNative(bytes, transferData);
} catch (IOException e) {
// it's best to send nothing if there were problems
}
}
use of org.eclipse.wst.server.core.internal.IMemento in project liferay-ide by liferay.
the class SDKCorePlugin method _saveGlobalSDKSettings.
private synchronized void _saveGlobalSDKSettings(SDK[] sdks) {
try {
LiferayCore.GLOBAL_SETTINGS_PATH.toFile().mkdirs();
File sdkGlobalFile = LiferayCore.GLOBAL_SETTINGS_PATH.append("sdks.xml").toFile();
Set<IMemento> existing = new HashSet<>();
if (sdkGlobalFile.exists()) {
try {
try (InputStream newInputStream = Files.newInputStream(sdkGlobalFile.toPath())) {
IMemento existingMemento = XMLMemento.loadMemento(newInputStream);
if (existingMemento != null) {
IMemento[] children = existingMemento.getChildren("sdk");
if (ListUtil.isNotEmpty(children)) {
for (IMemento child : children) {
IPath loc = Path.fromPortableString(child.getString("location"));
if ((loc != null) && loc.toFile().exists()) {
boolean duplicate = false;
for (SDK sdk : sdks) {
IPath sdkLocation = sdk.getLocation();
if (sdkLocation.toFile().equals(loc.toFile())) {
duplicate = true;
break;
}
}
if (!duplicate) {
existing.add(child);
}
}
}
}
}
}
} catch (Exception e) {
}
}
XMLMemento sdkMementos = XMLMemento.createWriteRoot("sdks");
for (IMemento exist : existing) {
_copyMemento(exist, sdkMementos.createChild("sdk"));
}
for (SDK sdk : sdks) {
IMemento memento = sdkMementos.createChild("sdk");
_addSDKToMemento(sdk, memento);
}
OutputStream fos = Files.newOutputStream(sdkGlobalFile.toPath());
sdkMementos.save(fos);
} catch (Exception e) {
logError("Unable to save global sdk settings", e);
}
}
use of org.eclipse.wst.server.core.internal.IMemento 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.IMemento 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);
}
}
}
use of org.eclipse.wst.server.core.internal.IMemento 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