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.
16 package org
.jetbrains
.idea
.maven
.execution
;
18 import com
.intellij
.execution
.ExecutionException
;
19 import com
.intellij
.execution
.Executor
;
20 import com
.intellij
.execution
.configurations
.*;
21 import com
.intellij
.execution
.process
.OSProcessHandler
;
22 import com
.intellij
.execution
.process
.ProcessAdapter
;
23 import com
.intellij
.execution
.process
.ProcessEvent
;
24 import com
.intellij
.execution
.runners
.ExecutionEnvironment
;
25 import com
.intellij
.execution
.runners
.ProgramRunner
;
26 import com
.intellij
.openapi
.module
.Module
;
27 import com
.intellij
.openapi
.options
.SettingsEditor
;
28 import com
.intellij
.openapi
.project
.Project
;
29 import com
.intellij
.openapi
.util
.Comparing
;
30 import com
.intellij
.openapi
.util
.InvalidDataException
;
31 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
32 import com
.intellij
.openapi
.util
.WriteExternalException
;
33 import com
.intellij
.util
.xmlb
.XmlSerializer
;
34 import org
.jdom
.Element
;
35 import org
.jetbrains
.annotations
.NotNull
;
36 import org
.jetbrains
.idea
.maven
.embedder
.MavenConsoleImpl
;
37 import org
.jetbrains
.idea
.maven
.project
.MavenGeneralSettings
;
38 import org
.jetbrains
.idea
.maven
.project
.MavenProjectsManager
;
39 import org
.jetbrains
.idea
.maven
.utils
.MavenConstants
;
43 public class MavenRunConfiguration
extends RunConfigurationBase
implements LocatableConfiguration
, ModuleRunProfile
{
44 private MavenSettings mySettings
;
46 protected MavenRunConfiguration(Project project
, ConfigurationFactory factory
, String name
) {
47 super(project
, factory
, name
);
48 mySettings
= new MavenSettings(project
);
51 public RunConfiguration
clone() {
52 MavenRunConfiguration clone
= (MavenRunConfiguration
)super.clone();
53 clone
.mySettings
= mySettings
.clone();
57 public SettingsEditor
<?
extends RunConfiguration
> getConfigurationEditor() {
58 return new MavenRunConfigurationSettings(getProject());
61 public JDOMExternalizable
createRunnerSettings(ConfigurationInfoProvider provider
) {
65 public SettingsEditor
<JDOMExternalizable
> getRunnerSettingsEditor(ProgramRunner runner
) {
69 public RunProfileState
getState(@NotNull final Executor executor
, @NotNull final ExecutionEnvironment env
) throws ExecutionException
{
70 JavaCommandLineState state
= new JavaCommandLineState(env
) {
71 protected JavaParameters
createJavaParameters() throws ExecutionException
{
72 return MavenExternalParameters
73 .createJavaParameters(mySettings
.myRunnerParameters
, mySettings
.myGeneralSettings
, mySettings
.myRunnerSettings
);
77 protected OSProcessHandler
startProcess() throws ExecutionException
{
78 OSProcessHandler result
= super.startProcess();
79 result
.addProcessListener(new ProcessAdapter() {
81 public void processTerminated(ProcessEvent event
) {
82 updateProjectsFolders();
88 state
.setConsoleBuilder(MavenConsoleImpl
.createConsoleBuilder(getProject()));
92 public void checkConfiguration() throws RuntimeConfigurationException
{
93 String filePath
= mySettings
.myRunnerParameters
.getPomFilePath();
94 if (filePath
== null || !new File(filePath
).isFile()) {
95 throw new RuntimeConfigurationError(RunnerBundle
.message("maven.run.configuration.error.file.not.found"));
99 private void updateProjectsFolders() {
100 MavenProjectsManager
.getInstance(getProject()).updateProjectTargetFolders();
104 public Module
[] getModules() {
105 return Module
.EMPTY_ARRAY
;
108 public MavenGeneralSettings
getGeneralSettings() {
109 return mySettings
.myGeneralSettings
;
112 public void setGeneralSettings(MavenGeneralSettings settings
) {
113 mySettings
.myGeneralSettings
= settings
;
116 public MavenRunnerSettings
getRunnerSettings() {
117 return mySettings
.myRunnerSettings
;
120 public void setRunnerSettings(MavenRunnerSettings settings
) {
121 mySettings
.myRunnerSettings
= settings
;
124 public MavenRunnerParameters
getRunnerParameters() {
125 return mySettings
.myRunnerParameters
;
128 public void setRunnerParameters(MavenRunnerParameters p
) {
129 mySettings
.myRunnerParameters
= p
;
132 public void readExternal(Element element
) throws InvalidDataException
{
133 super.readExternal(element
);
135 Element mavenSettingsElement
= element
.getChild(MavenSettings
.TAG
);
136 if (mavenSettingsElement
!= null) {
137 mySettings
= XmlSerializer
.deserialize(mavenSettingsElement
, MavenSettings
.class);
139 // fix old settings format
140 File workingDir
= mySettings
.myRunnerParameters
.getWorkingDirFile();
141 if (MavenConstants
.POM_XML
.equals(workingDir
.getName())) {
142 mySettings
.myRunnerParameters
.setWorkingDirPath(workingDir
.getParent());
145 if (mySettings
.myGeneralSettings
== null) mySettings
.myGeneralSettings
= new MavenGeneralSettings();
146 if (mySettings
.myRunnerSettings
== null) mySettings
.myRunnerSettings
= new MavenRunnerSettings();
147 if (mySettings
.myRunnerParameters
== null) mySettings
.myRunnerParameters
= new MavenRunnerParameters();
151 public void writeExternal(Element element
) throws WriteExternalException
{
152 super.writeExternal(element
);
153 element
.addContent(XmlSerializer
.serialize(mySettings
));
156 public boolean isGeneratedName() {
157 return Comparing
.equal(getName(), getGeneratedName());
160 public String
suggestedName() {
161 return getGeneratedName();
164 private String
getGeneratedName() {
165 return MavenRunConfigurationType
.generateName(getProject(), mySettings
.myRunnerParameters
);
168 public static class MavenSettings
implements Cloneable
{
169 public static final String TAG
= "MavenSettings";
171 public MavenGeneralSettings myGeneralSettings
;
172 public MavenRunnerSettings myRunnerSettings
;
173 public MavenRunnerParameters myRunnerParameters
;
175 /* reflection only */
176 public MavenSettings() {
179 public MavenSettings(Project project
) {
180 this(MavenProjectsManager
.getInstance(project
).getGeneralSettings(), MavenRunner
.getInstance(project
).getState(),
181 new MavenRunnerParameters());
184 private MavenSettings(MavenGeneralSettings cs
, MavenRunnerSettings rs
, MavenRunnerParameters rp
) {
185 myGeneralSettings
= cs
.clone();
186 myRunnerSettings
= rs
.clone();
187 myRunnerParameters
= rp
.clone();
190 protected MavenSettings
clone() {
191 return new MavenSettings(myGeneralSettings
, myRunnerSettings
, myRunnerParameters
);