2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com
.intellij
.uiDesigner
.snapShooter
;
19 import com
.intellij
.execution
.RunConfigurationExtension
;
20 import com
.intellij
.execution
.RunJavaConfiguration
;
21 import com
.intellij
.execution
.application
.ApplicationConfiguration
;
22 import com
.intellij
.execution
.configurations
.*;
23 import com
.intellij
.execution
.process
.OSProcessHandler
;
24 import com
.intellij
.execution
.process
.ProcessAdapter
;
25 import com
.intellij
.execution
.process
.ProcessEvent
;
26 import com
.intellij
.ide
.ui
.LafManagerListener
;
27 import com
.intellij
.openapi
.actionSystem
.DataProvider
;
28 import com
.intellij
.openapi
.components
.BaseComponent
;
29 import com
.intellij
.openapi
.components
.ProjectComponent
;
30 import com
.intellij
.openapi
.extensions
.AreaInstance
;
31 import com
.intellij
.openapi
.options
.SettingsEditor
;
32 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
33 import com
.intellij
.openapi
.util
.InvalidDataException
;
34 import com
.intellij
.openapi
.util
.WriteExternalException
;
35 import com
.intellij
.pom
.Navigatable
;
36 import com
.intellij
.uiDesigner
.core
.GridConstraints
;
37 import com
.intellij
.uiDesigner
.lw
.LwComponent
;
38 import com
.intellij
.util
.PathUtil
;
39 import com
.intellij
.util
.net
.NetUtils
;
40 import com
.intellij
.xml
.util
.XmlStringUtil
;
41 import com
.jgoodies
.forms
.layout
.FormLayout
;
42 import gnu
.trove
.THashMap
;
43 import org
.jdom
.Document
;
44 import org
.jdom
.Element
;
47 import java
.io
.IOException
;
49 import java
.util
.TreeSet
;
54 public class SnapShooterConfigurationExtension
extends RunConfigurationExtension
{
56 public <T
extends ModuleBasedConfiguration
& RunJavaConfiguration
> void updateJavaParameters(T configuration
, JavaParameters params
, RunnerSettings runnerSettings
) {
57 if (!(configuration
instanceof ApplicationConfiguration
)) {
60 ApplicationConfiguration appConfiguration
= (ApplicationConfiguration
) configuration
;
61 SnapShooterConfigurationSettings settings
= appConfiguration
.getUserData(SnapShooterConfigurationSettings
.SNAP_SHOOTER_KEY
);
62 if (settings
== null) {
63 settings
= new SnapShooterConfigurationSettings();
64 appConfiguration
.putUserData(SnapShooterConfigurationSettings
.SNAP_SHOOTER_KEY
, settings
);
66 if (appConfiguration
.ENABLE_SWING_INSPECTOR
) {
68 settings
.setLastPort(NetUtils
.findAvailableSocketPort());
70 catch(IOException ex
) {
71 settings
.setLastPort(-1);
75 if (appConfiguration
.ENABLE_SWING_INSPECTOR
&& settings
.getLastPort() != -1) {
76 params
.getProgramParametersList().prepend(appConfiguration
.MAIN_CLASS_NAME
);
77 params
.getProgramParametersList().prepend(Integer
.toString(settings
.getLastPort()));
78 // add +1 because idea_rt.jar will be added as the last entry to the classpath
79 params
.getProgramParametersList().prepend(Integer
.toString(params
.getClassPath().getPathList().size() + 1));
80 Set
<String
> paths
= new TreeSet
<String
>();
81 paths
.add(PathUtil
.getJarPathForClass(SnapShooter
.class)); // ui-designer-impl
82 paths
.add(PathUtil
.getJarPathForClass(BaseComponent
.class)); // appcore-api
83 paths
.add(PathUtil
.getJarPathForClass(ProjectComponent
.class)); // openapi
84 paths
.add(PathUtil
.getJarPathForClass(LwComponent
.class)); // UIDesignerCore
85 paths
.add(PathUtil
.getJarPathForClass(GridConstraints
.class)); // forms_rt
86 paths
.add(PathUtil
.getJarPathForClass(JDOMExternalizable
.class)); // util
87 paths
.add(PathUtil
.getJarPathForClass(Document
.class)); // JDOM
88 paths
.add(PathUtil
.getJarPathForClass(LafManagerListener
.class)); // ui-impl
89 paths
.add(PathUtil
.getJarPathForClass(DataProvider
.class)); // action-system-openapi
90 paths
.add(PathUtil
.getJarPathForClass(XmlStringUtil
.class)); // idea
91 paths
.add(PathUtil
.getJarPathForClass(Navigatable
.class)); // pom
92 paths
.add(PathUtil
.getJarPathForClass(AreaInstance
.class)); // extensions
93 paths
.add(PathUtil
.getJarPathForClass(THashMap
.class)); // trove4j
94 paths
.add(PathUtil
.getJarPathForClass(FormLayout
.class)); // jgoodies
95 for(String path
: paths
) {
96 params
.getClassPath().addFirst(path
);
98 params
.setMainClass("com.intellij.uiDesigner.snapShooter.SnapShooter");
102 public void handleStartProcess(final ModuleBasedConfiguration configuration
, final OSProcessHandler handler
) {
103 SnapShooterConfigurationSettings settings
= configuration
.getUserData(SnapShooterConfigurationSettings
.SNAP_SHOOTER_KEY
);
104 if (settings
!= null) {
105 final Runnable runnable
= settings
.getNotifyRunnable();
106 if (runnable
!= null) {
107 settings
.setNotifyRunnable(null);
108 handler
.addProcessListener(new ProcessAdapter() {
109 public void startNotified(final ProcessEvent event
) {
118 public <T
extends ModuleBasedConfiguration
& RunJavaConfiguration
> SettingsEditor
createEditor(T configuration
) {
119 return null; //To change body of implemented methods use File | Settings | File Templates.
123 public String
getEditorTitle() {
124 return null; //To change body of implemented methods use File | Settings | File Templates.
128 public String
getName() {
129 return "snapshooter";
133 public <T
extends ModuleBasedConfiguration
& RunJavaConfiguration
> Icon
getIcon(T runConfiguration
) {
134 return null; //To change body of implemented methods use File | Settings | File Templates.
138 public void readExternal(ModuleBasedConfiguration runConfiguration
, Element element
) throws InvalidDataException
{
143 public void writeExternal(ModuleBasedConfiguration runConfiguration
, Element element
) throws WriteExternalException
{
148 public <T
extends ModuleBasedConfiguration
& RunJavaConfiguration
> void patchConfiguration(T runJavaConfiguration
) {
152 public <T
extends ModuleBasedConfiguration
& RunJavaConfiguration
> void checkConfiguration(T runJavaConfiguration
)
153 throws RuntimeConfigurationException
{