Search in sources :

Example 1 with ServerRuntime

use of org.eclipse.jst.server.generic.servertype.definition.ServerRuntime in project webtools.servertools by eclipse.

the class ServerTypeDefinitionUtil method getServerTypeDefinition.

/**
 * Returns the server definition for runtime. Returns null
 * if the runtime is null or not a Generic server type.
 *
 * @param runtime
 * @return serverRuntime
 */
public static ServerRuntime getServerTypeDefinition(IRuntime runtime) {
    if (runtime == null)
        return null;
    GenericServerRuntime delegate = (GenericServerRuntime) runtime.loadAdapter(GenericServerRuntime.class, null);
    if (delegate == null)
        return null;
    String serverType = delegate.getRuntime().getRuntimeType().getId();
    Map properties = delegate.getServerInstanceProperties();
    ServerRuntime definition = CorePlugin.getDefault().getServerTypeDefinitionManager().getServerRuntimeDefinition(serverType, properties);
    return definition;
}
Also used : ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) Map(java.util.Map)

Example 2 with ServerRuntime

use of org.eclipse.jst.server.generic.servertype.definition.ServerRuntime in project webtools.servertools by eclipse.

the class ServerTypeDefinitionUtil method getServerClassPathEntry.

/**
 * Extracts the server classpath entry array.
 *
 * @param runtime
 * @return classpathEntry
 */
@SuppressWarnings("unchecked")
public static IClasspathEntry[] getServerClassPathEntry(IRuntime runtime) {
    ServerRuntime definition = getServerTypeDefinition(runtime);
    if (definition == null)
        return null;
    String ref = definition.getProject().getClasspathReference();
    ArrayList entryList = getClasspathEntries(ref, definition, false);
    return (IClasspathEntry[]) entryList.toArray(new IClasspathEntry[entryList.size()]);
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) ArrayList(java.util.ArrayList)

Example 3 with ServerRuntime

use of org.eclipse.jst.server.generic.servertype.definition.ServerRuntime in project webtools.servertools by eclipse.

the class GenericServer method setDefaults.

@SuppressWarnings("unchecked")
public void setDefaults(IProgressMonitor monitor) {
    ServerRuntime serverRuntime = this.getServerDefinition();
    // the runtime is not created yet and serverdef can not be determined.
    if (serverRuntime == null) {
        return;
    }
    List props = this.getServerDefinition().getProperty();
    Map instancePropsMap = new HashMap();
    for (Iterator iter = props.iterator(); iter.hasNext(); ) {
        Property element = (Property) iter.next();
        if (Property.CONTEXT_SERVER.equalsIgnoreCase(element.getContext())) {
            // if the property type is this is a combo, parse the value and use the first token as the default
            if (Property.TYPE_SELECT.equals(element.getType()) || Property.TYPE_SELECT_EDIT.equals(element.getType())) {
                // $NON-NLS-1$
                StringTokenizer tokenizer = new StringTokenizer(element.getDefault(), ",");
                if (tokenizer.hasMoreTokens()) {
                    String firstToken = tokenizer.nextToken();
                    instancePropsMap.put(element.getId(), firstToken);
                }
            } else {
                // not a combo, so just pass through the default value
                instancePropsMap.put(element.getId(), element.getDefault());
            }
        }
    }
    setServerInstanceProperties(instancePropsMap);
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.eclipse.jst.server.generic.servertype.definition.Property)

Example 4 with ServerRuntime

use of org.eclipse.jst.server.generic.servertype.definition.ServerRuntime in project webtools.servertools by eclipse.

the class ExternalServerBehaviour method setupStopLaunchConfiguration.

/**
 * Sets up the launch configuration for stopping the server.
 */
protected void setupStopLaunchConfiguration(GenericServerRuntime runtime, ILaunchConfigurationWorkingCopy wc) {
    clearDebuggingConfig();
    ServerRuntime serverDef = getServerDefinition();
    Resolver resolver = serverDef.getResolver();
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, resolver.resolveProperties(serverDef.getStop().getWorkingDirectory()));
    String external = resolver.resolveProperties(getExternalForOS(serverDef.getStop().getExternal()));
    wc.setAttribute(ExternalLaunchConfigurationDelegate.COMMANDLINE, external);
    // just use commandline for now
    Map environVars = getEnvironmentVariables(getServerDefinition().getStop());
    if (!environVars.isEmpty()) {
        wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, environVars);
    }
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, resolver.resolveProperties(serverDef.getStop().getProgramArgumentsAsString()));
    wc.setAttribute(ExternalLaunchConfigurationDelegate.EXECUTABLE_NAME, external);
    wc.setAttribute(ATTR_SERVER_ID, getServer().getId());
}
Also used : Resolver(org.eclipse.jst.server.generic.internal.xml.Resolver) ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) Map(java.util.Map)

Example 5 with ServerRuntime

use of org.eclipse.jst.server.generic.servertype.definition.ServerRuntime in project webtools.servertools by eclipse.

the class XMLUtils method readFile.

private ServerRuntime readFile(java.net.URI file) {
    // Create a resource set.
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the default resource factory -- only needed for
    // stand-alone!
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new ServerTypeResourceFactoryImpl());
    ServerTypePackage gstPack = ServerTypePackage.eINSTANCE;
    // Get the URI of the model file.
    URI fileURI = URI.createURI(file.toString());
    // Demand load the resource for this file.
    Resource resource = null;
    try {
        resource = resourceSet.getResource(fileURI, true);
    } catch (WrappedException e) {
        // sth wrong with this .server file.
        CorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 1, "Error loading the server type definition", // $NON-NLS-1$
        e));
    }
    if (resource != null) {
        ServerRuntime def = (ServerRuntime) resource.getContents().get(0);
        if (def != null) {
            def.setFilename(file.toString());
            return def;
        }
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WrappedException(org.eclipse.emf.common.util.WrappedException) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) Resource(org.eclipse.emf.ecore.resource.Resource) ServerTypeResourceFactoryImpl(org.eclipse.jst.server.generic.internal.servertype.definition.util.ServerTypeResourceFactoryImpl) ServerTypePackage(org.eclipse.jst.server.generic.internal.servertype.definition.ServerTypePackage) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

ServerRuntime (org.eclipse.jst.server.generic.servertype.definition.ServerRuntime)23 Map (java.util.Map)8 GenericServerRuntime (org.eclipse.jst.server.generic.core.internal.GenericServerRuntime)8 GenericServer (org.eclipse.jst.server.generic.core.internal.GenericServer)4 Iterator (java.util.Iterator)3 List (java.util.List)3 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)3 ArrayList (java.util.ArrayList)2 IExtension (org.eclipse.core.runtime.IExtension)2 IStatus (org.eclipse.core.runtime.IStatus)2 ServerTypeDefinitionManager (org.eclipse.jst.server.generic.core.internal.ServerTypeDefinitionManager)2 Resolver (org.eclipse.jst.server.generic.internal.xml.Resolver)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1