Search in sources :

Example 1 with IMemento

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) {
    }
}
Also used : Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) FileNotFoundException(java.io.FileNotFoundException) ResourceManager(org.eclipse.wst.server.core.internal.ResourceManager) Method(java.lang.reflect.Method) ServerDelegate(org.eclipse.wst.server.core.model.ServerDelegate) IMemento(org.eclipse.wst.server.core.internal.IMemento) FileInputStream(java.io.FileInputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with IMemento

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) {
    }
}
Also used : SDKManager(com.liferay.ide.sdk.core.SDKManager) FileNotFoundException(java.io.FileNotFoundException) SDK(com.liferay.ide.sdk.core.SDK) IMemento(org.eclipse.wst.server.core.internal.IMemento) FileInputStream(java.io.FileInputStream)

Example 3 with IMemento

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

Example 4 with IMemento

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);
}
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 5 with IMemento

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);
        }
    }
}
Also used : IMemento(org.eclipse.wst.server.core.internal.IMemento)

Aggregations

IMemento (org.eclipse.wst.server.core.internal.IMemento)10 IOException (java.io.IOException)5 XMLMemento (org.eclipse.wst.server.core.internal.XMLMemento)5 InputStream (java.io.InputStream)4 IServer (org.eclipse.wst.server.core.IServer)4 BackingStoreException (org.osgi.service.prefs.BackingStoreException)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 OutputStream (java.io.OutputStream)3 HashSet (java.util.HashSet)3 Server (org.eclipse.wst.server.core.internal.Server)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 IPath (org.eclipse.core.runtime.IPath)2 IRuntime (org.eclipse.wst.server.core.IRuntime)2 ResourceManager (org.eclipse.wst.server.core.internal.ResourceManager)2 SDK (com.liferay.ide.sdk.core.SDK)1 SDKManager (com.liferay.ide.sdk.core.SDKManager)1