Search in sources :

Example 1 with TomcatConfiguration

use of org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration in project liferay-ide by liferay.

the class LiferayTomcatServer method getPortalHomeUrl.

@Override
public URL getPortalHomeUrl() {
    try {
        TomcatConfiguration config = getTomcatConfiguration();
        if (config == null)
            return null;
        // $NON-NLS-1$
        String url = "http://" + getServer().getHost();
        int port = config.getMainPort().getPort();
        // $NON-NLS-1$
        port = ServerUtil.getMonitoredPort(getServer(), port, "web");
        if (port != 80)
            // $NON-NLS-1$
            url += ":" + port;
        return new URL(url);
    } catch (Exception ex) {
        return null;
    }
}
Also used : TomcatConfiguration(org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) MalformedURLException(java.net.MalformedURLException)

Example 2 with TomcatConfiguration

use of org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration in project webtools.servertools by eclipse.

the class ContextPublisherDelegate method execute.

public IStatus execute(int kind, IProgressMonitor monitor, IAdaptable info) throws CoreException {
    // this publisher only runs when there is a UI
    if (info == null)
        return Status.OK_STATUS;
    final Shell shell = (Shell) info.getAdapter(Shell.class);
    if (shell == null)
        return Status.OK_STATUS;
    IServer server = (IServer) getTaskModel().getObject(TaskModel.TASK_SERVER);
    TomcatServer tomcatServer = (TomcatServer) server.loadAdapter(TomcatServer.class, monitor);
    final TomcatConfiguration configuration = tomcatServer.getTomcatConfiguration();
    final boolean[] save = new boolean[1];
    List modules = (List) getTaskModel().getObject(TaskModel.TASK_MODULES);
    int size = modules.size();
    for (int i = 0; i < size; i++) {
        IModule[] module = (IModule[]) modules.get(i);
        final IModule m = module[module.length - 1];
        IWebModule webModule = (IWebModule) m.loadAdapter(IWebModule.class, monitor);
        final WebModule webModule2 = configuration.getWebModule(m);
        if (webModule != null && webModule2 != null) {
            String contextRoot = webModule.getContextRoot();
            if (contextRoot != null && !contextRoot.startsWith("/") && contextRoot.length() > 0)
                contextRoot = "/" + contextRoot;
            if (!contextRoot.equals(webModule2.getPath()) && shouldPrompt(m, contextRoot)) {
                final String context = contextRoot;
                shell.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        if (MessageDialog.openQuestion(shell, Messages.wizardTitle, NLS.bind(Messages.contextCleanup, m.getName()))) {
                            int index = configuration.getWebModules().indexOf(webModule2);
                            configuration.modifyWebModule(index, webModule2.getDocumentBase(), context, webModule2.isReloadable());
                            save[0] = true;
                        }
                    }
                });
                markProject(m, contextRoot);
            }
        }
    }
    if (save[0])
        tomcatServer.saveConfiguration(monitor);
    return Status.OK_STATUS;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) TomcatConfiguration(org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration) IWebModule(org.eclipse.jst.server.core.IWebModule) WebModule(org.eclipse.jst.server.tomcat.core.internal.WebModule) IWebModule(org.eclipse.jst.server.core.IWebModule) Shell(org.eclipse.swt.widgets.Shell) List(java.util.List) TomcatServer(org.eclipse.jst.server.tomcat.core.internal.TomcatServer)

Example 3 with TomcatConfiguration

use of org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration in project mdw-designer by CenturyLinkCloud.

the class TomcatServer method importRuntimeConfiguration.

@Override
public void importRuntimeConfiguration(IRuntime runtime, IProgressMonitor monitor) throws CoreException {
    // initialize state
    synchronized (versionLock) {
        configuration = null;
        currentVersion = 0;
        loadedVersion = 0;
    }
    if (runtime == null) {
        return;
    }
    IPath path = runtime.getLocation().append("conf");
    IFolder folder = getServer().getServerConfiguration();
    TomcatConfiguration tcConfig = new Tomcat70Configuration(folder);
    try {
        tcConfig.importFromPath(path, isTestEnvironment(), monitor);
    } catch (CoreException ce) {
        throw ce;
    }
    // update version
    synchronized (versionLock) {
        // configuration
        if (configuration == null) {
            configuration = tcConfig;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) TomcatConfiguration(org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with TomcatConfiguration

use of org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration in project mdw-designer by CenturyLinkCloud.

the class TomcatServer method getTomcatConfiguration.

@Override
public TomcatConfiguration getTomcatConfiguration() throws CoreException {
    int current;
    TomcatConfiguration tcConfig;
    // grab current state
    synchronized (versionLock) {
        current = currentVersion;
        tcConfig = configuration;
    }
    // configuration needs loading
    if (tcConfig == null || loadedVersion != current) {
        IFolder folder = getServer().getServerConfiguration();
        if (folder == null || !folder.exists()) {
            String path = null;
            if (folder != null) {
                path = folder.getFullPath().toOSString();
                IProject project = folder.getProject();
                if (project != null && project.exists() && !project.isOpen())
                    throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorConfigurationProjectClosed, path, project.getName()), null));
            }
            throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorNoConfiguration, path), null));
        }
        // not yet loaded
        if (tcConfig == null)
            tcConfig = new Tomcat70Configuration(folder);
        try {
            ((Tomcat70Configuration) tcConfig).load(folder, null);
            // update loaded version
            synchronized (versionLock) {
                // if newer version not already loaded, update version
                if (configuration == null || loadedVersion < current) {
                    configuration = tcConfig;
                    loadedVersion = current;
                }
            }
        } catch (CoreException ce) {
            // Ignore
            throw ce;
        }
    }
    return tcConfig;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) TomcatConfiguration(org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

TomcatConfiguration (org.eclipse.jst.server.tomcat.core.internal.TomcatConfiguration)4 CoreException (org.eclipse.core.runtime.CoreException)3 IFolder (org.eclipse.core.resources.IFolder)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IWebModule (org.eclipse.jst.server.core.IWebModule)1 TomcatServer (org.eclipse.jst.server.tomcat.core.internal.TomcatServer)1 WebModule (org.eclipse.jst.server.tomcat.core.internal.WebModule)1 Shell (org.eclipse.swt.widgets.Shell)1 IModule (org.eclipse.wst.server.core.IModule)1 IServer (org.eclipse.wst.server.core.IServer)1