use of org.eclipse.wst.server.core.internal.IMemento 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.IMemento in project liferay-ide by liferay.
the class ServerStartup method importGlobalSDKs.
private void importGlobalSDKs(File sdksFile) {
try {
final SDKManager manager = SDKManager.getInstance();
final IMemento sdksMemento = XMLMemento.loadMemento(new FileInputStream(sdksFile));
if (sdksMemento != null) {
final IMemento[] sdks = sdksMemento.getChildren("sdk");
if (ListUtil.isNotEmpty(sdks)) {
for (IMemento sdkMemento : sdks) {
final SDK newSDK = createSDKfromMemento(sdkMemento);
if (newSDK != null) {
final SDK existingSDK = manager.getSDK(newSDK.getName());
if (existingSDK == null) {
manager.addSDK(newSDK);
}
}
}
}
}
} catch (FileNotFoundException e) {
}
}
use of org.eclipse.wst.server.core.internal.IMemento in project webtools.servertools by eclipse.
the class ServerTransfer method nativeToJava.
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.Transfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
*/
protected Object nativeToJava(TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
if (bytes == null)
return null;
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
try {
IMemento memento = XMLMemento.loadMemento(in);
IMemento[] children = memento.getChildren("server");
int count = children.length;
IServer[] results = new IServer[count];
for (int i = 0; i < count; i++) {
Server server = new Server(null);
server.deserialize(children[i]);
results[i] = server;
}
return results;
} catch (Exception e) {
DND.error(DND.ERROR_INVALID_DATA);
}
return null;
}
use of org.eclipse.wst.server.core.internal.IMemento in project webtools.servertools by eclipse.
the class ModuleHelper method createJarContent.
public static void createJarContent(String name, int num, IPath path) throws Exception {
if (!path.toFile().exists())
path.toFile().mkdirs();
// create external jars
for (int i = 0; i < num; i++) {
Bundle bundle = Platform.getBundle("org.eclipse.core.runtime");
URL url = bundle.getEntry("/");
url = FileLocator.resolve(url);
String s = url.toString();
url = new URL(s.substring(4, s.length() - 2));
InputStream in = url.openStream();
IPath path2 = path.append("external_jar" + i + ".jar");
copyFile(in, path2.toOSString());
}
// update component file
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
IFile file = project.getFile(new Path(".settings").append("org.eclipse.wst.common.component"));
InputStream in = null;
XMLMemento memento = null;
try {
in = file.getContents();
memento = (XMLMemento) XMLMemento.loadMemento(in);
IMemento child = memento.getChild("project-modules");
child = memento.getChild("wb-module");
for (int i = 0; i < num; i++) {
IMemento newChild = child.createChild("dependent-module");
newChild.putString("deploy-path", "/WEB-INF/lib");
IPath path2 = path.append("external_jar" + i + ".jar");
newChild.putString("handle", "module:/classpath/lib/" + path2.toOSString());
XMLMemento child2 = (XMLMemento) newChild.createChild("dependency-type");
child2.putTextData("uses");
}
/* <dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/C:/Documents and Settings/Administrator/Desktop/com.ibm.version.adder_1.0.0.jar">
<dependency-type>uses</dependency-type>
</dependent-module>*/
} finally {
try {
in.close();
} catch (Exception ex) {
// ignore
}
}
// ByteArrayInputStream in = new ByteArrayInputStream(memento.getBytes());
in = memento.getInputStream();
file.setContents(in, true, true, null);
}
use of org.eclipse.wst.server.core.internal.IMemento in project webtools.servertools by eclipse.
the class MementoTestCase method copy.
protected void copy(IMemento a, IMemento b) {
String s = a.getString("name");
if (s != null)
b.putString("name", s);
s = a.getString("module-ids");
if (s != null)
b.putString("module-ids", s);
s = a.getString("module-type-id");
if (s != null)
b.putString("module-type-id", s);
s = a.getString("module-type-version");
if (s != null)
b.putString("module-type-version", s);
s = a.getString("stamp");
if (s != null)
b.putString("stamp", s);
IMemento[] children = a.getChildren("module");
if (children != null) {
for (IMemento ch : children) {
IMemento child = b.createChild("module");
copy(ch, child);
}
}
children = a.getChildren("folder");
if (children != null) {
for (IMemento ch : children) {
IMemento child = b.createChild("folder");
copy(ch, child);
}
}
children = a.getChildren("file");
if (children != null) {
for (IMemento ch : children) {
IMemento child = b.createChild("file");
copy(ch, child);
}
}
}
Aggregations