Search in sources :

Example 36 with IServer

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

the class TomcatLaunchConfigurationDelegate method launch.

public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    IServer server = ServerUtil.getServer(configuration);
    if (server == null) {
        Trace.trace(Trace.FINEST, "Launch configuration could not find server");
        // throw CoreException();
        return;
    }
    if (server.shouldPublish() && ServerCore.isAutoPublishing())
        server.publish(IServer.PUBLISH_INCREMENTAL, monitor);
    TomcatServerBehaviour tomcatServer = (TomcatServerBehaviour) server.loadAdapter(TomcatServerBehaviour.class, null);
    String mainTypeName = tomcatServer.getRuntimeClass();
    IVMInstall vm = verifyVMInstall(configuration);
    IVMRunner runner = vm.getVMRunner(mode);
    if (runner == null)
        runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
    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) {
            tomcatServer.stopImpl();
            throw ce;
        }
    }
    // Launch the configuration
    tomcatServer.setupLaunch(launch, mode, monitor);
    try {
        runner.run(runConfig, launch, monitor);
        tomcatServer.addProcessListener(launch.getProcesses()[0]);
    } catch (Exception e) {
        // Ensure we don't continue to think the server is starting
        tomcatServer.stopImpl();
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) Map(java.util.Map) CoreException(org.eclipse.core.runtime.CoreException)

Example 37 with IServer

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

the class PreviewSourcePathComputerDelegate 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 {
    List<IRuntimeClasspathEntry> classpaths = new ArrayList<IRuntimeClasspathEntry>();
    classpaths.addAll(Arrays.asList(JavaRuntime.computeUnresolvedSourceLookupPath(configuration)));
    List<ISourceContainer> sourcefolderList = new ArrayList<ISourceContainer>();
    IServer server = ServerUtil.getServer(configuration);
    if (server != null) {
        List<IJavaProject> list = new ArrayList<IJavaProject>();
        IModule[] modules = server.getModules();
        for (IModule module : modules) {
            IProject project = module.getProject();
            if (project != null) {
                IFolder moduleFolder = project.getFolder(module.getName());
                if (moduleFolder.exists()) {
                    sourcefolderList.add(new FolderSourceContainer(moduleFolder, true));
                }
                try {
                    if (project.hasNature(JavaCore.NATURE_ID)) {
                        IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
                        if (!list.contains(javaProject))
                            list.add(javaProject);
                    }
                } catch (Exception e) {
                // ignore
                }
            }
        }
        int size = list.size();
        IJavaProject[] projects = new IJavaProject[size];
        list.toArray(projects);
        for (IJavaProject project : projects) classpaths.addAll(Arrays.asList(JavaRuntime.computeUnresolvedRuntimeClasspath(project)));
    }
    IRuntimeClasspathEntry[] entries = new IRuntimeClasspathEntry[classpaths.size()];
    classpaths.toArray(entries);
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, configuration);
    ISourceContainer[] sourceContainers = JavaRuntime.getSourceContainers(resolved);
    if (!sourcefolderList.isEmpty()) {
        ISourceContainer[] combinedSourceContainers = new ISourceContainer[sourceContainers.length + sourcefolderList.size()];
        sourcefolderList.toArray(combinedSourceContainers);
        System.arraycopy(sourceContainers, 0, combinedSourceContainers, sourcefolderList.size(), sourceContainers.length);
        sourceContainers = combinedSourceContainers;
    }
    return sourceContainers;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) FolderSourceContainer(org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer) ArrayList(java.util.ArrayList) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 38 with IServer

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

the class ConfigurationResourceListener method resourceChanged.

/**
 * Currently, only changes to Tomcat configuration files are detected and the associated
 * server's state updated.  This method needs to be as brief as possible if the change
 * is unrelated to server configuration changes.  Since the Servers project would change
 * so rarely, it is worth saving some cycles in the resource listener by caching this project.
 */
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        IProject project = getServersProject();
        if (project != null) {
            IResourceDelta delta = event.getDelta();
            if (delta != null) {
                IResourceDelta serversProjectDelta = delta.findMember(project.getFullPath());
                if (serversProjectDelta != null) {
                    // The change occurred within the Servers project.
                    IResourceDelta[] childDelta = serversProjectDelta.getAffectedChildren();
                    if (childDelta.length > 0) {
                        IServer[] servers = ServerCore.getServers();
                        for (int i = 0; i < childDelta.length; i++) {
                            // Check if this subfolder of the Servers folder matches a Tomcat configuration folder
                            for (int j = 0; j < servers.length; j++) {
                                IServerType serverType = servers[j].getServerType();
                                if (serverType.getId().startsWith("org.eclipse.jst.server.tomcat.")) {
                                    IFolder configFolder = servers[j].getServerConfiguration();
                                    if (configFolder != null) {
                                        if (childDelta[i].getFullPath().equals(configFolder.getFullPath())) {
                                            // Found a Tomcat server affected by this delta.  Update this server's publish state.
                                            TomcatServerBehaviour tcServerBehaviour = (TomcatServerBehaviour) servers[j].loadAdapter(TomcatServerBehaviour.class, null);
                                            if (tcServerBehaviour != null) {
                                                // Indicate that this server needs to publish and restart if running
                                                tcServerBehaviour.setTomcatServerPublishState(IServer.PUBLISH_STATE_INCREMENTAL);
                                                tcServerBehaviour.setTomcatServerRestartState(true);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IServerType(org.eclipse.wst.server.core.IServerType) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta) IFolder(org.eclipse.core.resources.IFolder)

Example 39 with IServer

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

the class UpdateServerJob method run.

public IStatus run(IProgressMonitor monitor) {
    for (IServer server : servers) {
        if (server.getServerType() != null && server.getServerState() == IServer.STATE_UNKNOWN) {
            monitor.subTask(NLS.bind(Messages.jobUpdateServer, server.getName()));
            server.loadAdapter(ServerBehaviourDelegate.class, monitor);
        }
    }
    return Status.OK_STATUS;
}
Also used : IServer(org.eclipse.wst.server.core.IServer)

Example 40 with IServer

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

the class ServersViewDropAdapter method performDrop.

public boolean performDrop(Object data) {
    Object target = getCurrentTarget();
    IServer server = null;
    if (target instanceof IServer)
        server = (IServer) target;
    if (server == null)
        return false;
    Iterator iterator = null;
    if (data instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) data;
        iterator = sel.iterator();
    }
    if (iterator == null)
        return false;
    boolean b = true;
    while (iterator.hasNext()) {
        Object data2 = iterator.next();
        if (!doSel(server, data2))
            b = false;
    }
    return b;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

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