use of org.eclipse.wst.server.core.internal.XMLMemento 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.XMLMemento in project webtools.servertools by eclipse.
the class MementoTestCase method testMementoCreateSave.
public void testMementoCreateSave() throws Exception {
IPath path = getLocalPath(new Path("data").append("publish.xml"));
File f = File.createTempFile("perftest", null);
XMLMemento memento = (XMLMemento) XMLMemento.loadMemento(path.toOSString());
for (int i = 0; i < 5; i++) {
startMeasuring();
XMLMemento memento2 = XMLMemento.createWriteRoot("server");
copy(memento, memento2);
memento2.saveToFile(f.getAbsolutePath());
stopMeasuring();
f.delete();
}
commitMeasurements();
assertPerformance();
}
use of org.eclipse.wst.server.core.internal.XMLMemento in project webtools.servertools by eclipse.
the class MementoTestCase method testMementoSave.
public void testMementoSave() throws Exception {
IPath path = getLocalPath(new Path("data").append("publish.xml"));
File f = File.createTempFile("perftest", null);
XMLMemento memento = (XMLMemento) XMLMemento.loadMemento(path.toOSString());
for (int i = 0; i < 5; i++) {
startMeasuring();
memento.saveToFile(f.getAbsolutePath());
stopMeasuring();
f.delete();
}
commitMeasurements();
assertPerformance();
}
use of org.eclipse.wst.server.core.internal.XMLMemento 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.XMLMemento 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);
}
}
Aggregations