Search in sources :

Example 31 with IServer

use of org.eclipse.wst.server.core.IServer in project liferay-ide by liferay.

the class InitConfigureProjectPage method _createServerElement.

private void _createServerElement() {
    _serverLabel = createLabel(_pageParent, "Liferay Server Name:");
    _serverComb = new Combo(_pageParent, SWT.DROP_DOWN | SWT.READ_ONLY);
    _serverComb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    _serverButton = SWTUtil.createButton(_pageParent, "Add Server...");
    _serverButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ServerUIUtil.showNewServerWizard(_pageParent.getShell(), "liferay.bundle", null, "com.liferay.");
        }
    });
    ServerCore.addServerLifecycleListener(this);
    IServer[] servers = ServerCore.getServers();
    List<String> serverNames = new ArrayList<>();
    if (ListUtil.isNotEmpty(servers)) {
        for (IServer server : servers) {
            if (LiferayServerCore.newPortalBundle(server.getRuntime().getLocation()) != null) {
                serverNames.add(server.getName());
            }
        }
    }
    _serverComb.setItems(serverNames.toArray(new String[serverNames.size()]));
    _serverComb.select(0);
}
Also used : IServer(org.eclipse.wst.server.core.IServer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo)

Example 32 with IServer

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

the class GenericServerLaunchConfigurationDelegate method launch.

/* (non-Javadoc)
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
	 */
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    IServer server = ServerUtil.getServer(configuration);
    if (server == null) {
        abort(GenericServerCoreMessages.missingServer, null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
    // Commented until bug 210859 is resolved
    // if (server.shouldPublish() && ServerCore.isAutoPublishing())
    // server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
    @SuppressWarnings("null") GenericServerBehaviour genericServer = (GenericServerBehaviour) server.loadAdapter(ServerBehaviourDelegate.class, null);
    try {
        genericServer.setupLaunch(launch, mode, monitor);
        if (genericServer.getServer().getServerType().supportsRemoteHosts() && !SocketUtil.isLocalhost(genericServer.getServer().getHost())) {
            // no launch for remote servers
            return;
        }
        String mainTypeName = genericServer.getStartClassName();
        IVMInstall vm = verifyVMInstall(configuration);
        IVMRunner runner = vm.getVMRunner(mode);
        if (runner == null && ILaunchManager.PROFILE_MODE.equals(mode)) {
            runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
        }
        if (runner == null) {
            throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages.runModeNotSupported, null));
        }
        File workingDir = verifyWorkingDirectory(configuration);
        String workingDirName = null;
        if (workingDir != null)
            workingDirName = workingDir.getAbsolutePath();
        // Program & VM args
        String pgmArgs = getProgramArguments(configuration);
        String vmArgs = getVMArguments(configuration);
        String[] envp = getEnvironment(configuration);
        ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
        // VM-specific attributes
        Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
        // Classpath
        String[] classpath = getClasspath(configuration);
        // Create VM config
        VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
        runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
        runConfig.setVMArguments(execArgs.getVMArgumentsArray());
        runConfig.setWorkingDirectory(workingDirName);
        runConfig.setEnvironment(envp);
        runConfig.setVMSpecificAttributesMap(vmAttributesMap);
        // Bootpath
        String[] bootpath = getBootpath(configuration);
        if (bootpath != null && bootpath.length > 0)
            runConfig.setBootClassPath(bootpath);
        setDefaultSourceLocator(launch, configuration);
        if (ILaunchManager.PROFILE_MODE.equals(mode)) {
            try {
                ServerProfilerDelegate.configureProfiling(launch, vm, runConfig, monitor);
            } catch (CoreException ce) {
                genericServer.stopImpl();
                throw ce;
            }
        }
        // Launch the configuration
        genericServer.startPingThread();
        runner.run(runConfig, launch, monitor);
        genericServer.setProcess(launch.getProcesses()[0]);
    } catch (CoreException e) {
        // $NON-NLS-1$
        Trace.trace(Trace.SEVERE, "error launching generic server", e);
        genericServer.terminate();
        throw e;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IServer(org.eclipse.wst.server.core.IServer) IVMRunner(org.eclipse.jdt.launching.IVMRunner) VMRunnerConfiguration(org.eclipse.jdt.launching.VMRunnerConfiguration) IVMInstall(org.eclipse.jdt.launching.IVMInstall) CoreException(org.eclipse.core.runtime.CoreException) ExecutionArguments(org.eclipse.jdt.launching.ExecutionArguments) ServerBehaviourDelegate(org.eclipse.wst.server.core.model.ServerBehaviourDelegate) File(java.io.File) Map(java.util.Map)

Example 33 with IServer

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

the class GenericServerSourcePathComputerDelegate method computeSourceContainers.

/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
	 */
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
    IRuntimeClasspathEntry[] unresolvedEntries = JavaRuntime.computeUnresolvedSourceLookupPath(configuration);
    List<ISourceContainer> sourcefolderList = new ArrayList<ISourceContainer>();
    IServer server = ServerUtil.getServer(configuration);
    IModule[] modules = server.getModules();
    List<IJavaProject> javaProjectList = new ArrayList<IJavaProject>();
    processModules(sourcefolderList, modules, javaProjectList, server, monitor);
    IRuntimeClasspathEntry[] projectEntries = new IRuntimeClasspathEntry[javaProjectList.size()];
    for (int i = 0; i < javaProjectList.size(); i++) {
        projectEntries[i] = JavaRuntime.newDefaultProjectClasspathEntry(javaProjectList.get(i));
    }
    IRuntimeClasspathEntry[] entries = new IRuntimeClasspathEntry[projectEntries.length + unresolvedEntries.length];
    System.arraycopy(unresolvedEntries, 0, entries, 0, unresolvedEntries.length);
    System.arraycopy(projectEntries, 0, entries, unresolvedEntries.length, projectEntries.length);
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, configuration);
    ISourceContainer[] javaSourceContainers = JavaRuntime.getSourceContainers(resolved);
    if (!sourcefolderList.isEmpty()) {
        ISourceContainer[] combinedSourceContainers = new ISourceContainer[javaSourceContainers.length + sourcefolderList.size()];
        sourcefolderList.toArray(combinedSourceContainers);
        System.arraycopy(javaSourceContainers, 0, combinedSourceContainers, sourcefolderList.size(), javaSourceContainers.length);
        javaSourceContainers = combinedSourceContainers;
    }
    return javaSourceContainers;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArrayList(java.util.ArrayList) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry)

Example 34 with IServer

use of org.eclipse.wst.server.core.IServer 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 35 with IServer

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

the class ServerLocationEditorSection method addChangeListeners.

/**
 * Add listeners to detect undo changes and publishing of the server.
 */
protected void addChangeListeners() {
    listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (updating)
                return;
            updating = true;
            if (ITomcatServer.PROPERTY_INSTANCE_DIR.equals(event.getPropertyName()) || ITomcatServer.PROPERTY_TEST_ENVIRONMENT.equals(event.getPropertyName())) {
                updateServerDirButtons();
                updateServerDirFields();
                validate();
            } else if (ITomcatServer.PROPERTY_DEPLOY_DIR.equals(event.getPropertyName())) {
                String s = (String) event.getNewValue();
                ServerLocationEditorSection.this.deployDir.setText(s);
                updateDefaultDeployLink();
                validate();
            }
            updating = false;
        }
    };
    server.addPropertyChangeListener(listener);
    publishListener = new PublishAdapter() {

        public void publishFinished(IServer server2, IStatus status) {
            boolean flag = false;
            if (status.isOK() && server2.getModules().length == 0)
                flag = true;
            if (flag != allowRestrictedEditing) {
                allowRestrictedEditing = flag;
                // Update the state of the fields
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        boolean customServerDir = false;
                        if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
                            customServerDir = ServerLocationEditorSection.this.serverDirCustom.getSelection();
                        if (!ServerLocationEditorSection.this.serverDirMetadata.isDisposed())
                            ServerLocationEditorSection.this.serverDirMetadata.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDirInstall.isDisposed())
                            ServerLocationEditorSection.this.serverDirInstall.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
                            ServerLocationEditorSection.this.serverDirCustom.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDir.isDisposed())
                            ServerLocationEditorSection.this.serverDir.setEnabled(allowRestrictedEditing && customServerDir);
                        if (!ServerLocationEditorSection.this.serverDirBrowse.isDisposed())
                            ServerLocationEditorSection.this.serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
                        if (!ServerLocationEditorSection.this.setDefaultDeployDir.isDisposed())
                            ServerLocationEditorSection.this.setDefaultDeployDir.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.deployDir.isDisposed())
                            ServerLocationEditorSection.this.deployDir.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.deployDirBrowse.isDisposed())
                            ServerLocationEditorSection.this.deployDirBrowse.setEnabled(allowRestrictedEditing);
                    }
                });
            }
        }
    };
    server.getOriginal().addPublishListener(publishListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeListener(java.beans.PropertyChangeListener) PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter)

Aggregations

IServer (org.eclipse.wst.server.core.IServer)183 CoreException (org.eclipse.core.runtime.CoreException)39 IModule (org.eclipse.wst.server.core.IModule)32 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)30 Test (org.junit.Test)30 IProject (org.eclipse.core.resources.IProject)25 IStatus (org.eclipse.core.runtime.IStatus)25 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)23 ArrayList (java.util.ArrayList)20 File (java.io.File)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 Status (org.eclipse.core.runtime.Status)12 Iterator (java.util.Iterator)11 IPath (org.eclipse.core.runtime.IPath)11 IServerType (org.eclipse.wst.server.core.IServerType)11 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)11 IOException (java.io.IOException)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 Server (org.eclipse.wst.server.core.internal.Server)10 IFolder (org.eclipse.core.resources.IFolder)8