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
.runners
.ExecutionEnvironment
;
22 import com
.intellij
.execution
.runners
.ProgramRunner
;
23 import com
.intellij
.openapi
.module
.Module
;
24 import com
.intellij
.openapi
.options
.SettingsEditor
;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.openapi
.util
.Comparing
;
27 import com
.intellij
.openapi
.util
.InvalidDataException
;
28 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
29 import com
.intellij
.openapi
.util
.WriteExternalException
;
30 import com
.intellij
.util
.xmlb
.XmlSerializer
;
31 import org
.jdom
.Element
;
32 import org
.jetbrains
.annotations
.NotNull
;
33 import org
.jetbrains
.idea
.maven
.embedder
.MavenConsoleImpl
;
34 import org
.jetbrains
.idea
.maven
.project
.MavenGeneralSettings
;
35 import org
.jetbrains
.idea
.maven
.project
.MavenProjectsManager
;
36 import org
.jetbrains
.idea
.maven
.utils
.MavenConstants
;
40 public class MavenRunConfiguration
extends RunConfigurationBase
implements LocatableConfiguration
, ModuleRunProfile
{
41 private MavenSettings mySettings
;
43 protected MavenRunConfiguration(Project project
, ConfigurationFactory factory
, String name
) {
44 super(project
, factory
, name
);
45 mySettings
= new MavenSettings(project
);
48 public RunConfiguration
clone() {
49 MavenRunConfiguration clone
= (MavenRunConfiguration
)super.clone();
50 clone
.mySettings
= mySettings
.clone();
54 public SettingsEditor
<?
extends RunConfiguration
> getConfigurationEditor() {
55 return new MavenRunConfigurationSettings(getProject());
58 public JDOMExternalizable
createRunnerSettings(ConfigurationInfoProvider provider
) {
62 public SettingsEditor
<JDOMExternalizable
> getRunnerSettingsEditor(ProgramRunner runner
) {
66 public RunProfileState
getState(@NotNull final Executor executor
, @NotNull final ExecutionEnvironment env
) throws ExecutionException
{
67 JavaCommandLineState state
= new JavaCommandLineState(env
) {
68 protected JavaParameters
createJavaParameters() throws ExecutionException
{
69 return MavenExternalParameters
70 .createJavaParameters(mySettings
.myRunnerParameters
, mySettings
.myGeneralSettings
, mySettings
.myRunnerSettings
);
73 state
.setConsoleBuilder(MavenConsoleImpl
.createConsoleBuilder(getProject()));
77 public void checkConfiguration() throws RuntimeConfigurationException
{
78 String filePath
= mySettings
.myRunnerParameters
.getPomFilePath();
79 if (filePath
== null || !new File(filePath
).isFile()) {
80 throw new RuntimeConfigurationError(RunnerBundle
.message("maven.run.configuration.error.file.not.found"));
85 public Module
[] getModules() {
86 return Module
.EMPTY_ARRAY
;
89 public MavenGeneralSettings
getGeneralSettings() {
90 return mySettings
.myGeneralSettings
;
93 public void setGeneralSettings(MavenGeneralSettings settings
) {
94 mySettings
.myGeneralSettings
= settings
;
97 public MavenRunnerSettings
getRunnerSettings() {
98 return mySettings
.myRunnerSettings
;
101 public void setRunnerSettings(MavenRunnerSettings settings
) {
102 mySettings
.myRunnerSettings
= settings
;
105 public MavenRunnerParameters
getRunnerParameters() {
106 return mySettings
.myRunnerParameters
;
109 public void setRunnerParameters(MavenRunnerParameters p
) {
110 mySettings
.myRunnerParameters
= p
;
113 public void readExternal(Element element
) throws InvalidDataException
{
114 super.readExternal(element
);
116 Element mavenSettingsElement
= element
.getChild(MavenSettings
.TAG
);
117 if (mavenSettingsElement
!= null) {
118 mySettings
= XmlSerializer
.deserialize(mavenSettingsElement
, MavenSettings
.class);
120 // fix old settings format
121 File workingDir
= mySettings
.myRunnerParameters
.getWorkingDirFile();
122 if (MavenConstants
.POM_XML
.equals(workingDir
.getName())) {
123 mySettings
.myRunnerParameters
.setWorkingDirPath(workingDir
.getParent());
126 if (mySettings
.myGeneralSettings
== null) mySettings
.myGeneralSettings
= new MavenGeneralSettings();
127 if (mySettings
.myRunnerSettings
== null) mySettings
.myRunnerSettings
= new MavenRunnerSettings();
128 if (mySettings
.myRunnerParameters
== null) mySettings
.myRunnerParameters
= new MavenRunnerParameters();
132 public void writeExternal(Element element
) throws WriteExternalException
{
133 super.writeExternal(element
);
134 element
.addContent(XmlSerializer
.serialize(mySettings
));
137 public boolean isGeneratedName() {
138 return Comparing
.equal(getName(), getGeneratedName());
141 public String
suggestedName() {
142 return getGeneratedName();
145 private String
getGeneratedName() {
146 return MavenRunConfigurationType
.generateName(getProject(), mySettings
.myRunnerParameters
);
149 public static class MavenSettings
implements Cloneable
{
150 public static final String TAG
= "MavenSettings";
152 public MavenGeneralSettings myGeneralSettings
;
153 public MavenRunnerSettings myRunnerSettings
;
154 public MavenRunnerParameters myRunnerParameters
;
156 /* reflection only */
157 public MavenSettings() {
160 public MavenSettings(Project project
) {
161 this(MavenProjectsManager
.getInstance(project
).getGeneralSettings(),
162 MavenRunner
.getInstance(project
).getState(),
163 new MavenRunnerParameters());
166 private MavenSettings(MavenGeneralSettings cs
, MavenRunnerSettings rs
, MavenRunnerParameters rp
) {
167 myGeneralSettings
= cs
.clone();
168 myRunnerSettings
= rs
.clone();
169 myRunnerParameters
= rp
.clone();
172 protected MavenSettings
clone() {
173 return new MavenSettings(myGeneralSettings
, myRunnerSettings
, myRunnerParameters
);