WEB-13145 "Single instance only" not respected
[idea/community.git] / platform / lang-impl / testSources / com / intellij / execution / impl / FakeRunConfiguration.java
1 /*
2  * Copyright 2000-2016 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.execution.impl;
17
18 import com.intellij.execution.DefaultExecutionResult;
19 import com.intellij.execution.ExecutionException;
20 import com.intellij.execution.ExecutionResult;
21 import com.intellij.execution.Executor;
22 import com.intellij.execution.configurations.LocatableConfigurationBase;
23 import com.intellij.execution.configurations.RunConfiguration;
24 import com.intellij.execution.configurations.RunProfileState;
25 import com.intellij.execution.runners.ExecutionEnvironment;
26 import com.intellij.execution.runners.ProgramRunner;
27 import com.intellij.openapi.options.SettingsEditor;
28 import com.intellij.openapi.project.Project;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31
32 import java.util.concurrent.atomic.AtomicInteger;
33
34 public class FakeRunConfiguration extends LocatableConfigurationBase {
35
36   private static AtomicInteger CREATED_INSTANCES = new AtomicInteger(0);
37
38   private final boolean mySurviveSoftKill;
39
40   protected FakeRunConfiguration(@NotNull Project project, boolean surviveSoftKill) {
41     super(project, FakeConfigurationFactory.INSTANCE, nextName());
42     mySurviveSoftKill = surviveSoftKill;
43   }
44
45   private static String nextName() {
46     return "Fake #" + CREATED_INSTANCES.incrementAndGet();
47   }
48
49   @NotNull
50   @Override
51   public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
52     throw new UnsupportedOperationException("Not implemented");
53   }
54
55   @Nullable
56   @Override
57   public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
58     return new FakeRunProfileState();
59   }
60
61   public class FakeRunProfileState implements RunProfileState {
62     @Nullable
63     @Override
64     public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
65       return new DefaultExecutionResult(null, new FakeProcessHandler(mySurviveSoftKill));
66     }
67   }
68 }