Search in sources :

Example 16 with IRuntimeWorkingCopy

use of org.eclipse.wst.server.core.IRuntimeWorkingCopy in project webtools.servertools by eclipse.

the class PreviewServer method createPreviewServer.

public static IServer createPreviewServer(String serverName) {
    try {
        NullProgressMonitor monitor = new NullProgressMonitor();
        IRuntimeType runtimeType = ServerCore.findRuntimeType(PreviewRuntime.ID);
        IRuntimeWorkingCopy runtimeCopy = runtimeType.createRuntime(PreviewRuntime.ID, monitor);
        IRuntime runtime = runtimeCopy.save(true, monitor);
        IServerType serverType = ServerCore.findServerType(ID);
        IServerWorkingCopy workingCopy = serverType.createServer(ID, null, runtime, monitor);
        workingCopy.setName(serverName);
        workingCopy.setHost("localhost");
        return workingCopy.save(true, monitor);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error creating server", e);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServerType(org.eclipse.wst.server.core.IServerType) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) CoreException(org.eclipse.core.runtime.CoreException) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 17 with IRuntimeWorkingCopy

use of org.eclipse.wst.server.core.IRuntimeWorkingCopy in project webtools.servertools by eclipse.

the class PreviewStartup method startup.

public void startup() {
    // create runtime
    IRuntime[] runtimes = ServerCore.getRuntimes();
    IRuntime runtime = null;
    for (IRuntime r : runtimes) {
        if (r.getRuntimeType() != null && PreviewRuntime.ID.equals(r.getRuntimeType().getId())) {
            if (ID.equals(r.getId()))
                runtime = r;
        }
    }
    if (runtime == null) {
        try {
            IRuntimeType runtimeType = ServerCore.findRuntimeType(PreviewRuntime.ID);
            IRuntimeWorkingCopy wc = runtimeType.createRuntime(ID, null);
            wc.setName("My Preview");
            wc.setReadOnly(true);
            runtime = wc.save(true, null);
        } catch (CoreException ce) {
            Trace.trace(Trace.WARNING, "Could not create default preview runtime");
        }
    }
    // create server
    IServer[] servers = ServerCore.getServers();
    boolean found = false;
    for (IServer s : servers) {
        if (s.getServerType() != null && PreviewServer.ID.equals(s.getServerType().getId())) {
            if (ID.equals(s.getId()))
                found = true;
        }
    }
    if (!found) {
        try {
            IServerType serverType = ServerCore.findServerType(PreviewServer.ID);
            IServerWorkingCopy wc = serverType.createServer(ID, null, runtime, null);
            wc.setName("My preview");
            wc.setHost("localhost");
            wc.setReadOnly(true);
            wc.save(true, null);
        } catch (CoreException ce) {
            Trace.trace(Trace.WARNING, "Could not create default preview server");
        }
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) CoreException(org.eclipse.core.runtime.CoreException) IServerType(org.eclipse.wst.server.core.IServerType) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 18 with IRuntimeWorkingCopy

use of org.eclipse.wst.server.core.IRuntimeWorkingCopy in project webtools.servertools by eclipse.

the class HttpServer method createHttpServer.

public static IServer createHttpServer(String host, String serverName, IProgressMonitor monitor) {
    try {
        IRuntimeType runtimeType = ServerCore.findRuntimeType(HttpRuntime.ID);
        IRuntimeWorkingCopy runtimeCopy = runtimeType.createRuntime(HttpRuntime.ID, monitor);
        IRuntime runtime = runtimeCopy.save(true, monitor);
        IServerType serverType = ServerCore.findServerType(ID);
        IServerWorkingCopy workingCopy = serverType.createServer(ID, null, runtime, monitor);
        workingCopy.setName(serverName);
        workingCopy.setHost(host);
        return workingCopy.save(true, monitor);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error creating server", e);
    }
    return null;
}
Also used : IServerType(org.eclipse.wst.server.core.IServerType) IRuntimeType(org.eclipse.wst.server.core.IRuntimeType) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) CoreException(org.eclipse.core.runtime.CoreException) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 19 with IRuntimeWorkingCopy

use of org.eclipse.wst.server.core.IRuntimeWorkingCopy in project webtools.servertools by eclipse.

the class NewRuntimeWizardFragment method createChildFragments.

protected void createChildFragments(List<WizardFragment> list) {
    if (getTaskModel() == null)
        return;
    Object runtime = getTaskModel().getObject(TaskModel.TASK_RUNTIME);
    if (runtime == null)
        return;
    WizardFragment sub = null;
    if (runtime instanceof IRuntimeWorkingCopy)
        sub = getWizardFragment(((RuntimeWorkingCopy) runtime).getRuntimeType().getId());
    else if (runtime instanceof RuntimeTypeWithServerProxy)
        sub = getWizardFragment(((RuntimeTypeWithServerProxy) runtime).getId());
    if (sub != null)
        list.add(sub);
    Object serverObj = getTaskModel().getObject(TaskModel.TASK_SERVER);
    if (serverObj != null && serverObj instanceof IServerWorkingCopy) {
        IServerWorkingCopy server = (IServerWorkingCopy) serverObj;
        if (server.getServerType().hasServerConfiguration() && server instanceof ServerWorkingCopy) {
            ServerWorkingCopy swc = (ServerWorkingCopy) server;
            try {
                if (runtime instanceof IRuntimeWorkingCopy) {
                    RuntimeWorkingCopy runtimeWorkingCopy = (RuntimeWorkingCopy) runtime;
                    if (runtimeWorkingCopy.getLocation() != null && !runtimeWorkingCopy.getLocation().isEmpty())
                        swc.importRuntimeConfiguration(runtimeWorkingCopy, null);
                }
            } catch (CoreException ce) {
            // ignore
            }
        }
        list.add(new WizardFragment() {

            public void enter() {
                IRuntimeWorkingCopy runtime2 = (IRuntimeWorkingCopy) getTaskModel().getObject(TaskModel.TASK_RUNTIME);
                IServerWorkingCopy server2 = (IServerWorkingCopy) getTaskModel().getObject(TaskModel.TASK_SERVER);
                server2.setRuntime(runtime2);
            }
        });
        sub = getWizardFragment(server.getServerType().getId());
        if (sub != null)
            list.add(sub);
        list.add(WizardTaskUtil.SaveServerFragment);
    }
}
Also used : RuntimeTypeWithServerProxy(org.eclipse.wst.server.core.internal.RuntimeTypeWithServerProxy) ServerWorkingCopy(org.eclipse.wst.server.core.internal.ServerWorkingCopy) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) WizardFragment(org.eclipse.wst.server.ui.wizard.WizardFragment) CoreException(org.eclipse.core.runtime.CoreException) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) RuntimeWorkingCopy(org.eclipse.wst.server.core.internal.RuntimeWorkingCopy) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy)

Example 20 with IRuntimeWorkingCopy

use of org.eclipse.wst.server.core.IRuntimeWorkingCopy in project webtools.servertools by eclipse.

the class TomcatRuntimeWizardFragment method exit.

public void exit() {
    IRuntimeWorkingCopy runtime = (IRuntimeWorkingCopy) getTaskModel().getObject(TaskModel.TASK_RUNTIME);
    IPath path = runtime.getLocation();
    if (runtime.validate(null).getSeverity() != IStatus.ERROR)
        TomcatPlugin.setPreference("location" + runtime.getRuntimeType().getId(), path.toString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy)

Aggregations

IRuntimeWorkingCopy (org.eclipse.wst.server.core.IRuntimeWorkingCopy)41 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)16 IRuntime (org.eclipse.wst.server.core.IRuntime)13 IRuntimeType (org.eclipse.wst.server.core.IRuntimeType)12 CoreException (org.eclipse.core.runtime.CoreException)9 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)9 IServerType (org.eclipse.wst.server.core.IServerType)8 IPath (org.eclipse.core.runtime.IPath)6 IStatus (org.eclipse.core.runtime.IStatus)6 Path (org.eclipse.core.runtime.Path)6 Test (org.junit.Test)6 PortalRuntime (com.liferay.ide.server.core.portal.PortalRuntime)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 NewModuleFragmentOp (com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp)2 OverrideFilePath (com.liferay.ide.project.core.modules.fragment.OverrideFilePath)2 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 GenericServerRuntime (org.eclipse.jst.server.generic.core.internal.GenericServerRuntime)2 ITomcatRuntimeWorkingCopy (org.eclipse.jst.server.tomcat.core.internal.ITomcatRuntimeWorkingCopy)2