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 com
.intellij
.compiler
.options
;
18 import com
.intellij
.execution
.BeforeRunTask
;
19 import com
.intellij
.execution
.BeforeRunTaskProvider
;
20 import com
.intellij
.execution
.ExecutionBundle
;
21 import com
.intellij
.execution
.configurations
.RunConfiguration
;
22 import com
.intellij
.execution
.configurations
.RunProfileWithCompileBeforeLaunchOption
;
23 import com
.intellij
.execution
.remote
.RemoteConfiguration
;
24 import com
.intellij
.openapi
.actionSystem
.DataContext
;
25 import com
.intellij
.openapi
.application
.ApplicationManager
;
26 import com
.intellij
.openapi
.application
.ModalityState
;
27 import com
.intellij
.openapi
.compiler
.CompileContext
;
28 import com
.intellij
.openapi
.compiler
.CompileScope
;
29 import com
.intellij
.openapi
.compiler
.CompileStatusNotification
;
30 import com
.intellij
.openapi
.compiler
.CompilerManager
;
31 import com
.intellij
.openapi
.module
.Module
;
32 import com
.intellij
.openapi
.project
.Project
;
33 import com
.intellij
.openapi
.util
.Key
;
34 import com
.intellij
.util
.concurrency
.Semaphore
;
35 import org
.jetbrains
.annotations
.NonNls
;
36 import org
.jetbrains
.annotations
.NotNull
;
37 import org
.jetbrains
.annotations
.Nullable
;
42 public class CompileStepBeforeRun
extends BeforeRunTaskProvider
<CompileStepBeforeRun
.MakeBeforeRunTask
> {
43 public static final Key
<MakeBeforeRunTask
> ID
= Key
.create("Make");
44 private static final Key
<RunConfiguration
> RUN_CONFIGURATION
= Key
.create("RUN_CONFIGURATION");
46 @NonNls protected static final String MAKE_PROJECT_ON_RUN_KEY
= "makeProjectOnRun";
47 private final Project myProject
;
49 public CompileStepBeforeRun(@NotNull final Project project
) {
53 public Key
<MakeBeforeRunTask
> getId() {
57 public String
getDescription(final RunConfiguration runConfiguration
, MakeBeforeRunTask task
) {
58 return ExecutionBundle
.message("before.launch.compile.step");
61 public MakeBeforeRunTask
createTask(RunConfiguration runConfiguration
) {
62 return !(runConfiguration
instanceof RemoteConfiguration
) && runConfiguration
instanceof RunProfileWithCompileBeforeLaunchOption
63 ?
new MakeBeforeRunTask()
67 public boolean configureTask(RunConfiguration runConfiguration
, MakeBeforeRunTask task
) {
71 public boolean executeTask(DataContext context
, final RunConfiguration configuration
, MakeBeforeRunTask task
) {
72 if (!(configuration
instanceof RunProfileWithCompileBeforeLaunchOption
)) {
76 final RunProfileWithCompileBeforeLaunchOption runConfiguration
= (RunProfileWithCompileBeforeLaunchOption
)configuration
;
77 final Semaphore done
= new Semaphore();
78 final boolean[] result
= new boolean[1];
80 final CompileStatusNotification callback
= new CompileStatusNotification() {
81 public void finished(final boolean aborted
, final int errors
, final int warnings
, CompileContext compileContext
) {
82 if (errors
== 0 && !aborted
) {
90 ApplicationManager
.getApplication().invokeAndWait(new Runnable() {
93 final CompilerManager compilerManager
= CompilerManager
.getInstance(myProject
);
94 if (Boolean
.valueOf(System
.getProperty(MAKE_PROJECT_ON_RUN_KEY
, Boolean
.FALSE
.toString())).booleanValue()) {
95 // user explicitly requested whole-project make
96 scope
= compilerManager
.createProjectCompileScope(myProject
);
99 final Module
[] modules
= runConfiguration
.getModules();
100 if (modules
.length
> 0) {
101 scope
= compilerManager
.createModulesCompileScope(modules
, true);
104 scope
= compilerManager
.createProjectCompileScope(myProject
);
109 scope
.putUserData(RUN_CONFIGURATION
, configuration
);
110 compilerManager
.make(scope
, callback
);
112 }, ModalityState
.NON_MODAL
);
114 catch (Exception e
) {
122 public boolean hasConfigurationButton() {
127 public static RunConfiguration
getRunConfiguration(final CompileContext context
) {
128 return context
.getCompileScope().getUserData(RUN_CONFIGURATION
);
132 public static RunConfiguration
getRunConfiguration(final CompileScope compileScope
) {
133 return compileScope
.getUserData(RUN_CONFIGURATION
);
136 public static class MakeBeforeRunTask
extends BeforeRunTask
{
137 private MakeBeforeRunTask() {