mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-CR-2919: Please use Main.showMessage() for the above. There is no need to throw an exception.
This commit is contained in:
@@ -64,18 +64,18 @@ public final class SocketLock {
|
||||
public SocketLock() {
|
||||
serverSocket = acquireSocket();
|
||||
if (serverSocket == null) {
|
||||
String productName = ApplicationNamesInfo.getInstance().getProductName();
|
||||
if (Main.isHeadless()) { //team server inspections
|
||||
throw new RuntimeException("Only one instance of " + productName + " can be run at a time.");
|
||||
}
|
||||
String pathToLogFile = PathManager.getLogPath() + "/idea.log file".replace('/', File.separatorChar);
|
||||
JOptionPane.showMessageDialog(
|
||||
JOptionPane.getRootFrame(),
|
||||
CommonBundle.message("cannot.start.other.instance.is.running.error.message", productName, pathToLogFile),
|
||||
CommonBundle.message("title.warning"),
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
acquiredPort = -1;
|
||||
|
||||
if (!Main.isHeadless()) {
|
||||
String pathToLogFile = PathManager.getLogPath() + "/idea.log file".replace('/', File.separatorChar);
|
||||
JOptionPane.showMessageDialog(
|
||||
JOptionPane.getRootFrame(),
|
||||
CommonBundle.message("cannot.start.other.instance.is.running.error.message", ApplicationNamesInfo.getInstance().getProductName(),
|
||||
pathToLogFile),
|
||||
CommonBundle.message("title.warning"),
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
acquiredPort = serverSocket.getLocalPort();
|
||||
|
||||
@@ -243,29 +243,29 @@ public class StartupUtil {
|
||||
}
|
||||
|
||||
private synchronized static boolean lockSystemFolders(String[] args) {
|
||||
if (Main.isHeadless()) {
|
||||
// fast fix, disable in tests
|
||||
return true;
|
||||
}
|
||||
|
||||
assert ourLock == null;
|
||||
ourLock = new SocketLock();
|
||||
if (ourLock.getAcquiredPort() == -1) {
|
||||
showErrorTooManyInstances(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
SocketLock.ActivateStatus activateStatus = ourLock.lock(PathManager.getConfigPath(), PathManager.getSystemPath(), args);
|
||||
if (activateStatus != SocketLock.ActivateStatus.NO_INSTANCE) {
|
||||
if (Main.isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) {
|
||||
String message = "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time.";
|
||||
Main.showMessage("Too Many Instances", message, true);
|
||||
}
|
||||
showErrorTooManyInstances(activateStatus);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void showErrorTooManyInstances(@Nullable SocketLock.ActivateStatus activateStatus) {
|
||||
if (Main.isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) {
|
||||
String message = "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time.";
|
||||
Main.showMessage("Too Many Instances", message, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixProcessEnvironment(Logger log) {
|
||||
if (!Main.isCommandLine()) {
|
||||
System.setProperty("__idea.mac.env.lock", "unlocked");
|
||||
|
||||
@@ -16,24 +16,23 @@
|
||||
package com.intellij.idea;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author mike
|
||||
*/
|
||||
@Bombed(day = 20, month = Calendar.JUNE)
|
||||
public class LockSupportTest extends TestCase {
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class LockSupportTest {
|
||||
@Test(timeout = 30000)
|
||||
public void testLock() throws Exception {
|
||||
final SocketLock lock = new SocketLock();
|
||||
File temp = FileUtil.createTempDirectory("c", null);
|
||||
try {
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, lock.lock(temp.getPath() + "/c", temp.getPath() + "/s"));
|
||||
assertThat(lock.lock(temp.getPath() + "/c", temp.getPath() + "/s"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
}
|
||||
finally {
|
||||
lock.dispose();
|
||||
@@ -42,17 +41,18 @@ public class LockSupportTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
public void testTwoLocks() throws Exception {
|
||||
List<SocketLock> toClose = new ArrayList<SocketLock>();
|
||||
File temp = FileUtil.createTempDirectory("c", null);
|
||||
try {
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, createLock(toClose).lock(temp.getPath() + "/1", temp.getPath() + "/1-"));
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, createLock(toClose).lock(temp.getPath() + "/1.1", temp.getPath() + "/1-1"));
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, createLock(toClose).lock(temp.getPath() + "/2", temp.getPath() + "/2-"));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/1", temp.getPath() + "/1-"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/1.1", temp.getPath() + "/1-1"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/2", temp.getPath() + "/2-"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
|
||||
assertEquals(SocketLock.ActivateStatus.ACTIVATED, createLock(toClose).lock(temp.getPath() + "/2", temp.getPath() + "/2-"));
|
||||
assertEquals(SocketLock.ActivateStatus.ACTIVATED, createLock(toClose).lock(temp.getPath() + "/1", temp.getPath() + "/1-"));
|
||||
assertEquals(SocketLock.ActivateStatus.ACTIVATED, createLock(toClose).lock(temp.getPath() + "/1.1", temp.getPath() + "/1-1"));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/2", temp.getPath() + "/2-"), equalTo(SocketLock.ActivateStatus.ACTIVATED));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/1", temp.getPath() + "/1-"), equalTo(SocketLock.ActivateStatus.ACTIVATED));
|
||||
assertThat(createLock(toClose).lock(temp.getPath() + "/1.1", temp.getPath() + "/1-1"), equalTo(SocketLock.ActivateStatus.ACTIVATED));
|
||||
}
|
||||
finally {
|
||||
for (SocketLock lock : toClose) {
|
||||
@@ -70,17 +70,18 @@ public class LockSupportTest extends TestCase {
|
||||
return lock1;
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
public void testDispose() throws Exception {
|
||||
final SocketLock lock1 = new SocketLock();
|
||||
final SocketLock lock2 = new SocketLock();
|
||||
|
||||
File temp = FileUtil.createTempDirectory("c", null);
|
||||
try {
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, lock1.lock(temp.getPath() + "/1", temp.getPath() + "/1-"));
|
||||
assertEquals(SocketLock.ActivateStatus.ACTIVATED, lock2.lock(temp.getPath() + "/1", temp.getPath() + "/1-"));
|
||||
assertThat(lock1.lock(temp.getPath() + "/1", temp.getPath() + "/1-"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
assertThat(lock2.lock(temp.getPath() + "/1", temp.getPath() + "/1-"), equalTo(SocketLock.ActivateStatus.ACTIVATED));
|
||||
|
||||
lock1.dispose();
|
||||
assertEquals(SocketLock.ActivateStatus.NO_INSTANCE, lock2.lock(temp.getPath() + "/1", temp.getPath() + "/1-"));
|
||||
assertThat(lock2.lock(temp.getPath() + "/1", temp.getPath() + "/1-"), equalTo(SocketLock.ActivateStatus.NO_INSTANCE));
|
||||
lock2.dispose();
|
||||
}
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user