diff --git a/.idea/libraries/Netty.xml b/.idea/libraries/Netty.xml
index aafde743ce14..c094259951d9 100644
--- a/.idea/libraries/Netty.xml
+++ b/.idea/libraries/Netty.xml
@@ -1,11 +1,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/.idea/libraries/miglayout_swing.xml b/.idea/libraries/miglayout_swing.xml
new file mode 100644
index 000000000000..5eced334efaa
--- /dev/null
+++ b/.idea/libraries/miglayout_swing.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml
index 80bc93534f4f..035e49f13af7 100644
--- a/community-resources/src/idea/IdeaApplicationInfo.xml
+++ b/community-resources/src/idea/IdeaApplicationInfo.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java b/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java
index 1bdde25fc857..4457a9d94f92 100644
--- a/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java
+++ b/java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java
@@ -76,10 +76,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
-import java.util.concurrent.Future;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.RunnableFuture;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -91,26 +88,21 @@ public class CompileServerManager implements ApplicationComponent{
private static final String COMPILE_SERVER_SYSTEM_ROOT = "compile-server";
private static final String LOGGER_CONFIG = "log.xml";
private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.xml";
- private volatile ServerWrapper myProcessHandler;
+ private volatile OSProcessHandler myProcessHandler;
private final File mySystemDirectory;
@Nullable
private volatile CompileServerClient myClient;
- private final SequentialTaskExecutor myTaskExecutor = new SequentialTaskExecutor(new AsyncTaskExecutor() {
- @Override
- public void submit(Runnable runnable) {
- ApplicationManager.getApplication().executeOnPooledThread(runnable);
- }
- });
private final ProjectManager myProjectManager;
private static final int MAKE_TRIGGER_DELAY = 5 * 1000 /*5 seconds*/;
private final Map myAutomakeFutures = new HashMap();
private final CompileServerClasspathManager myClasspathManager = new CompileServerClasspathManager();
- private final AsyncTaskExecutor myAsyncExec = new AsyncTaskExecutor() {
+ private final Executor myPooledThreadExecutor = new Executor() {
@Override
- public void submit(Runnable runnable) {
- ApplicationManager.getApplication().executeOnPooledThread(runnable);
+ public void execute(Runnable command) {
+ ApplicationManager.getApplication().executeOnPooledThread(command);
}
};
+ private final SequentialTaskExecutor myTaskExecutor = new SequentialTaskExecutor(myPooledThreadExecutor);
public CompileServerManager(final ProjectManager projectManager) {
myProjectManager = projectManager;
@@ -335,7 +327,7 @@ public class CompileServerManager implements ApplicationComponent{
public RequestFuture submitCompilationTask(final Project project, final boolean isRebuild, final boolean isMake,
final Collection modules, final Collection artifacts,
final Collection paths,
- final Map _userData, final JpsServerResponseHandler handler) {
+ final Map userData, final JpsServerResponseHandler handler) {
final String projectId = getProjectPath(project);
final Ref futureRef = new Ref(null);
final RunnableFuture future = myTaskExecutor.submit(new Runnable() {
@@ -344,16 +336,9 @@ public class CompileServerManager implements ApplicationComponent{
try {
final CompileServerClient client = ensureServerRunningAndClientConnected(true);
if (client != null) {
- final Map userData = new LinkedHashMap();
- if (!isRebuild) { //todo pass user data on rebuild as well?
- userData.putAll(_userData);
- }
- if (Registry.is("compiler.server.use.external.javac.process")) {
- userData.put(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION, "true");
- }
final RequestFuture requestFuture = isRebuild ?
- client.sendRebuildRequest(projectId, handler, userData) :
- client.sendCompileRequest(isMake, projectId, modules, artifacts, paths, userData, handler);
+ client.sendRebuildRequest(projectId, handler, userData) :
+ client.sendCompileRequest(isMake, projectId, modules, artifacts, paths, userData, handler);
futureRef.set(requestFuture);
}
else {
@@ -397,9 +382,9 @@ public class CompileServerManager implements ApplicationComponent{
// executed in one thread at a time
@Nullable
private CompileServerClient ensureServerRunningAndClientConnected(boolean forceRestart) throws Throwable {
- final ServerWrapper ph = myProcessHandler;
+ final OSProcessHandler ph = myProcessHandler;
final CompileServerClient cl = myClient;
- final boolean processNotRunning = ph == null || ph.isDead();
+ final boolean processNotRunning = ph == null || ph.isProcessTerminated() || ph.isProcessTerminating();
final boolean clientNotConnected = cl == null || !cl.isConnected();
if (processNotRunning || clientNotConnected) {
@@ -412,105 +397,89 @@ public class CompileServerManager implements ApplicationComponent{
return null;
}
- final File workDirectory = new File(mySystemDirectory, COMPILE_SERVER_SYSTEM_ROOT);
- workDirectory.mkdirs();
- ensureLogConfigExists(workDirectory);
-
final int port = NetUtils.findAvailableSocketPort();
- final long serverPingInterval = Registry.intValue("compiler.server.ping.interval", -1) * 1000L;
- ServerWrapper wrapper = Registry.is("compiler.server.in.process") ? launchServerThread(workDirectory, port) : launchServerProcess(port, serverPingInterval, workDirectory);
+ final long serverPingInterval = Registry.intValue("compiler.server.ping.interval", -1) * 1000L;
+ final Process process = launchServer(port, serverPingInterval);
- CompileServerClient client = new CompileServerClient(serverPingInterval, myAsyncExec);
+ final OSProcessHandler processHandler = new OSProcessHandler(process, null) {
+ @Override
+ protected boolean shouldDestroyProcessRecursively() {
+ return true;
+ }
+ };
+ final StringBuilder serverStartMessage = new StringBuilder();
+ final Semaphore semaphore = new Semaphore();
+ semaphore.down();
+ processHandler.addProcessListener(new ProcessAdapter() {
+ @Override
+ public void onTextAvailable(ProcessEvent event, Key outputType) {
+ // re-translate server's output to idea.log
+ final String text = event.getText();
+ if (!StringUtil.isEmpty(text)) {
+ LOG.info("COMPILE_SERVER [" +outputType.toString() +"]: "+ text.trim());
+ }
+ }
+ });
+ processHandler.addProcessListener(new ProcessAdapter() {
+ @Override
+ public void processTerminated(ProcessEvent event) {
+ try {
+ processHandler.removeProcessListener(this);
+ }
+ finally {
+ semaphore.up();
+ }
+ }
+
+ @Override
+ public void onTextAvailable(ProcessEvent event, Key outputType) {
+ if (outputType == ProcessOutputTypes.STDERR) {
+ try {
+ final String text = event.getText();
+ if (text != null) {
+ if (text.contains(Server.SERVER_SUCCESS_START_MESSAGE) || text.contains(Server.SERVER_ERROR_START_MESSAGE)) {
+ processHandler.removeProcessListener(this);
+ }
+ if (serverStartMessage.length() > 0) {
+ serverStartMessage.append("\n");
+ }
+ serverStartMessage.append(text);
+ }
+ }
+ finally {
+ semaphore.up();
+ }
+ }
+ }
+ });
+ processHandler.startNotify();
+ semaphore.waitFor();
+
+ final String startupMsg = serverStartMessage.toString();
+ if (!startupMsg.contains(Server.SERVER_SUCCESS_START_MESSAGE)) {
+ throw new Exception("Server startup failed: " + startupMsg);
+ }
+
+ CompileServerClient client = new CompileServerClient(serverPingInterval, myPooledThreadExecutor);
boolean connected = false;
try {
connected = client.connect(NetUtils.getLocalHostString(), port);
if (connected) {
final RequestFuture setupFuture = sendSetupRequest(client);
setupFuture.waitFor();
- myProcessHandler = wrapper;
+ myProcessHandler = processHandler;
myClient = client;
}
}
finally {
if (!connected) {
- shutdownServer(cl, wrapper);
+ shutdownServer(cl, processHandler);
}
}
}
return myClient;
}
- private static ServerWrapper launchServerThread(final File workDirectory, final int port) {
- final Server server = new Server(workDirectory, Registry.is("compiler.server.use.memory.temp.cache"));
- //todo hostname
- server.start(port);
- return new ServerWrapper(null, server);
- }
-
- private ServerWrapper launchServerProcess(int port, long serverPingInterval, File workDirectory) throws Exception {
- final Process process = launchServer(port, serverPingInterval, workDirectory);
-
- final OSProcessHandler processHandler = new OSProcessHandler(process, null) {
- @Override
- protected boolean shouldDestroyProcessRecursively() {
- return true;
- }
- };
- final StringBuilder serverStartMessage = new StringBuilder();
- final Semaphore semaphore = new Semaphore();
- semaphore.down();
- processHandler.addProcessListener(new ProcessAdapter() {
- @Override
- public void onTextAvailable(ProcessEvent event, Key outputType) {
- // re-translate server's output to idea.log
- final String text = event.getText();
- if (!StringUtil.isEmpty(text)) {
- LOG.info("COMPILE_SERVER [" +outputType.toString() +"]: "+ text.trim());
- }
- }
- });
- processHandler.addProcessListener(new ProcessAdapter() {
- @Override
- public void processTerminated(ProcessEvent event) {
- try {
- processHandler.removeProcessListener(this);
- }
- finally {
- semaphore.up();
- }
- }
-
- @Override
- public void onTextAvailable(ProcessEvent event, Key outputType) {
- if (outputType == ProcessOutputTypes.STDERR) {
- try {
- final String text = event.getText();
- if (text != null) {
- if (text.contains(Server.SERVER_SUCCESS_START_MESSAGE) || text.contains(Server.SERVER_ERROR_START_MESSAGE)) {
- processHandler.removeProcessListener(this);
- }
- if (serverStartMessage.length() > 0) {
- serverStartMessage.append("\n");
- }
- serverStartMessage.append(text);
- }
- }
- finally {
- semaphore.up();
- }
- }
- }
- });
- processHandler.startNotify();
- semaphore.waitFor();
-
- final String startupMsg = serverStartMessage.toString();
- if (!startupMsg.contains(Server.SERVER_SUCCESS_START_MESSAGE)) {
- throw new Exception("Server startup failed: " + startupMsg);
- }
- return new ServerWrapper(processHandler, null);
- }
-
private static RequestFuture sendSetupRequest(final @NotNull CompileServerClient client) throws Exception {
final Map data = new HashMap();
@@ -593,7 +562,7 @@ public class CompileServerManager implements ApplicationComponent{
// commandLine.add((launcherUsed? "-J" : "") + "-D" + CharsetToolkit.FILE_ENCODING_PROPERTY + "=" + CharsetToolkit.getDefaultSystemCharset().name());
//}
- private Process launchServer(final int port, long pingInterval, File workDirectory) throws ExecutionException {
+ private Process launchServer(final int port, long pingInterval) throws ExecutionException {
// validate tools.jar presence
final JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
if (systemCompiler == null) {
@@ -642,6 +611,9 @@ public class CompileServerManager implements ApplicationComponent{
if (Registry.is("compiler.server.use.memory.temp.cache")) {
cmdLine.addParameter("-D"+ GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION + "=true");
}
+ if (Registry.is("compiler.server.use.external.javac.process")) {
+ cmdLine.addParameter("-D"+ GlobalOptions.USE_EXTERNAL_JAVAC_OPTION + "=true");
+ }
cmdLine.addParameter("-D"+ GlobalOptions.HOSTNAME_OPTION + "=" + NetUtils.getLocalHostString());
// javac's VM should use the same default locale that IDEA uses in order for javac to print messages in 'correct' language
@@ -672,6 +644,10 @@ public class CompileServerManager implements ApplicationComponent{
cmdLine.addParameter(org.jetbrains.jps.server.Server.class.getName());
cmdLine.addParameter(Integer.toString(port));
+ final File workDirectory = new File(mySystemDirectory, COMPILE_SERVER_SYSTEM_ROOT);
+ workDirectory.mkdirs();
+ ensureLogConfigExists(workDirectory);
+
cmdLine.addParameter(FileUtil.toSystemIndependentName(workDirectory.getPath()));
cmdLine.setWorkDirectory(workDirectory);
@@ -711,7 +687,7 @@ public class CompileServerManager implements ApplicationComponent{
shutdownServer(myClient, myProcessHandler);
}
- private static void shutdownServer(final CompileServerClient client, final ServerWrapper processHandler) {
+ private static void shutdownServer(final CompileServerClient client, final OSProcessHandler processHandler) {
try {
if (client != null && client.isConnected()) {
final Future future = client.sendShutdownRequest();
@@ -884,28 +860,4 @@ public class CompileServerManager implements ApplicationComponent{
}
}
}
-
- private static class ServerWrapper {
- final @Nullable OSProcessHandler myHandler;
- final @Nullable Server myServer;
-
- ServerWrapper(OSProcessHandler handler, Server server) {
- myHandler = handler;
- myServer = server;
- }
-
- public void destroyProcess() {
- if (myHandler != null) {
- myHandler.destroyProcess();
- } else if (myServer != null) {
- myServer.stop();
- }
- }
-
- public boolean isDead() {
- return myHandler != null && (myHandler.isProcessTerminated() || myHandler.isProcessTerminating()) ||
- myServer != null && myServer.isStopped();
- }
- }
}
-
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java
index 4ee35f67797b..57f4b67dbcbf 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -284,9 +284,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
ContainerUtil.addIfNotNull(request, requestsToRemove);
}
- final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
- fileSystem.removeWatchedRoots(requestsToRemove);
- final Set newRequests = fileSystem.addRootsToWatch(toAdd, true);
+ Set newRequests = LocalFileSystem.getInstance().replaceWatchedRoots(requestsToRemove, toAdd, true);
for (LocalFileSystem.WatchRequest request : newRequests) {
myWatchedOutputs.put(request.getRootPath(), request);
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java
index 0157fb78953a..d312a9475c69 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java
@@ -31,13 +31,14 @@ import java.util.List;
/**
* @author nik
*/
-public class BuildArtifactsBeforeRunTask extends BeforeRunTask {
+public class BuildArtifactsBeforeRunTask extends BeforeRunTask {
@NonNls public static final String NAME_ATTRIBUTE = "name";
@NonNls public static final String ARTIFACT_ELEMENT = "artifact";
private List myArtifactPointers = new ArrayList();
private final Project myProject;
public BuildArtifactsBeforeRunTask(Project project) {
+ super(BuildArtifactsBeforeRunTaskProvider.ID);
myProject = project;
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java
index ee2315e3a046..667bd73ea91e 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java
@@ -15,6 +15,7 @@
*/
package com.intellij.packaging.impl.run;
+import com.intellij.execution.BeforeRunTask;
import com.intellij.execution.BeforeRunTaskProvider;
import com.intellij.execution.RunManagerEx;
import com.intellij.execution.configurations.RunConfiguration;
@@ -33,6 +34,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Ref;
import com.intellij.packaging.artifacts.*;
+import com.intellij.packaging.impl.artifacts.PlainArtifactType;
import com.intellij.packaging.impl.compiler.ArtifactAwareCompiler;
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
import com.intellij.packaging.impl.compiler.ArtifactsCompiler;
@@ -63,8 +65,8 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider tasks = runManager.getBeforeRunTasks(configuration, ID);
+ for (BuildArtifactsBeforeRunTask task : tasks) {
final String artifactName = artifact.getName();
final List pointersList = task.getArtifactPointers();
final ArtifactPointer[] pointers = pointersList.toArray(new ArtifactPointer[pointersList.size()]);
@@ -83,18 +85,40 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider pointers = task.getArtifactPointers();
- if (!task.isEnabled() || pointers.isEmpty()) {
- return "Build Artifacts";
- }
- if (pointers.size() == 1) {
- return "Build '" + pointers.get(0).getArtifactName() + "' artifact";
- }
- return "Build " + pointers.size() + " artifacts";
+ @Override
+ public Icon getIcon() {
+ return PlainArtifactType.ARTIFACT_ICON;
}
- public boolean hasConfigurationButton() {
+ @Override
+ public String getName() {
+ return CompilerBundle.message("build.artifacts.before.run.description.empty");
+ }
+
+ @Override
+ public Icon getTaskIcon(BuildArtifactsBeforeRunTask task) {
+ List pointers = task.getArtifactPointers();
+ if (pointers == null || pointers.isEmpty())
+ return getIcon();
+ Artifact artifact = pointers.get(0).getArtifact();
+ if (artifact == null)
+ return getIcon();
+ return artifact.getArtifactType().getIcon();
+ }
+
+ @Override
+ public String getDescription(BuildArtifactsBeforeRunTask task) {
+ final List pointers = task.getArtifactPointers();
+ if (!task.isEnabled() || pointers.isEmpty()) {
+ return CompilerBundle.message("build.artifacts.before.run.description.empty");
+ }
+ if (pointers.size() == 1) {
+ return CompilerBundle.message("build.artifacts.before.run.description.single", pointers.get(0).getArtifactName());
+ }
+ return CompilerBundle.message("build.artifacts.before.run.description.multiple", pointers.size());
+ }
+
+ public boolean isConfigurable() {
return true;
}
@@ -115,7 +139,7 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider result = Ref.create(false);
final Semaphore finished = new Semaphore();
@@ -170,27 +203,35 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider tasks = editor.getStepsBeforeLaunch();
+ List myTasks = new ArrayList();
+ for (BeforeRunTask task : tasks) {
+ if (task instanceof BuildArtifactsBeforeRunTask) {
+ myTasks.add((BuildArtifactsBeforeRunTask)task);
+ }
}
- else {
- task.removeArtifact(artifact);
- if (task.getArtifactPointers().isEmpty()) {
- task.setEnabled(false);
+ for (BuildArtifactsBeforeRunTask task : myTasks) {
+ if (enable) {
+ task.addArtifact(artifact);
+ task.setEnabled(true);
+ }
+ else {
+ task.removeArtifact(artifact);
+ if (task.getArtifactPointers().isEmpty()) {
+ task.setEnabled(false);
+ }
}
}
- editor.updateBeforeRunTaskPanel(ID);
}
}
public static void setBuildArtifactBeforeRun(@NotNull Project project, @NotNull RunConfiguration configuration, @NotNull Artifact artifact) {
RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
- final BuildArtifactsBeforeRunTask buildArtifactsTask = runManager.getBeforeRunTask(configuration, ID);
- if (buildArtifactsTask != null) {
- buildArtifactsTask.setEnabled(true);
- buildArtifactsTask.addArtifact(artifact);
+ final List buildArtifactsTasks = runManager.getBeforeRunTasks(configuration, ID);
+ for (BuildArtifactsBeforeRunTask task : buildArtifactsTasks) {
+ task.setEnabled(true);
+ task.addArtifact(artifact);
+
}
}
}
diff --git a/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java b/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java
index 2822a51bac32..4c2a775ccd7e 100644
--- a/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java
+++ b/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java
@@ -32,12 +32,15 @@ import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Key;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import javax.swing.*;
+
/**
* @author spleaner
*/
@@ -47,6 +50,9 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider RUN_CONFIGURATION = Key.create("RUN_CONFIGURATION");
@NonNls protected static final String MAKE_PROJECT_ON_RUN_KEY = "makeProjectOnRun";
+
+ private static final Icon ICON = IconLoader.getIcon("/actions/compile.png");
+
private final Project myProject;
public CompileStepBeforeRun(@NotNull final Project project) {
@@ -57,10 +63,26 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider {
private MakeBeforeRunTask() {
+ super(ID);
setEnabled(true);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/inferNullity/AnnotateTask.java b/java/java-impl/src/com/intellij/codeInspection/inferNullity/AnnotateTask.java
new file mode 100644
index 000000000000..3cc23f4140ff
--- /dev/null
+++ b/java/java-impl/src/com/intellij/codeInspection/inferNullity/AnnotateTask.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInspection.inferNullity;
+
+import com.intellij.codeInsight.NullableNotNullManager;
+import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.openapi.project.Project;
+import com.intellij.util.SequentialModalProgressTask;
+import com.intellij.util.SequentialTask;
+
+class AnnotateTask implements SequentialTask {
+ private final Project myProject;
+ private final NullityInferrer myInferrer;
+ private final SequentialModalProgressTask myTask;
+ private int myCount = 0;
+ private final int myTotal;
+ private final NullableNotNullManager myNotNullManager;
+
+ public AnnotateTask(Project project, NullityInferrer inferrer, SequentialModalProgressTask progressTask) {
+ myProject = project;
+ myNotNullManager = NullableNotNullManager.getInstance(myProject);
+ myInferrer = inferrer;
+ myTask = progressTask;
+ myTotal = myInferrer.getCount();
+ }
+
+ @Override
+ public void prepare() {
+ }
+
+ @Override
+ public boolean isDone() {
+ return myCount > myTotal - 1;
+ }
+
+ @Override
+ public boolean iteration() {
+ final ProgressIndicator indicator = myTask.getIndicator();
+ if (indicator != null) {
+ indicator.setFraction(((double)myCount) / myTotal);
+ }
+
+ myInferrer.apply(myCount++, myProject, myNotNullManager);
+
+ return isDone();
+ }
+
+ @Override
+ public void stop() {
+ }
+}
\ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/codeInspection/inferNullity/InferNullityAnnotationsAction.java b/java/java-impl/src/com/intellij/codeInspection/inferNullity/InferNullityAnnotationsAction.java
index e4c214917b06..b3f54b8061d2 100644
--- a/java/java-impl/src/com/intellij/codeInspection/inferNullity/InferNullityAnnotationsAction.java
+++ b/java/java-impl/src/com/intellij/codeInspection/inferNullity/InferNullityAnnotationsAction.java
@@ -49,6 +49,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtil;
import com.intellij.ui.TitledSeparator;
import com.intellij.util.Function;
+import com.intellij.util.SequentialModalProgressTask;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -196,7 +197,12 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {
@Override
protected void run(Result result) throws Throwable {
- inferrer.apply(project);
+ if (!inferrer.nothingFoundMessage(project)) {
+ final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
+ progressTask.setMinIterationTime(200);
+ progressTask.setTask(new AnnotateTask(project, inferrer, progressTask));
+ ProgressManager.getInstance().run(progressTask);
+ }
}
}.execute();
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java b/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java
index 9b67b5603a78..8abcb1262dbe 100644
--- a/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java
+++ b/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java
@@ -31,14 +31,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.List;
public class NullityInferrer {
private static final int MAX_PASSES = 10;
private int numAnnotationsAdded = 0;
- private final HashSet> myNotNullSet = new HashSet>();
- private final HashSet> myNullableSet = new HashSet>();
+ private final List> myNotNullSet = new ArrayList>();
+ private final List> myNullableSet = new ArrayList>();
private final boolean myAnnotateLocalVariables;
private final SmartPointerManager myPointerManager;
@@ -139,29 +140,60 @@ public class NullityInferrer {
public void apply(final Project project) {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
for (SmartPsiElementPointer extends PsiModifierListOwner> pointer : myNullableSet) {
- final PsiModifierListOwner element = pointer.getElement();
- if (element != null) {
- if (shouldIgnore(element)) continue;
- new AddAnnotationFix(manager.getDefaultNullable(), element, manager.getDefaultNotNull()).invoke(project, null, element.getContainingFile());
- }
+ annotateNullable(project, manager, pointer);
}
for (SmartPsiElementPointer extends PsiModifierListOwner> pointer : myNotNullSet) {
- final PsiModifierListOwner element = pointer.getElement();
- if (element != null) {
- if (shouldIgnore(element)) continue;
- if (element instanceof PsiField && ((PsiField)element).hasInitializer() && element.hasModifierProperty(PsiModifier.FINAL)) continue;
- new AddAnnotationFix(manager.getDefaultNotNull(), element, manager.getDefaultNullable()).invoke(project, null,
- element.getContainingFile());
- }
+ annotateNotNull(project, manager, pointer);
}
+ nothingFoundMessage(project);
+ }
+
+ public boolean nothingFoundMessage(final Project project) {
if (myNullableSet.isEmpty() && myNotNullSet.isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Messages.showInfoMessage(project, "No places found to infer @Nullable/@NotNull", "Infer Nullity Results");
}
});
+ return true;
+ }
+ return false;
+ }
+
+ private void annotateNotNull(Project project,
+ NullableNotNullManager manager,
+ SmartPsiElementPointer extends PsiModifierListOwner> pointer) {
+ final PsiModifierListOwner element = pointer.getElement();
+ if (element != null) {
+ if (shouldIgnore(element)) return;
+ if (element instanceof PsiField && ((PsiField)element).hasInitializer() && element.hasModifierProperty(PsiModifier.FINAL)) return;
+ new AddAnnotationFix(manager.getDefaultNotNull(), element, manager.getDefaultNullable()).invoke(project, null,
+ element.getContainingFile());
+ }
+ }
+
+ private void annotateNullable(Project project,
+ NullableNotNullManager manager,
+ SmartPsiElementPointer extends PsiModifierListOwner> pointer) {
+ final PsiModifierListOwner element = pointer.getElement();
+ if (element != null) {
+ if (shouldIgnore(element)) return;
+ new AddAnnotationFix(manager.getDefaultNullable(), element, manager.getDefaultNotNull()).invoke(project, null, element.getContainingFile());
+ }
+ }
+
+ public int getCount() {
+ return myNotNullSet.size() + myNullableSet.size();
+ }
+
+ public void apply(int i, Project project, NullableNotNullManager manager) {
+ if (i < myNullableSet.size()) {
+ annotateNullable(project, manager, myNullableSet.get(i));
+ } else {
+ i -= myNullableSet.size();
+ annotateNotNull(project, manager, myNotNullSet.get(i));
}
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java
index 9d7aaeb2ea1b..d98c89203767 100644
--- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java
+++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java
@@ -300,9 +300,9 @@ public class RefJavaManagerImpl extends RefJavaManager {
public void export(final RefEntity refEntity, final Element element) {
if (refEntity instanceof RefElement) {
- final PsiElement psiElement = ((RefElement)refEntity).getElement();
- if (psiElement != null) {
- final PsiFile psiFile = psiElement.getContainingFile();
+ final SmartPsiElementPointer pointer = ((RefElement)refEntity).getPointer();
+ if (pointer != null) {
+ final PsiFile psiFile = pointer.getContainingFile();
if (psiFile instanceof PsiJavaFile) {
appendPackageElement(element, ((PsiJavaFile)psiFile).getPackageName());
}
diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerProjectExtensionImpl.java
index b491285c9cef..328faa3b77e1 100644
--- a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerProjectExtensionImpl.java
+++ b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerProjectExtensionImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,12 +98,7 @@ public class CompilerProjectExtensionImpl extends CompilerProjectExtension {
public void setCompilerOutputUrl(String compilerOutputUrl) {
VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(compilerOutputUrl, myProject, null);
setCompilerOutputPointer(pointer);
- final LocalFileSystem.WatchRequest watchRequest =
- LocalFileSystem.getInstance().addRootToWatch(ProjectRootManagerImpl.extractLocalPath(compilerOutputUrl), true);
- if (myCompilerOutputWatchRequest != null) {
- LocalFileSystem.getInstance().removeWatchedRoot(myCompilerOutputWatchRequest);
- }
- myCompilerOutputWatchRequest = watchRequest;
+ myCompilerOutputWatchRequest = LocalFileSystem.getInstance().replaceWatchedRoot(myCompilerOutputWatchRequest, compilerOutputUrl, true);
}
@NotNull
diff --git a/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java b/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java
index d85d6ab526b2..4d44ef4541a9 100644
--- a/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java
+++ b/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
+import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Consumer;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -45,7 +46,7 @@ public class ClassLiteralGetter {
PsiElement position = parameters.getPosition();
if (classParameter instanceof PsiWildcardType) {
final PsiWildcardType wildcardType = (PsiWildcardType)classParameter;
- classParameter = wildcardType.getBound();
+ classParameter = wildcardType.isSuper() ? wildcardType.getSuperBound() : wildcardType.getExtendsBound();
addInheritors = wildcardType.isExtends() && classParameter instanceof PsiClassType;
} else if (!matcher.getPrefix().isEmpty()) {
addInheritors = true;
diff --git a/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java b/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java
index b089a229aa2f..4bc9f66c28c1 100644
--- a/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java
+++ b/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,6 +67,11 @@ public class PsiWildcardType extends PsiType {
public static PsiWildcardType changeBound(@NotNull PsiWildcardType type, @NotNull PsiType newBound) {
LOG.assertTrue(type.getBound() != null);
+ if (type.myIsExtending) {
+ if (newBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
+ return createUnbounded(type.myManager);
+ }
+ }
return new PsiWildcardType(type.myManager, type.myIsExtending, newBound);
}
diff --git a/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java b/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java
index ab97e1b3b53d..22e0c9dc0a0b 100644
--- a/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java
+++ b/java/java-psi-api/src/com/intellij/psi/util/TypeConversionUtil.java
@@ -659,7 +659,7 @@ public class TypeConversionUtil {
return left.equals(right) || isAssignable(((PsiCapturedWildcardType)left).getLowerBound(), right, false);
}
if (right instanceof PsiCapturedWildcardType) {
- return isAssignable(left, ((PsiCapturedWildcardType)right).getUpperBound(), false);
+ return isAssignable(left, ((PsiCapturedWildcardType)right).getUpperBound(), allowUncheckedConversion);
}
if (left instanceof PsiWildcardType) {
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CapturedWildcardAssignments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CapturedWildcardAssignments.java
index f105923eb1b1..b750cd27b9a7 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CapturedWildcardAssignments.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/CapturedWildcardAssignments.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import java.util.Iterator;
+import java.util.*;
public class Test {
public static void bar() {
@@ -24,4 +24,16 @@ public class Test {
public static Class extends Iterator> foo() {
return null;
}
-}
\ No newline at end of file
+}
+
+class Example {
+ static List extends AbstractTreeNode> treeNodes = null;
+
+ public static void main(String[] args) {
+ for (AbstractTreeNode treeNode : treeNodes) {
+
+ }
+ }
+
+}
+class AbstractTreeNode {}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV57343.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV57343.java
index 63ecda1fd9e2..30456212a21b 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV57343.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV57343.java
@@ -1,6 +1,6 @@
class D {
void foo(D> x){
- bar(x,x);
+ bar(x,x);
}
void bar(D extends T> x, D super T> y){}
}
\ No newline at end of file
diff --git a/java/java-tests/testData/find/findInClassHierarchy/src/A.java b/java/java-tests/testData/find/findInClassHierarchy/src/A.java
new file mode 100644
index 000000000000..285f551b4789
--- /dev/null
+++ b/java/java-tests/testData/find/findInClassHierarchy/src/A.java
@@ -0,0 +1,18 @@
+public class A {
+ void foo(Object o) {
+ if (o instanceof String){}
+ }
+}
+
+class AImpl extends A {
+ void foo(Object o) {
+ if (o instanceof String){}
+ }
+}
+
+class B {
+ void bar(Object o) {
+ if (o instanceof String){}
+ }
+}
+
diff --git a/java/java-tests/testData/find/findInPath/src/s.java b/java/java-tests/testData/find/findInPath/src/s.java
new file mode 100644
index 000000000000..02306018d545
--- /dev/null
+++ b/java/java-tests/testData/find/findInPath/src/s.java
@@ -0,0 +1,3 @@
+class s {
+ String s = "xx.yy";
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/find/findInPath/src/x/dd.properties b/java/java-tests/testData/find/findInPath/src/x/dd.properties
new file mode 100644
index 000000000000..f2e9b8253292
--- /dev/null
+++ b/java/java-tests/testData/find/findInPath/src/x/dd.properties
@@ -0,0 +1,3 @@
+xx.yy=zzzz
+aaa.bbb=zzz
+cccc=c
\ No newline at end of file
diff --git a/java/java-tests/testData/find/findManager/src/test/FindTest.java b/java/java-tests/testData/find/findManager/src/test/FindTest.java
new file mode 100644
index 000000000000..6cd59ff2b476
--- /dev/null
+++ b/java/java-tests/testData/find/findManager/src/test/FindTest.java
@@ -0,0 +1,11 @@
+package test;
+public class FindTest {
+ public static void main(String[] args) {
+ System.out.println(" done");
+//done
+ System.out.println("done");
+ System.out.println(" done");
+ System.out.println(" done2");
+//done!
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/find/findManager/src1/tests/FindTests.java b/java/java-tests/testData/find/findManager/src1/tests/FindTests.java
new file mode 100644
index 000000000000..657becd99530
--- /dev/null
+++ b/java/java-tests/testData/find/findManager/src1/tests/FindTests.java
@@ -0,0 +1,11 @@
+package tests;
+public class FindTests {
+ public static void main(String[] args) {
+ System.out.println(" done");
+//done
+ System.out.println("done");
+ System.out.println(" done");
+ System.out.println(" done2");
+//done!
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/find/libUnderProject/lib/B.java b/java/java-tests/testData/find/libUnderProject/lib/B.java
new file mode 100644
index 000000000000..634b3185283e
--- /dev/null
+++ b/java/java-tests/testData/find/libUnderProject/lib/B.java
@@ -0,0 +1 @@
+// TargetWord
\ No newline at end of file
diff --git a/java/java-tests/testData/find/libUnderProject/src/A.java b/java/java-tests/testData/find/libUnderProject/src/A.java
new file mode 100644
index 000000000000..634b3185283e
--- /dev/null
+++ b/java/java-tests/testData/find/libUnderProject/src/A.java
@@ -0,0 +1 @@
+// TargetWord
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
new file mode 100644
index 000000000000..660ba9dcfe0c
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
@@ -0,0 +1,428 @@
+package com.intellij.find;
+
+import com.intellij.JavaTestUtil;
+import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
+import com.intellij.find.impl.FindInProjectUtil;
+import com.intellij.find.replaceInProject.ReplaceInProjectManager;
+import com.intellij.lang.properties.IProperty;
+import com.intellij.lang.properties.psi.PropertiesFile;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.fileTypes.FileTypes;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
+import com.intellij.openapi.roots.ContentEntry;
+import com.intellij.openapi.roots.ModifiableRootModel;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.search.LocalSearchScope;
+import com.intellij.testFramework.PlatformTestUtil;
+import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.testFramework.fixtures.TempDirTestFixture;
+import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
+import com.intellij.usageView.UsageInfo;
+import com.intellij.usages.Usage;
+import com.intellij.util.ArrayUtil;
+import com.intellij.util.ThrowableRunnable;
+import com.intellij.util.WaitFor;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/*
+ * @author: MYakovlev
+ * Date: Oct 17, 2002
+ * Time: 7:53:31 PM
+ */
+@SuppressWarnings({"HardCodedStringLiteral"})
+public class FindManagerTest extends DaemonAnalyzerTestCase {
+ protected VirtualFile[] mySourceDirs;
+
+ public void testFindString() throws Exception{
+ FindManager findManager = FindManager.getInstance(myProject);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("done");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+
+ String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}";
+ FindResult findResult = findManager.findString(text, 0, findModel);
+ assertTrue(findResult.isStringFound());
+
+ findModel = new FindModel();
+ findModel.setStringToFind("done");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(true);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+
+ findResult = findManager.findString(text, 40, findModel);
+ assertFalse(findResult.isStringFound());
+
+ findModel = new FindModel();
+ findModel.setStringToFind("done");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(true);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+ findModel.setForward(false);
+
+ findResult = findManager.findString(text, 40, findModel);
+ assertTrue(findResult.isStringFound());
+
+ findModel = new FindModel();
+ findModel.setStringToFind("done");
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+
+ findResult = findManager.findString(text, 0, findModel);
+ assertTrue(findResult.isStringFound());
+
+ findModel = new FindModel();
+ findModel.setStringToFind("don");
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+
+ final FindResult[] findResultArr = new FindResult[1];
+ findInNewThread(findModel, findManager, text, 0, findResultArr);
+ new WaitFor(30 *1000){
+ @Override
+ protected boolean condition() {
+ return findResultArr[0] != null;
+ }
+ }.assertCompleted();
+
+ assertFalse(findResultArr[0].isStringFound());
+ }
+
+ private static Thread findInNewThread(final FindModel model,
+ final FindManager findManager,
+ final CharSequence text,
+ final int offset,
+ final FindResult[] op_result){
+ op_result[0] = null;
+ Thread findThread = new Thread(){
+ @Override
+ public void run(){
+ op_result[0] = findManager.findString(text, offset, model);
+ }
+ };
+ findThread.start();
+ return findThread;
+ }
+
+ public void testFindUsages() throws Exception{
+ initProject("findManager", "src", "src1");
+ final String projectDir = (PathManagerEx.getTestDataPath() + "/find/findManager").replace('/', File.separatorChar);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("done");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+ findModel.setProjectScope(true);
+ findModel.setDirectoryName(projectDir + File.separatorChar + "src1");
+ findModel.setWithSubdirectories(true);
+ checkFindUsages(12, findModel);
+
+ //findModel = new FindModel();
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+ findModel.setProjectScope(false);
+ findModel.setDirectoryName(projectDir + File.separatorChar + "src1");
+ findModel.setWithSubdirectories(true);
+ checkFindUsages(6, findModel);
+
+ findModel.setWholeWordsOnly(true);
+ checkFindUsages(5, findModel);
+// findModel.setForward(false);
+// findModel.setCaseSensitive();
+
+
+ }
+
+ private void checkFindUsages(int expectedResults, FindModel findModel) throws Exception{
+ Collection usages = findUsages(findModel);
+ assertEquals(expectedResults, usages.size());
+ }
+
+ private List findUsages(final FindModel findModel) {
+ PsiDirectory psiDirectory = FindInProjectUtil.getPsiDirectory(findModel, myProject);
+ return FindInProjectUtil.findUsages(findModel, psiDirectory, myProject);
+ }
+
+ public void testFindWholeWordsInProperties() throws Exception {
+ initProject("findInPath", "src");
+
+ searchProperty("xx.yy");
+ searchProperty(".yy");
+ searchProperty("xx.");
+ }
+
+ private void searchProperty(String query) {
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind(query);
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+ findModel.setProjectScope(true);
+ findModel.setDirectoryName(mySourceDirs[0].getPath());
+ findModel.setWithSubdirectories(true);
+
+ List usages = findUsages(findModel);
+ assertEquals(2, usages.size());
+ if (!(usages.get(0).getElement().getContainingFile() instanceof PsiJavaFile)) {
+ Collections.swap(usages, 0, 1);
+ }
+ PsiElement element = usages.get(0).getElement();
+ //assertTrue(element instanceof PsiJavaFile);
+ PsiElement refElement = element.findElementAt(usages.get(0).getRangeInElement().getStartOffset()).getParent();
+ assertTrue(refElement instanceof PsiLiteralExpression);
+ assertEquals("xx.yy", ((PsiLiteralExpression)refElement).getValue());
+
+ VirtualFile file = mySourceDirs[0].findFileByRelativePath("x/dd.properties");
+ PropertiesFile propertiesFile = (PropertiesFile)PsiManager.getInstance(myProject).findFile(file);
+ element = usages.get(1).getElement();
+ //assertTrue(element instanceof PropertiesFile);
+ refElement = element.findElementAt(usages.get(1).getRangeInElement().getStartOffset()).getParent();
+ assertTrue(refElement instanceof IProperty);
+ assertSame(propertiesFile.findPropertyByKey("xx.yy"), refElement);
+ }
+
+ public void testFindInClassHierarchy() throws Exception {
+ initProject("findInClassHierarchy", "src");
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("instanceof");
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+ final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
+ final PsiClass baseClass = facade.findClass("A", GlobalSearchScope.allScope(getProject()));
+ final PsiClass implClass = facade.findClass("AImpl", GlobalSearchScope.allScope(getProject()));
+ findModel.setCustomScope(new LocalSearchScope(new PsiElement[]{baseClass, implClass}));
+
+ List usages = findUsages(findModel);
+ assertEquals(2, usages.size());
+ }
+
+ public void testReplaceRegexp() throws Throwable {
+ FindManager findManager = FindManager.getInstance(myProject);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("bug(?=here)");
+ findModel.setStringToReplace("x$0y");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+ findModel.setRegularExpressions(true);
+ findModel.setPromptOnReplace(false);
+
+ findManager.setFindNextModel(null);
+ findManager.getFindInFileModel().copyFrom(findModel);
+
+ String text = "bughere\n" + "bughere";
+ configureByText(FileTypes.PLAIN_TEXT, text);
+ boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
+ assertTrue(succ);
+
+ assertEquals("xbugyhere\n" + "xbugyhere", getEditor().getDocument().getText());
+ }
+ public void testReplaceRegexp1() throws Throwable {
+ FindManager findManager = FindManager.getInstance(myProject);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("bug(?=here)");
+ findModel.setStringToReplace("$0");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+ findModel.setRegularExpressions(true);
+ findModel.setPromptOnReplace(false);
+
+ findManager.setFindNextModel(null);
+ findManager.getFindInFileModel().copyFrom(findModel);
+
+ String text = "bughere\n" + "bughere";
+ configureByText(FileTypes.PLAIN_TEXT, text);
+ boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
+ assertTrue(succ);
+
+ assertEquals(text, getEditor().getDocument().getText());
+ }
+
+ public void testReplaceRegexpWithNewLine() throws Throwable {
+ FindManager findManager = FindManager.getInstance(myProject);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("xxx");
+ findModel.setStringToReplace("xxx\\n");
+ findModel.setWholeWordsOnly(false);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+ findModel.setRegularExpressions(true);
+ findModel.setPromptOnReplace(false);
+
+ findManager.setFindNextModel(null);
+ findManager.getFindInFileModel().copyFrom(findModel);
+
+ String text = "xxx";
+ configureByText(FileTypes.PLAIN_TEXT, text);
+ boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
+ assertTrue(succ);
+
+ assertEquals(text+"\n", getEditor().getDocument().getText());
+ }
+
+ private void initProject(String folderName, final String... sourceDirs) throws Exception{
+ final String testDir = JavaTestUtil.getJavaTestDataPath() + "/find/" + folderName;
+ ApplicationManager.getApplication().runWriteAction(new Runnable(){
+ @Override
+ public void run(){
+ try{
+ mySourceDirs = new VirtualFile[sourceDirs.length];
+ for (int i = 0; i < sourceDirs.length; i++){
+ String sourceDir = sourceDirs[i];
+ mySourceDirs[i] = LocalFileSystem.getInstance().refreshAndFindFileByPath(new File(testDir + File.separatorChar + sourceDir).getCanonicalPath().replace(File.separatorChar, '/'));
+ }
+ VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(new File(testDir).getCanonicalPath().replace(File.separatorChar, '/'));
+
+ final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
+ final ModifiableRootModel rootModel = rootManager.getModifiableModel();
+ rootModel.clear();
+ // configure source and output path
+ final ContentEntry contentEntry = rootModel.addContentEntry(projectDir);
+ for (VirtualFile sourceDir : mySourceDirs) {
+ contentEntry.addSourceFolder(sourceDir, false);
+ }
+
+ Sdk jdk = JavaSdkImpl.getMockJdk17();
+ rootModel.setSdk(jdk);
+
+ rootModel.commit();
+ }
+ catch (Exception e){
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
+
+ public void testReplaceAll() throws Throwable {
+ FindManager findManager = FindManager.getInstance(myProject);
+
+ FindModel findModel = new FindModel();
+ String toFind = "xxx";
+ String toReplace = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+ findModel.setStringToFind(toFind);
+ findModel.setStringToReplace(toReplace);
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(false);
+ findModel.setProjectScope(true);
+ findModel.setRegularExpressions(false);
+ findModel.setPromptOnReplace(false);
+
+ findManager.setFindNextModel(null);
+ findManager.getFindInFileModel().copyFrom(findModel);
+
+ String text = StringUtil.repeat(toFind + "\n",6);
+ configureByText(FileTypes.PLAIN_TEXT, text);
+
+ List usages = FindUtil.findAll(getProject(), myEditor, findModel);
+ for (Usage usage : usages) {
+ ReplaceInProjectManager.getInstance(getProject()).doReplace(usage, findModel, Collections.emptySet());
+ }
+ String newText = StringUtil.repeat(toReplace + "\n",6);
+ assertEquals(newText, getEditor().getDocument().getText());
+ }
+
+ public void testFindInFileUnderLibraryUnderProject() throws Exception {
+ initProject("libUnderProject", "src");
+ PsiTestUtil.addLibrary(myModule, "lib", JavaTestUtil.getJavaTestDataPath() + "/find/libUnderProject/lib", new String[]{""}, ArrayUtil.EMPTY_STRING_ARRAY);
+
+ FindModel findModel = new FindModel();
+ findModel.setStringToFind("TargetWord");
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+
+ findModel.setWholeWordsOnly(false);
+ assertSize(2, findUsages(findModel));
+
+ /* todo
+ findModel.setWholeWordsOnly(true);
+ assertSize(2, findUsages(findModel));
+ */
+ }
+
+ public void testLocalScopeSearchPerformance() throws Exception {
+ final int count = 3000;
+ TempDirTestFixture fixture = new LightTempDirTestFixtureImpl();
+ fixture.setUp();
+
+ try {
+ String sampleText = StringUtil.repeat("zoo TargetWord foo bar goo\n", count);
+ for (int i = 0; i < count; i++) {
+ fixture.createFile("a" + i + ".txt", sampleText);
+ }
+ PsiTestUtil.addSourceContentToRoots(myModule, fixture.getFile(""));
+
+ VirtualFile file = fixture.createFile("target.txt", sampleText);
+ PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
+ final FindModel findModel = new FindModel();
+ findModel.setStringToFind("TargetWord");
+ findModel.setWholeWordsOnly(true);
+ findModel.setFromCursor(false);
+ findModel.setGlobal(true);
+ findModel.setMultipleFiles(true);
+
+ ThrowableRunnable test = new ThrowableRunnable() {
+ @Override
+ public void run() throws Throwable {
+ assertSize(count, findUsages(findModel));
+ }
+ };
+
+ findModel.setCustomScope(GlobalSearchScope.fileScope(psiFile));
+ PlatformTestUtil.startPerformanceTest("slow", 500, test).attempts(1).cpuBound().usesAllCPUCores().assertTiming();
+
+ findModel.setCustomScope(new LocalSearchScope(psiFile));
+ PlatformTestUtil.startPerformanceTest("slow", 500, test).attempts(1).cpuBound().usesAllCPUCores().assertTiming();
+ }
+ finally {
+ fixture.tearDown();
+ }
+ }
+
+
+}
diff --git a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveClassTest.java b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveClassTest.java
index 8eab910851f0..93614eae30b7 100644
--- a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveClassTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveClassTest.java
@@ -170,7 +170,7 @@ public class ResolveClassTest extends ResolveTestCase {
PsiReference ref = configure();
long start = System.currentTimeMillis();
assertNull(ref.resolve());
- PlatformTestUtil.assertTiming("exponent?", 20000, System.currentTimeMillis() - start);
+ PlatformTestUtil.assertTiming("exponent?", 200, System.currentTimeMillis() - start);
}
public void testStaticImportNetwork() throws Exception {
diff --git a/jps/jps-builders/src/org/jetbrains/jps/api/AsyncTaskExecutor.java b/jps/jps-builders/src/org/jetbrains/jps/api/AsyncTaskExecutor.java
deleted file mode 100644
index 745834c7de69..000000000000
--- a/jps/jps-builders/src/org/jetbrains/jps/api/AsyncTaskExecutor.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.jetbrains.jps.api;
-
-/**
-* @author Eugene Zhuravlev
-* Date: 2/28/12
-*/
-public interface AsyncTaskExecutor {
- AsyncTaskExecutor DEFAULT = new AsyncTaskExecutor() {
- @Override
- public void submit(Runnable runnable) {
- new Thread(runnable).start();
- }
- };
-
- void submit(Runnable runnable);
-}
diff --git a/jps/jps-builders/src/org/jetbrains/jps/api/SequentialTaskExecutor.java b/jps/jps-builders/src/org/jetbrains/jps/api/SequentialTaskExecutor.java
index de47b287cca2..4bc851c017d9 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/api/SequentialTaskExecutor.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/api/SequentialTaskExecutor.java
@@ -1,6 +1,7 @@
package org.jetbrains.jps.api;
import java.util.Queue;
+import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RunnableFuture;
@@ -11,7 +12,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Date: 9/24/11
*/
public class SequentialTaskExecutor {
- private final AsyncTaskExecutor myExecutor;
+ private final Executor myExecutor;
private final Queue myTaskQueue = new LinkedBlockingQueue();
private final AtomicBoolean myInProgress = new AtomicBoolean(false);
private final Runnable USER_TASK_RUNNER = new Runnable() {
@@ -31,7 +32,7 @@ public class SequentialTaskExecutor {
}
};
- public SequentialTaskExecutor(AsyncTaskExecutor executor) {
+ public SequentialTaskExecutor(Executor executor) {
myExecutor = executor;
}
@@ -48,7 +49,7 @@ public class SequentialTaskExecutor {
private void processQueue() {
if (!myInProgress.getAndSet(true)) {
- myExecutor.submit(USER_TASK_RUNNER);
+ myExecutor.execute(USER_TASK_RUNNER);
}
}
diff --git a/jps/jps-builders/src/org/jetbrains/jps/api/SharedThreadPool.java b/jps/jps-builders/src/org/jetbrains/jps/api/SharedThreadPool.java
index 508abe015b3f..da26e58c6ff0 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/api/SharedThreadPool.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/api/SharedThreadPool.java
@@ -9,10 +9,4 @@ import java.util.concurrent.Executors;
*/
public class SharedThreadPool {
public static final ExecutorService INSTANCE = Executors.newCachedThreadPool();
- public static final AsyncTaskExecutor ASYNC_EXEC = new AsyncTaskExecutor() {
- @Override
- public void submit(Runnable runnable) {
- INSTANCE.submit(runnable);
- }
- };
}
diff --git a/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java b/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java
index 72cfb5850034..2f263acb40b0 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/client/CompileServerClient.java
@@ -6,7 +6,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.api.*;
-import java.util.*;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -20,7 +24,7 @@ public class CompileServerClient extends SimpleProtobufClient myPingFuture;
private final long myServerPingInterval;
- public CompileServerClient(long serverPingInterval, final AsyncTaskExecutor asyncExec) {
+ public CompileServerClient(long serverPingInterval, final Executor asyncExec) {
super(JpsRemoteProto.Message.getDefaultInstance(), asyncExec, new UUIDGetter() {
@NotNull
public UUID getSessionUUID(@NotNull MessageEvent e) {
diff --git a/jps/jps-builders/src/org/jetbrains/jps/client/ProtobufClientMessageHandler.java b/jps/jps-builders/src/org/jetbrains/jps/client/ProtobufClientMessageHandler.java
index 9c6477f29512..ecb25bd5ec45 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/client/ProtobufClientMessageHandler.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/client/ProtobufClientMessageHandler.java
@@ -6,12 +6,12 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jps.api.AsyncTaskExecutor;
import org.jetbrains.jps.api.RequestFuture;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
/**
* @author Eugene Zhuravlev
@@ -22,9 +22,9 @@ final class ProtobufClientMessageHandler exte
@NotNull
private final UUIDGetter myUuidGetter;
private final SimpleProtobufClient myClient;
- private final AsyncTaskExecutor myAsyncExec;
+ private final Executor myAsyncExec;
- public ProtobufClientMessageHandler(@NotNull UUIDGetter uuidGetter, SimpleProtobufClient client, AsyncTaskExecutor asyncExec) {
+ public ProtobufClientMessageHandler(@NotNull UUIDGetter uuidGetter, SimpleProtobufClient client, Executor asyncExec) {
myUuidGetter = uuidGetter;
myClient = client;
myAsyncExec = asyncExec;
@@ -92,7 +92,7 @@ final class ProtobufClientMessageHandler exte
}
finally {
// make sure the client is in disconnected state
- myAsyncExec.submit(new Runnable() {
+ myAsyncExec.execute(new Runnable() {
@Override
public void run() {
myClient.disconnect();
diff --git a/jps/jps-builders/src/org/jetbrains/jps/client/SimpleProtobufClient.java b/jps/jps-builders/src/org/jetbrains/jps/client/SimpleProtobufClient.java
index 19544249f0c5..8260ff486704 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/client/SimpleProtobufClient.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/client/SimpleProtobufClient.java
@@ -10,13 +10,11 @@ import org.jboss.netty.handler.codec.protobuf.ProtobufEncoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jps.api.AsyncTaskExecutor;
import org.jetbrains.jps.api.RequestFuture;
import java.net.InetSocketAddress;
import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -25,7 +23,6 @@ import java.util.concurrent.atomic.AtomicReference;
*/
public class SimpleProtobufClient {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.client.SimpleProtobufClient");
- private final ExecutorService ourExecutor = Executors.newCachedThreadPool();
private static enum State {
DISCONNECTED, CONNECTING, CONNECTED, DISCONNECTING
@@ -37,9 +34,9 @@ public class SimpleProtobufClient {
protected volatile ChannelFuture myConnectFuture;
private final ProtobufClientMessageHandler myMessageHandler;
- public SimpleProtobufClient(final MessageLite msgDefaultInstance, final AsyncTaskExecutor asyncExec, final UUIDGetter uuidGetter) {
+ public SimpleProtobufClient(final MessageLite msgDefaultInstance, final Executor asyncExec, final UUIDGetter uuidGetter) {
myMessageHandler = new ProtobufClientMessageHandler(uuidGetter, this, asyncExec);
- myChannelFactory = new NioClientSocketChannelFactory(ourExecutor, ourExecutor, 1);
+ myChannelFactory = new NioClientSocketChannelFactory(asyncExec, asyncExec, 1);
myPipelineFactory = new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
@@ -117,13 +114,8 @@ public class SimpleProtobufClient {
catch (Throwable e) {
LOG.error(e);
}
- try {
- final ChannelFuture closeFuture = future.getChannel().close();
- closeFuture.awaitUninterruptibly();
- }
- finally {
- myChannelFactory.releaseExternalResources();
- }
+ final ChannelFuture closeFuture = future.getChannel().close();
+ closeFuture.awaitUninterruptibly();
}
}
finally {
diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java
index a84911754c50..4eb3dfa3f5ac 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java
@@ -7,13 +7,13 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.io.MappingFailedException;
import com.intellij.util.io.PersistentEnumerator;
-import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.*;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.api.GlobalOptions;
import org.jetbrains.jps.api.RequestFuture;
import org.jetbrains.jps.api.SharedThreadPool;
import org.jetbrains.jps.incremental.java.ExternalJavacDescriptor;
+import org.jetbrains.jps.incremental.java.JavaBuilder;
import org.jetbrains.jps.incremental.java.JavaBuilderLogger;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.messages.CompilerMessage;
@@ -164,7 +164,7 @@ public class IncProjectBuilder {
return context;
}
- private static void flushContext(@Nullable CompileContext context) {
+ private static void flushContext(CompileContext context) {
if (context != null) {
context.getTimestampStorage().force();
context.getDataManager().flush(false);
@@ -181,16 +181,14 @@ public class IncProjectBuilder {
}
ExternalJavacDescriptor.KEY.set(context, null);
}
- if (context == null || context.getBuilderParameter(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null) {
- cleanupJavacNameTable();
- }
+ cleanupJavacNameTable();
}
private static boolean ourClenupFailed = false;
private static void cleanupJavacNameTable() {
try {
- if (!ourClenupFailed) {
+ if (JavaBuilder.USE_EMBEDDED_JAVAC && !ourClenupFailed) {
final Field freelistField = Class.forName("com.sun.tools.javac.util.Name$Table").getDeclaredField("freelist");
freelistField.setAccessible(true);
freelistField.set(null, com.sun.tools.javac.util.List.nil());
diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java
index 14e158ff66a4..64d96061c30c 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java
@@ -56,6 +56,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
private static final String FORMS_BUILDER_NAME = "forms";
private static final String JAVA_EXTENSION = ".java";
private static final String FORM_EXTENSION = ".form";
+ public static final boolean USE_EMBEDDED_JAVAC = System.getProperty(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null;
public static final FileFilter JAVA_SOURCES_FILTER = new FileFilter() {
public boolean accept(File file) {
@@ -385,7 +386,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
final ClassProcessingConsumer classesConsumer = new ClassProcessingConsumer(context, outputSink);
try {
final boolean rc;
- if (context.getBuilderParameter(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null) {
+ if (USE_EMBEDDED_JAVAC) {
rc = JavacMain.compile(
options, files, classpath, platformCp, sourcePath, outs, diagnosticSink, classesConsumer, context.getCancelStatus()
);
diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerClient.java b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerClient.java
index 136f07ce4798..c32e27d5fe5e 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerClient.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerClient.java
@@ -17,7 +17,7 @@ import java.util.*;
public class JavacServerClient extends SimpleProtobufClient{
public JavacServerClient() {
- super(JavacRemoteProto.Message.getDefaultInstance(), SharedThreadPool.ASYNC_EXEC, new UUIDGetter() {
+ super(JavacRemoteProto.Message.getDefaultInstance(), SharedThreadPool.INSTANCE, new UUIDGetter() {
@NotNull
public UUID getSessionUUID(@NotNull MessageEvent e) {
final JavacRemoteProto.Message message = (JavacRemoteProto.Message)e.getMessage();
diff --git a/jps/jps-builders/src/org/jetbrains/jps/server/Server.java b/jps/jps-builders/src/org/jetbrains/jps/server/Server.java
index baacea57e79d..9987b88e0550 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/server/Server.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/server/Server.java
@@ -1,6 +1,7 @@
package org.jetbrains.jps.server;
//import com.intellij.openapi.diagnostic.Logger;
+
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ConcurrencyUtil;
import org.apache.log4j.Level;
@@ -17,17 +18,13 @@ import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jps.api.AsyncTaskExecutor;
import org.jetbrains.jps.api.GlobalOptions;
import org.jetbrains.jps.api.JpsRemoteProto;
import org.jetbrains.jps.incremental.Utils;
import java.io.File;
import java.net.InetSocketAddress;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
/**
* @author Eugene Zhuravlev
@@ -70,21 +67,21 @@ public class Server {
private final ScheduledExecutorService myScheduler;
private final ServerMessageHandler myMessageHandler;
- public Server(File systemDir, boolean cachesInMemory) {
+ public Server(File systemDir) {
Utils.setSystemRoot(systemDir);
final ExecutorService threadPool = Executors.newCachedThreadPool();
myScheduler = ConcurrencyUtil.newSingleScheduledThreadExecutor("Client activity checker", Thread.MIN_PRIORITY);
myBuildsExecutor = Executors.newFixedThreadPool(MAX_SIMULTANEOUS_BUILD_SESSIONS);
myChannelFactory = new NioServerSocketChannelFactory(threadPool, threadPool, 1);
final ChannelRegistrar channelRegistrar = new ChannelRegistrar();
- myMessageHandler = new ServerMessageHandler(this, new AsyncTaskExecutor() {
+ myMessageHandler = new ServerMessageHandler(this, new Executor() {
@Override
- public void submit(final Runnable runnable) {
+ public void execute(final Runnable command) {
myBuildsExecutor.submit(new Runnable() {
@Override
public void run() {
try {
- runnable.run();
+ command.run();
}
finally {
Thread.interrupted(); // clear interrupted status before returning to pull
@@ -105,17 +102,6 @@ public class Server {
);
}
};
- ServerState.getInstance().setKeepTempCachesInMemory(cachesInMemory);
- Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook thread") {
- public void run() {
- try {
- myMessageHandler.cancelAllBuildsAndClearState();
- }
- finally {
- Server.this.stop();
- }
- }
- });
}
public void start(int listenPort) {
@@ -192,10 +178,6 @@ public class Server {
myLastPingTime = System.currentTimeMillis();
}
- public boolean isStopped() {
- return myScheduler.isShutdown();
- }
-
public static void main(String[] args) {
try {
int port = DEFAULT_SERVER_PORT;
@@ -212,10 +194,21 @@ public class Server {
systemDir = new File(args[1]);
}
- final Server server = new Server(systemDir, System.getProperty(GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION) != null);
+ final Server server = new Server(systemDir);
+ Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook thread") {
+ public void run() {
+ try {
+ server.myMessageHandler.cancelAllBuildsAndClearState();
+ }
+ finally {
+ server.stop();
+ }
+ }
+ });
initLoggers();
server.start(port);
+ ServerState.getInstance().setKeepTempCachesInMemory(System.getProperty(GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION) != null);
System.out.println("Server classpath: " + System.getProperty("java.class.path"));
System.err.println(SERVER_SUCCESS_START_MESSAGE + port);
diff --git a/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java b/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java
index 49fbfc7dcb26..c2f9fa3802cb 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java
@@ -15,6 +15,7 @@ import java.io.File;
import java.io.PrintStream;
import java.util.*;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
import java.util.concurrent.RunnableFuture;
/**
@@ -27,9 +28,9 @@ class ServerMessageHandler extends SimpleChannelHandler {
private final Map myTaskExecutors = new HashMap();
private final List> myBuildsInProgress = Collections.synchronizedList(new LinkedList>());
private final Server myServer;
- private final AsyncTaskExecutor myAsyncExecutor;
+ private final Executor myAsyncExecutor;
- public ServerMessageHandler(Server server, final AsyncTaskExecutor asyncExecutor) {
+ public ServerMessageHandler(Server server, final Executor asyncExecutor) {
myServer = server;
myAsyncExecutor = asyncExecutor;
}
@@ -80,13 +81,14 @@ class ServerMessageHandler extends SimpleChannelHandler {
new GlobalLibrary(library.getName(), library.getPathList())
);
}
- final String globalEncoding = setupCommand.isInitialized()? setupCommand.getGlobalEncoding() : null;
- facade.setGlobals(libs, pathVars, globalEncoding, setupCommand.getIgnoredFilesPatterns());
+ final String globalEncoding = setupCommand.hasGlobalEncoding()? setupCommand.getGlobalEncoding() : null;
+ final String ignoredPatterns = setupCommand.hasIgnoredFilesPatterns()? setupCommand.getIgnoredFilesPatterns() : null;
+ facade.setGlobals(libs, pathVars, globalEncoding, ignoredPatterns);
reply = ProtoUtil.toMessage(sessionId, ProtoUtil.createCommandCompletedEvent(null));
break;
case SHUTDOWN_COMMAND :
- myAsyncExecutor.submit(new Runnable() {
+ myAsyncExecutor.execute(new Runnable() {
public void run() {
try {
cancelAllBuildsAndClearState();
diff --git a/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java b/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java
index 30ae9c556c1e..d9ee61e73f45 100644
--- a/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java
+++ b/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java
@@ -45,7 +45,7 @@ class ServerState {
private final List myGlobalLibraries = new ArrayList();
private volatile String myGlobalEncoding = null;
private volatile boolean myKeepTempCachesInMemory = false;
- private String myIgnoredFilesPatterns;
+ private volatile String myIgnoredFilesPatterns;
public void setGlobals(List libs, Map pathVars, String globalEncoding, String ignoredFilesPatterns) {
synchronized (myConfigurationLock) {
@@ -53,7 +53,7 @@ class ServerState {
myGlobalLibraries.addAll(libs);
myPathVariables.putAll(pathVars);
myGlobalEncoding = StringUtil.isEmpty(globalEncoding)? null : globalEncoding;
- myIgnoredFilesPatterns = ignoredFilesPatterns;
+ myIgnoredFilesPatterns = StringUtil.isEmpty(ignoredFilesPatterns)? "" : ignoredFilesPatterns;
}
}
diff --git a/lib/miglayout-swing.jar b/lib/miglayout-swing.jar
new file mode 100644
index 000000000000..81b75f3e6bd3
Binary files /dev/null and b/lib/miglayout-swing.jar differ
diff --git a/lib/netty-3.3.1.Final.jar b/lib/netty-3.3.1.Final.jar
deleted file mode 100644
index a107dc9b3874..000000000000
Binary files a/lib/netty-3.3.1.Final.jar and /dev/null differ
diff --git a/lib/netty-3.4.0.Final.jar b/lib/netty-3.4.0.Final.jar
new file mode 100644
index 000000000000..eea4d1080ea8
Binary files /dev/null and b/lib/netty-3.4.0.Final.jar differ
diff --git a/lib/required_for_dist.txt b/lib/required_for_dist.txt
index a4e372026865..67d57ba064e6 100644
--- a/lib/required_for_dist.txt
+++ b/lib/required_for_dist.txt
@@ -28,6 +28,7 @@ log4j.jar
jgoodies-common-1.2.1.jar
jgoodies-looks-2.4.2.jar
microba.jar
+miglayout-swing.jar
nanoxml-2.2.3.jar
nekohtml-1.9.14.jar
org.eclipse.jdt.core_3.5.2.v_981_R35x.jar
@@ -45,5 +46,5 @@ xmlrpc-2.0.jar
xpp3-1.1.4-min.jar
xstream.jar
swingx-core-1.6.2.jar
-netty-3.3.1.Final.jar
+netty-3.4.0.Final.jar
protobuf-2.4.1.jar
diff --git a/lib/src/miglayout-sources.jar b/lib/src/miglayout-sources.jar
new file mode 100644
index 000000000000..328016e31f74
Binary files /dev/null and b/lib/src/miglayout-sources.jar differ
diff --git a/lib/src/netty-3.3.1.Final-sources.jar b/lib/src/netty-3.4.0.Final-sources.jar
similarity index 58%
rename from lib/src/netty-3.3.1.Final-sources.jar
rename to lib/src/netty-3.4.0.Final-sources.jar
index a29b723be1d7..55fb6aa0b518 100644
Binary files a/lib/src/netty-3.3.1.Final-sources.jar and b/lib/src/netty-3.4.0.Final-sources.jar differ
diff --git a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java
index b1f8120f1465..fad6015d02f0 100644
--- a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java
+++ b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java
@@ -16,15 +16,28 @@
package com.intellij.execution;
+import com.intellij.openapi.util.Key;
import org.jdom.Element;
+import org.jetbrains.annotations.NotNull;
/**
* @author Eugene Zhuravlev
* Date: May 18, 2009
*/
-public abstract class BeforeRunTask implements Cloneable{
+public abstract class BeforeRunTask implements Cloneable {
+ @NotNull
+ protected final Key myProviderId;
private boolean myIsEnabled;
+ protected BeforeRunTask(@NotNull Key providerId) {
+ myProviderId = providerId;
+ }
+
+ @NotNull
+ public final Key getProviderId() {
+ return myProviderId;
+ }
+
public boolean isEnabled() {
return myIsEnabled;
}
@@ -59,13 +72,13 @@ public abstract class BeforeRunTask implements Cloneable{
if (o == null || getClass() != o.getClass()) return false;
BeforeRunTask that = (BeforeRunTask)o;
-
+ if (myProviderId != that.myProviderId) return false;
if (myIsEnabled != that.myIsEnabled) return false;
return true;
}
public int hashCode() {
- return (myIsEnabled ? 1 : 0);
+ return 31 * myProviderId.hashCode() + (myIsEnabled ? 1 : 0);
}
}
diff --git a/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java b/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java
index 2085bcadf15c..eec2d04f2d39 100644
--- a/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java
+++ b/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java
@@ -25,9 +25,13 @@ package com.intellij.execution;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.Nullable;
+import javax.swing.*;
+
public abstract class BeforeRunTaskProvider {
public static final ExtensionPointName> EXTENSION_POINT_NAME = new ExtensionPointName>("com.intellij.stepsBeforeRunProvider");
@@ -35,9 +39,22 @@ public abstract class BeforeRunTaskProvider {
public abstract Key getId();
- public abstract String getDescription(final RunConfiguration runConfiguration, T task);
+ public abstract String getName();
- public abstract boolean hasConfigurationButton();
+ @Nullable
+ public Icon getIcon() {
+ return null;
+ };
+
+ public abstract String getDescription(T task);
+
+
+ @Nullable
+ public Icon getTaskIcon(T task) {
+ return null;
+ }
+
+ public abstract boolean isConfigurable();
/**
* @return 'before run' task for the configuration or null, if the task from this provider is not applicable to the specified configuration
@@ -50,8 +67,18 @@ public abstract class BeforeRunTaskProvider {
*/
public abstract boolean configureTask(final RunConfiguration runConfiguration, T task);
+ public abstract boolean canExecuteTask(RunConfiguration configuration, T task);
+
public abstract boolean executeTask(DataContext context, RunConfiguration configuration, T task);
+ /**
+ *
+ * @return true if at most one task may be configured
+ */
+ public boolean isSingleton() {
+ return false;
+ }
+
/**
* Get runner id that current run is about to be made by
* @param context data context that is passed to {@link #executeTask(com.intellij.openapi.actionSystem.DataContext, com.intellij.execution.configurations.RunConfiguration, BeforeRunTask)}
@@ -61,4 +88,14 @@ public abstract class BeforeRunTaskProvider {
public static String getRunnerId(DataContext context) {
return (String)context.getData(RUNNER_ID);
}
+
+ @Nullable
+ public static BeforeRunTaskProvider getProvider(Project project, Key key) {
+ BeforeRunTaskProvider[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, project);
+ for (BeforeRunTaskProvider provider : providers) {
+ if (provider.getId() == key)
+ return (BeforeRunTaskProvider)provider;
+ }
+ return null;
+ }
}
\ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java
index 53791bb8dec8..92a23259e39b 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java
@@ -130,7 +130,8 @@ class DaemonListeners implements Disposable {
@Override
public void caretPositionChanged(CaretEvent e) {
Editor editor = e.getEditor();
- if (!editor.getComponent().isShowing() || !worthBothering(editor.getDocument(), editor.getProject())) {
+ if ((!editor.getComponent().isShowing() && !ApplicationManager.getApplication().isUnitTestMode()) ||
+ !worthBothering(editor.getDocument(), editor.getProject())) {
return; //no need to stop daemon if something happened in the console
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandJavadocsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandDocCommentsHandler.java
similarity index 88%
rename from java/java-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandJavadocsHandler.java
rename to platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandDocCommentsHandler.java
index 91b30142ec00..199acc9159bc 100644
--- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandJavadocsHandler.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseExpandDocCommentsHandler.java
@@ -20,16 +20,16 @@ import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiDocCommentBase;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
-import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.NotNull;
-public class CollapseExpandJavadocsHandler implements CodeInsightActionHandler {
+public class CollapseExpandDocCommentsHandler implements CodeInsightActionHandler {
private final boolean myExpand;
- public CollapseExpandJavadocsHandler(boolean isExpand) {
+ public CollapseExpandDocCommentsHandler(boolean isExpand) {
myExpand = isExpand;
}
@@ -45,7 +45,7 @@ public class CollapseExpandJavadocsHandler implements CodeInsightActionHandler {
public void run() {
for (FoldRegion region : allFoldRegions) {
PsiElement element = EditorFoldingInfo.get(editor).getPsiElement(region);
- if (element instanceof PsiDocComment) {
+ if (element instanceof PsiDocCommentBase) {
region.setExpanded(myExpand);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandJavadocsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseDocCommentsAction.java
similarity index 80%
rename from java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandJavadocsAction.java
rename to platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseDocCommentsAction.java
index 95c87f3d6db9..38af70944d57 100644
--- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandJavadocsAction.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseDocCommentsAction.java
@@ -17,11 +17,11 @@ package com.intellij.codeInsight.folding.impl.actions;
import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.codeInsight.actions.BaseCodeInsightAction;
-import com.intellij.codeInsight.folding.impl.CollapseExpandJavadocsHandler;
+import com.intellij.codeInsight.folding.impl.CollapseExpandDocCommentsHandler;
-public class ExpandJavadocsAction extends BaseCodeInsightAction{
+public class CollapseDocCommentsAction extends BaseCodeInsightAction{
@Override
protected CodeInsightActionHandler getHandler(){
- return new CollapseExpandJavadocsHandler(true);
+ return new CollapseExpandDocCommentsHandler(false);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseJavadocsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandDocCommentsAction.java
similarity index 80%
rename from java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseJavadocsAction.java
rename to platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandDocCommentsAction.java
index a5bee9a87c8e..6d2d95ff9ee4 100644
--- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseJavadocsAction.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandDocCommentsAction.java
@@ -17,11 +17,11 @@ package com.intellij.codeInsight.folding.impl.actions;
import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.codeInsight.actions.BaseCodeInsightAction;
-import com.intellij.codeInsight.folding.impl.CollapseExpandJavadocsHandler;
+import com.intellij.codeInsight.folding.impl.CollapseExpandDocCommentsHandler;
-public class CollapseJavadocsAction extends BaseCodeInsightAction{
+public class ExpandDocCommentsAction extends BaseCodeInsightAction{
@Override
protected CodeInsightActionHandler getHandler(){
- return new CollapseExpandJavadocsHandler(false);
+ return new CollapseExpandDocCommentsHandler(true);
}
}
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java
index 8097af612960..9071543e5984 100644
--- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java
+++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java
@@ -87,6 +87,13 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
if (myIsDeleted) return false;
return ApplicationManager.getApplication().runReadAction(new Computable() {
public Boolean compute() {
+
+ final PsiFile file = myID.getContainingFile();
+ //no need to check resolve in offline mode
+ if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
+ return file != null && file.isPhysical();
+ }
+
final PsiElement element = getElement();
return element != null && element.isPhysical();
}
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
index e7469ec93ff3..e5b1a24a19fa 100644
--- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
+++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
@@ -43,6 +43,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
@@ -210,8 +211,8 @@ public class RefManagerImpl extends RefManager {
if (refEntity instanceof RefElement) {
final RefElement refElement = (RefElement)refEntity;
- PsiElement psiElement = refElement.getElement();
- PsiFile psiFile = psiElement.getContainingFile();
+ final SmartPsiElementPointer pointer = refElement.getPointer();
+ PsiFile psiFile = pointer.getContainingFile();
Element fileElement = new Element("file");
Element lineElement = new Element("line");
@@ -220,9 +221,10 @@ public class RefManagerImpl extends RefManager {
fileElement.addContent(virtualFile.getUrl());
if (actualLine == -1) {
- final Document document = PsiDocumentManager.getInstance(refElement.getRefManager().getProject()).getDocument(psiFile);
+ final Document document = PsiDocumentManager.getInstance(pointer.getProject()).getDocument(psiFile);
LOG.assertTrue(document != null);
- lineElement.addContent(String.valueOf(document.getLineNumber(psiElement.getTextOffset()) + 1));
+ final Segment range = pointer.getRange();
+ lineElement.addContent(String.valueOf(range != null ? (document.getLineNumber(range.getStartOffset()) + 1) : -1));
}
else {
lineElement.addContent(String.valueOf(actualLine));
diff --git a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java
index b221a829268b..714bc7a2317f 100644
--- a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java
+++ b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collection;
-import java.util.Map;
+import java.util.List;
/**
* Manages {@link RunConfiguration}s.
@@ -55,20 +55,23 @@ public abstract class RunManagerEx extends RunManager {
@NotNull
public abstract RunnerAndConfigurationSettings createConfiguration(String name, ConfigurationFactory type);
- public abstract void addConfiguration(RunnerAndConfigurationSettings settings, boolean isShared, Map, BeforeRunTask> tasks);
+ public abstract void addConfiguration(RunnerAndConfigurationSettings settings, boolean isShared, List tasks);
public abstract void addConfiguration(final RunnerAndConfigurationSettings settings, final boolean isShared);
public abstract boolean isConfigurationShared(RunnerAndConfigurationSettings settings);
@NotNull
- public abstract Map, BeforeRunTask> getBeforeRunTasks(RunConfiguration settings);
-
- @Nullable
- public abstract T getBeforeRunTask(RunConfiguration settings, Key taskProviderID);
+ public abstract List getBeforeRunTasks(RunConfiguration settings);
@NotNull
- public abstract Collection getBeforeRunTasks(Key taskProviderID, boolean includeOnlyActiveTasks);
+ public abstract List getBeforeRunTasks(RunConfiguration settings, boolean includeOnlyActiveTasks);
+
+ @NotNull
+ public abstract List getBeforeRunTasks(RunConfiguration settings, Key taskProviderID);
+
+ @NotNull
+ public abstract List getBeforeRunTasks(Key taskProviderID, boolean includeOnlyActiveTasks);
public abstract RunnerAndConfigurationSettings findConfigurationByName(@Nullable final String name);
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java b/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java
index 638759607a8a..fe59622cc785 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java
+++ b/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java
@@ -39,9 +39,8 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Set;
+import java.util.*;
+import java.util.List;
public abstract class BaseExecuteBeforeRunDialog extends DialogWrapper {
@@ -180,8 +179,12 @@ public abstract class BaseExecuteBeforeRunDialog extend
}
private boolean isConfigurationAssigned(RunConfiguration configuration) {
- final T task = RunManagerEx.getInstanceEx(myProject).getBeforeRunTask(configuration, getTaskID());
- return task != null && isRunning(task);
+ final java.util.List tasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(configuration, getTaskID());
+ for (T task : tasks) {
+ if (isRunning(task))
+ return true;
+ }
+ return false;
}
protected void doOKAction() {
@@ -215,20 +218,24 @@ public abstract class BaseExecuteBeforeRunDialog extend
protected abstract boolean isRunning(T task);
private void update(RunConfiguration config, boolean enabled, RunManagerImpl runManager) {
- T task = runManager.getBeforeRunTask(config, getTaskID());
- if (task == null) return;
-
+ List tasks = runManager.getBeforeRunTasks(config);
+ BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, getTaskID());
+ if (provider == null)
+ return;
+ T task = provider.createTask(config);
+ update(task);
+ task.setEnabled(true);
if (enabled) {
- task.setEnabled(true);
- update(task);
+ if (!tasks.contains(task)) {
+ tasks.add(task);
+ }
}
else {
- if (isRunning(task)) {
- task.setEnabled(false);
- clear(task);
+ if (tasks.contains(task)) {
+ tasks.remove(task);
}
- // do not change the task otherwise
}
+ runManager.setBeforeRunTasks(config, tasks);
}
protected abstract void update(T task);
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java b/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java
new file mode 100644
index 000000000000..d9a797a8cde1
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.execution.impl;
+
+import com.intellij.execution.*;
+import com.intellij.execution.configurations.RunConfiguration;
+import com.intellij.execution.configurations.UnknownRunConfiguration;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.DefaultActionGroup;
+import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.ui.popup.JBPopupFactory;
+import com.intellij.openapi.ui.popup.ListPopup;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.Pair;
+import com.intellij.ui.*;
+import com.intellij.ui.components.JBList;
+import com.intellij.util.containers.hash.HashSet;
+import net.miginfocom.swing.MigLayout;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Vassiliy Kudryashov
+ */
+class BeforeRunStepsPanel extends JPanel {
+ private JCheckBox myShowSettingsBeforeRunCheckBox;
+ private JBList myList;
+ private final CollectionListModel myModel;
+ private RunConfiguration myRunConfiguration;
+
+ private final List originalTasks = new ArrayList();
+ private StepsBeforeRunListener myListener;
+
+ BeforeRunStepsPanel(StepsBeforeRunListener listener) {
+ myListener = listener;
+ myModel = new CollectionListModel();
+ myList = new JBList(myModel);
+ myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ myList.setCellRenderer(new MyListCellRenderer());
+ ToolbarDecorator myDecorator = ToolbarDecorator.createDecorator(myList);
+ myDecorator.setEditAction(new AnActionButtonRunnable() {
+ @Override
+ public void run(AnActionButton button) {
+ int index = myList.getSelectedIndex();
+ if (index ==-1)
+ return;
+ Pair> selection = getSelection();
+ if (selection == null)
+ return;
+ BeforeRunTask task = selection.getFirst();
+ BeforeRunTaskProvider provider = selection.getSecond();
+ if (provider.configureTask(myRunConfiguration, task)) {
+ myModel.setElementAt(task, index);
+ }
+ }
+ });
+ myDecorator.setEditActionUpdater(new AnActionButtonUpdater() {
+ @Override
+ public boolean isEnabled(AnActionEvent e) {
+ Pair> selection = getSelection();
+ return selection != null && selection.getSecond().isConfigurable();
+ }
+ });
+ myDecorator.setAddAction(new AnActionButtonRunnable() {
+ @Override
+ public void run(AnActionButton button) {
+ doAddAction(button);
+ }
+ });
+
+ myShowSettingsBeforeRunCheckBox = new JCheckBox(ExecutionBundle.message("configuration.edit.before.run"));
+
+ setLayout(new MigLayout("fill, ins 0, gap 10"));
+ add(myShowSettingsBeforeRunCheckBox, "shrinky, wrap");
+ add(myDecorator.createPanel(), "grow, push");
+ }
+
+ @Nullable
+ private Pair> getSelection() {
+ final int index = myList.getSelectedIndex();
+ if (index ==-1)
+ return null;
+ BeforeRunTask task = myModel.getElementAt(index);
+ Key providerId = task.getProviderId();
+ BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), providerId);
+ return provider != null ? Pair.create(task, provider) : null;
+ }
+
+ void doReset(RunnerAndConfigurationSettings settings) {
+ myRunConfiguration = settings.getConfiguration();
+
+ originalTasks.clear();
+ originalTasks.addAll(RunManagerImpl.getInstanceImpl(myRunConfiguration.getProject()).getBeforeRunTasks(myRunConfiguration, true));
+ myModel.replaceAll(originalTasks);
+ myShowSettingsBeforeRunCheckBox.setSelected(settings.isEditBeforeRun());
+ myShowSettingsBeforeRunCheckBox.setEnabled(!(myRunConfiguration instanceof UnknownRunConfiguration));
+ }
+
+ public List getTasks(boolean applyCurrentState) {
+ if (applyCurrentState) {
+ originalTasks.clear();
+ originalTasks.addAll(myModel.getItems());
+ }
+ return Collections.unmodifiableList(originalTasks);
+ }
+
+ public boolean needEditBeforeRun() {
+ return myShowSettingsBeforeRunCheckBox.isSelected();
+ }
+
+ void doAddAction(AnActionButton button) {
+ if (myRunConfiguration instanceof UnknownRunConfiguration) {
+ return;
+ }
+
+ final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
+ final BeforeRunTaskProvider[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME,
+ myRunConfiguration.getProject());
+ final List activeProviderKeys = getActiveProviderKeys();
+
+ DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
+ for (final BeforeRunTaskProvider provider : providers) {
+ String providerName = provider.getName();
+ if (provider.createTask(myRunConfiguration) == null)
+ continue;
+ if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton())
+ continue;
+ AnAction providerAction = new AnAction(providerName, null, provider.getIcon()) {
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ BeforeRunTask task = provider.createTask(myRunConfiguration);
+ if (task != null) {
+ provider.configureTask(myRunConfiguration, task);
+ if (!provider.canExecuteTask(myRunConfiguration, task))
+ return;
+ } else {
+ return;
+ }
+ task.setEnabled(true);
+
+ Set configurationSet = new HashSet();
+ getAllRunBeforeRuns(task, configurationSet);
+ if (configurationSet.contains(myRunConfiguration)) {
+ JOptionPane.showMessageDialog(BeforeRunStepsPanel.this,
+ ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning",
+ myRunConfiguration.getName(),
+ provider.getDescription(task)),
+ ExecutionBundle.message("warning.common.title"),JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ myModel.add(task);
+ myListener.fireStepsBeforeRunChanged();
+ }
+ };
+ actionGroup.add(providerAction);
+ }
+ final ListPopup popup =
+ popupFactory.createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup,
+ SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null,
+ -1, Condition.TRUE);
+ popup.show(button.getPreferredPopupPoint());
+ }
+
+ private List getActiveProviderKeys() {
+ List result = new ArrayList();
+ for (BeforeRunTask task : myModel.getItems()) {
+ result.add(task.getProviderId());
+ }
+ return result;
+ }
+
+ private void getAllRunBeforeRuns(BeforeRunTask task, Set configurationSet) {
+ if (task instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
+ RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask runTask
+ = (RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)task;
+ RunConfiguration configuration = runTask.getSettings().getConfiguration();
+
+ List tasks = RunManagerImpl.getInstanceImpl(configuration.getProject()).getBeforeRunTasks(configuration, true);
+ for (BeforeRunTask beforeRunTask : tasks) {
+ if (beforeRunTask instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
+ configurationSet.add(((RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)beforeRunTask).getSettings().getConfiguration());
+ getAllRunBeforeRuns(beforeRunTask, configurationSet);
+ }
+ }
+ }
+ }
+
+ interface StepsBeforeRunListener {
+ void fireStepsBeforeRunChanged();
+ }
+
+ private class MyListCellRenderer extends JBList.StripedListCellRenderer {
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (value instanceof BeforeRunTask) {
+ BeforeRunTask task = (BeforeRunTask)value;
+ BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), task.getProviderId());
+ if (provider != null) {
+ setIcon(provider.getTaskIcon(task));
+ setText(provider.getDescription(task));
+ }
+ }
+ return this;
+ }
+ }
+}
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.form b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.form
index 8973059b4e7d..89bbe4fdf05f 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.form
+++ b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.form
@@ -17,13 +17,13 @@
-
+
-
+
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java
index 6a8b5f35018d..dd93b12e5e12 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java
+++ b/platform/lang-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java
@@ -17,8 +17,6 @@
package com.intellij.execution.impl;
import com.intellij.execution.BeforeRunTask;
-import com.intellij.execution.BeforeRunTaskProvider;
-import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.UnknownRunConfiguration;
@@ -27,48 +25,43 @@ import com.intellij.ide.impl.TypeSafeDataProviderAdapter;
import com.intellij.openapi.actionSystem.DataKey;
import com.intellij.openapi.actionSystem.DataSink;
import com.intellij.openapi.actionSystem.TypeSafeDataProvider;
-import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
-import com.intellij.openapi.ui.FixedSizeButton;
import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Key;
-import com.intellij.util.ui.UIUtil;
-import gnu.trove.THashMap;
+import net.miginfocom.swing.MigLayout;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
/**
* User: anna
* Date: 27-Mar-2006
*/
-public class ConfigurationSettingsEditorWrapper extends SettingsEditor {
+public class ConfigurationSettingsEditorWrapper extends SettingsEditor
+ implements BeforeRunStepsPanel.StepsBeforeRunListener {
public static DataKey CONFIGURATION_EDITOR_KEY = DataKey.create("ConfigurationSettingsEditor");
private JPanel myComponentPlace;
private JCheckBox myCbStoreProjectConfiguration;
private JPanel myWholePanel;
- private JPanel myStepsPanel;
- private JCheckBox myShowSettingsBeforeRunCheckBox;
- private Map, BeforeRunTask> myStepsBeforeLaunch;
- private final Map, StepBeforeLaunchRow> myStepBeforeLaunchRows = new THashMap, StepBeforeLaunchRow>();
+ private JPanel myBeforeLaunchContainer;
+ private BeforeRunStepsPanel myBeforeRunStepsPanel;
private boolean myStoreProjectConfiguration;
- private boolean myEditBeforeRun;
private final ConfigurationSettingsEditor myEditor;
public ConfigurationSettingsEditorWrapper(final RunnerAndConfigurationSettings settings) {
myEditor = new ConfigurationSettingsEditor(settings);
Disposer.register(this, myEditor);
+ myBeforeRunStepsPanel = new BeforeRunStepsPanel(this);
+ myBeforeLaunchContainer.setLayout(new MigLayout("fill, ins 0"));
+ myBeforeLaunchContainer.add(myBeforeRunStepsPanel, "grow, push");
doReset(settings);
}
@@ -76,54 +69,8 @@ public class ConfigurationSettingsEditorWrapper extends SettingsEditor[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME,
- runConfiguration.getProject());
- myStepsPanel.removeAll();
- if (runConfiguration instanceof UnknownRunConfiguration) {
- myStepsPanel.setVisible(false);
- }
- else {
- List stepsRows = new ArrayList();
- for (BeforeRunTaskProvider provider : providers) {
- final BeforeRunTask task = myStepsBeforeLaunch.get(provider.getId());
- if (task != null) {
- final StepBeforeLaunchRow stepRow = new StepBeforeLaunchRow(runConfiguration, provider, task);
- myStepBeforeLaunchRows.put(provider.getId(), stepRow);
- stepsRows.add(stepRow);
- }
- }
-
- int maxStepRowWidth = 0;
- for (StepBeforeLaunchRow stepRow : stepsRows) {
- maxStepRowWidth = Math.max(maxStepRowWidth, stepRow.getPreferredSize().width);
- }
- if (maxStepRowWidth * 3 < getComponent().getPreferredSize().width || maxStepRowWidth < 200) {
- myStepsPanel.setLayout(new GridLayout(0, 3, UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
- } else if (maxStepRowWidth * 2 < getComponent().getPreferredSize().width || maxStepRowWidth < 300) {
- myStepsPanel.setLayout(new GridLayout(0, 2, UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
- } else {
- myStepsPanel.setLayout(new GridLayout(0, 1, UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
- }
- for (StepBeforeLaunchRow stepRow : stepsRows) {
- myStepsPanel.add(stepRow);
- }
- }
-
- myEditBeforeRun = settings.isEditBeforeRun();
- myShowSettingsBeforeRunCheckBox = new JCheckBox(ExecutionBundle.message("configuration.edit.before.run"));
- myShowSettingsBeforeRunCheckBox.setEnabled(!(runConfiguration instanceof UnknownRunConfiguration));
- myShowSettingsBeforeRunCheckBox.setSelected(myEditBeforeRun);
- myShowSettingsBeforeRunCheckBox.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- myEditBeforeRun = myShowSettingsBeforeRunCheckBox.isSelected();
- }
- });
- myShowSettingsBeforeRunCheckBox.setVisible(!settings.isTemplate());
- myStepsPanel.add(myShowSettingsBeforeRunCheckBox);
+ myBeforeRunStepsPanel.doReset(settings);
+ myBeforeLaunchContainer.setVisible(!(runConfiguration instanceof UnknownRunConfiguration));
myStoreProjectConfiguration = runManager.isConfigurationShared(settings);
myCbStoreProjectConfiguration.setEnabled(!(runConfiguration instanceof UnknownRunConfiguration));
@@ -141,15 +88,10 @@ public class ConfigurationSettingsEditorWrapper extends SettingsEditor key) {
- myStepBeforeLaunchRows.get(key).update(myStepsBeforeLaunch.get(key));
- }
-
protected void disposeEditor() {
}
@@ -172,71 +114,22 @@ public class ConfigurationSettingsEditorWrapper extends SettingsEditor, BeforeRunTask> getStepsBeforeLaunch() {
- return Collections.unmodifiableMap(myStepsBeforeLaunch);
+ public List getStepsBeforeLaunch() {
+ return Collections.unmodifiableList(myBeforeRunStepsPanel.getTasks(false));
}
public boolean isStoreProjectConfiguration() {
return myStoreProjectConfiguration;
}
- private class StepBeforeLaunchRow extends JPanel {
- private final JCheckBox myCheckBox;
- private FixedSizeButton myButton;
- private final RunConfiguration myRunConfiguration;
- private final BeforeRunTaskProvider myProvider;
-
- public StepBeforeLaunchRow(final RunConfiguration runConfiguration, final BeforeRunTaskProvider provider,
- final BeforeRunTask beforeRunTask) {
- super(new GridBagLayout());
- myRunConfiguration = runConfiguration;
- myProvider = provider;
- final boolean isChecked = beforeRunTask.isEnabled();
- myCheckBox = new JCheckBox(provider.getDescription(runConfiguration, beforeRunTask), isChecked);
- GridBagConstraints gc = new GridBagConstraints(GridBagConstraints.RELATIVE, 0 , 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0, 0);
- add(myCheckBox, gc);
- gc.weightx = 1;
- if (provider.hasConfigurationButton()) {
- myButton = new FixedSizeButton(20);
- add(myButton, gc);
-
- myButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (provider.configureTask(runConfiguration, beforeRunTask)) {
- myCheckBox.setText(provider.getDescription(runConfiguration, beforeRunTask));
- fireEditorStateChanged();
- }
- }
- });
- }
- else {
- add(Box.createHorizontalBox(), gc);
- }
- enableSettings(beforeRunTask);
- myCheckBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- beforeRunTask.setEnabled(myCheckBox.isSelected());
- enableSettings(beforeRunTask);
- }
- });
- }
-
- private void enableSettings(final BeforeRunTask task) {
- if (myButton != null) {
- myButton.setEnabled(myCheckBox.isSelected());
- }
- myCheckBox.setText(myProvider.getDescription(myRunConfiguration, task));
- }
-
- public void update(BeforeRunTask task) {
- myCheckBox.setSelected(task.isEnabled());
- enableSettings(task);
- }
+ @Override
+ public void fireStepsBeforeRunChanged() {
+ fireEditorStateChanged();
}
private class MyDataProvider implements TypeSafeDataProvider {
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java
index d2672ff88fc1..f15e9fa2c222 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java
+++ b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java
@@ -31,7 +31,6 @@ import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
@@ -41,9 +40,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
/**
* @author dyoma
@@ -99,24 +96,25 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
final RunConfiguration runConfiguration = (RunConfiguration)configuration;
final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
- final Map, BeforeRunTask> activeProviders = new LinkedHashMap, BeforeRunTask>();
- for (final BeforeRunTaskProvider provider : Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myProject)) {
- final BeforeRunTask task = runManager.getBeforeRunTask(runConfiguration, provider.getId());
- if (task != null && task.isEnabled()) {
- activeProviders.put(provider, task);
+ final List activeTasks = new ArrayList();
+ final List tasks = runManager.getBeforeRunTasks(runConfiguration);
+ for (BeforeRunTask task : tasks) {
+ if (task != null && task.isEnabled()) {
+ activeTasks.add(task);
+ }
}
- }
ConfigurationPerRunnerSettings configurationSettings = state != null ? state.getConfigurationSettings() : null;
final DataContext projectContext = SimpleDataContext.getProjectContext(myProject);
final DataContext dataContext = configurationSettings != null ? SimpleDataContext
.getSimpleContext(BeforeRunTaskProvider.RUNNER_ID, configurationSettings.getRunnerId(), projectContext) : projectContext;
- if (!activeProviders.isEmpty()) {
+ if (!activeTasks.isEmpty()) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
- for (BeforeRunTaskProvider provider : activeProviders.keySet()) {
- if(!provider.executeTask(dataContext, runConfiguration, activeProviders.get(provider))) {
+ for (BeforeRunTask task : activeTasks) {
+ BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
+ if(provider != null && !provider.executeTask(dataContext, runConfiguration, task)) {
if (onCancelRunnable != null) {
SwingUtilities.invokeLater(onCancelRunnable);
}
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java
index 4963327c22db..8eea1482dfaf 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java
+++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java
@@ -33,7 +33,6 @@ import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.IconLoader;
-import com.intellij.openapi.util.Key;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.*;
import com.intellij.ui.components.JBScrollPane;
@@ -65,6 +64,7 @@ import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.net.URL;
import java.util.*;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -895,7 +895,7 @@ class RunConfigurable extends BaseConfigurable {
});
final ListPopup popup =
popupFactory.createListPopup(new BaseListPopupStep(
- ExecutionBundle.message("add.new.run.configuration.acrtion.name"), configurationTypes) {
+ ExecutionBundle.message("add.new.run.configuration.acrtion.name"), configurationTypes) {
@NotNull
public String getTextFor(final ConfigurationType type) {
@@ -953,7 +953,7 @@ class RunConfigurable extends BaseConfigurable {
}
});
return new BaseListPopupStep(
- ExecutionBundle.message("add.new.run.configuration.action.name", type.getDisplayName()), factories) {
+ ExecutionBundle.message("add.new.run.configuration.action.name", type.getDisplayName()), factories) {
@NotNull
public String getTextFor(final ConfigurationFactory value) {
@@ -1168,15 +1168,15 @@ class RunConfigurable extends BaseConfigurable {
private static class RunConfigurationBean {
private final RunnerAndConfigurationSettings mySettings;
private final boolean myShared;
- private final Map, BeforeRunTask> myStepsBeforeLaunch;
+ private final List myStepsBeforeLaunch;
private final SingleConfigurationConfigurable myConfigurable;
public RunConfigurationBean(final RunnerAndConfigurationSettings settings,
final boolean shared,
- final Map, BeforeRunTask> stepsBeforeLaunch) {
+ final List stepsBeforeLaunch) {
mySettings = settings;
myShared = shared;
- myStepsBeforeLaunch = Collections.unmodifiableMap(stepsBeforeLaunch);
+ myStepsBeforeLaunch = Collections.unmodifiableList(stepsBeforeLaunch);
myConfigurable = null;
}
@@ -1196,7 +1196,7 @@ class RunConfigurable extends BaseConfigurable {
return myShared;
}
- public Map, BeforeRunTask> getStepsBeforeLaunch() {
+ public List getStepsBeforeLaunch() {
return myStepsBeforeLaunch;
}
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java
new file mode 100644
index 000000000000..5aa825b75ca8
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java
@@ -0,0 +1,347 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.execution.impl;
+
+import com.intellij.execution.*;
+import com.intellij.execution.configurations.ConfigurationType;
+import com.intellij.execution.configurations.RunConfiguration;
+import com.intellij.execution.executors.DefaultRunExecutor;
+import com.intellij.execution.process.ProcessAdapter;
+import com.intellij.execution.process.ProcessEvent;
+import com.intellij.execution.process.ProcessHandler;
+import com.intellij.execution.runners.ExecutionEnvironment;
+import com.intellij.execution.runners.ProgramRunner;
+import com.intellij.execution.ui.RunContentDescriptor;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.util.Key;
+import com.intellij.ui.ColoredListCellRenderer;
+import com.intellij.ui.SimpleTextAttributes;
+import com.intellij.ui.components.JBList;
+import com.intellij.ui.components.JBScrollPane;
+import com.intellij.util.concurrency.Semaphore;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Vassiliy Kudryashov
+ */
+public class RunConfigurationBeforeRunProvider
+extends BeforeRunTaskProvider {
+ private static final Icon ICON = IconLoader.getIcon("/actions/execute.png");
+
+ public static final Key ID = Key.create("RunConfigurationTask");
+
+ private static final Logger LOG = Logger.getInstance("#com.intellij.execution.impl.RunConfigurationBeforeRunProvider");
+
+ private final Project myProject;
+
+ public RunConfigurationBeforeRunProvider(Project project) {
+ myProject = project;
+ }
+
+ @Override
+ public Key getId() {
+ return ID;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return ICON;
+ }
+
+ @Override
+ public Icon getTaskIcon(RunConfigurableBeforeRunTask task) {
+ if (task.getSettings() == null)
+ return null;
+ return ProgramRunnerUtil.getConfigurationIcon(myProject, task.getSettings(), false);
+ }
+
+ @Override
+ public String getName() {
+ return ExecutionBundle.message("before.launch.run.another.configuration");
+ }
+
+ @Override
+ public String getDescription(RunConfigurableBeforeRunTask task) {
+ if (task.getSettings() == null) {
+ return ExecutionBundle.message("before.launch.run.another.configuration");
+ }
+ else {
+ return ExecutionBundle.message("before.launch.run.certain.configuration", task.getSettings().getName());
+ }
+ }
+
+ @Override
+ public boolean isConfigurable() {
+ return true;
+ }
+
+ @Override
+ public RunConfigurableBeforeRunTask createTask(RunConfiguration runConfiguration) {
+ return new RunConfigurableBeforeRunTask();
+ }
+
+ @Override
+ public boolean configureTask(RunConfiguration runConfiguration, RunConfigurableBeforeRunTask task) {
+ final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(runConfiguration.getProject());
+
+ final ArrayList configurations
+ = new ArrayList(runManager.getSortedConfigurations());
+ String executorId = DefaultRunExecutor.getRunExecutorInstance().getId();
+ for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
+ RunnerAndConfigurationSettings settings = iterator.next();
+ final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings);
+ if (runner == null)
+ iterator.remove();
+ }
+
+ SelectionDialog dialog =
+ new SelectionDialog(task.getSettings(), configurations);
+ dialog.show();
+ RunnerAndConfigurationSettings settings = dialog.getSelectedSettings();
+ if (settings != null) {
+ task.setSettings(settings);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean canExecuteTask(RunConfiguration configuration,
+ RunConfigurableBeforeRunTask task) {
+ RunnerAndConfigurationSettings settings = task.getSettings();
+ if (settings == null) {
+ return false;
+ }
+ String executorId = DefaultRunExecutor.getRunExecutorInstance().getId();
+ final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings);
+ if (runner == null)
+ return false;
+ final ExecutionEnvironment environment = new ExecutionEnvironment(runner, settings, myProject);
+ return runner.canRun(executorId, environment.getRunProfile());
+ }
+
+ @Override
+ public boolean executeTask(final DataContext dataContext, RunConfiguration configuration, RunConfigurableBeforeRunTask task) {
+ RunnerAndConfigurationSettings settings = task.getSettings();
+ if (settings == null) {
+ return false;
+ }
+ final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
+ String executorId = executor.getId();
+ final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings);
+ if (runner == null)
+ return false;
+ final ExecutionEnvironment environment = new ExecutionEnvironment(runner, settings, myProject);
+ if (!runner.canRun(executorId, environment.getRunProfile())) {
+ return false;
+ }
+ else {
+ final Semaphore targetDone = new Semaphore();
+ final boolean[] result = new boolean[1];
+ try {
+ ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+
+ public void run() {
+ targetDone.down();
+ try {
+ runner.execute(executor, environment, new ProgramRunner.Callback() {
+ @Override
+ public void processStarted(RunContentDescriptor descriptor) {
+ ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null;
+ if (processHandler != null) {
+ processHandler.addProcessListener(new ProcessAdapter() {
+ @Override
+ public void processTerminated(ProcessEvent event) {
+ result[0] = event.getExitCode() == 0;
+ targetDone.up();
+ }
+ });
+ }
+ }
+ });
+ }
+ catch (ExecutionException e) {
+ LOG.error(e);
+ }
+ }
+ }, ModalityState.NON_MODAL);
+ }
+ catch (Exception e) {
+ LOG.error(e);
+ return false;
+ }
+ targetDone.waitFor();
+ return result[0];
+ }
+ }
+
+ class RunConfigurableBeforeRunTask extends BeforeRunTask {
+ private String myConfigurationName;
+ private String myConfigurationType;
+ private boolean myInitialized = false;
+
+ private RunnerAndConfigurationSettings mySettings;
+
+ RunConfigurableBeforeRunTask() {
+ super(ID);
+ }
+
+ @Override
+ public void writeExternal(Element element) {
+ super.writeExternal(element);
+ if (myConfigurationName != null && myConfigurationType != null) {
+ element.setAttribute("run_configuration_name", myConfigurationName);
+ element.setAttribute("run_configuration_type", myConfigurationType);
+ }
+ else if (mySettings != null) {
+ element.setAttribute("run_configuration_name", mySettings.getName());
+ element.setAttribute("run_configuration_type", mySettings.getType().getId());
+ }
+ }
+
+ @Override
+ public void readExternal(Element element) {
+ super.readExternal(element);
+ Attribute configurationNameAttr = element.getAttribute("run_configuration_name");
+ Attribute configurationTypeAttr = element.getAttribute("run_configuration_type");
+ myConfigurationName = configurationNameAttr != null ? configurationNameAttr.getValue() : null;
+ myConfigurationType = configurationTypeAttr != null ? configurationTypeAttr.getValue() : null;
+ }
+
+ void init() {
+ if (myInitialized) {
+ return;
+ }
+ if (myConfigurationName != null && myConfigurationType != null) {
+ Collection configurations = RunManagerImpl.getInstanceImpl(myProject).getSortedConfigurations();
+ for (RunnerAndConfigurationSettings runConfiguration : configurations) {
+ ConfigurationType type = runConfiguration.getType();
+ if (myConfigurationName.equals(runConfiguration.getName())
+ && type != null
+ && myConfigurationType.equals(type.getId())) {
+ setSettings(runConfiguration);
+ return;
+ }
+ }
+ }
+ }
+
+ void setSettings(RunnerAndConfigurationSettings settings) {
+ mySettings = settings;
+ myInitialized = true;
+ }
+
+ RunnerAndConfigurationSettings getSettings() {
+ init();
+ return mySettings;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ RunConfigurableBeforeRunTask that = (RunConfigurableBeforeRunTask)o;
+
+ if (myConfigurationName != null ? !myConfigurationName.equals(that.myConfigurationName) : that.myConfigurationName != null) return false;
+ if (myConfigurationType != null ? !myConfigurationType.equals(that.myConfigurationType) : that.myConfigurationType != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (myConfigurationName != null ? myConfigurationName.hashCode() : 0);
+ result = 31 * result + (myConfigurationType != null ? myConfigurationType.hashCode() : 0);
+ return result;
+ }
+ }
+
+ private class SelectionDialog extends DialogWrapper {
+ private RunnerAndConfigurationSettings mySelectedSettings;
+ @NotNull private final List mySettings;
+ private JBList myJBList;
+
+ private SelectionDialog(RunnerAndConfigurationSettings selectedSettings, @NotNull List settings) {
+ super(myProject);
+ setTitle("Choose Configuration to Execute");
+ mySelectedSettings = selectedSettings;
+ mySettings = settings;
+ init();
+ myJBList.setSelectedValue(mySelectedSettings, true);
+ }
+
+ @Override
+ protected JComponent createCenterPanel() {
+ myJBList = new JBList(mySettings);
+ myJBList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ myJBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ Object selectedValue = myJBList.getSelectedValue();
+ if (selectedValue instanceof RunnerAndConfigurationSettings) {
+ mySelectedSettings = (RunnerAndConfigurationSettings)selectedValue;
+ }
+ else {
+ mySelectedSettings = null;
+ }
+ setOKActionEnabled(mySelectedSettings != null);
+ }
+ });
+ myJBList.setCellRenderer(new ColoredListCellRenderer() {
+ @Override
+ protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
+ if (value instanceof RunnerAndConfigurationSettings) {
+ RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings)value;
+ RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject);
+ setIcon(runManager.getConfigurationIcon(settings));
+ RunConfiguration configuration = settings.getConfiguration();
+ append(configuration.getName(), runManager.isTemporary(configuration)
+ ? SimpleTextAttributes.GRAY_ATTRIBUTES
+ : SimpleTextAttributes.REGULAR_ATTRIBUTES);
+ }
+ }
+ });
+ return new JBScrollPane(myJBList);
+ }
+
+ @Nullable
+ RunnerAndConfigurationSettings getSelectedSettings() {
+ return mySelectedSettings;
+ }
+ }
+}
diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java
index 1bebd81a8414..0061cdad34f7 100644
--- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java
+++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java
@@ -48,11 +48,7 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
private final Map myConfigurations =
new LinkedHashMap(); // template configurations are not included here
private final Map mySharedConfigurations = new TreeMap();
- /**
- * configurationID -> [BeforeTaskProviderName->BeforeRunTask]
- */
- private final Map, BeforeRunTask>> myConfigurationToBeforeTasksMap =
- new WeakHashMap, BeforeRunTask>>();
+ private final Map> myConfigurationToBeforeTasksMap = new WeakHashMap>();
// When readExternal not all configuration may be loaded, so we need to remember the selected configuration
// so that when it is eventually loaded, we can mark is as a selected.
@@ -244,7 +240,7 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
public void addConfiguration(RunnerAndConfigurationSettings settings,
boolean shared,
- Map, BeforeRunTask> tasks) {
+ List tasks) {
final RunConfiguration configuration = settings.getConfiguration();
Integer existingId = findConfigurationIdByUniqueName(getUniqueName(settings));
@@ -441,35 +437,12 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
((RunnerAndConfigurationSettingsImpl)settings).writeExternal(configurationElement);
if (!(settings.getConfiguration() instanceof UnknownRunConfiguration)) {
- final Map, BeforeRunTask> tasks = getBeforeRunTasks(settings.getConfiguration());
- Map, BeforeRunTask> templateTasks;
- if (!settings.isTemplate()) {
- final RunnerAndConfigurationSettings templateSettings = getConfigurationTemplate(settings.getFactory());
- templateTasks = getBeforeRunTasks(templateSettings.getConfiguration());
- }
- else {
- templateTasks = null;
- }
- final List> order = new ArrayList>(tasks.keySet());
- Collections.sort(order, new Comparator>() {
- public int compare(Key extends BeforeRunTask> o1, Key extends BeforeRunTask> o2) {
- return o1.toString().compareToIgnoreCase(o2.toString());
- }
- });
+ final List tasks = getBeforeRunTasks(settings.getConfiguration());
final Element methodsElement = new Element(METHOD);
- for (Key extends BeforeRunTask> providerID : order) {
- final BeforeRunTask beforeRunTask = tasks.get(providerID);
-
- if (templateTasks != null) {
- final BeforeRunTask templateTask = templateTasks.get(providerID);
- if (beforeRunTask.equals(templateTask)) {
- continue; // not neccesary saving if the task is the same as template
- }
- }
-
+ for (BeforeRunTask task : tasks) {
final Element child = new Element(OPTION);
- child.setAttribute(NAME_ATTR, providerID.toString());
- beforeRunTask.writeExternal(child);
+ child.setAttribute(NAME_ATTR, task.getProviderId().toString());
+ task.writeExternal(child);
methodsElement.addContent(child);
}
configurationElement.addContent(methodsElement);
@@ -575,13 +548,13 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
}
final Element methodsElement = element.getChild(METHOD);
- final Map, BeforeRunTask> map = readStepsBeforeRun(methodsElement, settings);
+ final List tasks = readStepsBeforeRun(methodsElement, settings);
if (settings.isTemplate()) {
myTemplateConfigurationsMap.put(factory.getType().getId() + "." + factory.getName(), settings);
- setBeforeRunTasks(settings.getConfiguration(), map);
+ setBeforeRunTasks(settings.getConfiguration(), tasks);
}
else {
- addConfiguration(settings, isShared, map);
+ addConfiguration(settings, isShared, tasks);
if (Boolean.valueOf(element.getAttributeValue(SELECTED_ATTR)).booleanValue()) { //to support old style
setSelectedConfiguration(settings);
}
@@ -590,9 +563,8 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
}
@NotNull
- private Map, BeforeRunTask> readStepsBeforeRun(final Element child,
- RunnerAndConfigurationSettings settings) {
- final Map, BeforeRunTask> map = new HashMap, BeforeRunTask>();
+ private List readStepsBeforeRun(final Element child, RunnerAndConfigurationSettings settings) {
+ final List result = new ArrayList();
if (child != null) {
for (Object o : child.getChildren(OPTION)) {
final Element methodElement = (Element)o;
@@ -602,11 +574,11 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
final BeforeRunTask beforeRunTask = provider.createTask(settings.getConfiguration());
if (beforeRunTask != null) {
beforeRunTask.readExternal(methodElement);
- map.put(id, beforeRunTask);
+ result.add(beforeRunTask);
}
}
}
- return map;
+ return result;
}
@@ -730,22 +702,27 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
return shared != null && shared.booleanValue();
}
- public Collection getBeforeRunTasks(Key taskProviderID, boolean includeOnlyActiveTasks) {
- final Collection tasks = new ArrayList();
+ @NotNull
+ public List getBeforeRunTasks(Key taskProviderID, boolean includeOnlyActiveTasks) {
+ final List tasks = new ArrayList();
if (includeOnlyActiveTasks) {
- final Set checkedTemplates = new HashSet();
+ final List checkedTemplates = new ArrayList();
for (RunnerAndConfigurationSettings settings : myConfigurations.values()) {
- final BeforeRunTask runTask = getBeforeRunTask(settings.getConfiguration(), taskProviderID);
- if (runTask != null && runTask.isEnabled()) {
- tasks.add((T)runTask);
- }
- else {
- final RunnerAndConfigurationSettings template = getConfigurationTemplate(settings.getFactory());
- if (!checkedTemplates.contains(template)) {
- checkedTemplates.add(template);
- final BeforeRunTask templateTask = getBeforeRunTask(template.getConfiguration(), taskProviderID);
- if (templateTask != null && templateTask.isEnabled()) {
- tasks.add((T)templateTask);
+ final List runTasks = getBeforeRunTasks(settings.getConfiguration());
+ for (BeforeRunTask task : runTasks) {
+ if (task != null && task.isEnabled() && task.getProviderId() == taskProviderID) {
+ tasks.add((T)task);
+ }
+ else {
+ final RunnerAndConfigurationSettings template = getConfigurationTemplate(settings.getFactory());
+ if (!checkedTemplates.contains(template)) {
+ checkedTemplates.add(template);
+ final List templateTasks = getBeforeRunTasks(template.getConfiguration());
+ for (BeforeRunTask templateTask : templateTasks) {
+ if (templateTask != null && templateTask.isEnabled() && templateTask.getProviderId() == taskProviderID) {
+ tasks.add((T)templateTask);
+ }
+ }
}
}
}
@@ -753,15 +730,17 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
}
else {
for (RunnerAndConfigurationSettings settings : myTemplateConfigurationsMap.values()) {
- final T task = getBeforeRunTask(settings.getConfiguration(), taskProviderID);
- if (task != null) {
- tasks.add(task);
+ final List tasks_ = getBeforeRunTasks(settings.getConfiguration());
+ for (BeforeRunTask task : tasks_) {
+ if (task != null && task.getProviderId() == taskProviderID)
+ tasks.add((T)task);
}
}
for (RunnerAndConfigurationSettings settings : myConfigurations.values()) {
- final T task = getBeforeRunTask(settings.getConfiguration(), taskProviderID);
- if (task != null) {
- tasks.add(task);
+ final List tasks_ = getBeforeRunTasks(settings.getConfiguration());
+ for (BeforeRunTask task : tasks_) {
+ if (task != null && task.getProviderId() == taskProviderID)
+ tasks.add((T)task);
}
}
}
@@ -811,49 +790,64 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
return null;
}
- @Nullable
- public T getBeforeRunTask(RunConfiguration settings, Key taskProviderID) {
- Map, BeforeRunTask> tasks = myConfigurationToBeforeTasksMap.get(settings);
- if (tasks == null) {
- tasks = getBeforeRunTasks(settings);
- myConfigurationToBeforeTasksMap.put(settings, tasks);
+ @NotNull
+ @Override
+ public List getBeforeRunTasks(RunConfiguration settings, Key taskProviderID) {
+ List tasks = getBeforeRunTasks(settings);
+ List result = new ArrayList();
+ for (BeforeRunTask task : tasks) {
+ if (task.getProviderId() == taskProviderID)
+ result.add((T)task);
}
- return (T)tasks.get(taskProviderID);
+ return result;
}
- public Map, BeforeRunTask> getBeforeRunTasks(final RunConfiguration settings) {
- final Map, BeforeRunTask> tasks = myConfigurationToBeforeTasksMap.get(settings);
+ @NotNull
+ public List getBeforeRunTasks(final RunConfiguration settings) {
+ return getBeforeRunTasks(settings, false);
+ }
+ @NotNull
+ @Override
+ public List getBeforeRunTasks(RunConfiguration settings, boolean includeOnlyActiveTasks) {
+ final List tasks = myConfigurationToBeforeTasksMap.get(settings);
if (tasks != null) {
- final Map, BeforeRunTask> _tasks = new HashMap, BeforeRunTask>();
- for (Map.Entry, BeforeRunTask> entry : tasks.entrySet()) {
- _tasks.put(entry.getKey(), entry.getValue().clone());
- }
- return _tasks;
+ return getCopies(tasks, includeOnlyActiveTasks);
}
final RunnerAndConfigurationSettings template = getConfigurationTemplate(settings.getFactory());
- final Map, BeforeRunTask> templateTasks = myConfigurationToBeforeTasksMap.get(template.getConfiguration());
+ final List templateTasks = myConfigurationToBeforeTasksMap.get(template.getConfiguration());
if (templateTasks != null) {
- final Map, BeforeRunTask> _tasks = new HashMap, BeforeRunTask>();
- for (Map.Entry, BeforeRunTask> entry : templateTasks.entrySet()) {
- _tasks.put(entry.getKey(), entry.getValue().clone());
- }
- return _tasks;
+ return getCopies(templateTasks, includeOnlyActiveTasks);
}
- final Map, BeforeRunTask> _tasks = new HashMap, BeforeRunTask>();
+ final List _tasks = new ArrayList();
for (BeforeRunTaskProvider extends BeforeRunTask> provider : Extensions
.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myProject)) {
BeforeRunTask task = provider.createTask(settings);
if (task != null) {
+ if (includeOnlyActiveTasks && !task.isEnabled())
+ continue;
Key extends BeforeRunTask> providerID = provider.getId();
- _tasks.put(providerID, task);
+ _tasks.add(task);
settings.getFactory().configureBeforeRunTaskDefaults(providerID, task);
}
}
return _tasks;
}
+ @NotNull
+ private static List getCopies(List original, boolean includeOnlyActiveTasks) {
+ List result = new ArrayList();
+ if (original != null) {
+ for (BeforeRunTask task : original) {
+ if (includeOnlyActiveTasks && !task.isEnabled())
+ continue;
+ result.add(task.clone());
+ }
+ }
+ return result;
+ }
+
public void shareConfiguration(final RunConfiguration runConfiguration, final boolean shareConfiguration) {
RunnerAndConfigurationSettings settings = getSettings(runConfiguration);
boolean shouldFire = settings != null && isConfigurationShared(settings) != shareConfiguration;
@@ -864,14 +858,8 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
if (shouldFire) fireRunConfigurationChanged(settings);
}
- public final void setBeforeRunTasks(final RunConfiguration runConfiguration, Map, BeforeRunTask> tasks) {
- final Map, BeforeRunTask> taskMap = getBeforeRunTasks(runConfiguration);
- for (Map.Entry, BeforeRunTask> entry : tasks.entrySet()) {
- //if (taskMap.containsKey(entry.getKey())) {
- taskMap.put(entry.getKey(), entry.getValue());
- //}
- }
- myConfigurationToBeforeTasksMap.put(runConfiguration, taskMap);
+ public final void setBeforeRunTasks(final RunConfiguration runConfiguration, List tasks) {
+ myConfigurationToBeforeTasksMap.put(runConfiguration, tasks);
fireBeforeRunTasksUpdated();
}
@@ -881,7 +869,7 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
}
public void addConfiguration(final RunnerAndConfigurationSettings settings, final boolean isShared) {
- addConfiguration(settings, isShared, Collections., BeforeRunTask>emptyMap());
+ addConfiguration(settings, isShared, new ArrayList());
}
public static RunManagerImpl getInstanceImpl(final Project project) {
@@ -958,8 +946,8 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
}
private void initProviderMaps() {
- myBeforeStepsMap = new HashMap, BeforeRunTaskProvider>();
- myProviderKeysMap = new HashMap>();
+ myBeforeStepsMap = new LinkedHashMap, BeforeRunTaskProvider>();
+ myProviderKeysMap = new LinkedHashMap