4c763838879a1f32f120a81a869a854fd296bb50
[idea/community.git] / java / execution / impl / src / com / intellij / execution / remote / RemoteConfiguration.java
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * @author Jeka
19  */
20 package com.intellij.execution.remote;
21
22 import com.intellij.debugger.engine.RemoteStateState;
23 import com.intellij.debugger.impl.GenericDebuggerRunnerSettings;
24 import com.intellij.debugger.settings.DebuggerSettings;
25 import com.intellij.diagnostic.logging.LogConfigurationPanel;
26 import com.intellij.execution.ExecutionBundle;
27 import com.intellij.execution.ExecutionException;
28 import com.intellij.execution.Executor;
29 import com.intellij.execution.configurations.*;
30 import com.intellij.execution.runners.ExecutionEnvironment;
31 import com.intellij.openapi.module.Module;
32 import com.intellij.openapi.options.SettingsEditor;
33 import com.intellij.openapi.options.SettingsEditorGroup;
34 import com.intellij.openapi.project.Project;
35 import com.intellij.openapi.util.DefaultJDOMExternalizer;
36 import com.intellij.openapi.util.InvalidDataException;
37 import com.intellij.openapi.util.WriteExternalException;
38 import org.jdom.Element;
39 import org.jetbrains.annotations.NotNull;
40
41 import java.util.Collection;
42
43 public class RemoteConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule> {
44
45   public void writeExternal(final Element element) throws WriteExternalException {
46     super.writeExternal(element);
47     final Module module = getConfigurationModule().getModule();
48     if (module != null) { // default value
49       writeModule(element);
50     }
51     DefaultJDOMExternalizer.writeExternal(this, element);
52   }
53
54   public void readExternal(final Element element) throws InvalidDataException {
55     super.readExternal(element);
56     readModule(element);
57     DefaultJDOMExternalizer.readExternal(this, element);
58   }
59
60   public boolean USE_SOCKET_TRANSPORT;
61   public boolean SERVER_MODE;
62   public String SHMEM_ADDRESS;
63   public String HOST;
64   public String PORT;
65
66   public RemoteConfiguration(final String name, final Project project, ConfigurationFactory configurationFactory) {
67     super(name, new JavaRunConfigurationModule(project, true), configurationFactory);
68   }
69
70   public RemoteConnection createRemoteConnection() {
71     return new RemoteConnection(USE_SOCKET_TRANSPORT, HOST, USE_SOCKET_TRANSPORT ? PORT : SHMEM_ADDRESS, SERVER_MODE);
72   }
73
74   public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
75     GenericDebuggerRunnerSettings debuggerSettings = ((GenericDebuggerRunnerSettings)env.getRunnerSettings().getData());
76     debuggerSettings.LOCAL = false;
77     debuggerSettings.setDebugPort(USE_SOCKET_TRANSPORT ? PORT : SHMEM_ADDRESS);
78     debuggerSettings.setTransport(USE_SOCKET_TRANSPORT ? DebuggerSettings.SOCKET_TRANSPORT : DebuggerSettings.SHMEM_TRANSPORT);
79     return new RemoteStateState(getProject(), createRemoteConnection(), env.getRunnerSettings(), env.getConfigurationSettings());
80   }
81
82   public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
83     SettingsEditorGroup<RemoteConfiguration> group = new SettingsEditorGroup<RemoteConfiguration>();
84     group.addEditor(ExecutionBundle.message("run.configuration.configuration.tab.title"), new RemoteConfigurable(getProject()));
85     group.addEditor(ExecutionBundle.message("logs.tab.title"), new LogConfigurationPanel<RemoteConfiguration>());
86     return group;
87   }
88
89   protected ModuleBasedConfiguration createInstance() {
90     return new RemoteConfiguration(getName(), getProject(), RemoteConfigurationType.getInstance().getConfigurationFactories()[0]);
91   }
92
93   public Collection<Module> getValidModules() {
94     return getAllModules();
95   }
96
97   
98 }