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
.execution
.impl
;
19 import com
.intellij
.execution
.RunnerRegistry
;
20 import com
.intellij
.execution
.configurations
.RunProfile
;
21 import com
.intellij
.execution
.runners
.ProgramRunner
;
22 import com
.intellij
.openapi
.extensions
.Extensions
;
23 import com
.intellij
.openapi
.util
.Comparing
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
27 import java
.util
.ArrayList
;
28 import java
.util
.List
;
31 // TODO[spLeaner]: eliminate
32 public class RunnerRegistryImpl
extends RunnerRegistry
{
33 private final List
<ProgramRunner
> myRunnersOrder
= new ArrayList
<ProgramRunner
>();
36 public String
getComponentName() {
37 return "RunnerRegistryImpl";
40 public boolean hasRunner(@NotNull final String executorId
, @NotNull final RunProfile settings
) {
41 final ProgramRunner
[] runners
= getRegisteredRunners();
42 for (final ProgramRunner runner
: runners
) {
43 if (runner
.canRun(executorId
, settings
)) {
51 public ProgramRunner
getRunner(final String executorId
, final RunProfile settings
) {
52 final ProgramRunner
[] runners
= getRegisteredRunners();
53 for (final ProgramRunner runner
: runners
) {
54 if (runner
.canRun(executorId
, settings
)) {
62 public void initComponent() {
63 final ProgramRunner
[] runners
= Extensions
.getExtensions(ProgramRunner
.PROGRAM_RUNNER_EP
);
64 for (ProgramRunner runner
: runners
) {
65 registerRunner(runner
);
69 public synchronized void disposeComponent() {
70 while (myRunnersOrder
.size() > 0) {
71 final ProgramRunner runner
= myRunnersOrder
.get(myRunnersOrder
.size() - 1);
72 unregisterRunner(runner
);
76 public synchronized void registerRunner(final ProgramRunner runner
) {
77 if (myRunnersOrder
.contains(runner
)) return;
78 myRunnersOrder
.add(runner
);
81 public synchronized void unregisterRunner(final ProgramRunner runner
) {
82 myRunnersOrder
.remove(runner
);
85 public synchronized ProgramRunner
[] getRegisteredRunners() {
86 return myRunnersOrder
.toArray(new ProgramRunner
[myRunnersOrder
.size()]);
90 public ProgramRunner
findRunnerById(String id
) {
91 ProgramRunner
[] registeredRunners
= getRegisteredRunners();
92 for (ProgramRunner registeredRunner
: registeredRunners
) {
93 if (Comparing
.equal(id
, registeredRunner
.getRunnerId())) {
94 return registeredRunner
;