Search in sources :

Example 1 with XMLMemento

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);
}
Also used : XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) Bundle(org.osgi.framework.Bundle) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URL(java.net.URL) IMemento(org.eclipse.wst.server.core.internal.IMemento) IOException(java.io.IOException)

Example 2 with XMLMemento

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) File(java.io.File)

Example 3 with XMLMemento

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) File(java.io.File)

Example 4 with XMLMemento

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
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IMemento(org.eclipse.wst.server.core.internal.IMemento)

Example 5 with XMLMemento

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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) XMLMemento(org.eclipse.wst.server.core.internal.XMLMemento) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) File(java.io.File) IMemento(org.eclipse.wst.server.core.internal.IMemento) HashSet(java.util.HashSet)

Aggregations

XMLMemento (org.eclipse.wst.server.core.internal.XMLMemento)7 File (java.io.File)5 IMemento (org.eclipse.wst.server.core.internal.IMemento)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 IPath (org.eclipse.core.runtime.IPath)4 OutputStream (java.io.OutputStream)3 HashSet (java.util.HashSet)3 HashMap (java.util.HashMap)2 Path (org.eclipse.core.runtime.Path)2 IServer (org.eclipse.wst.server.core.IServer)2 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 IRuntime (org.eclipse.wst.server.core.IRuntime)1 IRuntimeType (org.eclipse.wst.server.core.IRuntimeType)1 IServerType (org.eclipse.wst.server.core.IServerType)1 Server (org.eclipse.wst.server.core.internal.Server)1 Bundle (org.osgi.framework.Bundle)1