From c2524b1cc90e377ec599ada8b6afb56ec103946f Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 12 Jun 2013 21:14:20 +0400 Subject: [PATCH 01/47] IDEA-107980 Gradle: Enhance Xmx gradle daemon processing Using 512Mb as a default value only for 32-bit systems --- .../plugins/gradle/settings/GradleExecutionSettings.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleExecutionSettings.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleExecutionSettings.java index 5beb1daeed0c..b661a44a1658 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleExecutionSettings.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleExecutionSettings.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.gradle.settings; import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings; +import com.intellij.openapi.util.SystemInfo; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; @@ -44,7 +45,7 @@ public class GradleExecutionSettings extends ExternalSystemExecutionSettings { @Nullable private String myJavaHome; public GradleExecutionSettings(@Nullable String gradleHome, @Nullable String serviceDirectory, boolean wrapper) { - this(gradleHome, serviceDirectory, wrapper, SystemProperties.getIntProperty("gradle.daemon.xmx.mb", 512)); + this(gradleHome, serviceDirectory, wrapper, SystemProperties.getIntProperty("gradle.daemon.xmx.mb", SystemInfo.is32Bit ? 512 : 1024)); } public GradleExecutionSettings(@Nullable String gradleHome, @Nullable String serviceDirectory, boolean wrapper, int daemonXmx) { From 68f5dc5f1cdc3c5d8bb426279a735970df4d804c Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 12 Jun 2013 20:46:48 +0200 Subject: [PATCH 02/47] PsiAnchor: for class files, base language is Any while file language is Java :( --- .../src/com/intellij/psi/PsiAnchor.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/PsiAnchor.java b/platform/core-impl/src/com/intellij/psi/PsiAnchor.java index be1442f06f6f..52c6c1bf986d 100644 --- a/platform/core-impl/src/com/intellij/psi/PsiAnchor.java +++ b/platform/core-impl/src/com/intellij/psi/PsiAnchor.java @@ -58,7 +58,7 @@ public abstract class PsiAnchor { if (element instanceof PsiFile) { VirtualFile virtualFile = ((PsiFile)element).getVirtualFile(); - if (virtualFile != null) return new PsiFileReference(virtualFile, element.getProject(), element.getLanguage()); + if (virtualFile != null) return new PsiFileReference(virtualFile, (PsiFile)element); return new HardReference(element); } if (element instanceof PsiDirectory) { @@ -262,12 +262,23 @@ public abstract class PsiAnchor { private static class PsiFileReference extends PsiAnchor { private final VirtualFile myFile; private final Project myProject; - @Nullable private final Language myLanguage; + @NotNull private final Language myLanguage; - private PsiFileReference(@NotNull VirtualFile file, @NotNull Project project, @NotNull Language language) { + private PsiFileReference(@NotNull VirtualFile file, @NotNull PsiFile psiFile) { myFile = file; - myProject = project; - myLanguage = language; + myProject = psiFile.getProject(); + myLanguage = findLanguage(psiFile); + } + + private static Language findLanguage(PsiFile file) { + FileViewProvider vp = file.getViewProvider(); + Set languages = vp.getLanguages(); + for (Language language : languages) { + if (file.equals(vp.getPsi(language))) { + return language; + } + } + throw new AssertionError("Non-retrievable file: " + file.getClass() + "; " + file.getLanguage() + "; " + languages); } @Override @@ -299,7 +310,7 @@ public abstract class PsiAnchor { PsiFileReference reference = (PsiFileReference)o; if (!myFile.equals(reference.myFile)) return false; - if (myLanguage != null ? !myLanguage.equals(reference.myLanguage) : reference.myLanguage != null) return false; + if (!myLanguage.equals(reference.myLanguage)) return false; if (!myProject.equals(reference.myProject)) return false; return true; @@ -307,9 +318,7 @@ public abstract class PsiAnchor { @Override public int hashCode() { - int result = myFile.hashCode(); - result = 31 * result + (myLanguage != null ? myLanguage.hashCode() : 0); - return result; + return 31 * myFile.hashCode() + (myLanguage.hashCode()); } } From 4657089ce10371cc946ed55c31b2ef84de104026 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Jun 2013 12:14:43 +0400 Subject: [PATCH 03/47] platform: catch exceptions in startup thread --- .../intellij/ide/plugins/PluginManager.java | 25 +++++++++---------- .../src/com/intellij/idea/StartupUtil.java | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 2ce3a3c4fe4f..1732ab693114 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -18,6 +18,7 @@ package com.intellij.ide.plugins; import com.intellij.ide.ClassUtilCore; import com.intellij.ide.IdeBundle; +import com.intellij.idea.StartupUtil; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; @@ -38,13 +39,13 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; /** * @author mike */ -@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) // No logger is loaded at this time so we have to use these. public class PluginManager extends PluginManagerCore { @NonNls public static final String INSTALLED_TXT = "installed.txt"; @@ -55,11 +56,10 @@ public class PluginManager extends PluginManagerCore { /** * Called via reflection */ - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral"}) protected static void start(final String mainClass, final String methodName, final String[] args) { startupStart = System.nanoTime(); try { - //noinspection HardCodedStringLiteral ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { @Override public void uncaughtException(Thread t, Throwable e) { @@ -82,21 +82,20 @@ public class PluginManager extends PluginManagerCore { //noinspection RedundantArrayCreation method.invoke(null, new Object[]{args}); } - catch (Exception e) { - e.printStackTrace(System.err); - String message = "Error while accessing " + mainClass + "." + methodName + " with arguments: " + Arrays.asList(args); - if ("true".equals(System.getProperty("java.awt.headless"))) { - //noinspection UseOfSystemOutOrSystemErr - System.err.println(message); - } - else { - JOptionPane.showMessageDialog(null, message + ": " + e.getClass().getName() + ": " + e.getMessage() + "\n" + ExceptionUtil.getThrowableText(e), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); + catch (Throwable t) { + //noinspection InstanceofCatchParameter + if (t instanceof InvocationTargetException) { + t = t.getCause(); } + + String message = "Error while accessing " + mainClass + "." + methodName + " with arguments: " + Arrays.asList(args) + + "\n" + ExceptionUtil.getThrowableText(t); + StartupUtil.showError("Error starting IntelliJ Platform", message); + System.exit(1); } } }; - //noinspection HardCodedStringLiteral new Thread(threadGroup, runnable, "Idea Main Thread").start(); } catch (Exception e) { diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index c05df8fdb349..897eb6b2cc62 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -77,7 +77,7 @@ public class StartupUtil { return isHeadless; } - private static void showError(final String title, final String message) { + public static void showError(final String title, final String message) { if (isHeadless()) { //noinspection UseOfSystemOutOrSystemErr System.out.println(message); From 6b04442d5e45c764c8ba3943913d1e14368d78b9 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Jun 2013 14:22:50 +0400 Subject: [PATCH 04/47] platform: unified check for headless environment --- .../bootstrap/src/com/intellij/idea/Main.java | 56 +++++++++++-------- .../com/intellij/idea/IdeaApplication.java | 14 +++-- .../src/com/intellij/idea/SocketLock.java | 4 +- .../src/com/intellij/idea/StartupUtil.java | 12 ++-- .../src/com/intellij/idea/MainImpl.java | 11 +--- 5 files changed, 51 insertions(+), 46 deletions(-) diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index f67a902d8afc..43fc8d7f3df9 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.idea; import com.intellij.ide.Bootstrap; @@ -36,20 +35,20 @@ import java.util.List; public class Main { private static boolean isHeadless; - private Main() { - } + private Main() { } @SuppressWarnings("MethodNamesDifferingOnlyByCase") public static void main(final String[] args) { - isHeadless = isHeadless(args); - if (isHeadless) { + isHeadless = _isHeadless(args); + + if (isHeadless()) { System.setProperty("java.awt.headless", Boolean.TRUE.toString()); } else if (GraphicsEnvironment.isHeadless()) { throw new HeadlessException("Unable to detect graphics environment"); } - if (!isHeadless) { + if (!isHeadless()) { try { installPatch(); } @@ -86,37 +85,42 @@ public class Main { Bootstrap.main(args, Main.class.getName() + "Impl", "start"); } - public static boolean isHeadless(final String[] args) { - final Boolean forceEnabledHeadlessMode = Boolean.valueOf(System.getProperty("java.awt.headless")); + private static boolean _isHeadless(String[] args) { + if (GraphicsEnvironment.isHeadless()) { + return true; + } - @NonNls final String antAppCode = "ant"; - @NonNls final String duplocateCode = "duplocate"; - @NonNls final String traverseUI = "traverseUI"; if (args.length == 0) { return false; } - final String firstArg = args[0]; - return forceEnabledHeadlessMode || - Comparing.strEqual(firstArg, antAppCode) || - Comparing.strEqual(firstArg, duplocateCode) || - Comparing.strEqual(firstArg, traverseUI) || + + String firstArg = args[0]; + return Comparing.strEqual(firstArg, "ant") || + Comparing.strEqual(firstArg, "duplocate") || + Comparing.strEqual(firstArg, "traverseUI") || (firstArg.length() < 20 && firstArg.endsWith("inspect")); } + public static boolean isHeadless() { + return isHeadless; + } + + /** @deprecated use {@link #isHeadless()} (to remove in IDEA 14) */ + @SuppressWarnings("unused") + public static boolean isHeadless(final String[] args) { + return isHeadless(); + } + public static boolean isUITraverser(final String[] args) { return args.length > 0 && Comparing.strEqual(args[0], "traverseUI"); } public static boolean isCommandLine(final String[] args) { - if (isHeadless(args)) return true; + if (isHeadless()) return true; @NonNls final String diffAppCode = "diff"; return args.length > 0 && Comparing.strEqual(args[0], diffAppCode); } - public static boolean isHeadless() { - return isHeadless; - } - private static void installPatch() throws IOException { String platform = System.getProperty("idea.platform.prefix", "idea"); String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase(); @@ -124,9 +128,13 @@ public class Main { File copyPatchFile = new File(System.getProperty("java.io.tmpdir"), patchFileName + "_copy"); // always delete previous patch copy - if (!FileUtilRt.delete(copyPatchFile)) throw new IOException("Cannot create temporary patch file"); + if (!FileUtilRt.delete(copyPatchFile)) { + throw new IOException("Cannot create temporary patch file"); + } - if (!originalPatchFile.exists()) return; + if (!originalPatchFile.exists()) { + return; + } if (!originalPatchFile.renameTo(copyPatchFile) || !FileUtilRt.delete(originalPatchFile)) { throw new IOException("Cannot create temporary patch file"); diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 1641c8dd7838..d89b7e40a5c5 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -24,6 +24,7 @@ import com.intellij.ide.CommandLineProcessor; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.IdeRepaintManager; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationType; @@ -79,14 +80,15 @@ public class IdeaApplication { myArgs = args; boolean isInternal = Boolean.valueOf(System.getProperty(IDEA_IS_INTERNAL_PROPERTY)).booleanValue(); + boolean headless = Main.isHeadless(); + if (!headless) { + patchSystem(); + } + if (Main.isCommandLine(args)) { - boolean headless = Main.isHeadless(args); - if (!headless) patchSystem(); new CommandLineApplication(isInternal, false, headless); } else { - patchSystem(); - Splash splash = null; if (myArgs.length == 0) { myStarter = getStarter(); @@ -159,7 +161,7 @@ public class IdeaApplication { protected ApplicationStarter getStarter() { if (myArgs.length > 0) { - PluginManager.getPlugins(); + PluginManagerCore.getPlugins(); ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.APPLICATION_STARTER); final ApplicationStarter[] starters = point.getExtensions(); @@ -268,7 +270,7 @@ public class IdeaApplication { final AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); lifecyclePublisher.appFrameCreated(args, willOpenProject); LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); - PluginManager.dumpPluginClassStatistics(); + PluginManagerCore.dumpPluginClassStatistics(); if (!willOpenProject.get()) { WelcomeFrame.showNow(); lifecyclePublisher.welcomeScreenDisplayed(); diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index ecdf70aed992..d2b0fbf09b7d 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -88,7 +88,7 @@ public class SocketLock { if (mySocket == null) { if (!myIsDialogShown) { final String productName = ApplicationNamesInfo.getInstance().getProductName(); - if (StartupUtil.isHeadless()) { //team server inspections + if (Main.isHeadless()) { //team server inspections throw new RuntimeException("Only one instance of " + productName + " can be run at a time."); } @NonNls final String pathToLogFile = PathManager.getLogPath() + "/idea.log file".replace('/', File.separatorChar); diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index 897eb6b2cc62..a2f386c6bd9d 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -54,8 +54,6 @@ public class StartupUtil { public static final boolean NO_SNAPPY = SystemProperties.getBooleanProperty("idea.no.snappy", false); - static boolean isHeadless; - private static SocketLock ourLock; private static String myDefaultLAF; @@ -73,12 +71,14 @@ public class StartupUtil { return !Arrays.asList(args).contains(NO_SPLASH); } + /** @deprecated use {@link Main#isHeadless()} (to remove in IDEA 14) */ + @SuppressWarnings("unused") public static boolean isHeadless() { - return isHeadless; + return Main.isHeadless(); } public static void showError(final String title, final String message) { - if (isHeadless()) { + if (Main.isHeadless()) { //noinspection UseOfSystemOutOrSystemErr System.out.println(message); } @@ -146,7 +146,7 @@ public class StartupUtil { } if (activateStatus != SocketLock.ActivateStatus.NO_INSTANCE) { - if (isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) { + if (Main.isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) { showError("Error", "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time."); } return false; @@ -231,7 +231,7 @@ public class StartupUtil { IdeaWin32.isAvailable(); // logging is done there } - if (SystemInfo.isWin2kOrNewer && !isHeadless) { + if (SystemInfo.isWin2kOrNewer && !Main.isHeadless()) { try { System.loadLibrary(SystemInfo.isAMD64 ? "focusKiller64" : "focusKiller"); log.info("Using \"FocusKiller\" library to prevent focus stealing."); diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 0faeeb706a0a..8df8971e6152 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -15,16 +15,12 @@ */ package com.intellij.idea; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.application.ConfigImportHelper; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.SystemInfoRt; import com.intellij.ui.AppUIUtil; import com.intellij.util.PlatformUtils; -import com.intellij.util.text.DateFormatUtilRt; +import com.intellij.util.PlatformUtilsCore; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -39,10 +35,9 @@ public class MainImpl { * Called from PluginManager via reflection. */ protected static void start(final String[] args) { - System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); + System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); - StartupUtil.isHeadless = Main.isHeadless(args); - if (!StartupUtil.isHeadless) { + if (!Main.isHeadless()) { AppUIUtil.updateFrameClass(); AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); AppUIUtil.registerBundledFonts(); From 34e520e9c3a0c4e55951abd9497b55f8de50a330 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 11 Jun 2013 18:57:13 +0400 Subject: [PATCH 05/47] platform: log exceptions once --- .../diagnostic/DefaultIdeaErrorLogger.java | 50 +++++++------------ .../src/com/intellij/idea/IdeaLogger.java | 27 ++++------ 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java index f73bce667320..3488bce03487 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -16,7 +16,6 @@ package com.intellij.diagnostic; import com.intellij.notification.Notification; -import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; @@ -35,13 +34,14 @@ import java.lang.reflect.InvocationTargetException; * @author kir */ public class DefaultIdeaErrorLogger implements ErrorLogger { - private static boolean ourOomOccured = false; + private static boolean ourOomOccurred = false; private static boolean ourLoggerBroken = false; - private static boolean mappingFailedNotificationPosted = false; + private static boolean ourMappingFailedNotificationPosted = false; + @NonNls private static final String FATAL_ERROR_NOTIFICATION_PROPERTY = "idea.fatal.error.notification"; @NonNls private static final String DISABLED_VALUE = "disabled"; @NonNls private static final String ENABLED_VALUE = "enabled"; - @NonNls private static final String PARAM_PERMGEN = "PermGen"; + @NonNls private static final String PARAM_PERM_GEN = "PermGen"; public boolean canHandle(IdeaLoggingEvent event) { if (ourLoggerBroken) return false; @@ -56,7 +56,7 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal() || - isOOMError(event.getThrowable()) || + isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException; } catch (LinkageError e) { @@ -68,13 +68,8 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } } - /** - * @noinspection CallToPrintStackTrace - */ public void handle(IdeaLoggingEvent event) { - if (ourLoggerBroken) { - return; - } + if (ourLoggerBroken) return; try { Throwable throwable = event.getThrowable(); @@ -84,11 +79,11 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { else if (throwable instanceof MappingFailedException) { processMappingFailed(event); } - else if (!ourOomOccured) { + else if (!ourOomOccurred) { MessagePool messagePool = MessagePool.getInstance(); LogMessage message = messagePool.addIdeFatalMessage(event); if (message != null && ApplicationManager.getApplication() != null) { - notifyUi(messagePool, message); + ErrorNotifier.notifyUi(message, messagePool); } } } @@ -99,14 +94,9 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLoggerBroken = true; } - e.printStackTrace(); } } - private static void notifyUi(MessagePool messagePool, LogMessage message) { - ErrorNotifier.notifyUi(message, messagePool); - } - private static boolean isOOMError(Throwable throwable) { return throwable instanceof OutOfMemoryError || (throwable instanceof VirtualMachineError && @@ -114,17 +104,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { throwable.getMessage().contains("CodeCache")); } - /** - * @noinspection CallToPrintStackTrace - */ private static void processOOMError(final Throwable throwable) throws InterruptedException, InvocationTargetException { - ourOomOccured = true; - throwable.printStackTrace(); + ourOomOccurred = true; SwingUtilities.invokeAndWait(new Runnable() { public void run() { String message = throwable.getMessage(); - OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERMGEN) + OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERM_GEN) ? OutOfMemoryDialog.MemoryKind.PERM_GEN : message != null && message.contains("CodeCache") ? OutOfMemoryDialog.MemoryKind.CODE_CACHE @@ -135,13 +121,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } private static void processMappingFailed(final IdeaLoggingEvent event) throws InterruptedException, InvocationTargetException { - if (!mappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { - mappingFailedNotificationPosted = true; - final String exceptionMessage = event.getThrowable().getMessage(); - final String text = exceptionMessage + - "
Possible cause: unable to allocate continuous memory chunk of necessary size.
Reducing JVM's maximum heap size (-Xmx) may help."; - Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), NotificationDisplayType.BALLOON, null); + if (!ourMappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { + ourMappingFailedNotificationPosted = true; + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") String exceptionMessage = event.getThrowable().getMessage(); + String text = exceptionMessage + + "
Possible cause: unable to allocate continuous memory chunk of necessary size.
" + + "Reducing JVM maximum heap size (-Xmx) may help."; + Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), null); } } - } diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java index 0c24c336acff..17de69c30b7c 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -44,7 +44,6 @@ public class IdeaLogger extends Logger { public static String ourLastActionId = ""; - private final org.apache.log4j.Logger myLogger; /** If not null - it means that errors occurred and it is the first of them. */ public static Exception ourErrorsOccurred; @@ -59,25 +58,24 @@ public class IdeaLogger extends Logger { static { InputStream stream = Logger.class.getResourceAsStream(COMPILATION_TIMESTAMP_RESOURCE_NAME); if (stream != null) { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); try { - String s = reader.readLine(); - if (s != null) { - ourCompilationTimestamp = s.trim(); - } - } - catch (IOException ignored) { - } - finally { + LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); try { - stream.close(); + String s = reader.readLine(); + if (s != null) { + ourCompilationTimestamp = s.trim(); + } } - catch (IOException ignored) { + finally { + reader.close(); } } + catch (IOException ignored) { } } } + private final org.apache.log4j.Logger myLogger; + IdeaLogger(org.apache.log4j.Logger logger) { myLogger = logger; } @@ -134,9 +132,6 @@ public class IdeaLogger extends Logger { myLogger.error(message + (!detailString.isEmpty() ? "\nDetails: " + detailString : ""), t); logErrorHeader(); - if (t != null && t.getCause() != null) { - myLogger.error("Original exception: ", t.getCause()); - } } private void logErrorHeader() { From ed4d1a73021be3aa7856ba4e94a97b8644e6425b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Jun 2013 11:46:36 +0400 Subject: [PATCH 06/47] platform: unified handling of startup errors --- .../src/com/intellij/ide/Bootstrap.java | 33 +-- .../src/com/intellij/ide/ClassloaderUtil.java | 72 ++---- .../bootstrap/src/com/intellij/idea/Main.java | 153 +++++++----- .../intellij/diagnostic/PluginException.java | 9 +- .../components/impl/ComponentManagerImpl.java | 183 ++++++--------- .../intellij/ide/plugins/PluginManager.java | 222 +++++++++++------- .../com/intellij/idea/IdeaApplication.java | 60 ++--- .../src/com/intellij/idea/StartupUtil.java | 56 ++--- .../application/impl/ApplicationImpl.java | 64 ++--- .../fileTypes/impl/FileTypeManagerImpl.java | 8 +- .../src/com/intellij/idea/MainImpl.java | 34 ++- .../intellij/openapi/diagnostic/Logger.java | 52 ++-- 12 files changed, 427 insertions(+), 519 deletions(-) diff --git a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java index 5853fcf99601..05280434f3d0 100644 --- a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java +++ b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -17,7 +17,6 @@ package com.intellij.ide; import com.intellij.util.lang.UrlClassLoader; -import javax.swing.*; import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; @@ -29,31 +28,19 @@ import java.util.List; public class Bootstrap { private static final String PLUGIN_MANAGER = "com.intellij.ide.plugins.PluginManager"; - private Bootstrap() {} + private Bootstrap() { } - public static void main(final String[] args, final String mainClass, final String methodName) { + public static void main(String[] args, String mainClass, String methodName) throws Exception { main(args, mainClass, methodName, new ArrayList()); } - public static void main(final String[] args, final String mainClass, final String methodName, final List classpathElements) { - final UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); - try { - WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); + public static void main(String[] args, String mainClass, String methodName, List classpathElements) throws Exception { + UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); + WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); - final Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); - - final Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); - startMethod.setAccessible(true); - startMethod.invoke(null, mainClass, methodName, args); - } - catch (Exception e) { - if ("true".equals(System.getProperty("java.awt.headless"))) { - //noinspection UseOfSystemOutOrSystemErr - e.printStackTrace(System.err); - } - else { - JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage(), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); - } - } + Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); + Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); + startMethod.setAccessible(true); + startMethod.invoke(null, mainClass, methodName, args); } } \ No newline at end of file diff --git a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java index 84461aded7c9..6d6f715d026d 100644 --- a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java +++ b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -30,7 +30,6 @@ import com.intellij.util.lang.UrlClassLoader; import com.intellij.util.text.StringTokenizer; import org.jetbrains.annotations.NonNls; -import javax.swing.*; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -44,76 +43,33 @@ import java.util.regex.Pattern; public class ClassloaderUtil extends ClassUtilCore { @NonNls public static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath"; - @SuppressWarnings({"HardCodedStringLiteral"}) - private static final String ERROR = "Error"; - private ClassloaderUtil() {} public static Logger getLogger() { return Logger.getInstance("ClassloaderUtil"); } - public static UrlClassLoader initClassloader(final List classpathElements) { + public static UrlClassLoader initClassloader(final List classpathElements) throws Exception { PathManager.loadProperties(); - try { - addParentClasspath(classpathElements); - addIDEALibraries(classpathElements); - addAdditionalClassPath(classpathElements); - } - catch (IllegalArgumentException e) { - if (Main.isHeadless()) { - getLogger().error(e); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); - } - System.exit(1); - } - catch (MalformedURLException e) { - if (Main.isHeadless()) { - getLogger().error(e.getMessage()); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); - } - System.exit(1); - } + addParentClasspath(classpathElements); + addIDEALibraries(classpathElements); + addAdditionalClassPath(classpathElements); filterClassPath(classpathElements); + UrlClassLoader newClassLoader = new UrlClassLoader(classpathElements, null, true, true); - UrlClassLoader newClassLoader = null; - try { - newClassLoader = new UrlClassLoader(classpathElements, null, true, true); - - // prepare plugins - if (!isLoadingOfExternalPluginsDisabled()) { - try { - StartupActionScriptManager.executeActionScript(); - } - catch (IOException e) { - final String errorMessage = "Error executing plugin installation script: " + e.getMessage(); - if (Main.isHeadless()) { - System.out.println(errorMessage); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), errorMessage, ERROR, JOptionPane.INFORMATION_MESSAGE); - } - } + // prepare plugins + if (!isLoadingOfExternalPluginsDisabled()) { + try { + StartupActionScriptManager.executeActionScript(); } - - Thread.currentThread().setContextClassLoader(newClassLoader); - - } - catch (Exception e) { - Logger logger = getLogger(); - if (logger == null) { - e.printStackTrace(System.err); - } - else { - logger.error(e); + catch (IOException e) { + Main.showMessage("Plugin Installation Error", e); } } + + Thread.currentThread().setContextClassLoader(newClassLoader); return newClassLoader; } diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index 43fc8d7f3df9..182946c2c786 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -20,72 +20,75 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.util.ArrayUtilRt; +import com.intellij.util.ExceptionUtil; import com.intellij.util.Restarter; -import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; +import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; +@SuppressWarnings({"UseOfSystemOutOrSystemErr", "MethodNamesDifferingOnlyByCase"}) public class Main { + public static final int UPDATE_FAILED = 1; + public static final int STARTUP_EXCEPTION = 2; + public static final int STARTUP_IMPOSSIBLE = 3; + public static final int LICENSE_ERROR = 4; + public static final int PLUGIN_ERROR = 5; + private static boolean isHeadless; + private static boolean isCommandLine; private Main() { } - @SuppressWarnings("MethodNamesDifferingOnlyByCase") public static void main(final String[] args) { - isHeadless = _isHeadless(args); + setFlags(args); if (isHeadless()) { System.setProperty("java.awt.headless", Boolean.TRUE.toString()); } - else if (GraphicsEnvironment.isHeadless()) { - throw new HeadlessException("Unable to detect graphics environment"); - } + else { + if (GraphicsEnvironment.isHeadless()) { + throw new HeadlessException("Unable to detect graphics environment"); + } - if (!isHeadless()) { try { installPatch(); } - catch (IOException e) { - e.printStackTrace(); - - File log = null; - try { - log = FileUtilRt.createTempFile("patch", ".log", false); - PrintWriter writer = new PrintWriter(log); - try { - e.printStackTrace(writer); - } - finally { - writer.close(); - } - } - catch (IOException ignore) { - ignore.printStackTrace(); - } - - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - catch (Throwable ignore) { - } - String message = e.getMessage() - + "\n" + (log == null ? "Log cannot be saved" : "Log is saved in " + log) - + "\n\nPlease download and install update manually" ; - JOptionPane.showMessageDialog(null, message, "Cannot Apply Patch", JOptionPane.ERROR_MESSAGE); + catch (Throwable t) { + showMessage("Update Failed", t); + System.exit(UPDATE_FAILED); } } - Bootstrap.main(args, Main.class.getName() + "Impl", "start"); + try { + Bootstrap.main(args, Main.class.getName() + "Impl", "start"); + } + catch (Throwable t) { + showMessage("Start Failed", t); + System.exit(STARTUP_EXCEPTION); + } } - private static boolean _isHeadless(String[] args) { + public static boolean isHeadless() { + return isHeadless; + } + + public static boolean isCommandLine() { + return isCommandLine; + } + + public static void setFlags(String[] args) { + isHeadless = isHeadless(args); + isCommandLine = isCommandLine(args); + } + + private static boolean isHeadless(String[] args) { if (GraphicsEnvironment.isHeadless()) { return true; } @@ -101,26 +104,15 @@ public class Main { (firstArg.length() < 20 && firstArg.endsWith("inspect")); } - public static boolean isHeadless() { - return isHeadless; - } - - /** @deprecated use {@link #isHeadless()} (to remove in IDEA 14) */ - @SuppressWarnings("unused") - public static boolean isHeadless(final String[] args) { - return isHeadless(); + private static boolean isCommandLine(String[] args) { + if (isHeadless()) return true; + return args.length > 0 && Comparing.strEqual(args[0], "diff"); } public static boolean isUITraverser(final String[] args) { return args.length > 0 && Comparing.strEqual(args[0], "traverseUI"); } - public static boolean isCommandLine(final String[] args) { - if (isHeadless()) return true; - @NonNls final String diffAppCode = "diff"; - return args.length > 0 && Comparing.strEqual(args[0], diffAppCode); - } - private static void installPatch() throws IOException { String platform = System.getProperty("idea.platform.prefix", "idea"); String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase(); @@ -140,20 +132,55 @@ public class Main { throw new IOException("Cannot create temporary patch file"); } - List args = new ArrayList(); - if (SystemInfo.isWindows) { - args.add(Restarter.createTempExecutable(new File(PathManager.getBinPath(), "vistalauncher.exe")).getPath()); + int status = 0; + if (Restarter.isSupported()) { + List args = new ArrayList(); + + if (SystemInfo.isWindows) { + File launcher = new File(PathManager.getBinPath(), "VistaLauncher.exe"); + args.add(Restarter.createTempExecutable(launcher).getPath()); + } + + Collections.addAll(args, + System.getProperty("java.home") + "/bin/java", + "-Xmx500m", + "-classpath", + copyPatchFile.getPath(), + "com.intellij.updater.Runner", + "install", + PathManager.getHomePath()); + + status = Restarter.scheduleRestart(ArrayUtilRt.toStringArray(args)); + } + else { + String message = "Patch update is not supported - please do it manually"; + showMessage("Update Error", message, true); } - Collections.addAll(args, - System.getProperty("java.home") + "/bin/java", - "-Xmx500m", - "-classpath", - copyPatchFile.getPath(), - "com.intellij.updater.Runner", - "install", - PathManager.getHomePath()); + System.exit(status); + } - System.exit(Restarter.scheduleRestart(args.toArray(new String[args.size()]))); + public static void showMessage(String title, Throwable t) { + String message = "Internal exception, please report to http://youtrack.jetbrains.com\n\n" + ExceptionUtil.getThrowableText(t); + showMessage(title, message, true); + } + + public static void showMessage(String title, String message, boolean error) { + if (isCommandLine()) { + PrintStream stream = error ? System.err : System.out; + stream.println(title + ": " + message); + } + else { + try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } + catch (Throwable ignore) { } + + JTextPane textPane = new JTextPane(); + textPane.setEditable(false); + textPane.setText(message.replaceAll("\t", " ")); + textPane.setBackground(UIManager.getColor("Panel.background")); + + int type = error ? JOptionPane.ERROR_MESSAGE : JOptionPane.INFORMATION_MESSAGE; + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), textPane, title, type); + } } } diff --git a/platform/core-api/src/com/intellij/diagnostic/PluginException.java b/platform/core-api/src/com/intellij/diagnostic/PluginException.java index 1710d05cd34a..3a520ebc466c 100644 --- a/platform/core-api/src/com/intellij/diagnostic/PluginException.java +++ b/platform/core-api/src/com/intellij/diagnostic/PluginException.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -19,11 +19,8 @@ import com.intellij.openapi.extensions.PluginId; import org.jetbrains.annotations.NonNls; /** - * Created by IntelliJ IDEA. - * User: stathik - * Date: Jan 8, 2004 - * Time: 3:06:43 PM - * To change this template use Options | File Templates. + * @author stathik + * @since Jan 8, 2004 */ public class PluginException extends RuntimeException { private final PluginId myPluginId; diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index e231cb1e3ea6..a33f22150dae 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -105,21 +105,10 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements try { myComponentsRegistry.loadClasses(); - final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); + Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); for (Class componentInterface : componentInterfaces) { ProgressIndicatorProvider.checkCanceled(); - try { - createComponent(componentInterface); - } - catch (StateStorageException e) { - throw e; - } - catch (ProcessCanceledException e) { - throw e; - } - catch(Exception e) { - LOG.error(e); - } + createComponent(componentInterface); } } finally { @@ -209,35 +198,12 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return null; } - private void initComponent(Object component) { - final ProgressIndicator indicator = getProgressIndicator(); - if (indicator != null) { - indicator.checkCanceled(); - } - - try { - initializeComponent(component, false); - if (component instanceof BaseComponent) { - ((BaseComponent)component).initComponent(); - } - } - catch (StateStorageException e) { - throw e; - } - catch (ProcessCanceledException e) { - throw e; - } - catch (Throwable ex) { - handleInitComponentError(ex, false, component.getClass().getName(), null); - } - } - @Nullable protected static ProgressIndicator getProgressIndicator() { return ProgressIndicatorProvider.getGlobalProgressIndicator(); } - protected double getPercentageOfComponentsLoaded() { + protected float getPercentageOfComponentsLoaded() { return myComponentsRegistry.getPercentageOfComponentsLoaded(); } @@ -245,8 +211,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public void initializeComponent(Object component, boolean service) { } - - protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { + protected void handleInitComponentError(Throwable ex, String componentClassName, ComponentConfig config) { LOG.error(ex); } @@ -358,7 +323,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements getComponents(); } - protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable final PluginDescriptor descriptor, final boolean defaultProject) { + protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable PluginDescriptor descriptor, boolean defaultProject) { myConfigurator.loadComponentsConfiguration(components, descriptor, defaultProject); } @@ -426,7 +391,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements protected class ComponentsRegistry { private final Map myInterfaceToLockMap = new THashMap(); private final Map myInterfaceToClassMap = new THashMap(); - private final ArrayList myComponentInterfaces = new ArrayList(); // keeps order of component's registration + private final List myComponentInterfaces = new ArrayList(); // keeps order of component's registration private final Map myNameToComponent = new THashMap(); private final List myComponentConfigs = new ArrayList(); private final List myImplementations = new ArrayList(); @@ -452,7 +417,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements interfaceClass : Class.forName(config.getImplementationClass(), true, loader); if (myInterfaceToClassMap.get(interfaceClass) != null) { - throw new ComponentAlreadyRegisteredException(interfaceClass); + throw new RuntimeException("Component already registered: " + interfaceClass.getName()); } getPicoContainer().registerComponent(new ComponentConfigComponentAdapter(config, implementationClass)); @@ -460,17 +425,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements myComponentClassToConfig.put(implementationClass, config); myComponentInterfaces.add(interfaceClass); } - catch (ComponentAlreadyRegisteredException ex) { - throw new Error(ex); - } - catch (Throwable e) { - handleInitComponentError(e, false, null, config); - } - } - - private class ComponentAlreadyRegisteredException extends Exception { - private ComponentAlreadyRegisteredException(Class interfaceClass) { - super(interfaceClass.getName() + " component already registered"); + catch (Throwable t) { + handleInitComponentError(t, null, config); } } @@ -492,8 +448,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return myInterfaceToClassMap.containsKey(interfaceClass); } - public double getPercentageOfComponentsLoaded() { - return ((double)myImplementations.size()) / myComponentConfigs.size(); + public float getPercentageOfComponentsLoaded() { + return ((float)myImplementations.size()) / myComponentConfigs.size(); } private void registerComponentInstance(final Object component) { @@ -565,57 +521,66 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public ComponentConfigComponentAdapter(final ComponentConfig config, Class implementationClass) { myConfig = config; + final String componentKey = config.getInterfaceClass(); myDelegate = new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(componentKey, implementationClass, null, true)) { - @Override - public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { - Object componentInstance = null; - try { - long startTime = myInitialized ? 0 : System.nanoTime(); - componentInstance = super.getComponentInstance(picoContainer); - - if (!myInitialized) { - if (myInitializing) { - if (myConfig.pluginDescriptor != null) { - LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); - } - else { - LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); - } - } - - try { - myInitializing = true; - myComponentsRegistry.registerComponentInstance(componentInstance); - initComponent(componentInstance); - long endTime = System.nanoTime(); - long ms = (endTime - startTime) / 1000000; - if (ms > 10) { - if (logSlowComponents()) { - LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); - } - } - } - finally { - myInitializing = false; - } - - myInitialized = true; - } - } - catch (ProcessCanceledException e) { - throw e; - } - catch (StateStorageException e) { - throw e; - } - catch (Throwable t) { - handleInitComponentError(t, componentInstance == null, componentKey, config); - } - return componentInstance; + @Override + public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { + ProgressIndicator indicator = getProgressIndicator(); + if (indicator != null) { + indicator.checkCanceled(); } - }; + Object componentInstance = null; + try { + long startTime = myInitialized ? 0 : System.nanoTime(); + + componentInstance = super.getComponentInstance(picoContainer); + + if (!myInitialized) { + if (myInitializing) { + if (myConfig.pluginDescriptor != null) { + LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); + } + else { + LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); + } + } + + try { + myInitializing = true; + myComponentsRegistry.registerComponentInstance(componentInstance); + + initializeComponent(componentInstance, false); + if (componentInstance instanceof BaseComponent) { + ((BaseComponent)componentInstance).initComponent(); + } + + long ms = (System.nanoTime() - startTime) / 1000000; + if (ms > 10 && logSlowComponents()) { + LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); + } + } + finally { + myInitializing = false; + } + + myInitialized = true; + } + } + catch (ProcessCanceledException e) { + throw e; + } + catch (StateStorageException e) { + throw e; + } + catch (Throwable t) { + handleInitComponentError(t, componentKey, config); + } + + return componentInstance; + } + }; } @Override @@ -625,27 +590,23 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Override public Class getComponentImplementation() { - return getDelegate().getComponentImplementation(); + return myDelegate.getComponentImplementation(); } @Override public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { - return getDelegate().getComponentInstance(container); + return myDelegate.getComponentInstance(container); } @Override public void verify(final PicoContainer container) throws PicoIntrospectionException { - getDelegate().verify(container); + myDelegate.verify(container); } @Override public void accept(final PicoVisitor visitor) { visitor.visitComponentAdapter(this); - getDelegate().accept(visitor); - } - - private ComponentAdapter getDelegate() { - return myDelegate; + myDelegate.accept(visitor); } } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 1732ab693114..384d8f56fba9 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.plugins; import com.intellij.ide.ClassUtilCore; import com.intellij.ide.IdeBundle; -import com.intellij.idea.StartupUtil; +import com.intellij.idea.Main; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.components.ComponentConfig; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.progress.ProcessCanceledException; @@ -31,7 +32,6 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.util.ArrayUtil; -import com.intellij.util.ExceptionUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,9 +39,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.List; /** * @author mike @@ -56,91 +55,99 @@ public class PluginManager extends PluginManagerCore { /** * Called via reflection */ - @SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral"}) + @SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral", "finally"}) protected static void start(final String mainClass, final String methodName, final String[] args) { startupStart = System.nanoTime(); - try { - ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { - @Override - public void uncaughtException(Thread t, Throwable e) { - if (!(e instanceof ProcessCanceledException)) { - PluginManagerCore.getLogger().error(e); - } - } - }; - Runnable runnable = new Runnable() { - @Override - public void run() { + Main.setFlags(args); + + ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { + @Override + public void uncaughtException(Thread t, Throwable e) { + if (e instanceof StartupAbortedException) { + StartupAbortedException se = (StartupAbortedException)e; try { - ClassUtilCore.clearJarURLCache(); - - Class aClass = Class.forName(mainClass); - Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); - method.setAccessible(true); - - //noinspection RedundantArrayCreation - method.invoke(null, new Object[]{args}); - } - catch (Throwable t) { - //noinspection InstanceofCatchParameter - if (t instanceof InvocationTargetException) { - t = t.getCause(); + if (se.logError()) { + if (Logger.isInitialized()) { + getLogger().error(e); + } + Main.showMessage("Start Failed", e); } - - String message = "Error while accessing " + mainClass + "." + methodName + " with arguments: " + Arrays.asList(args) + - "\n" + ExceptionUtil.getThrowableText(t); - StartupUtil.showError("Error starting IntelliJ Platform", message); - System.exit(1); + } + finally { + System.exit(se.exitCode()); } } - }; - new Thread(threadGroup, runnable, "Idea Main Thread").start(); - } - catch (Exception e) { - PluginManagerCore.getLogger().error(e); - } + if (!(e instanceof ProcessCanceledException)) { + getLogger().error(e); + } + } + }; + + Runnable runnable = new Runnable() { + @Override + public void run() { + try { + ClassUtilCore.clearJarURLCache(); + + Class aClass = Class.forName(mainClass); + Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); + method.setAccessible(true); + Object[] argsArray = {args}; + method.invoke(null, argsArray); + } + catch (Throwable t) { + throw new StartupAbortedException(t); + } + } + }; + + new Thread(threadGroup, runnable, "Idea Main Thread").start(); } public static void reportPluginError() { if (myPluginError != null) { - Notifications.Bus.notify(new Notification(IdeBundle.message("title.plugin.error"), IdeBundle.message("title.plugin.error"), - myPluginError, NotificationType.ERROR, new NotificationListener() { - @Override - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - notification.expire(); - final String description = event.getDescription(); - if (EDIT.equals(description)) { - final PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); - IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); - ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); - return; - } - final List disabledPlugins = PluginManagerCore.getDisabledPlugins(); - if (myPlugins2Disable != null && DISABLE.equals(description)) { - for (String pluginId : myPlugins2Disable) { - if (!disabledPlugins.contains(pluginId)) { - disabledPlugins.add(pluginId); - } - } - } else if (myPlugins2Enable != null && ENABLE.equals(description)) { - disabledPlugins.removeAll(myPlugins2Enable); - } - try { - PluginManagerCore.saveDisabledPlugins(disabledPlugins, false); - } - catch (IOException ignore) { - } - myPlugins2Enable = null; - myPlugins2Disable = null; + String message = IdeBundle.message("title.plugin.error"); + Notifications.Bus.notify(new Notification(message, message, myPluginError, NotificationType.ERROR, new NotificationListener() { + @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + notification.expire(); + + String description = event.getDescription(); + if (EDIT.equals(description)) { + PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); + IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); + ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); + return; } - })); + + List disabledPlugins = getDisabledPlugins(); + if (myPlugins2Disable != null && DISABLE.equals(description)) { + for (String pluginId : myPlugins2Disable) { + if (!disabledPlugins.contains(pluginId)) { + disabledPlugins.add(pluginId); + } + } + } + else if (myPlugins2Enable != null && ENABLE.equals(description)) { + disabledPlugins.removeAll(myPlugins2Enable); + } + + try { + saveDisabledPlugins(disabledPlugins, false); + } + catch (IOException ignore) { } + + myPlugins2Enable = null; + myPlugins2Disable = null; + } + })); myPluginError = null; } } - public static boolean isPluginInstalled(PluginId id) { return getPlugin(id) != null; } @@ -156,24 +163,59 @@ public class PluginManager extends PluginManagerCore { return null; } - public static void disableIncompatiblePlugin(final Object cause, final Throwable ex) { - final PluginId pluginId = getPluginByClassName(cause.getClass().getName()); - if (pluginId != null && !ApplicationManager.getApplication().isHeadlessEnvironment()) { - final boolean success = PluginManagerCore.disablePlugin(pluginId.getIdString()); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), - "Incompatible plugin detected: " + pluginId.getIdString() + - (success ? "\nThe plugin has been disabled" : ""), - "Plugin Manager", - JOptionPane.ERROR_MESSAGE); - } - }); + public static void handleComponentError(Throwable t, String componentClassName, ComponentConfig config) { + if (t instanceof StartupAbortedException) { + throw (StartupAbortedException)t; + } + + PluginId pluginId = config != null ? config.getPluginId() : getPluginByClassName(componentClassName); + + if (pluginId != null && !CORE_PLUGIN_ID.equals(pluginId.getIdString())) { + getLogger().warn(t); + + disablePlugin(pluginId.getIdString()); + + String message = + "Plugin '" + pluginId.getIdString() + "' failed to initialize and will be disabled\n" + + "(reason: " + t.getMessage() + ")\n\n" + + ApplicationNamesInfo.getInstance().getFullProductName() + " will be restarted."; + Main.showMessage("Plugin Error", message, false); + + throw new StartupAbortedException(t).exitCode(Main.PLUGIN_ERROR).logError(false); } else { - // should never happen - throw new RuntimeException(ex); + throw new StartupAbortedException("Fatal error initializing '" + componentClassName + "'", t); + } + } + + public static class StartupAbortedException extends RuntimeException { + private int exitCode = Main.STARTUP_EXCEPTION; + private boolean logError = true; + + public StartupAbortedException(Throwable cause) { + super(cause); + } + + public StartupAbortedException(String message, Throwable cause) { + super(message, cause); + } + + public int exitCode() { + return exitCode; + } + + public StartupAbortedException exitCode(int exitCode) { + this.exitCode = exitCode; + return this; + } + + public boolean logError() { + return logError; + } + + public StartupAbortedException logError(boolean logError) { + this.logError = logError; + return this; } } } diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index d89b7e40a5c5..4604d57a6777 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -18,7 +18,6 @@ package com.intellij.idea; import com.intellij.ExtensionPoints; import com.intellij.Patches; import com.intellij.concurrency.JobScheduler; -import com.intellij.diagnostic.PluginException; import com.intellij.ide.AppLifecycleListener; import com.intellij.ide.CommandLineProcessor; import com.intellij.ide.IdeEventQueue; @@ -37,10 +36,12 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.updateSettings.impl.UpdateChecker; import com.intellij.openapi.updateSettings.impl.UpdateSettings; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.SystemDock; @@ -55,7 +56,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -85,7 +85,7 @@ public class IdeaApplication { patchSystem(); } - if (Main.isCommandLine(args)) { + if (Main.isCommandLine()) { new CommandLineApplication(isInternal, false, headless); } else { @@ -164,12 +164,13 @@ public class IdeaApplication { PluginManagerCore.getPlugins(); ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.APPLICATION_STARTER); - final ApplicationStarter[] starters = point.getExtensions(); + ApplicationStarter[] starters = point.getExtensions(); String key = myArgs[0]; for (ApplicationStarter o : starters) { if (Comparing.equal(o.getCommandName(), key)) return o; } } + return new IdeStarter(); } @@ -177,17 +178,9 @@ public class IdeaApplication { return ourInstance; } - public void run() { + public void run() throws Exception { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - try { - app.load(PathManager.getOptionsPath()); - } - catch (IOException e) { - e.printStackTrace(); - } - catch (InvalidDataException e) { - e.printStackTrace(); - } + app.load(PathManager.getOptionsPath()); myStarter.main(myArgs); myStarter = null; //GC it @@ -254,36 +247,28 @@ public class IdeaApplication { @Override public void main(String[] args) { - SystemDock.updateMenu(); + // Event queue should not be changed during initialization of application components. // It also cannot be changed before initialization of application components because IdeEventQueue uses other // application components. So it is proper to perform replacement only here. ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - // app.setupIdeQueue(IdeEventQueue.getInstance()); WindowManagerImpl windowManager = (WindowManagerImpl)WindowManager.getInstance(); + IdeEventQueue.getInstance().setWindowManager(windowManager); - try { - IdeEventQueue.getInstance().setWindowManager(windowManager); + Ref willOpenProject = new Ref(Boolean.FALSE); + AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); + lifecyclePublisher.appFrameCreated(args, willOpenProject); - final Ref willOpenProject = new Ref(Boolean.FALSE); - final AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); - lifecyclePublisher.appFrameCreated(args, willOpenProject); - LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); - PluginManagerCore.dumpPluginClassStatistics(); - if (!willOpenProject.get()) { - WelcomeFrame.showNow(); - lifecyclePublisher.welcomeScreenDisplayed(); - } - else { - windowManager.showFrame(); - } + LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); + PluginManagerCore.dumpPluginClassStatistics(); + + if (!willOpenProject.get()) { + WelcomeFrame.showNow(); + lifecyclePublisher.welcomeScreenDisplayed(); } - catch (PluginException e) { - Messages.showErrorDialog("Plugin " + e.getPluginId() + " couldn't be loaded, the IDE will now exit.\n" + - "See the full details in the log.\n" + - e.getMessage(), "Plugin Error"); - System.exit(-1); + else { + windowManager.showFrame(); } app.invokeLater(new Runnable() { @@ -323,7 +308,6 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); } - } private void loadProject() { diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index a2f386c6bd9d..93e12c8440d8 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -15,7 +15,7 @@ */ package com.intellij.idea; -import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.ide.startupWizard.StartupWizard; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationNamesInfo; @@ -37,7 +37,6 @@ import org.jetbrains.annotations.NonNls; import org.xerial.snappy.Snappy; import org.xerial.snappy.SnappyLoader; -import javax.swing.*; import java.io.File; import java.io.InputStream; import java.lang.management.ManagementFactory; @@ -77,14 +76,8 @@ public class StartupUtil { return Main.isHeadless(); } - public static void showError(final String title, final String message) { - if (Main.isHeadless()) { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(message); - } - else { - JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, title, JOptionPane.ERROR_MESSAGE); - } + public synchronized static void addExternalInstanceListener(Consumer> consumer) { + ourLock.setActivateListener(consumer); } /** @@ -97,17 +90,9 @@ public class StartupUtil { Class.forName("com.sun.jdi.Field"); } catch (ClassNotFoundException e) { - showError("Error", "'tools.jar' is not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + - "Please ensure JAVA_HOME points to JDK rather than JRE."); - return false; - } - } - - if (!"true".equals(System.getProperty("idea.no.jdk.check"))) { - final String version = System.getProperty("java.version"); - if (!SystemInfo.isJavaVersionAtLeast("1.6")) { - showError("Java Version Mismatch", "The JDK version is " + version + ".\n" + - ApplicationNamesInfo.getInstance().getProductName() + " requires JDK 1.6 or higher."); + String message = "'tools.jar' seems to be not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + + "Please ensure JAVA_HOME points to JDK rather than JRE."; + Main.showMessage("JDK Required", message, true); return false; } } @@ -117,18 +102,20 @@ public class StartupUtil { private synchronized static boolean checkSystemFolders() { final String configPath = PathManager.getConfigPath(); - if (configPath == null || !new File(configPath).isDirectory()) { - showError("Invalid config path", "Config path '" + configPath + "' is invalid.\n" + - "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."); + if (!new File(configPath).isDirectory()) { + String message = "Config path '" + configPath + "' is invalid.\n" + + "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."; + Main.showMessage("Invalid Config Path", message, true); return false; } final String systemPath = PathManager.getSystemPath(); if (systemPath == null || !new File(systemPath).isDirectory()) { - showError("Invalid system path", "System path '" + systemPath + "' is invalid.\n" + - "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."); + String message = "System path '" + systemPath + "' is invalid.\n" + + "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."; + Main.showMessage("Invalid System Path", message, true); return false; } @@ -147,7 +134,8 @@ public class StartupUtil { if (activateStatus != SocketLock.ActivateStatus.NO_INSTANCE) { if (Main.isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) { - showError("Error", "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time."); + String message = "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time."; + Main.showMessage("Too Many Instances", message, true); } return false; } @@ -167,15 +155,10 @@ public class StartupUtil { final StartupWizard startupWizard = new StartupWizard(pages); startupWizard.setCancelText("Skip"); startupWizard.show(); - PluginManager.invalidatePlugins(); + PluginManagerCore.invalidatePlugins(); } } - public synchronized static void addExternalInstanceListener(Consumer> consumer) { - ourLock.setActivateListener(consumer); - } - - static void fixProcessEnvironment(Logger log) { boolean envReady = EnvironmentUtil.isEnvironmentReady(); // trigger environment loading if (!envReady) { @@ -183,7 +166,6 @@ public class StartupUtil { } } - private static final String JAVA_IO_TEMP_DIR = "java.io.tmpdir"; static void loadSystemLibraries(final Logger log) { @@ -280,7 +262,7 @@ public class StartupUtil { loadNativeLibrary.invoke(null, loaderClass); } - public static void startLogging(final Logger log) { + static void startLogging(final Logger log) { Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook - logging") { public void run() { log.info( diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 48d8b85b133d..f092d21e0e43 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -22,6 +22,7 @@ import com.intellij.diagnostic.PluginException; import com.intellij.ide.*; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.idea.StartupUtil; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.*; @@ -37,7 +38,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProcessCanceledException; @@ -89,8 +89,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application private static final Logger LOG = Logger.getInstance("#com.intellij.application.impl.ApplicationImpl"); private final ModalityState MODALITY_STATE_NONE = ModalityState.NON_MODAL; - // about writer preference: the way the java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync is implemented, the - // writer thread will be always at the queue head and therefore, java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() + // about writer preference: the way the j.u.c.l.ReentrantReadWriteLock.NonfairSync is implemented, the + // writer thread will be always at the queue head and therefore, j.u.c.l.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() // will return true if the write action is pending, exactly as we need private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(false); @@ -361,55 +361,25 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } @Override - protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { - if (myHandlingInitComponentError) { - return; - } - myHandlingInitComponentError = true; - try { - PluginId pluginId = config == null ? PluginManager.getPluginByClassName(componentClassName) : config.getPluginId(); - if (pluginId != null) { - LOG.warn(ex); - @NonNls final String errorMessage = - "Plugin " + pluginId.getIdString() + " failed to initialize and will be disabled:\n" + ex.getMessage() + - "\nPlease restart " + ApplicationNamesInfo.getInstance().getFullProductName() + "."; - PluginManager.disablePlugin(pluginId.getIdString()); - if (!myHeadlessMode) { - JOptionPane.showMessageDialog(null, errorMessage); - } - else if (!isUnitTestMode()) { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(errorMessage); - System.exit(1); - } - return; // do not call super + protected void handleInitComponentError(Throwable t, String componentClassName, ComponentConfig config) { + if (!myHandlingInitComponentError) { + myHandlingInitComponentError = true; + try { + PluginManager.handleComponentError(t, componentClassName, config); } - if (fatal) { - LOG.error(ex); - @NonNls final String errorMessage = "Fatal error initializing class " + componentClassName + ":\n" + - StringUtil.trimLog(ex.toString(), 239) + - "\nComplete error stacktrace was written to " + PathManager.getLogPath() + "/idea.log"; - if (!myHeadlessMode) { - JOptionPane.showMessageDialog(null, errorMessage); - } - else { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(errorMessage); - } + finally { + myHandlingInitComponentError = false; } - super.handleInitComponentError(ex, fatal, componentClassName, config); - } - finally { - myHandlingInitComponentError = false; } } private void loadApplicationComponents() { - PluginManager.initPlugins(mySplash); - final IdeaPluginDescriptor[] plugins = PluginManager.getPlugins(); + PluginManagerCore.initPlugins(mySplash); + IdeaPluginDescriptor[] plugins = PluginManagerCore.getPlugins(); for (IdeaPluginDescriptor plugin : plugins) { - if (PluginManager.shouldSkipPlugin(plugin)) continue; - loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); + if (!PluginManagerCore.shouldSkipPlugin(plugin)) { + loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); + } } } @@ -417,7 +387,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application protected synchronized Object createComponent(Class componentInterface) { Object component = super.createComponent(componentInterface); if (mySplash != null) { - mySplash.showProgress("", (float)(0.65f + getPercentageOfComponentsLoaded() * 0.35f)); + mySplash.showProgress("", 0.65f + getPercentageOfComponentsLoaded() * 0.35f); } return component; } @@ -1440,7 +1410,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application public void run() { if (ex instanceof PluginException) { final PluginException pluginException = (PluginException)ex; - PluginManager.disablePlugin(pluginException.getPluginId().getIdString()); + PluginManagerCore.disablePlugin(pluginException.getPluginId().getIdString()); Messages.showMessageDialog("The plugin " + pluginException.getPluginId() + " failed to save settings and has been disabled. Please restart " + diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index fd6e291e0b27..0ff8fe8b00fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -149,12 +149,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } }; - for (final FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { + for (FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { try { factory.createFileTypes(consumer); } - catch (final Error ex) { - PluginManager.disableIncompatiblePlugin(factory, ex); + catch (Throwable t) { + PluginManager.handleComponentError(t, factory.getClass().getName(), null); } } } @@ -191,7 +191,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return null; - } @Override @@ -218,7 +217,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return new Document(root); - } @Override diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 8df8971e6152..819edae1328f 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.idea; +import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.application.ConfigImportHelper; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; @@ -25,7 +26,7 @@ import com.intellij.util.ui.UIUtil; import javax.swing.*; -@SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "UnusedDeclaration"}) +@SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral"}) public class MainImpl { private static final String LOG_CATEGORY = "#com.intellij.idea.Main"; @@ -44,43 +45,40 @@ public class MainImpl { UIUtil.initDefaultLAF(); - final boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); + boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); if (isNewConfigFolder) { ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); } } if (!StartupUtil.checkStartupPossible(args)) { // It uses config folder! - System.exit(-1); + System.exit(Main.STARTUP_IMPOSSIBLE); } Logger.setFactory(LoggerFactory.getInstance()); - - final Logger LOG = Logger.getInstance(LOG_CATEGORY); - + Logger LOG = Logger.getInstance(LOG_CATEGORY); StartupUtil.startLogging(LOG); - _main(args); - } - - protected static void _main(final String[] args) { // http://weblogs.java.net/blog/shan_man/archive/2005/06/improved_drag_g.html System.setProperty("sun.swing.enableImprovedDragGesture", ""); - Logger LOG = Logger.getInstance(LOG_CATEGORY); StartupUtil.fixProcessEnvironment(LOG); StartupUtil.loadSystemLibraries(LOG); - startApplication(args); - } - - private static void startApplication(final String[] args) { - final IdeaApplication app = new IdeaApplication(args); //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - app.run(); + try { + new IdeaApplication(args).run(); + } + catch (PluginManager.StartupAbortedException e) { + throw e; + } + catch (Throwable t) { + throw new PluginManager.StartupAbortedException(t); + } } }); } -} \ No newline at end of file +} diff --git a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java index 6eea70f39aa9..bac5d8cab2cf 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java +++ b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -26,17 +26,23 @@ public abstract class Logger { Logger getLoggerInstance(String category); } - public static Factory ourFactory = new Factory() { + private static class DefaultFactory implements Factory { @Override public Logger getLoggerInstance(String category) { return new DefaultLogger(category); } - }; + } + + public static Factory ourFactory = new DefaultFactory(); public static void setFactory(Factory factory) { ourFactory = factory; } + public static boolean isInitialized() { + return !(ourFactory instanceof DefaultFactory); + } + public static Logger getInstance(@NonNls String category) { return ourFactory.getLoggerInstance(category); } @@ -48,9 +54,29 @@ public abstract class Logger { public abstract boolean isDebugEnabled(); public abstract void debug(@NonNls String message); + public abstract void debug(@Nullable Throwable t); + public abstract void debug(@NonNls String message, @Nullable Throwable t); + public void info(@NotNull Throwable t) { + info(t.getMessage(), t); + } + + public abstract void info(@NonNls String message); + + public abstract void info(@NonNls String message, @Nullable Throwable t); + + public void warn(@NonNls String message) { + warn(message, null); + } + + public void warn(@NotNull Throwable t) { + warn(t.getMessage(), t); + } + + public abstract void warn(@NonNls String message, @Nullable Throwable t); + public void error(@NonNls String message) { error(message, new Throwable(), ArrayUtil.EMPTY_STRING_ARRAY); } @@ -70,27 +96,8 @@ public abstract class Logger { error(t.getMessage(), t, ArrayUtil.EMPTY_STRING_ARRAY); } - public void warn(@NonNls String message) { - warn(message, null); - } - - public void warn(@NotNull Throwable t) { - warn(t.getMessage(), t); - } - - public abstract void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details); - public abstract void info(@NonNls String message); - - public abstract void info(@NonNls String message, @Nullable Throwable t); - - public abstract void warn(@NonNls String message, @Nullable Throwable t); - - public void info(@NotNull Throwable t) { - info(t.getMessage(), t); - } - public boolean assertTrue(boolean value, @NonNls Object message) { if (!value) { @NonNls StringBuilder resultMessage = new StringBuilder("Assertion failed"); @@ -107,5 +114,4 @@ public abstract class Logger { } public abstract void setLevel(Level level); - } From e6033a8788347940659ff78b397e4fd39c90e041 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Jun 2013 14:46:10 +0400 Subject: [PATCH 07/47] platform: system L&F in startup dialogs --- .../src/com/intellij/ide/plugins/PluginManager.java | 5 +++++ platform/platform-main/src/com/intellij/idea/MainImpl.java | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 384d8f56fba9..5c9f61efba7d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.util.ArrayUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,6 +62,10 @@ public class PluginManager extends PluginManagerCore { Main.setFlags(args); + if (!Main.isHeadless()) { + UIUtil.initDefaultLAF(); + } + ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { @Override public void uncaughtException(Thread t, Throwable e) { diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 819edae1328f..f5a46afff940 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -22,7 +22,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.ui.AppUIUtil; import com.intellij.util.PlatformUtils; import com.intellij.util.PlatformUtilsCore; -import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -43,8 +42,6 @@ public class MainImpl { AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); AppUIUtil.registerBundledFonts(); - UIUtil.initDefaultLAF(); - boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); if (isNewConfigFolder) { ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); From 8ca876c25e0ad3624108bdbb1036128d1037f31c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Jun 2013 16:21:38 +0400 Subject: [PATCH 08/47] platform: direct dependencies instead of service polling; tests moved --- .../util/xml/impl/DomManagerImpl.java | 70 +++++++++++-------- .../intellij/util/xml/DomAnnotationsTest.java | 17 ++++- .../intellij/util/xml/DomChildrenTest.java | 16 +++++ .../util/xml/DomConcurrencyStressTest.java | 15 +++- .../intellij/util/xml/DomExtensionsTest.java | 15 +++- .../util/xml/DomHardCoreTestCase.java | 16 ++++- .../util/xml/DomHighlightingLiteTest.java | 15 +++- .../util/xml/DomModelMergingTest.java | 22 +++++- .../intellij/util/xml/DomNamespacesTest.java | 16 ++++- .../util/xml/DomSimpleValuesTest.java | 16 +++++ .../SimpleValuesIncrementalUpdateTest.java | 18 ++++- .../util/xml/{ => impl}/DomTestCase.java | 24 +++++-- .../xml/impl/IncrementalUpdateEventsTest.java | 16 ++++- 13 files changed, 227 insertions(+), 49 deletions(-) rename xml/dom-tests/tests/com/intellij/util/xml/{ => impl}/DomTestCase.java (83%) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java index 574355c66859..ed67161b6773 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java @@ -1,15 +1,27 @@ +/* + * Copyright 2000-2013 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.util.xml.impl; import com.intellij.ide.highlighter.DomSupportEnabled; import com.intellij.ide.startup.StartupManagerEx; import com.intellij.openapi.Disposable; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; @@ -57,36 +69,44 @@ import java.util.Set; */ public final class DomManagerImpl extends DomManager { private static final Key MOCK = Key.create("MockElement"); + static final Key> CACHED_FILE_ELEMENT = Key.create("CACHED_FILE_ELEMENT"); static final Key MOCK_DESCRIPTION = Key.create("MockDescription"); - static final SemKey FILE_DESCRIPTION_KEY = SemKey.createKey("FILE_DESCRIPTION_KEY"); - public static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); + static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); static final SemKey DOM_INDEXED_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_INDEXED_HANDLER_KEY"); static final SemKey DOM_COLLECTION_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_COLLECTION_HANDLER_KEY"); static final SemKey DOM_CUSTOM_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_CUSTOM_HANDLER_KEY"); static final SemKey DOM_ATTRIBUTE_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_ATTRIBUTE_HANDLER_KEY"); private final EventDispatcher myListeners = EventDispatcher.create(DomEventListener.class); - private final ConverterManagerImpl myConverterManager; - private final GenericValueReferenceProvider myGenericValueReferenceProvider = new GenericValueReferenceProvider(); private final Project myProject; + private final SemService mySemService; + private final ConverterManager myConverterManager; private final DomApplicationComponent myApplicationComponent; private final PsiFileFactory myFileFactory; + private final ProjectFileIndex myFileIndex; private long myModificationCount; private boolean myChanging; - private final ProjectFileIndex myFileIndex; - private final SemService mySemService; - public DomManagerImpl(final Project project, final XmlAspect xmlAspect) { + public DomManagerImpl(Project project, + final XmlAspect xmlAspect, + SemService semService, + ConverterManager converterManager, + DomApplicationComponent appComponent, + PsiFileFactory fileFactory, + ProjectFileIndex fileIndex) { myProject = project; - mySemService = SemService.getSemService(project); - myConverterManager = (ConverterManagerImpl)ServiceManager.getService(ConverterManager.class); - myApplicationComponent = DomApplicationComponent.getInstance(); - final PomModel pomModel = PomManager.getModel(project); + mySemService = semService; + myConverterManager = converterManager; + myApplicationComponent = appComponent; + myFileFactory = fileFactory; + myFileIndex = fileIndex; + + PomModel pomModel = PomManager.getModel(project); pomModel.addModelListener(new PomModelListener() { public void modelChanged(PomModelEvent event) { final XmlChangeSet changeSet = (XmlChangeSet)event.getChangeSet(xmlAspect); @@ -105,11 +125,7 @@ public final class DomManagerImpl extends DomManager { } }, project); - myFileFactory = PsiFileFactory.getInstance(project); - - final PsiManager psiManager = PsiManager.getInstance(project); - - final Runnable setupVfsListeners = new Runnable() { + Runnable setupVfsListeners = new Runnable() { public void run() { final VirtualFileAdapter listener = new VirtualFileAdapter() { private final List myDeletionEvents = new SmartList(); @@ -125,7 +141,7 @@ public final class DomManagerImpl extends DomManager { } public void beforeFileDeletion(final VirtualFileEvent event) { - if (!project.isDisposed()) { + if (!myProject.isDisposed()) { beforeFileDeletion(event.getFile()); } } @@ -148,7 +164,7 @@ public final class DomManagerImpl extends DomManager { public void fileDeleted(VirtualFileEvent event) { if (!myDeletionEvents.isEmpty()) { - if (!project.isDisposed()) { + if (!myProject.isDisposed()) { for (DomEvent domEvent : myDeletionEvents) { fireEvent(domEvent); } @@ -164,18 +180,17 @@ public final class DomManagerImpl extends DomManager { } } }; - VirtualFileManager.getInstance().addVirtualFileListener(listener, project); + VirtualFileManager.getInstance().addVirtualFileListener(listener, myProject); } }; - final StartupManager startupManager = StartupManager.getInstance(project); + StartupManager startupManager = StartupManager.getInstance(project); if (!((StartupManagerEx)startupManager).startupActivityPassed()) { startupManager.registerStartupActivity(setupVfsListeners); - } else { + } + else { setupVfsListeners.run(); } - - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); } private void processVfsChange(final VirtualFile file) { @@ -507,7 +522,4 @@ public final class DomManagerImpl extends DomManager { public SemService getSemService() { return mySemService; } - - - private final static Logger LOG = Logger.getInstance(DomManagerImpl.class); } diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java index f6d86922174a..49110e2c0f4a 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; @@ -11,13 +23,14 @@ import com.intellij.psi.PsiFileFactory; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.highlighting.*; +import com.intellij.util.xml.impl.DomTestCase; import java.util.Arrays; /** * @author peter */ -public class DomAnnotationsTest extends DomTestCase{ +public class DomAnnotationsTest extends DomTestCase { @Override protected T createElement(final String xml, final Class aClass) { diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java index 169c66b5aae0..89229bf889c5 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.util.xml; import com.intellij.openapi.application.ApplicationManager; @@ -11,6 +26,7 @@ import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; import java.lang.reflect.Type; import java.util.ArrayList; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java index e0aa679039e2..4a94d0e5ba26 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; @@ -16,6 +28,7 @@ import com.intellij.semantic.SemService; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.Timings; import com.intellij.util.xml.impl.DomFileElementImpl; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomExtender; import com.intellij.util.xml.reflect.DomExtenderEP; import com.intellij.util.xml.reflect.DomExtensionsRegistrar; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java index 7977a8d103c9..5aa8c0b2255d 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; @@ -9,6 +21,7 @@ import com.intellij.testFramework.IdeaTestUtil; import com.intellij.util.Consumer; import com.intellij.util.ParameterizedTypeImpl; import com.intellij.util.ReflectionUtil; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.*; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java index 934bf2928ec6..c2f13f6368cb 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; @@ -14,8 +26,8 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.psi.xml.XmlTagValue; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomApplicationComponent; import com.intellij.util.xml.impl.DomManagerImpl; +import com.intellij.util.xml.impl.DomTestCase; /** * @author peter diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java index 2486c87e1b9b..623b11616f59 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; @@ -22,6 +34,7 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.MockSchemesManagerFactory; import com.intellij.util.xml.highlighting.*; import com.intellij.util.xml.impl.DefaultDomAnnotator; +import com.intellij.util.xml.impl.DomTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java index 6dc47ed8a06a..9efc125bb83c 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java @@ -1,16 +1,32 @@ /* - * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2013 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.util.xml; import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.util.xml.impl.DomTestCase; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * @author peter */ -public class DomModelMergingTest extends DomTestCase{ +public class DomModelMergingTest extends DomTestCase { private ModelMerger myMerger; @Override diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java index 9c24fa57557b..8d92c019129f 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java @@ -1,6 +1,17 @@ /* - * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. - * Use is subject to license terms. + * Copyright 2000-2013 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.util.xml; @@ -9,6 +20,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.impl.DomFileElementImpl; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomGenericInfo; import java.util.List; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java index 4fcdcf0d91d1..8911df1c22ac 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 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.util.xml; import com.intellij.openapi.application.Result; @@ -7,6 +22,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.ui.DomUIFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java index fe4038235825..2a2bf1a4e2f3 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java @@ -1,12 +1,28 @@ +/* + * Copyright 2000-2013 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.util.xml; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; /** * @author peter */ -public class SimpleValuesIncrementalUpdateTest extends DomTestCase{ +public class SimpleValuesIncrementalUpdateTest extends DomTestCase { public void testAttributeChange() throws Throwable { final MyElement element = createElement(""); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java similarity index 83% rename from xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java rename to xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java index 7531e4838739..37682943b3eb 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java @@ -1,4 +1,19 @@ -package com.intellij.util.xml; +/* + * Copyright 2000-2013 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.util.xml.impl; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; @@ -10,11 +25,8 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.xml.*; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomApplicationComponent; -import com.intellij.util.xml.impl.DomFileElementImpl; -import com.intellij.util.xml.impl.DomInvocationHandler; -import com.intellij.util.xml.impl.DomManagerImpl; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -72,7 +84,7 @@ public abstract class DomTestCase extends LightIdeaTestCase { return element; } - protected static T createElement(final DomManager domManager, final String xml, final Class aClass) + public static T createElement(final DomManager domManager, final String xml, final Class aClass) throws IncorrectOperationException { final String name = "a.xml"; final XmlFile file = (XmlFile)PsiFileFactory.getInstance(domManager.getProject()).createFileFromText(name, xml); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java index 9df3cceb1849..2f7f2fefcd90 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java @@ -1,10 +1,24 @@ +/* + * Copyright 2000-2013 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.util.xml.impl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.DomElement; -import com.intellij.util.xml.DomTestCase; import com.intellij.util.xml.SubTag; import com.intellij.util.xml.events.DomEvent; From 95a06519ec931841dae88c51a8e13926c86ca3ac Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Jun 2013 17:11:49 +0400 Subject: [PATCH 09/47] platform: ancient Swing property dropped --- platform/platform-main/src/com/intellij/idea/MainImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index f5a46afff940..8153954f660f 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -56,9 +56,6 @@ public class MainImpl { Logger LOG = Logger.getInstance(LOG_CATEGORY); StartupUtil.startLogging(LOG); - // http://weblogs.java.net/blog/shan_man/archive/2005/06/improved_drag_g.html - System.setProperty("sun.swing.enableImprovedDragGesture", ""); - StartupUtil.fixProcessEnvironment(LOG); StartupUtil.loadSystemLibraries(LOG); From 621b7418a9b859ab7590a4b743b5c8f6b90859cb Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Jun 2013 17:40:48 +0400 Subject: [PATCH 10/47] platform: common startup code extracted --- .../src/com/intellij/idea/StartupUtil.java | 87 ++++++++++++------- .../src/com/intellij/idea/MainImpl.java | 59 ++++--------- 2 files changed, 74 insertions(+), 72 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index 93e12c8440d8..28ee2fbfe8c2 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -19,6 +19,7 @@ import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.ide.startupWizard.StartupWizard; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.application.ConfigImportHelper; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.application.impl.ApplicationInfoImpl; @@ -28,6 +29,7 @@ import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.win32.IdeaWin32; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.AppUIUtil; import com.intellij.util.Consumer; import com.intellij.util.EnvironmentUtil; import com.intellij.util.SystemProperties; @@ -37,10 +39,10 @@ import org.jetbrains.annotations.NonNls; import org.xerial.snappy.Snappy; import org.xerial.snappy.SnappyLoader; +import javax.swing.*; import java.io.File; import java.io.InputStream; import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -80,6 +82,48 @@ public class StartupUtil { ourLock.setActivateListener(consumer); } + interface AppStarter { + void start(boolean newConfigFolder); + } + + static void prepareAndStart(String[] args, AppStarter appStarter) { + boolean newConfigFolder = false; + + if (!Main.isHeadless()) { + AppUIUtil.updateFrameClass(); + AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); + AppUIUtil.registerBundledFonts(); + + newConfigFolder = PathManager.ensureConfigFolderExists(true); + if (newConfigFolder) { + ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); + } + } + + boolean canStart = checkJdkVersion() && checkSystemFolders() && lockSystemFolders(args); // note: uses config folder! + if (!canStart) { + System.exit(Main.STARTUP_IMPOSSIBLE); + } + + Logger.setFactory(LoggerFactory.getInstance()); + Logger log = Logger.getInstance(Main.class); + startLogging(log); + fixProcessEnvironment(log); + loadSystemLibraries(log); + + appStarter.start(newConfigFolder); + } + + static void runStartupWizard() { + final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); + if (!pages.isEmpty()) { + final StartupWizard startupWizard = new StartupWizard(pages); + startupWizard.setCancelText("Skip"); + startupWizard.show(); + PluginManagerCore.invalidatePlugins(); + } + } + /** * Checks if the program can run under the JDK it was started with. */ @@ -143,23 +187,7 @@ public class StartupUtil { return true; } - static boolean checkStartupPossible(String[] args) { - return checkJdkVersion() && - checkSystemFolders() && - lockSystemFolders(args); - } - - static void runStartupWizard() { - final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); - if (!pages.isEmpty()) { - final StartupWizard startupWizard = new StartupWizard(pages); - startupWizard.setCancelText("Skip"); - startupWizard.show(); - PluginManagerCore.invalidatePlugins(); - } - } - - static void fixProcessEnvironment(Logger log) { + private static void fixProcessEnvironment(Logger log) { boolean envReady = EnvironmentUtil.isEnvironmentReady(); // trigger environment loading if (!envReady) { log.info("initializing environment"); @@ -168,7 +196,7 @@ public class StartupUtil { private static final String JAVA_IO_TEMP_DIR = "java.io.tmpdir"; - static void loadSystemLibraries(final Logger log) { + private static void loadSystemLibraries(final Logger log) { // load JNA and Snappy in own temp directory - to avoid collisions and work around no-exec /tmp final File ideaTempDir = new File(PathManager.getSystemPath(), "tmp"); if (!(ideaTempDir.mkdirs() || ideaTempDir.exists())) { @@ -262,28 +290,25 @@ public class StartupUtil { loadNativeLibrary.invoke(null, loaderClass); } - static void startLogging(final Logger log) { + private static void startLogging(final Logger log) { Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook - logging") { public void run() { - log.info( - "------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); + log.info("------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); } }); - log.info( - "------------------------------------------------------ IDE STARTED ------------------------------------------------------"); + log.info("------------------------------------------------------ IDE STARTED ------------------------------------------------------"); - final ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); - final ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); + ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); + ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); log.info("IDE: " + namesInfo.getFullProductName() + " (build #" + appInfo.getBuild() + ", " + DateFormatUtilRt.formatBuildDate(appInfo.getBuildDate()) + ")"); log.info("OS: " + SystemInfoRt.OS_NAME + " (" + SystemInfoRt.OS_VERSION + ")"); - log.info("JRE: " + System.getProperty("java.runtime.version", "-") + " (" + System.getProperty("java.vendor", "-") + ")"); log.info("JVM: " + System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.vendor", "-") + ")"); - RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); - List arguments = RuntimemxBean.getInputArguments(); - - if (arguments != null) log.info("JVM Args: " + StringUtil.join(arguments, " ")); + List arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); + if (arguments != null) { + log.info("JVM Args: " + StringUtil.join(arguments, " ")); + } } } diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 8153954f660f..2376bebac862 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -16,19 +16,13 @@ package com.intellij.idea; import com.intellij.ide.plugins.PluginManager; -import com.intellij.openapi.application.ConfigImportHelper; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.ui.AppUIUtil; import com.intellij.util.PlatformUtils; import com.intellij.util.PlatformUtilsCore; import javax.swing.*; -@SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral"}) +@SuppressWarnings({"UnusedDeclaration"}) public class MainImpl { - private static final String LOG_CATEGORY = "#com.intellij.idea.Main"; - private MainImpl() { } /** @@ -37,41 +31,24 @@ public class MainImpl { protected static void start(final String[] args) { System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); - if (!Main.isHeadless()) { - AppUIUtil.updateFrameClass(); - AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); - AppUIUtil.registerBundledFonts(); - - boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); - if (isNewConfigFolder) { - ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); - } - } - - if (!StartupUtil.checkStartupPossible(args)) { // It uses config folder! - System.exit(Main.STARTUP_IMPOSSIBLE); - } - - Logger.setFactory(LoggerFactory.getInstance()); - Logger LOG = Logger.getInstance(LOG_CATEGORY); - StartupUtil.startLogging(LOG); - - StartupUtil.fixProcessEnvironment(LOG); - StartupUtil.loadSystemLibraries(LOG); - - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { + StartupUtil.prepareAndStart(args, new StartupUtil.AppStarter() { @Override - public void run() { - try { - new IdeaApplication(args).run(); - } - catch (PluginManager.StartupAbortedException e) { - throw e; - } - catch (Throwable t) { - throw new PluginManager.StartupAbortedException(t); - } + public void start(boolean newConfigFolder) { + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + new IdeaApplication(args).run(); + } + catch (PluginManager.StartupAbortedException e) { + throw e; + } + catch (Throwable t) { + throw new PluginManager.StartupAbortedException(t); + } + } + }); } }); } From 61650a3cab4ce92c65b21b7ba1bb33317c77bde7 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 11:51:16 +0400 Subject: [PATCH 11/47] ignore schedule in tests --- .../testframework/sm/runner/GeneralTestEventsProcessor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java index 0e881e2e4381..0ed666883608 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java @@ -24,6 +24,7 @@ import com.intellij.openapi.util.Key; import com.intellij.testIntegration.TestLocationProvider; import com.intellij.util.Processor; import com.intellij.util.containers.TransferToEDTQueue; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -119,7 +120,10 @@ public abstract class GeneralTestEventsProcessor implements Disposable { */ public void addToInvokeLater(final Runnable runnable) { final Application application = ApplicationManager.getApplication(); - if (application.isHeadlessEnvironment() && !application.isUnitTestMode() || SwingUtilities.isEventDispatchThread()) { + final boolean unitTestMode = application.isUnitTestMode(); + if (unitTestMode) { + UIUtil.invokeLaterIfNeeded(runnable); + } else if (application.isHeadlessEnvironment() || SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { From bafaae33db12a53821445875b12e261ae05ae878 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 12 Jun 2013 20:56:14 +0200 Subject: [PATCH 12/47] IndexTest -> community --- .../testSrc/com/intellij/index/IndexTest.java | 173 ++++++++++++++++++ .../com/intellij/index/StringIndex.java | 82 +++++++++ 2 files changed, 255 insertions(+) create mode 100644 java/java-tests/testSrc/com/intellij/index/IndexTest.java create mode 100644 java/java-tests/testSrc/com/intellij/index/StringIndex.java diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.java b/java/java-tests/testSrc/com/intellij/index/IndexTest.java new file mode 100644 index 000000000000..11c5990e3e47 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.java @@ -0,0 +1,173 @@ +package com.intellij.index; + +import com.intellij.openapi.util.Factory; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.testFramework.IdeaTestCase; +import com.intellij.util.indexing.MapIndexStorage; +import com.intellij.util.indexing.StorageException; +import com.intellij.util.io.*; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.File; +import java.io.IOException; +import java.util.*; + +/** + * @author Eugene Zhuravlev + * Date: Dec 12, 2007 + */ +public class IndexTest extends IdeaTestCase { + + public void testUpdate() throws StorageException, IOException { + final File storageFile = FileUtil.createTempFile("indextest", "storage"); + final File metaIndexFile = FileUtil.createTempFile("indextest_inputs", "storage"); + final MapIndexStorage indexStorage = new MapIndexStorage(storageFile, new EnumeratorStringDescriptor(), new EnumeratorStringDescriptor(), 16 * 1024); + final StringIndex index = new StringIndex(indexStorage, new Factory>>() { + @Override + public PersistentHashMap> create() { + try { + return createMetaIndex(metaIndexFile); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + + try { +// build index + index.update("com/ppp/a.java", "a b c d", null); + index.update("com/ppp/b.java", "a b g h", null); + index.update("com/ppp/c.java", "a z f", null); + index.update("com/ppp/d.java", "a a u y z", null); + index.update("com/ppp/e.java", "a n chj e c d", null); + + assertDataEquals(index.getFilesByWord("a"), "com/ppp/a.java", "com/ppp/b.java", "com/ppp/c.java", "com/ppp/d.java", "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("b"), "com/ppp/a.java", "com/ppp/b.java"); + assertDataEquals(index.getFilesByWord("c"), "com/ppp/a.java", "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("d"), "com/ppp/a.java", "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("g"), "com/ppp/b.java"); + assertDataEquals(index.getFilesByWord("h"), "com/ppp/b.java"); + assertDataEquals(index.getFilesByWord("z"), "com/ppp/c.java", "com/ppp/d.java"); + assertDataEquals(index.getFilesByWord("f"), "com/ppp/c.java"); + assertDataEquals(index.getFilesByWord("u"), "com/ppp/d.java"); + assertDataEquals(index.getFilesByWord("y"), "com/ppp/d.java"); + assertDataEquals(index.getFilesByWord("n"), "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("chj"), "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("e"), "com/ppp/e.java"); + + // update index + + index.update("com/ppp/d.java", "a u y z", "a a u y z"); + assertDataEquals(index.getFilesByWord("a"), "com/ppp/a.java", "com/ppp/b.java", "com/ppp/c.java", "com/ppp/d.java", "com/ppp/e.java"); + index.update("com/ppp/d.java", "u y z", "a u y z"); + assertDataEquals(index.getFilesByWord("a"), "com/ppp/a.java", "com/ppp/b.java", "com/ppp/c.java", "com/ppp/e.java"); + index.update("com/ppp/d.java", "a a a u y z", "u y z"); + assertDataEquals(index.getFilesByWord("a"), "com/ppp/a.java", "com/ppp/b.java", "com/ppp/c.java", "com/ppp/d.java", "com/ppp/e.java"); + + index.update("com/ppp/e.java", "a n chj e c d z", "a n chj e c d"); + assertDataEquals(index.getFilesByWord("z"), "com/ppp/c.java", "com/ppp/d.java", "com/ppp/e.java"); + + index.update("com/ppp/b.java", null, "a b g h"); + assertDataEquals(index.getFilesByWord("a"), "com/ppp/a.java", "com/ppp/c.java", "com/ppp/d.java", "com/ppp/e.java"); + assertDataEquals(index.getFilesByWord("b"), "com/ppp/a.java"); + assertDataEquals(index.getFilesByWord("g")); + assertDataEquals(index.getFilesByWord("h")); + } + finally { + indexStorage.close(); + FileUtil.delete(storageFile); + } + } + + private PersistentHashMap> createMetaIndex(File metaIndexFile) throws IOException { + return new PersistentHashMap>(metaIndexFile, new EnumeratorIntegerDescriptor(), new DataExternalizer>() { + @Override + public void save(DataOutput out, Collection value) throws IOException { + DataInputOutputUtil.writeINT(out, value.size()); + for (String key : value) { + out.writeUTF(key); + } + } + + @Override + public Collection read(DataInput in) throws IOException { + final int size = DataInputOutputUtil.readINT(in); + final List list = new ArrayList(); + for (int idx = 0; idx < size; idx++) { + list.add(in.readUTF()); + } + return list; + } + }); + } + + /* + public void testStubIndexUnsavedDocumentsIndexing() throws IncorrectOperationException, IOException, StorageException { + IdeaTestUtil.registerExtension(StubIndexExtension.EP_NAME, new TextStubIndexExtension(), getTestRootDisposable()); + IdeaTestUtil.registerExtension(StubIndexExtension.EP_NAME, new ClassNameStubIndexExtension(), getTestRootDisposable()); + FileTypeManager.getInstance().registerFileType(TestFileType.INSTANCE, "fff"); + final FFFLangParserDefinition parserDefinition = new FFFLangParserDefinition(); + LanguageParserDefinitions.INSTANCE.addExplicitExtension(FFFLanguage.INSTANCE, parserDefinition); + + final TestStubElementType stubType = new TestStubElementType(); + SerializationManager.getInstance().registerSerializer(TestStubElement.class, stubType); + + final File fffFile = new File(FileUtil.createTempDirectory("testing", "stubindex"), "MyClass.fff"); + fffFile.createNewFile(); + + final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fffFile); + + assertNotNull(vFile); + assertEquals(TestFileType.INSTANCE, vFile.getFileType()); + + try { + final MockPsiFile psiFile = new MockPsiFile(vFile, MockPsiManager.getInstance(myProject)); + + final MockPsiClass cls = new MockPsiClass("com.company.MyClass"); + psiFile.add(cls); + + final MockPsiMethod aaaMethod = new MockPsiMethod("aaa"); + cls.addMethod(aaaMethod); + final MockPsiMethod bbbMethod = new MockPsiMethod("bbb"); + cls.addMethod(bbbMethod); + + final PsiFileStubImpl fileStub = new PsiFileStubImpl(psiFile); + final TestStubElement clsStub = stubType.createStub(cls, fileStub); + stubType.createStub(aaaMethod, clsStub); + stubType.createStub(bbbMethod, clsStub); + + final ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); + SerializationManager.getInstance().serialize(fileStub, new DataOutputStream(arrayStream)); + + final FileBasedIndex fbi = FileBasedIndex.getInstance(); + final UpdatableIndex stubUpdatingIndex = fbi.getIndex(StubUpdatingIndex.INDEX_ID); + final MemoryIndexStorage storage = (MemoryIndexStorage)((MapReduceIndex)stubUpdatingIndex).getStorage(); + + // initial + final int fileId = FileBasedIndex.getFileId(vFile); + final byte[] bytes = arrayStream.toByteArray(); + stubUpdatingIndex.update(fileId, new FileContent(vFile, bytes), null); + + final ValueContainer data = stubUpdatingIndex.getData(fileId); + final List trees = data.toValueList(); + + final SerializedStubTree tree = assertOneElement(trees); + + assertTrue(Comparing.equal(bytes, tree.getBytes())); + + final StubElement deserialized = tree.getStub(); + } + finally { + LanguageParserDefinitions.INSTANCE.removeExplicitExtension(FFFLanguage.INSTANCE, parserDefinition); + } + + } + */ + + private static void assertDataEquals(List actual, T... expected) { + assertTrue(new HashSet(Arrays.asList(expected)).equals(new HashSet(actual))); + } + +} diff --git a/java/java-tests/testSrc/com/intellij/index/StringIndex.java b/java/java-tests/testSrc/com/intellij/index/StringIndex.java new file mode 100644 index 000000000000..e48d5be0e0ca --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/index/StringIndex.java @@ -0,0 +1,82 @@ +package com.intellij.index; + +import com.intellij.openapi.util.Factory; +import com.intellij.util.indexing.DataIndexer; +import com.intellij.util.indexing.IndexStorage; +import com.intellij.util.indexing.MapReduceIndex; +import com.intellij.util.indexing.StorageException; +import com.intellij.util.io.PersistentHashMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Eugene Zhuravlev + * Date: Dec 12, 2007 + */ +public class StringIndex { + private final MapReduceIndex myIndex; + + public StringIndex(final IndexStorage storage, final Factory>> factory) + throws IOException { + myIndex = new MapReduceIndex(null, new Indexer(), storage); + myIndex.setInputIdToDataKeysIndex(factory); + } + + public List getFilesByWord(String word) throws StorageException { + return myIndex.getData(word).toValueList(); + } + + public void update(final String path, @Nullable String content, @Nullable String oldContent) throws StorageException { + myIndex.update(path.hashCode(), toInput(path, content)); + } + + @Nullable + private PathContentPair toInput(@NotNull String path, @Nullable String content) { + return content != null ? new PathContentPair(path, content) : null; + } + + private static class Indexer implements DataIndexer { + @Override + @NotNull + public Map map(final PathContentPair inputData) { + final Map _map = new HashMap(); + final StringBuilder builder = new StringBuilder(); + final String content = inputData.content; + for (int idx = 0; idx < content.length(); idx++) { + final char ch = content.charAt(idx); + if (Character.isWhitespace(ch)) { + if (builder.length() > 0) { + _map.put(builder.toString(), inputData.path); + builder.setLength(0); + } + } + else { + builder.append(ch); + } + } + // emit the last word + if (builder.length() > 0) { + _map.put(builder.toString(), inputData.path); + builder.setLength(0); + } + return _map; + } + } + + private static final class PathContentPair { + final String path; + final String content; + + public PathContentPair(final String path, final String content) { + this.path = path; + this.content = content; + } + } + +} From 2375b931602744b6c10689d47155952900ae36df Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 13 Jun 2013 09:51:23 +0200 Subject: [PATCH 13/47] test for stub-ast mismatch --- .../testSrc/com/intellij/index/IndexTest.java | 43 +++++++++++++++++++ .../testFramework/PlatformTestUtil.java | 9 ++++ 2 files changed, 52 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.java b/java/java-tests/testSrc/com/intellij/index/IndexTest.java index 11c5990e3e47..6b84a760f4e1 100644 --- a/java/java-tests/testSrc/com/intellij/index/IndexTest.java +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.java @@ -1,8 +1,20 @@ package com.intellij.index; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.PsiManagerEx; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.IdeaTestCase; +import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.testFramework.PsiTestUtil; import com.intellij.util.indexing.MapIndexStorage; import com.intellij.util.indexing.StorageException; import com.intellij.util.io.*; @@ -169,5 +181,36 @@ public class IndexTest extends IdeaTestCase { private static void assertDataEquals(List actual, T... expected) { assertTrue(new HashSet(Arrays.asList(expected)).equals(new HashSet(actual))); } + + public void _testCollectedPsiWithChangedDocument() throws IOException { + VirtualFile dir = getVirtualFile(createTempDirectory()); + PsiTestUtil.addSourceContentToRoots(myModule, dir); + + final VirtualFile vFile = createChildData(dir, "Foo.java"); + VfsUtil.saveText(vFile, "class Foo {}"); + + final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject()); + final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject()); + assertNotNull(facade.findClass("Foo", scope)); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vFile); + assertNotNull(psiFile); + + Document document = FileDocumentManager.getInstance().getDocument(vFile); + document.deleteString(0, document.getTextLength()); + assertNotNull(facade.findClass("Foo", scope)); + + psiFile = null; + PlatformTestUtil.tryGcSoftlyReachableObjects(); + assertNull(((PsiManagerEx)PsiManager.getInstance(getProject())).getFileManager().getCachedPsiFile(vFile)); + + // should be assertNull(facade.findClass("Foo", scope)); + // or the file should not be allowed to be gc'ed + facade.findClass("Foo", scope).getText(); + } + }); + } } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index b14bdd7beb9e..2ed8cd76c785 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -47,6 +47,7 @@ import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.util.Alarm; import com.intellij.util.ArrayUtil; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import com.intellij.util.io.ZipUtil; import com.intellij.util.ui.UIUtil; @@ -66,6 +67,7 @@ import java.awt.event.InvocationEvent; import java.io.File; import java.io.IOException; import java.io.StringWriter; +import java.lang.ref.SoftReference; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.*; @@ -769,4 +771,11 @@ public class PlatformTestUtil { public static String loadFileText(@NotNull String fileName) throws IOException { return StringUtil.convertLineSeparators(FileUtil.loadFile(new File(fileName))); } + + public static void tryGcSoftlyReachableObjects() { + List list = ContainerUtil.newArrayList(); + for (int i = 0; i < 100; i++) { + list.add(new SoftReference(new byte[(int)Runtime.getRuntime().freeMemory() / 2])); + } + } } From c4beab5f4f95809588405527f545124ca4010ee1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Jun 2013 12:11:02 +0400 Subject: [PATCH 14/47] Changes reverted --- .../src/com/intellij/ide/Bootstrap.java | 31 ++- .../src/com/intellij/ide/ClassloaderUtil.java | 74 ++++-- .../bootstrap/src/com/intellij/idea/Main.java | 183 ++++++-------- .../intellij/diagnostic/PluginException.java | 7 +- .../components/impl/ComponentManagerImpl.java | 171 ++++++++----- .../diagnostic/DefaultIdeaErrorLogger.java | 48 ++-- .../intellij/ide/plugins/PluginManager.java | 226 +++++++----------- .../com/intellij/idea/IdeaApplication.java | 72 +++--- .../src/com/intellij/idea/IdeaLogger.java | 25 +- .../src/com/intellij/idea/SocketLock.java | 2 +- .../src/com/intellij/idea/StartupUtil.java | 143 ++++++----- .../application/impl/ApplicationImpl.java | 64 +++-- .../fileTypes/impl/FileTypeManagerImpl.java | 8 +- .../src/com/intellij/idea/MainImpl.java | 82 +++++-- .../intellij/openapi/diagnostic/Logger.java | 50 ++-- .../util/xml/impl/DomManagerImpl.java | 55 +++-- .../intellij/util/xml/DomAnnotationsTest.java | 3 +- .../intellij/util/xml/DomChildrenTest.java | 1 - .../util/xml/DomConcurrencyStressTest.java | 1 - .../intellij/util/xml/DomExtensionsTest.java | 1 - .../util/xml/DomHardCoreTestCase.java | 2 +- .../util/xml/DomHighlightingLiteTest.java | 1 - .../util/xml/DomModelMergingTest.java | 8 +- .../intellij/util/xml/DomNamespacesTest.java | 1 - .../util/xml/DomSimpleValuesTest.java | 1 - .../util/xml/{impl => }/DomTestCase.java | 9 +- .../SimpleValuesIncrementalUpdateTest.java | 3 +- .../xml/impl/IncrementalUpdateEventsTest.java | 1 + 28 files changed, 687 insertions(+), 586 deletions(-) rename xml/dom-tests/tests/com/intellij/util/xml/{impl => }/DomTestCase.java (92%) diff --git a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java index 05280434f3d0..4d12c4bf6255 100644 --- a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java +++ b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java @@ -17,6 +17,7 @@ package com.intellij.ide; import com.intellij.util.lang.UrlClassLoader; +import javax.swing.*; import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; @@ -28,19 +29,31 @@ import java.util.List; public class Bootstrap { private static final String PLUGIN_MANAGER = "com.intellij.ide.plugins.PluginManager"; - private Bootstrap() { } + private Bootstrap() {} - public static void main(String[] args, String mainClass, String methodName) throws Exception { + public static void main(final String[] args, final String mainClass, final String methodName) { main(args, mainClass, methodName, new ArrayList()); } - public static void main(String[] args, String mainClass, String methodName, List classpathElements) throws Exception { - UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); - WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); + public static void main(final String[] args, final String mainClass, final String methodName, final List classpathElements) { + final UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); + try { + WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); - Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); - Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); - startMethod.setAccessible(true); - startMethod.invoke(null, mainClass, methodName, args); + final Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); + + final Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); + startMethod.setAccessible(true); + startMethod.invoke(null, mainClass, methodName, args); + } + catch (Exception e) { + if ("true".equals(System.getProperty("java.awt.headless"))) { + //noinspection UseOfSystemOutOrSystemErr + e.printStackTrace(System.err); + } + else { + JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage(), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); + } + } } } \ No newline at end of file diff --git a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java index 6d6f715d026d..d31e2383c4fb 100644 --- a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java +++ b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java @@ -30,6 +30,7 @@ import com.intellij.util.lang.UrlClassLoader; import com.intellij.util.text.StringTokenizer; import org.jetbrains.annotations.NonNls; +import javax.swing.*; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -43,33 +44,76 @@ import java.util.regex.Pattern; public class ClassloaderUtil extends ClassUtilCore { @NonNls public static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath"; + @SuppressWarnings({"HardCodedStringLiteral"}) + private static final String ERROR = "Error"; + private ClassloaderUtil() {} public static Logger getLogger() { return Logger.getInstance("ClassloaderUtil"); } - public static UrlClassLoader initClassloader(final List classpathElements) throws Exception { + public static UrlClassLoader initClassloader(final List classpathElements) { PathManager.loadProperties(); - addParentClasspath(classpathElements); - addIDEALibraries(classpathElements); - addAdditionalClassPath(classpathElements); - - filterClassPath(classpathElements); - UrlClassLoader newClassLoader = new UrlClassLoader(classpathElements, null, true, true); - - // prepare plugins - if (!isLoadingOfExternalPluginsDisabled()) { - try { - StartupActionScriptManager.executeActionScript(); + try { + addParentClasspath(classpathElements); + addIDEALibraries(classpathElements); + addAdditionalClassPath(classpathElements); + } + catch (IllegalArgumentException e) { + if (Main.isHeadless()) { + getLogger().error(e); + } else { + JOptionPane + .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); } - catch (IOException e) { - Main.showMessage("Plugin Installation Error", e); + System.exit(1); + } + catch (MalformedURLException e) { + if (Main.isHeadless()) { + getLogger().error(e.getMessage()); + } else { + JOptionPane + .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); } + System.exit(1); } - Thread.currentThread().setContextClassLoader(newClassLoader); + filterClassPath(classpathElements); + + UrlClassLoader newClassLoader = null; + try { + newClassLoader = new UrlClassLoader(classpathElements, null, true, true); + + // prepare plugins + if (!isLoadingOfExternalPluginsDisabled()) { + try { + StartupActionScriptManager.executeActionScript(); + } + catch (IOException e) { + final String errorMessage = "Error executing plugin installation script: " + e.getMessage(); + if (Main.isHeadless()) { + System.out.println(errorMessage); + } else { + JOptionPane + .showMessageDialog(JOptionPane.getRootFrame(), errorMessage, ERROR, JOptionPane.INFORMATION_MESSAGE); + } + } + } + + Thread.currentThread().setContextClassLoader(newClassLoader); + + } + catch (Exception e) { + Logger logger = getLogger(); + if (logger == null) { + e.printStackTrace(System.err); + } + else { + logger.error(e); + } + } return newClassLoader; } diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index 182946c2c786..499f5ec1b583 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.intellij.idea; import com.intellij.ide.Bootstrap; @@ -20,99 +21,102 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtilRt; -import com.intellij.util.ArrayUtilRt; -import com.intellij.util.ExceptionUtil; import com.intellij.util.Restarter; +import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; -import java.io.PrintStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@SuppressWarnings({"UseOfSystemOutOrSystemErr", "MethodNamesDifferingOnlyByCase"}) public class Main { - public static final int UPDATE_FAILED = 1; - public static final int STARTUP_EXCEPTION = 2; - public static final int STARTUP_IMPOSSIBLE = 3; - public static final int LICENSE_ERROR = 4; - public static final int PLUGIN_ERROR = 5; - private static boolean isHeadless; - private static boolean isCommandLine; - private Main() { } + private Main() { + } + @SuppressWarnings("MethodNamesDifferingOnlyByCase") public static void main(final String[] args) { - setFlags(args); - - if (isHeadless()) { + isHeadless = isHeadless(args); + if (isHeadless) { System.setProperty("java.awt.headless", Boolean.TRUE.toString()); } - else { - if (GraphicsEnvironment.isHeadless()) { - throw new HeadlessException("Unable to detect graphics environment"); - } + else if (GraphicsEnvironment.isHeadless()) { + throw new HeadlessException("Unable to detect graphics environment"); + } + if (!isHeadless) { try { installPatch(); } - catch (Throwable t) { - showMessage("Update Failed", t); - System.exit(UPDATE_FAILED); + catch (IOException e) { + e.printStackTrace(); + + File log = null; + try { + log = FileUtilRt.createTempFile("patch", ".log", false); + PrintWriter writer = new PrintWriter(log); + try { + e.printStackTrace(writer); + } + finally { + writer.close(); + } + } + catch (IOException ignore) { + ignore.printStackTrace(); + } + + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Throwable ignore) { + } + String message = e.getMessage() + + "\n" + (log == null ? "Log cannot be saved" : "Log is saved in " + log) + + "\n\nPlease download and install update manually" ; + JOptionPane.showMessageDialog(null, message, "Cannot Apply Patch", JOptionPane.ERROR_MESSAGE); } } - try { - Bootstrap.main(args, Main.class.getName() + "Impl", "start"); - } - catch (Throwable t) { - showMessage("Start Failed", t); - System.exit(STARTUP_EXCEPTION); - } + Bootstrap.main(args, Main.class.getName() + "Impl", "start"); } - public static boolean isHeadless() { - return isHeadless; - } - - public static boolean isCommandLine() { - return isCommandLine; - } - - public static void setFlags(String[] args) { - isHeadless = isHeadless(args); - isCommandLine = isCommandLine(args); - } - - private static boolean isHeadless(String[] args) { - if (GraphicsEnvironment.isHeadless()) { - return true; - } + public static boolean isHeadless(final String[] args) { + final Boolean forceEnabledHeadlessMode = Boolean.valueOf(System.getProperty("java.awt.headless")); + @NonNls final String antAppCode = "ant"; + @NonNls final String duplocateCode = "duplocate"; + @NonNls final String traverseUI = "traverseUI"; if (args.length == 0) { return false; } - - String firstArg = args[0]; - return Comparing.strEqual(firstArg, "ant") || - Comparing.strEqual(firstArg, "duplocate") || - Comparing.strEqual(firstArg, "traverseUI") || + final String firstArg = args[0]; + return forceEnabledHeadlessMode || + Comparing.strEqual(firstArg, antAppCode) || + Comparing.strEqual(firstArg, duplocateCode) || + Comparing.strEqual(firstArg, traverseUI) || (firstArg.length() < 20 && firstArg.endsWith("inspect")); } - private static boolean isCommandLine(String[] args) { - if (isHeadless()) return true; - return args.length > 0 && Comparing.strEqual(args[0], "diff"); - } - public static boolean isUITraverser(final String[] args) { return args.length > 0 && Comparing.strEqual(args[0], "traverseUI"); } + public static boolean isCommandLine(final String[] args) { + if (isHeadless(args)) return true; + @NonNls final String diffAppCode = "diff"; + return args.length > 0 && Comparing.strEqual(args[0], diffAppCode); + } + + public static boolean isHeadless() { + return isHeadless; + } + private static void installPatch() throws IOException { String platform = System.getProperty("idea.platform.prefix", "idea"); String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase(); @@ -120,67 +124,28 @@ public class Main { File copyPatchFile = new File(System.getProperty("java.io.tmpdir"), patchFileName + "_copy"); // always delete previous patch copy - if (!FileUtilRt.delete(copyPatchFile)) { - throw new IOException("Cannot create temporary patch file"); - } + if (!FileUtilRt.delete(copyPatchFile)) throw new IOException("Cannot create temporary patch file"); - if (!originalPatchFile.exists()) { - return; - } + if (!originalPatchFile.exists()) return; if (!originalPatchFile.renameTo(copyPatchFile) || !FileUtilRt.delete(originalPatchFile)) { throw new IOException("Cannot create temporary patch file"); } - int status = 0; - if (Restarter.isSupported()) { - List args = new ArrayList(); - - if (SystemInfo.isWindows) { - File launcher = new File(PathManager.getBinPath(), "VistaLauncher.exe"); - args.add(Restarter.createTempExecutable(launcher).getPath()); - } - - Collections.addAll(args, - System.getProperty("java.home") + "/bin/java", - "-Xmx500m", - "-classpath", - copyPatchFile.getPath(), - "com.intellij.updater.Runner", - "install", - PathManager.getHomePath()); - - status = Restarter.scheduleRestart(ArrayUtilRt.toStringArray(args)); - } - else { - String message = "Patch update is not supported - please do it manually"; - showMessage("Update Error", message, true); + List args = new ArrayList(); + if (SystemInfo.isWindows) { + args.add(Restarter.createTempExecutable(new File(PathManager.getBinPath(), "vistalauncher.exe")).getPath()); } - System.exit(status); - } + Collections.addAll(args, + System.getProperty("java.home") + "/bin/java", + "-Xmx500m", + "-classpath", + copyPatchFile.getPath(), + "com.intellij.updater.Runner", + "install", + PathManager.getHomePath()); - public static void showMessage(String title, Throwable t) { - String message = "Internal exception, please report to http://youtrack.jetbrains.com\n\n" + ExceptionUtil.getThrowableText(t); - showMessage(title, message, true); - } - - public static void showMessage(String title, String message, boolean error) { - if (isCommandLine()) { - PrintStream stream = error ? System.err : System.out; - stream.println(title + ": " + message); - } - else { - try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } - catch (Throwable ignore) { } - - JTextPane textPane = new JTextPane(); - textPane.setEditable(false); - textPane.setText(message.replaceAll("\t", " ")); - textPane.setBackground(UIManager.getColor("Panel.background")); - - int type = error ? JOptionPane.ERROR_MESSAGE : JOptionPane.INFORMATION_MESSAGE; - JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), textPane, title, type); - } + System.exit(Restarter.scheduleRestart(args.toArray(new String[args.size()]))); } } diff --git a/platform/core-api/src/com/intellij/diagnostic/PluginException.java b/platform/core-api/src/com/intellij/diagnostic/PluginException.java index 3a520ebc466c..3d4e5da85f75 100644 --- a/platform/core-api/src/com/intellij/diagnostic/PluginException.java +++ b/platform/core-api/src/com/intellij/diagnostic/PluginException.java @@ -19,8 +19,11 @@ import com.intellij.openapi.extensions.PluginId; import org.jetbrains.annotations.NonNls; /** - * @author stathik - * @since Jan 8, 2004 + * Created by IntelliJ IDEA. + * User: stathik + * Date: Jan 8, 2004 + * Time: 3:06:43 PM + * To change this template use Options | File Templates. */ public class PluginException extends RuntimeException { private final PluginId myPluginId; diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index a33f22150dae..83270ac75ea8 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -105,10 +105,21 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements try { myComponentsRegistry.loadClasses(); - Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); + final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); for (Class componentInterface : componentInterfaces) { ProgressIndicatorProvider.checkCanceled(); - createComponent(componentInterface); + try { + createComponent(componentInterface); + } + catch (StateStorageException e) { + throw e; + } + catch (ProcessCanceledException e) { + throw e; + } + catch(Exception e) { + LOG.error(e); + } } } finally { @@ -198,12 +209,35 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return null; } + private void initComponent(Object component) { + final ProgressIndicator indicator = getProgressIndicator(); + if (indicator != null) { + indicator.checkCanceled(); + } + + try { + initializeComponent(component, false); + if (component instanceof BaseComponent) { + ((BaseComponent)component).initComponent(); + } + } + catch (StateStorageException e) { + throw e; + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Throwable ex) { + handleInitComponentError(ex, false, component.getClass().getName(), null); + } + } + @Nullable protected static ProgressIndicator getProgressIndicator() { return ProgressIndicatorProvider.getGlobalProgressIndicator(); } - protected float getPercentageOfComponentsLoaded() { + protected double getPercentageOfComponentsLoaded() { return myComponentsRegistry.getPercentageOfComponentsLoaded(); } @@ -211,7 +245,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public void initializeComponent(Object component, boolean service) { } - protected void handleInitComponentError(Throwable ex, String componentClassName, ComponentConfig config) { + + protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { LOG.error(ex); } @@ -323,7 +358,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements getComponents(); } - protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable PluginDescriptor descriptor, boolean defaultProject) { + protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable final PluginDescriptor descriptor, final boolean defaultProject) { myConfigurator.loadComponentsConfiguration(components, descriptor, defaultProject); } @@ -391,7 +426,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements protected class ComponentsRegistry { private final Map myInterfaceToLockMap = new THashMap(); private final Map myInterfaceToClassMap = new THashMap(); - private final List myComponentInterfaces = new ArrayList(); // keeps order of component's registration + private final ArrayList myComponentInterfaces = new ArrayList(); // keeps order of component's registration private final Map myNameToComponent = new THashMap(); private final List myComponentConfigs = new ArrayList(); private final List myImplementations = new ArrayList(); @@ -417,7 +452,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements interfaceClass : Class.forName(config.getImplementationClass(), true, loader); if (myInterfaceToClassMap.get(interfaceClass) != null) { - throw new RuntimeException("Component already registered: " + interfaceClass.getName()); + throw new ComponentAlreadyRegisteredException(interfaceClass); } getPicoContainer().registerComponent(new ComponentConfigComponentAdapter(config, implementationClass)); @@ -425,8 +460,17 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements myComponentClassToConfig.put(implementationClass, config); myComponentInterfaces.add(interfaceClass); } - catch (Throwable t) { - handleInitComponentError(t, null, config); + catch (ComponentAlreadyRegisteredException ex) { + throw new Error(ex); + } + catch (Throwable e) { + handleInitComponentError(e, false, null, config); + } + } + + private class ComponentAlreadyRegisteredException extends Exception { + private ComponentAlreadyRegisteredException(Class interfaceClass) { + super(interfaceClass.getName() + " component already registered"); } } @@ -448,8 +492,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return myInterfaceToClassMap.containsKey(interfaceClass); } - public float getPercentageOfComponentsLoaded() { - return ((float)myImplementations.size()) / myComponentConfigs.size(); + public double getPercentageOfComponentsLoaded() { + return ((double)myImplementations.size()) / myComponentConfigs.size(); } private void registerComponentInstance(final Object component) { @@ -521,66 +565,57 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public ComponentConfigComponentAdapter(final ComponentConfig config, Class implementationClass) { myConfig = config; - final String componentKey = config.getInterfaceClass(); myDelegate = new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(componentKey, implementationClass, null, true)) { - @Override - public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { - ProgressIndicator indicator = getProgressIndicator(); - if (indicator != null) { - indicator.checkCanceled(); - } + @Override + public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { + Object componentInstance = null; + try { + long startTime = myInitialized ? 0 : System.nanoTime(); + componentInstance = super.getComponentInstance(picoContainer); - Object componentInstance = null; - try { - long startTime = myInitialized ? 0 : System.nanoTime(); - - componentInstance = super.getComponentInstance(picoContainer); - - if (!myInitialized) { - if (myInitializing) { - if (myConfig.pluginDescriptor != null) { - LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); + if (!myInitialized) { + if (myInitializing) { + if (myConfig.pluginDescriptor != null) { + LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); + } + else { + LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); + } } - else { - LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); + + try { + myInitializing = true; + myComponentsRegistry.registerComponentInstance(componentInstance); + initComponent(componentInstance); + long endTime = System.nanoTime(); + long ms = (endTime - startTime) / 1000000; + if (ms > 10) { + if (logSlowComponents()) { + LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); + } + } } + finally { + myInitializing = false; + } + + myInitialized = true; } - - try { - myInitializing = true; - myComponentsRegistry.registerComponentInstance(componentInstance); - - initializeComponent(componentInstance, false); - if (componentInstance instanceof BaseComponent) { - ((BaseComponent)componentInstance).initComponent(); - } - - long ms = (System.nanoTime() - startTime) / 1000000; - if (ms > 10 && logSlowComponents()) { - LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); - } - } - finally { - myInitializing = false; - } - - myInitialized = true; } + catch (ProcessCanceledException e) { + throw e; + } + catch (StateStorageException e) { + throw e; + } + catch (Throwable t) { + handleInitComponentError(t, componentInstance == null, componentKey, config); + } + return componentInstance; } - catch (ProcessCanceledException e) { - throw e; - } - catch (StateStorageException e) { - throw e; - } - catch (Throwable t) { - handleInitComponentError(t, componentKey, config); - } + }; - return componentInstance; - } - }; } @Override @@ -590,23 +625,27 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Override public Class getComponentImplementation() { - return myDelegate.getComponentImplementation(); + return getDelegate().getComponentImplementation(); } @Override public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { - return myDelegate.getComponentInstance(container); + return getDelegate().getComponentInstance(container); } @Override public void verify(final PicoContainer container) throws PicoIntrospectionException { - myDelegate.verify(container); + getDelegate().verify(container); } @Override public void accept(final PicoVisitor visitor) { visitor.visitComponentAdapter(this); - myDelegate.accept(visitor); + getDelegate().accept(visitor); + } + + private ComponentAdapter getDelegate() { + return myDelegate; } } } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java index 3488bce03487..139d3eaa2e47 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java @@ -16,6 +16,7 @@ package com.intellij.diagnostic; import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; @@ -34,14 +35,13 @@ import java.lang.reflect.InvocationTargetException; * @author kir */ public class DefaultIdeaErrorLogger implements ErrorLogger { - private static boolean ourOomOccurred = false; + private static boolean ourOomOccured = false; private static boolean ourLoggerBroken = false; - private static boolean ourMappingFailedNotificationPosted = false; - + private static boolean mappingFailedNotificationPosted = false; @NonNls private static final String FATAL_ERROR_NOTIFICATION_PROPERTY = "idea.fatal.error.notification"; @NonNls private static final String DISABLED_VALUE = "disabled"; @NonNls private static final String ENABLED_VALUE = "enabled"; - @NonNls private static final String PARAM_PERM_GEN = "PermGen"; + @NonNls private static final String PARAM_PERMGEN = "PermGen"; public boolean canHandle(IdeaLoggingEvent event) { if (ourLoggerBroken) return false; @@ -56,7 +56,7 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal() || - isOOMError(event.getThrowable()) || + isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException; } catch (LinkageError e) { @@ -68,8 +68,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } } + /** + * @noinspection CallToPrintStackTrace + */ public void handle(IdeaLoggingEvent event) { - if (ourLoggerBroken) return; + if (ourLoggerBroken) { + return; + } try { Throwable throwable = event.getThrowable(); @@ -79,11 +84,11 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { else if (throwable instanceof MappingFailedException) { processMappingFailed(event); } - else if (!ourOomOccurred) { + else if (!ourOomOccured) { MessagePool messagePool = MessagePool.getInstance(); LogMessage message = messagePool.addIdeFatalMessage(event); if (message != null && ApplicationManager.getApplication() != null) { - ErrorNotifier.notifyUi(message, messagePool); + notifyUi(messagePool, message); } } } @@ -94,9 +99,14 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLoggerBroken = true; } + e.printStackTrace(); } } + private static void notifyUi(MessagePool messagePool, LogMessage message) { + ErrorNotifier.notifyUi(message, messagePool); + } + private static boolean isOOMError(Throwable throwable) { return throwable instanceof OutOfMemoryError || (throwable instanceof VirtualMachineError && @@ -104,13 +114,17 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { throwable.getMessage().contains("CodeCache")); } + /** + * @noinspection CallToPrintStackTrace + */ private static void processOOMError(final Throwable throwable) throws InterruptedException, InvocationTargetException { - ourOomOccurred = true; + ourOomOccured = true; + throwable.printStackTrace(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { String message = throwable.getMessage(); - OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERM_GEN) + OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERMGEN) ? OutOfMemoryDialog.MemoryKind.PERM_GEN : message != null && message.contains("CodeCache") ? OutOfMemoryDialog.MemoryKind.CODE_CACHE @@ -121,13 +135,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } private static void processMappingFailed(final IdeaLoggingEvent event) throws InterruptedException, InvocationTargetException { - if (!ourMappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { - ourMappingFailedNotificationPosted = true; - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") String exceptionMessage = event.getThrowable().getMessage(); - String text = exceptionMessage + - "
Possible cause: unable to allocate continuous memory chunk of necessary size.
" + - "Reducing JVM maximum heap size (-Xmx) may help."; - Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), null); + if (!mappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { + mappingFailedNotificationPosted = true; + final String exceptionMessage = event.getThrowable().getMessage(); + final String text = exceptionMessage + + "
Possible cause: unable to allocate continuous memory chunk of necessary size.
Reducing JVM's maximum heap size (-Xmx) may help."; + Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), NotificationDisplayType.BALLOON, null); } } + } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 5c9f61efba7d..2ce3a3c4fe4f 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -13,18 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.intellij.ide.plugins; import com.intellij.ide.ClassUtilCore; import com.intellij.ide.IdeBundle; -import com.intellij.idea.Main; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; -import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.components.ComponentConfig; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.progress.ProcessCanceledException; @@ -32,7 +30,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.util.ArrayUtil; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ExceptionUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,11 +39,12 @@ import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.io.IOException; import java.lang.reflect.Method; -import java.util.List; +import java.util.*; /** * @author mike */ +@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) // No logger is loaded at this time so we have to use these. public class PluginManager extends PluginManagerCore { @NonNls public static final String INSTALLED_TXT = "installed.txt"; @@ -56,103 +55,93 @@ public class PluginManager extends PluginManagerCore { /** * Called via reflection */ - @SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral", "finally"}) + @SuppressWarnings({"UnusedDeclaration"}) protected static void start(final String mainClass, final String methodName, final String[] args) { startupStart = System.nanoTime(); + try { + //noinspection HardCodedStringLiteral + ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { + @Override + public void uncaughtException(Thread t, Throwable e) { + if (!(e instanceof ProcessCanceledException)) { + PluginManagerCore.getLogger().error(e); + } + } + }; - Main.setFlags(args); - - if (!Main.isHeadless()) { - UIUtil.initDefaultLAF(); - } - - ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { - @Override - public void uncaughtException(Thread t, Throwable e) { - if (e instanceof StartupAbortedException) { - StartupAbortedException se = (StartupAbortedException)e; + Runnable runnable = new Runnable() { + @Override + public void run() { try { - if (se.logError()) { - if (Logger.isInitialized()) { - getLogger().error(e); - } - Main.showMessage("Start Failed", e); + ClassUtilCore.clearJarURLCache(); + + Class aClass = Class.forName(mainClass); + Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); + method.setAccessible(true); + + //noinspection RedundantArrayCreation + method.invoke(null, new Object[]{args}); + } + catch (Exception e) { + e.printStackTrace(System.err); + String message = "Error while accessing " + mainClass + "." + methodName + " with arguments: " + Arrays.asList(args); + if ("true".equals(System.getProperty("java.awt.headless"))) { + //noinspection UseOfSystemOutOrSystemErr + System.err.println(message); + } + else { + JOptionPane.showMessageDialog(null, message + ": " + e.getClass().getName() + ": " + e.getMessage() + "\n" + ExceptionUtil.getThrowableText(e), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); } } - finally { - System.exit(se.exitCode()); - } } + }; - if (!(e instanceof ProcessCanceledException)) { - getLogger().error(e); - } - } - }; - - Runnable runnable = new Runnable() { - @Override - public void run() { - try { - ClassUtilCore.clearJarURLCache(); - - Class aClass = Class.forName(mainClass); - Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); - method.setAccessible(true); - Object[] argsArray = {args}; - method.invoke(null, argsArray); - } - catch (Throwable t) { - throw new StartupAbortedException(t); - } - } - }; - - new Thread(threadGroup, runnable, "Idea Main Thread").start(); + //noinspection HardCodedStringLiteral + new Thread(threadGroup, runnable, "Idea Main Thread").start(); + } + catch (Exception e) { + PluginManagerCore.getLogger().error(e); + } } public static void reportPluginError() { if (myPluginError != null) { - String message = IdeBundle.message("title.plugin.error"); - Notifications.Bus.notify(new Notification(message, message, myPluginError, NotificationType.ERROR, new NotificationListener() { - @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") - @Override - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - notification.expire(); - - String description = event.getDescription(); - if (EDIT.equals(description)) { - PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); - IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); - ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); - return; - } - - List disabledPlugins = getDisabledPlugins(); - if (myPlugins2Disable != null && DISABLE.equals(description)) { - for (String pluginId : myPlugins2Disable) { - if (!disabledPlugins.contains(pluginId)) { - disabledPlugins.add(pluginId); - } + Notifications.Bus.notify(new Notification(IdeBundle.message("title.plugin.error"), IdeBundle.message("title.plugin.error"), + myPluginError, NotificationType.ERROR, new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + notification.expire(); + final String description = event.getDescription(); + if (EDIT.equals(description)) { + final PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); + IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); + ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); + return; } + final List disabledPlugins = PluginManagerCore.getDisabledPlugins(); + if (myPlugins2Disable != null && DISABLE.equals(description)) { + for (String pluginId : myPlugins2Disable) { + if (!disabledPlugins.contains(pluginId)) { + disabledPlugins.add(pluginId); + } + } + } else if (myPlugins2Enable != null && ENABLE.equals(description)) { + disabledPlugins.removeAll(myPlugins2Enable); + } + try { + PluginManagerCore.saveDisabledPlugins(disabledPlugins, false); + } + catch (IOException ignore) { + } + myPlugins2Enable = null; + myPlugins2Disable = null; } - else if (myPlugins2Enable != null && ENABLE.equals(description)) { - disabledPlugins.removeAll(myPlugins2Enable); - } - - try { - saveDisabledPlugins(disabledPlugins, false); - } - catch (IOException ignore) { } - - myPlugins2Enable = null; - myPlugins2Disable = null; - } - })); + })); myPluginError = null; } } + public static boolean isPluginInstalled(PluginId id) { return getPlugin(id) != null; } @@ -168,59 +157,24 @@ public class PluginManager extends PluginManagerCore { return null; } - public static void handleComponentError(Throwable t, String componentClassName, ComponentConfig config) { - if (t instanceof StartupAbortedException) { - throw (StartupAbortedException)t; - } - - PluginId pluginId = config != null ? config.getPluginId() : getPluginByClassName(componentClassName); - - if (pluginId != null && !CORE_PLUGIN_ID.equals(pluginId.getIdString())) { - getLogger().warn(t); - - disablePlugin(pluginId.getIdString()); - - String message = - "Plugin '" + pluginId.getIdString() + "' failed to initialize and will be disabled\n" + - "(reason: " + t.getMessage() + ")\n\n" + - ApplicationNamesInfo.getInstance().getFullProductName() + " will be restarted."; - Main.showMessage("Plugin Error", message, false); - - throw new StartupAbortedException(t).exitCode(Main.PLUGIN_ERROR).logError(false); + public static void disableIncompatiblePlugin(final Object cause, final Throwable ex) { + final PluginId pluginId = getPluginByClassName(cause.getClass().getName()); + if (pluginId != null && !ApplicationManager.getApplication().isHeadlessEnvironment()) { + final boolean success = PluginManagerCore.disablePlugin(pluginId.getIdString()); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), + "Incompatible plugin detected: " + pluginId.getIdString() + + (success ? "\nThe plugin has been disabled" : ""), + "Plugin Manager", + JOptionPane.ERROR_MESSAGE); + } + }); } else { - throw new StartupAbortedException("Fatal error initializing '" + componentClassName + "'", t); - } - } - - public static class StartupAbortedException extends RuntimeException { - private int exitCode = Main.STARTUP_EXCEPTION; - private boolean logError = true; - - public StartupAbortedException(Throwable cause) { - super(cause); - } - - public StartupAbortedException(String message, Throwable cause) { - super(message, cause); - } - - public int exitCode() { - return exitCode; - } - - public StartupAbortedException exitCode(int exitCode) { - this.exitCode = exitCode; - return this; - } - - public boolean logError() { - return logError; - } - - public StartupAbortedException logError(boolean logError) { - this.logError = logError; - return this; + // should never happen + throw new RuntimeException(ex); } } } diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 4604d57a6777..1641c8dd7838 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -18,12 +18,12 @@ package com.intellij.idea; import com.intellij.ExtensionPoints; import com.intellij.Patches; import com.intellij.concurrency.JobScheduler; +import com.intellij.diagnostic.PluginException; import com.intellij.ide.AppLifecycleListener; import com.intellij.ide.CommandLineProcessor; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.IdeRepaintManager; import com.intellij.ide.plugins.PluginManager; -import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationType; @@ -36,12 +36,10 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.updateSettings.impl.UpdateChecker; import com.intellij.openapi.updateSettings.impl.UpdateSettings; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.SystemDock; @@ -56,6 +54,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -80,15 +79,14 @@ public class IdeaApplication { myArgs = args; boolean isInternal = Boolean.valueOf(System.getProperty(IDEA_IS_INTERNAL_PROPERTY)).booleanValue(); - boolean headless = Main.isHeadless(); - if (!headless) { - patchSystem(); - } - - if (Main.isCommandLine()) { + if (Main.isCommandLine(args)) { + boolean headless = Main.isHeadless(args); + if (!headless) patchSystem(); new CommandLineApplication(isInternal, false, headless); } else { + patchSystem(); + Splash splash = null; if (myArgs.length == 0) { myStarter = getStarter(); @@ -161,16 +159,15 @@ public class IdeaApplication { protected ApplicationStarter getStarter() { if (myArgs.length > 0) { - PluginManagerCore.getPlugins(); + PluginManager.getPlugins(); ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.APPLICATION_STARTER); - ApplicationStarter[] starters = point.getExtensions(); + final ApplicationStarter[] starters = point.getExtensions(); String key = myArgs[0]; for (ApplicationStarter o : starters) { if (Comparing.equal(o.getCommandName(), key)) return o; } } - return new IdeStarter(); } @@ -178,9 +175,17 @@ public class IdeaApplication { return ourInstance; } - public void run() throws Exception { + public void run() { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - app.load(PathManager.getOptionsPath()); + try { + app.load(PathManager.getOptionsPath()); + } + catch (IOException e) { + e.printStackTrace(); + } + catch (InvalidDataException e) { + e.printStackTrace(); + } myStarter.main(myArgs); myStarter = null; //GC it @@ -247,28 +252,36 @@ public class IdeaApplication { @Override public void main(String[] args) { - SystemDock.updateMenu(); + SystemDock.updateMenu(); // Event queue should not be changed during initialization of application components. // It also cannot be changed before initialization of application components because IdeEventQueue uses other // application components. So it is proper to perform replacement only here. ApplicationEx app = ApplicationManagerEx.getApplicationEx(); + // app.setupIdeQueue(IdeEventQueue.getInstance()); WindowManagerImpl windowManager = (WindowManagerImpl)WindowManager.getInstance(); - IdeEventQueue.getInstance().setWindowManager(windowManager); - Ref willOpenProject = new Ref(Boolean.FALSE); - AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); - lifecyclePublisher.appFrameCreated(args, willOpenProject); + try { + IdeEventQueue.getInstance().setWindowManager(windowManager); - LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); - PluginManagerCore.dumpPluginClassStatistics(); - - if (!willOpenProject.get()) { - WelcomeFrame.showNow(); - lifecyclePublisher.welcomeScreenDisplayed(); + final Ref willOpenProject = new Ref(Boolean.FALSE); + final AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); + lifecyclePublisher.appFrameCreated(args, willOpenProject); + LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); + PluginManager.dumpPluginClassStatistics(); + if (!willOpenProject.get()) { + WelcomeFrame.showNow(); + lifecyclePublisher.welcomeScreenDisplayed(); + } + else { + windowManager.showFrame(); + } } - else { - windowManager.showFrame(); + catch (PluginException e) { + Messages.showErrorDialog("Plugin " + e.getPluginId() + " couldn't be loaded, the IDE will now exit.\n" + + "See the full details in the log.\n" + + e.getMessage(), "Plugin Error"); + System.exit(-1); } app.invokeLater(new Runnable() { @@ -308,6 +321,7 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); } + } private void loadProject() { diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java index 17de69c30b7c..6f075573a6a2 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java @@ -44,6 +44,7 @@ public class IdeaLogger extends Logger { public static String ourLastActionId = ""; + private final org.apache.log4j.Logger myLogger; /** If not null - it means that errors occurred and it is the first of them. */ public static Exception ourErrorsOccurred; @@ -58,24 +59,25 @@ public class IdeaLogger extends Logger { static { InputStream stream = Logger.class.getResourceAsStream(COMPILATION_TIMESTAMP_RESOURCE_NAME); if (stream != null) { + LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); try { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); + String s = reader.readLine(); + if (s != null) { + ourCompilationTimestamp = s.trim(); + } + } + catch (IOException ignored) { + } + finally { try { - String s = reader.readLine(); - if (s != null) { - ourCompilationTimestamp = s.trim(); - } + stream.close(); } - finally { - reader.close(); + catch (IOException ignored) { } } - catch (IOException ignored) { } } } - private final org.apache.log4j.Logger myLogger; - IdeaLogger(org.apache.log4j.Logger logger) { myLogger = logger; } @@ -132,6 +134,9 @@ public class IdeaLogger extends Logger { myLogger.error(message + (!detailString.isEmpty() ? "\nDetails: " + detailString : ""), t); logErrorHeader(); + if (t != null && t.getCause() != null) { + myLogger.error("Original exception: ", t.getCause()); + } } private void logErrorHeader() { diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index d2b0fbf09b7d..d77b870c7112 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -88,7 +88,7 @@ public class SocketLock { if (mySocket == null) { if (!myIsDialogShown) { final String productName = ApplicationNamesInfo.getInstance().getProductName(); - if (Main.isHeadless()) { //team server inspections + if (StartupUtil.isHeadless()) { //team server inspections throw new RuntimeException("Only one instance of " + productName + " can be run at a time."); } @NonNls final String pathToLogFile = PathManager.getLogPath() + "/idea.log file".replace('/', File.separatorChar); diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index 28ee2fbfe8c2..c05df8fdb349 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -15,11 +15,10 @@ */ package com.intellij.idea; -import com.intellij.ide.plugins.PluginManagerCore; +import com.intellij.ide.plugins.PluginManager; import com.intellij.ide.startupWizard.StartupWizard; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.application.ConfigImportHelper; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.application.impl.ApplicationInfoImpl; @@ -29,7 +28,6 @@ import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.win32.IdeaWin32; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.AppUIUtil; import com.intellij.util.Consumer; import com.intellij.util.EnvironmentUtil; import com.intellij.util.SystemProperties; @@ -43,6 +41,7 @@ import javax.swing.*; import java.io.File; import java.io.InputStream; import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -55,6 +54,8 @@ public class StartupUtil { public static final boolean NO_SNAPPY = SystemProperties.getBooleanProperty("idea.no.snappy", false); + static boolean isHeadless; + private static SocketLock ourLock; private static String myDefaultLAF; @@ -72,55 +73,17 @@ public class StartupUtil { return !Arrays.asList(args).contains(NO_SPLASH); } - /** @deprecated use {@link Main#isHeadless()} (to remove in IDEA 14) */ - @SuppressWarnings("unused") public static boolean isHeadless() { - return Main.isHeadless(); + return isHeadless; } - public synchronized static void addExternalInstanceListener(Consumer> consumer) { - ourLock.setActivateListener(consumer); - } - - interface AppStarter { - void start(boolean newConfigFolder); - } - - static void prepareAndStart(String[] args, AppStarter appStarter) { - boolean newConfigFolder = false; - - if (!Main.isHeadless()) { - AppUIUtil.updateFrameClass(); - AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); - AppUIUtil.registerBundledFonts(); - - newConfigFolder = PathManager.ensureConfigFolderExists(true); - if (newConfigFolder) { - ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); - } + private static void showError(final String title, final String message) { + if (isHeadless()) { + //noinspection UseOfSystemOutOrSystemErr + System.out.println(message); } - - boolean canStart = checkJdkVersion() && checkSystemFolders() && lockSystemFolders(args); // note: uses config folder! - if (!canStart) { - System.exit(Main.STARTUP_IMPOSSIBLE); - } - - Logger.setFactory(LoggerFactory.getInstance()); - Logger log = Logger.getInstance(Main.class); - startLogging(log); - fixProcessEnvironment(log); - loadSystemLibraries(log); - - appStarter.start(newConfigFolder); - } - - static void runStartupWizard() { - final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); - if (!pages.isEmpty()) { - final StartupWizard startupWizard = new StartupWizard(pages); - startupWizard.setCancelText("Skip"); - startupWizard.show(); - PluginManagerCore.invalidatePlugins(); + else { + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, title, JOptionPane.ERROR_MESSAGE); } } @@ -134,9 +97,17 @@ public class StartupUtil { Class.forName("com.sun.jdi.Field"); } catch (ClassNotFoundException e) { - String message = "'tools.jar' seems to be not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + - "Please ensure JAVA_HOME points to JDK rather than JRE."; - Main.showMessage("JDK Required", message, true); + showError("Error", "'tools.jar' is not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + + "Please ensure JAVA_HOME points to JDK rather than JRE."); + return false; + } + } + + if (!"true".equals(System.getProperty("idea.no.jdk.check"))) { + final String version = System.getProperty("java.version"); + if (!SystemInfo.isJavaVersionAtLeast("1.6")) { + showError("Java Version Mismatch", "The JDK version is " + version + ".\n" + + ApplicationNamesInfo.getInstance().getProductName() + " requires JDK 1.6 or higher."); return false; } } @@ -146,20 +117,18 @@ public class StartupUtil { private synchronized static boolean checkSystemFolders() { final String configPath = PathManager.getConfigPath(); - if (!new File(configPath).isDirectory()) { - String message = "Config path '" + configPath + "' is invalid.\n" + - "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."; - Main.showMessage("Invalid Config Path", message, true); + if (configPath == null || !new File(configPath).isDirectory()) { + showError("Invalid config path", "Config path '" + configPath + "' is invalid.\n" + + "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."); return false; } final String systemPath = PathManager.getSystemPath(); if (systemPath == null || !new File(systemPath).isDirectory()) { - String message = "System path '" + systemPath + "' is invalid.\n" + - "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."; - Main.showMessage("Invalid System Path", message, true); + showError("Invalid system path", "System path '" + systemPath + "' is invalid.\n" + + "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."); return false; } @@ -177,9 +146,8 @@ public class StartupUtil { } 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); + if (isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) { + showError("Error", "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time."); } return false; } @@ -187,16 +155,38 @@ public class StartupUtil { return true; } - private static void fixProcessEnvironment(Logger log) { + static boolean checkStartupPossible(String[] args) { + return checkJdkVersion() && + checkSystemFolders() && + lockSystemFolders(args); + } + + static void runStartupWizard() { + final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); + if (!pages.isEmpty()) { + final StartupWizard startupWizard = new StartupWizard(pages); + startupWizard.setCancelText("Skip"); + startupWizard.show(); + PluginManager.invalidatePlugins(); + } + } + + public synchronized static void addExternalInstanceListener(Consumer> consumer) { + ourLock.setActivateListener(consumer); + } + + + static void fixProcessEnvironment(Logger log) { boolean envReady = EnvironmentUtil.isEnvironmentReady(); // trigger environment loading if (!envReady) { log.info("initializing environment"); } } + private static final String JAVA_IO_TEMP_DIR = "java.io.tmpdir"; - private static void loadSystemLibraries(final Logger log) { + static void loadSystemLibraries(final Logger log) { // load JNA and Snappy in own temp directory - to avoid collisions and work around no-exec /tmp final File ideaTempDir = new File(PathManager.getSystemPath(), "tmp"); if (!(ideaTempDir.mkdirs() || ideaTempDir.exists())) { @@ -241,7 +231,7 @@ public class StartupUtil { IdeaWin32.isAvailable(); // logging is done there } - if (SystemInfo.isWin2kOrNewer && !Main.isHeadless()) { + if (SystemInfo.isWin2kOrNewer && !isHeadless) { try { System.loadLibrary(SystemInfo.isAMD64 ? "focusKiller64" : "focusKiller"); log.info("Using \"FocusKiller\" library to prevent focus stealing."); @@ -290,25 +280,28 @@ public class StartupUtil { loadNativeLibrary.invoke(null, loaderClass); } - private static void startLogging(final Logger log) { + public static void startLogging(final Logger log) { Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook - logging") { public void run() { - log.info("------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); + log.info( + "------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); } }); - log.info("------------------------------------------------------ IDE STARTED ------------------------------------------------------"); + log.info( + "------------------------------------------------------ IDE STARTED ------------------------------------------------------"); - ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); - ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); + final ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); + final ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); log.info("IDE: " + namesInfo.getFullProductName() + " (build #" + appInfo.getBuild() + ", " + DateFormatUtilRt.formatBuildDate(appInfo.getBuildDate()) + ")"); log.info("OS: " + SystemInfoRt.OS_NAME + " (" + SystemInfoRt.OS_VERSION + ")"); + log.info("JRE: " + System.getProperty("java.runtime.version", "-") + " (" + System.getProperty("java.vendor", "-") + ")"); log.info("JVM: " + System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.vendor", "-") + ")"); - List arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); - if (arguments != null) { - log.info("JVM Args: " + StringUtil.join(arguments, " ")); - } + RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); + List arguments = RuntimemxBean.getInputArguments(); + + if (arguments != null) log.info("JVM Args: " + StringUtil.join(arguments, " ")); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index f092d21e0e43..48d8b85b133d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -22,7 +22,6 @@ import com.intellij.diagnostic.PluginException; import com.intellij.ide.*; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; -import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.idea.StartupUtil; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.*; @@ -38,6 +37,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProcessCanceledException; @@ -89,8 +89,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application private static final Logger LOG = Logger.getInstance("#com.intellij.application.impl.ApplicationImpl"); private final ModalityState MODALITY_STATE_NONE = ModalityState.NON_MODAL; - // about writer preference: the way the j.u.c.l.ReentrantReadWriteLock.NonfairSync is implemented, the - // writer thread will be always at the queue head and therefore, j.u.c.l.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() + // about writer preference: the way the java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync is implemented, the + // writer thread will be always at the queue head and therefore, java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() // will return true if the write action is pending, exactly as we need private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(false); @@ -361,25 +361,55 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } @Override - protected void handleInitComponentError(Throwable t, String componentClassName, ComponentConfig config) { - if (!myHandlingInitComponentError) { - myHandlingInitComponentError = true; - try { - PluginManager.handleComponentError(t, componentClassName, config); + protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { + if (myHandlingInitComponentError) { + return; + } + myHandlingInitComponentError = true; + try { + PluginId pluginId = config == null ? PluginManager.getPluginByClassName(componentClassName) : config.getPluginId(); + if (pluginId != null) { + LOG.warn(ex); + @NonNls final String errorMessage = + "Plugin " + pluginId.getIdString() + " failed to initialize and will be disabled:\n" + ex.getMessage() + + "\nPlease restart " + ApplicationNamesInfo.getInstance().getFullProductName() + "."; + PluginManager.disablePlugin(pluginId.getIdString()); + if (!myHeadlessMode) { + JOptionPane.showMessageDialog(null, errorMessage); + } + else if (!isUnitTestMode()) { + //noinspection UseOfSystemOutOrSystemErr + System.out.println(errorMessage); + System.exit(1); + } + return; // do not call super } - finally { - myHandlingInitComponentError = false; + if (fatal) { + LOG.error(ex); + @NonNls final String errorMessage = "Fatal error initializing class " + componentClassName + ":\n" + + StringUtil.trimLog(ex.toString(), 239) + + "\nComplete error stacktrace was written to " + PathManager.getLogPath() + "/idea.log"; + if (!myHeadlessMode) { + JOptionPane.showMessageDialog(null, errorMessage); + } + else { + //noinspection UseOfSystemOutOrSystemErr + System.out.println(errorMessage); + } } + super.handleInitComponentError(ex, fatal, componentClassName, config); + } + finally { + myHandlingInitComponentError = false; } } private void loadApplicationComponents() { - PluginManagerCore.initPlugins(mySplash); - IdeaPluginDescriptor[] plugins = PluginManagerCore.getPlugins(); + PluginManager.initPlugins(mySplash); + final IdeaPluginDescriptor[] plugins = PluginManager.getPlugins(); for (IdeaPluginDescriptor plugin : plugins) { - if (!PluginManagerCore.shouldSkipPlugin(plugin)) { - loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); - } + if (PluginManager.shouldSkipPlugin(plugin)) continue; + loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); } } @@ -387,7 +417,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application protected synchronized Object createComponent(Class componentInterface) { Object component = super.createComponent(componentInterface); if (mySplash != null) { - mySplash.showProgress("", 0.65f + getPercentageOfComponentsLoaded() * 0.35f); + mySplash.showProgress("", (float)(0.65f + getPercentageOfComponentsLoaded() * 0.35f)); } return component; } @@ -1410,7 +1440,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application public void run() { if (ex instanceof PluginException) { final PluginException pluginException = (PluginException)ex; - PluginManagerCore.disablePlugin(pluginException.getPluginId().getIdString()); + PluginManager.disablePlugin(pluginException.getPluginId().getIdString()); Messages.showMessageDialog("The plugin " + pluginException.getPluginId() + " failed to save settings and has been disabled. Please restart " + diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index 0ff8fe8b00fd..fd6e291e0b27 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -149,12 +149,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } }; - for (FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { + for (final FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { try { factory.createFileTypes(consumer); } - catch (Throwable t) { - PluginManager.handleComponentError(t, factory.getClass().getName(), null); + catch (final Error ex) { + PluginManager.disableIncompatiblePlugin(factory, ex); } } } @@ -191,6 +191,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return null; + } @Override @@ -217,6 +218,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return new Document(root); + } @Override diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 2376bebac862..0faeeb706a0a 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -15,41 +15,77 @@ */ package com.intellij.idea; -import com.intellij.ide.plugins.PluginManager; +import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.application.ConfigImportHelper; +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.impl.ApplicationInfoImpl; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.SystemInfoRt; +import com.intellij.ui.AppUIUtil; import com.intellij.util.PlatformUtils; -import com.intellij.util.PlatformUtilsCore; +import com.intellij.util.text.DateFormatUtilRt; +import com.intellij.util.ui.UIUtil; import javax.swing.*; -@SuppressWarnings({"UnusedDeclaration"}) +@SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "UnusedDeclaration"}) public class MainImpl { + private static final String LOG_CATEGORY = "#com.intellij.idea.Main"; + private MainImpl() { } /** * Called from PluginManager via reflection. */ protected static void start(final String[] args) { - System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); + System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); - StartupUtil.prepareAndStart(args, new StartupUtil.AppStarter() { - @Override - public void start(boolean newConfigFolder) { - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - try { - new IdeaApplication(args).run(); - } - catch (PluginManager.StartupAbortedException e) { - throw e; - } - catch (Throwable t) { - throw new PluginManager.StartupAbortedException(t); - } - } - }); + StartupUtil.isHeadless = Main.isHeadless(args); + if (!StartupUtil.isHeadless) { + AppUIUtil.updateFrameClass(); + AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); + AppUIUtil.registerBundledFonts(); + + UIUtil.initDefaultLAF(); + + final boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); + if (isNewConfigFolder) { + ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); + } + } + + if (!StartupUtil.checkStartupPossible(args)) { // It uses config folder! + System.exit(-1); + } + + Logger.setFactory(LoggerFactory.getInstance()); + + final Logger LOG = Logger.getInstance(LOG_CATEGORY); + + StartupUtil.startLogging(LOG); + + _main(args); + } + + protected static void _main(final String[] args) { + // http://weblogs.java.net/blog/shan_man/archive/2005/06/improved_drag_g.html + System.setProperty("sun.swing.enableImprovedDragGesture", ""); + + Logger LOG = Logger.getInstance(LOG_CATEGORY); + StartupUtil.fixProcessEnvironment(LOG); + StartupUtil.loadSystemLibraries(LOG); + + startApplication(args); + } + + private static void startApplication(final String[] args) { + final IdeaApplication app = new IdeaApplication(args); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + public void run() { + app.run(); } }); } -} +} \ No newline at end of file diff --git a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java index bac5d8cab2cf..7a07bec9ae5e 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java +++ b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java @@ -26,23 +26,17 @@ public abstract class Logger { Logger getLoggerInstance(String category); } - private static class DefaultFactory implements Factory { + public static Factory ourFactory = new Factory() { @Override public Logger getLoggerInstance(String category) { return new DefaultLogger(category); } - } - - public static Factory ourFactory = new DefaultFactory(); + }; public static void setFactory(Factory factory) { ourFactory = factory; } - public static boolean isInitialized() { - return !(ourFactory instanceof DefaultFactory); - } - public static Logger getInstance(@NonNls String category) { return ourFactory.getLoggerInstance(category); } @@ -54,29 +48,9 @@ public abstract class Logger { public abstract boolean isDebugEnabled(); public abstract void debug(@NonNls String message); - public abstract void debug(@Nullable Throwable t); - public abstract void debug(@NonNls String message, @Nullable Throwable t); - public void info(@NotNull Throwable t) { - info(t.getMessage(), t); - } - - public abstract void info(@NonNls String message); - - public abstract void info(@NonNls String message, @Nullable Throwable t); - - public void warn(@NonNls String message) { - warn(message, null); - } - - public void warn(@NotNull Throwable t) { - warn(t.getMessage(), t); - } - - public abstract void warn(@NonNls String message, @Nullable Throwable t); - public void error(@NonNls String message) { error(message, new Throwable(), ArrayUtil.EMPTY_STRING_ARRAY); } @@ -96,8 +70,27 @@ public abstract class Logger { error(t.getMessage(), t, ArrayUtil.EMPTY_STRING_ARRAY); } + public void warn(@NonNls String message) { + warn(message, null); + } + + public void warn(@NotNull Throwable t) { + warn(t.getMessage(), t); + } + + public abstract void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details); + public abstract void info(@NonNls String message); + + public abstract void info(@NonNls String message, @Nullable Throwable t); + + public abstract void warn(@NonNls String message, @Nullable Throwable t); + + public void info(@NotNull Throwable t) { + info(t.getMessage(), t); + } + public boolean assertTrue(boolean value, @NonNls Object message) { if (!value) { @NonNls StringBuilder resultMessage = new StringBuilder("Assertion failed"); @@ -114,4 +107,5 @@ public abstract class Logger { } public abstract void setLevel(Level level); + } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java index ed67161b6773..10b65fe7f0e4 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java @@ -18,10 +18,13 @@ package com.intellij.util.xml.impl; import com.intellij.ide.highlighter.DomSupportEnabled; import com.intellij.ide.startup.StartupManagerEx; import com.intellij.openapi.Disposable; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; @@ -69,44 +72,36 @@ import java.util.Set; */ public final class DomManagerImpl extends DomManager { private static final Key MOCK = Key.create("MockElement"); - static final Key> CACHED_FILE_ELEMENT = Key.create("CACHED_FILE_ELEMENT"); static final Key MOCK_DESCRIPTION = Key.create("MockDescription"); + static final SemKey FILE_DESCRIPTION_KEY = SemKey.createKey("FILE_DESCRIPTION_KEY"); - static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); + public static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); static final SemKey DOM_INDEXED_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_INDEXED_HANDLER_KEY"); static final SemKey DOM_COLLECTION_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_COLLECTION_HANDLER_KEY"); static final SemKey DOM_CUSTOM_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_CUSTOM_HANDLER_KEY"); static final SemKey DOM_ATTRIBUTE_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_ATTRIBUTE_HANDLER_KEY"); private final EventDispatcher myListeners = EventDispatcher.create(DomEventListener.class); + private final ConverterManagerImpl myConverterManager; + private final GenericValueReferenceProvider myGenericValueReferenceProvider = new GenericValueReferenceProvider(); private final Project myProject; - private final SemService mySemService; - private final ConverterManager myConverterManager; private final DomApplicationComponent myApplicationComponent; private final PsiFileFactory myFileFactory; - private final ProjectFileIndex myFileIndex; private long myModificationCount; private boolean myChanging; + private final ProjectFileIndex myFileIndex; + private final SemService mySemService; - public DomManagerImpl(Project project, - final XmlAspect xmlAspect, - SemService semService, - ConverterManager converterManager, - DomApplicationComponent appComponent, - PsiFileFactory fileFactory, - ProjectFileIndex fileIndex) { + public DomManagerImpl(final Project project, final XmlAspect xmlAspect) { myProject = project; - mySemService = semService; - myConverterManager = converterManager; - myApplicationComponent = appComponent; - myFileFactory = fileFactory; - myFileIndex = fileIndex; - - PomModel pomModel = PomManager.getModel(project); + mySemService = SemService.getSemService(project); + myConverterManager = (ConverterManagerImpl)ServiceManager.getService(ConverterManager.class); + myApplicationComponent = DomApplicationComponent.getInstance(); + final PomModel pomModel = PomManager.getModel(project); pomModel.addModelListener(new PomModelListener() { public void modelChanged(PomModelEvent event) { final XmlChangeSet changeSet = (XmlChangeSet)event.getChangeSet(xmlAspect); @@ -125,7 +120,11 @@ public final class DomManagerImpl extends DomManager { } }, project); - Runnable setupVfsListeners = new Runnable() { + myFileFactory = PsiFileFactory.getInstance(project); + + final PsiManager psiManager = PsiManager.getInstance(project); + + final Runnable setupVfsListeners = new Runnable() { public void run() { final VirtualFileAdapter listener = new VirtualFileAdapter() { private final List myDeletionEvents = new SmartList(); @@ -141,7 +140,7 @@ public final class DomManagerImpl extends DomManager { } public void beforeFileDeletion(final VirtualFileEvent event) { - if (!myProject.isDisposed()) { + if (!project.isDisposed()) { beforeFileDeletion(event.getFile()); } } @@ -164,7 +163,7 @@ public final class DomManagerImpl extends DomManager { public void fileDeleted(VirtualFileEvent event) { if (!myDeletionEvents.isEmpty()) { - if (!myProject.isDisposed()) { + if (!project.isDisposed()) { for (DomEvent domEvent : myDeletionEvents) { fireEvent(domEvent); } @@ -180,17 +179,18 @@ public final class DomManagerImpl extends DomManager { } } }; - VirtualFileManager.getInstance().addVirtualFileListener(listener, myProject); + VirtualFileManager.getInstance().addVirtualFileListener(listener, project); } }; - StartupManager startupManager = StartupManager.getInstance(project); + final StartupManager startupManager = StartupManager.getInstance(project); if (!((StartupManagerEx)startupManager).startupActivityPassed()) { startupManager.registerStartupActivity(setupVfsListeners); - } - else { + } else { setupVfsListeners.run(); } + + myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); } private void processVfsChange(final VirtualFile file) { @@ -522,4 +522,7 @@ public final class DomManagerImpl extends DomManager { public SemService getSemService() { return mySemService; } + + + private final static Logger LOG = Logger.getInstance(DomManagerImpl.class); } diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java index 49110e2c0f4a..298bf9ea9a16 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java @@ -23,14 +23,13 @@ import com.intellij.psi.PsiFileFactory; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.highlighting.*; -import com.intellij.util.xml.impl.DomTestCase; import java.util.Arrays; /** * @author peter */ -public class DomAnnotationsTest extends DomTestCase { +public class DomAnnotationsTest extends DomTestCase{ @Override protected T createElement(final String xml, final Class aClass) { diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java index 89229bf889c5..ba33cf4ba00f 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java @@ -26,7 +26,6 @@ import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomTestCase; import java.lang.reflect.Type; import java.util.ArrayList; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java index 4a94d0e5ba26..8e78b570e9fb 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java @@ -28,7 +28,6 @@ import com.intellij.semantic.SemService; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.Timings; import com.intellij.util.xml.impl.DomFileElementImpl; -import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomExtender; import com.intellij.util.xml.reflect.DomExtenderEP; import com.intellij.util.xml.reflect.DomExtensionsRegistrar; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java index 5aa8c0b2255d..e013091b79cf 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java @@ -21,7 +21,6 @@ import com.intellij.testFramework.IdeaTestUtil; import com.intellij.util.Consumer; import com.intellij.util.ParameterizedTypeImpl; import com.intellij.util.ReflectionUtil; -import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.*; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java index c2f13f6368cb..e4d6d65be887 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java @@ -26,8 +26,8 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.psi.xml.XmlTagValue; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomApplicationComponent; import com.intellij.util.xml.impl.DomManagerImpl; -import com.intellij.util.xml.impl.DomTestCase; /** * @author peter diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java index 623b11616f59..8a57ba6d8d64 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java @@ -34,7 +34,6 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.MockSchemesManagerFactory; import com.intellij.util.xml.highlighting.*; import com.intellij.util.xml.impl.DefaultDomAnnotator; -import com.intellij.util.xml.impl.DomTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java index 9efc125bb83c..f94d568c26d5 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java @@ -16,17 +16,13 @@ package com.intellij.util.xml; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.util.xml.impl.DomTestCase; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author peter */ -public class DomModelMergingTest extends DomTestCase { +public class DomModelMergingTest extends DomTestCase{ private ModelMerger myMerger; @Override diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java index 8d92c019129f..ae96a3b5062a 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java @@ -20,7 +20,6 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.impl.DomFileElementImpl; -import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomGenericInfo; import java.util.List; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java index 8911df1c22ac..5e42f0678f83 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java @@ -22,7 +22,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.ui.DomUIFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java similarity index 92% rename from xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java rename to xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java index 37682943b3eb..16fedacfca67 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.util.xml.impl; +package com.intellij.util.xml; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; @@ -25,8 +25,11 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.util.IncorrectOperationException; -import com.intellij.util.xml.*; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomApplicationComponent; +import com.intellij.util.xml.impl.DomFileElementImpl; +import com.intellij.util.xml.impl.DomInvocationHandler; +import com.intellij.util.xml.impl.DomManagerImpl; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -84,7 +87,7 @@ public abstract class DomTestCase extends LightIdeaTestCase { return element; } - public static T createElement(final DomManager domManager, final String xml, final Class aClass) + protected static T createElement(final DomManager domManager, final String xml, final Class aClass) throws IncorrectOperationException { final String name = "a.xml"; final XmlFile file = (XmlFile)PsiFileFactory.getInstance(domManager.getProject()).createFileFromText(name, xml); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java index 2a2bf1a4e2f3..d85066b560d7 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java @@ -17,12 +17,11 @@ package com.intellij.util.xml; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomTestCase; /** * @author peter */ -public class SimpleValuesIncrementalUpdateTest extends DomTestCase { +public class SimpleValuesIncrementalUpdateTest extends DomTestCase{ public void testAttributeChange() throws Throwable { final MyElement element = createElement(""); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java index 2f7f2fefcd90..e191e3eacfc0 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java @@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.DomElement; +import com.intellij.util.xml.DomTestCase; import com.intellij.util.xml.SubTag; import com.intellij.util.xml.events.DomEvent; From 23e5ffd1a76f37ad5c130d03d5685541967c0b93 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 12:19:51 +0400 Subject: [PATCH 15/47] accept all runnables in queue --- .../sm/runner/GeneralTestEventsProcessor.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java index 0ed666883608..305f42a2ba5e 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java @@ -39,7 +39,6 @@ import javax.swing.*; * and name of test method */ public abstract class GeneralTestEventsProcessor implements Disposable { - private boolean myDisposed = false; private TransferToEDTQueue myTransferToEDTQueue = new TransferToEDTQueue("SM queue", new Processor() { @Override @@ -99,17 +98,10 @@ public abstract class GeneralTestEventsProcessor implements Disposable { public abstract void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider); @Override - public void dispose() { - myDisposed = true; - } + public void dispose() {} public Condition getDisposedCondition() { - return new Condition() { - @Override - public boolean value(Object o) { - return myDisposed; - } - }; + return Condition.FALSE; } /** From 9b0ab4986c0f639ad1580fefe946f9eeeda6d76b Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 13 Jun 2013 12:34:55 +0400 Subject: [PATCH 16/47] IDEA-104500 Gradle: Allow to reuse common logic for other external systems Correct non-existing jar files registration during import from external system --- .../project/manage/LibraryDataService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java index 75491a2c77be..4c34b4ff0537 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java @@ -16,10 +16,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; -import com.intellij.openapi.vfs.JarFileSystem; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtilCore; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.openapi.vfs.*; import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; @@ -132,7 +130,14 @@ public class LibraryDataService implements ProjectDataService Date: Thu, 13 Jun 2013 13:04:41 +0400 Subject: [PATCH 17/47] Changes fixed and re-applied --- .../src/com/intellij/ide/Bootstrap.java | 31 +-- .../src/com/intellij/ide/ClassloaderUtil.java | 70 +----- .../bootstrap/src/com/intellij/idea/Main.java | 195 +++++++++------ .../intellij/diagnostic/PluginException.java | 7 +- .../components/impl/ComponentManagerImpl.java | 181 ++++++-------- .../diagnostic/DefaultIdeaErrorLogger.java | 48 ++-- .../intellij/ide/plugins/PluginManager.java | 228 +++++++++++------- .../com/intellij/idea/IdeaApplication.java | 72 +++--- .../src/com/intellij/idea/IdeaLogger.java | 25 +- .../src/com/intellij/idea/SocketLock.java | 2 +- .../src/com/intellij/idea/StartupUtil.java | 143 +++++------ .../application/impl/ApplicationImpl.java | 64 ++--- .../fileTypes/impl/FileTypeManagerImpl.java | 8 +- .../src/com/intellij/idea/MainImpl.java | 83 ++----- .../intellij/openapi/diagnostic/Logger.java | 50 ++-- .../util/xml/impl/DomManagerImpl.java | 55 ++--- .../intellij/util/xml/DomAnnotationsTest.java | 3 +- .../intellij/util/xml/DomChildrenTest.java | 1 + .../util/xml/DomConcurrencyStressTest.java | 1 + .../intellij/util/xml/DomExtensionsTest.java | 1 + .../util/xml/DomHardCoreTestCase.java | 2 +- .../util/xml/DomHighlightingLiteTest.java | 1 + .../util/xml/DomModelMergingTest.java | 8 +- .../intellij/util/xml/DomNamespacesTest.java | 1 + .../util/xml/DomSimpleValuesTest.java | 1 + .../SimpleValuesIncrementalUpdateTest.java | 3 +- .../util/xml/{ => impl}/DomTestCase.java | 9 +- .../xml/impl/IncrementalUpdateEventsTest.java | 1 - 28 files changed, 597 insertions(+), 697 deletions(-) rename xml/dom-tests/tests/com/intellij/util/xml/{ => impl}/DomTestCase.java (92%) diff --git a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java index 4d12c4bf6255..05280434f3d0 100644 --- a/platform/bootstrap/src/com/intellij/ide/Bootstrap.java +++ b/platform/bootstrap/src/com/intellij/ide/Bootstrap.java @@ -17,7 +17,6 @@ package com.intellij.ide; import com.intellij.util.lang.UrlClassLoader; -import javax.swing.*; import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; @@ -29,31 +28,19 @@ import java.util.List; public class Bootstrap { private static final String PLUGIN_MANAGER = "com.intellij.ide.plugins.PluginManager"; - private Bootstrap() {} + private Bootstrap() { } - public static void main(final String[] args, final String mainClass, final String methodName) { + public static void main(String[] args, String mainClass, String methodName) throws Exception { main(args, mainClass, methodName, new ArrayList()); } - public static void main(final String[] args, final String mainClass, final String methodName, final List classpathElements) { - final UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); - try { - WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); + public static void main(String[] args, String mainClass, String methodName, List classpathElements) throws Exception { + UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements); + WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader); - final Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); - - final Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); - startMethod.setAccessible(true); - startMethod.invoke(null, mainClass, methodName, args); - } - catch (Exception e) { - if ("true".equals(System.getProperty("java.awt.headless"))) { - //noinspection UseOfSystemOutOrSystemErr - e.printStackTrace(System.err); - } - else { - JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage(), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); - } - } + Class klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader); + Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class); + startMethod.setAccessible(true); + startMethod.invoke(null, mainClass, methodName, args); } } \ No newline at end of file diff --git a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java index d31e2383c4fb..6d6f715d026d 100644 --- a/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java +++ b/platform/bootstrap/src/com/intellij/ide/ClassloaderUtil.java @@ -30,7 +30,6 @@ import com.intellij.util.lang.UrlClassLoader; import com.intellij.util.text.StringTokenizer; import org.jetbrains.annotations.NonNls; -import javax.swing.*; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -44,76 +43,33 @@ import java.util.regex.Pattern; public class ClassloaderUtil extends ClassUtilCore { @NonNls public static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath"; - @SuppressWarnings({"HardCodedStringLiteral"}) - private static final String ERROR = "Error"; - private ClassloaderUtil() {} public static Logger getLogger() { return Logger.getInstance("ClassloaderUtil"); } - public static UrlClassLoader initClassloader(final List classpathElements) { + public static UrlClassLoader initClassloader(final List classpathElements) throws Exception { PathManager.loadProperties(); - try { - addParentClasspath(classpathElements); - addIDEALibraries(classpathElements); - addAdditionalClassPath(classpathElements); - } - catch (IllegalArgumentException e) { - if (Main.isHeadless()) { - getLogger().error(e); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); - } - System.exit(1); - } - catch (MalformedURLException e) { - if (Main.isHeadless()) { - getLogger().error(e.getMessage()); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), e.getMessage(), ERROR, JOptionPane.INFORMATION_MESSAGE); - } - System.exit(1); - } + addParentClasspath(classpathElements); + addIDEALibraries(classpathElements); + addAdditionalClassPath(classpathElements); filterClassPath(classpathElements); + UrlClassLoader newClassLoader = new UrlClassLoader(classpathElements, null, true, true); - UrlClassLoader newClassLoader = null; - try { - newClassLoader = new UrlClassLoader(classpathElements, null, true, true); - - // prepare plugins - if (!isLoadingOfExternalPluginsDisabled()) { - try { - StartupActionScriptManager.executeActionScript(); - } - catch (IOException e) { - final String errorMessage = "Error executing plugin installation script: " + e.getMessage(); - if (Main.isHeadless()) { - System.out.println(errorMessage); - } else { - JOptionPane - .showMessageDialog(JOptionPane.getRootFrame(), errorMessage, ERROR, JOptionPane.INFORMATION_MESSAGE); - } - } + // prepare plugins + if (!isLoadingOfExternalPluginsDisabled()) { + try { + StartupActionScriptManager.executeActionScript(); } - - Thread.currentThread().setContextClassLoader(newClassLoader); - - } - catch (Exception e) { - Logger logger = getLogger(); - if (logger == null) { - e.printStackTrace(System.err); - } - else { - logger.error(e); + catch (IOException e) { + Main.showMessage("Plugin Installation Error", e); } } + + Thread.currentThread().setContextClassLoader(newClassLoader); return newClassLoader; } diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index 499f5ec1b583..182946c2c786 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.idea; import com.intellij.ide.Bootstrap; @@ -21,102 +20,99 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.util.ArrayUtilRt; +import com.intellij.util.ExceptionUtil; import com.intellij.util.Restarter; -import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; +import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; +@SuppressWarnings({"UseOfSystemOutOrSystemErr", "MethodNamesDifferingOnlyByCase"}) public class Main { + public static final int UPDATE_FAILED = 1; + public static final int STARTUP_EXCEPTION = 2; + public static final int STARTUP_IMPOSSIBLE = 3; + public static final int LICENSE_ERROR = 4; + public static final int PLUGIN_ERROR = 5; + private static boolean isHeadless; + private static boolean isCommandLine; - private Main() { - } + private Main() { } - @SuppressWarnings("MethodNamesDifferingOnlyByCase") public static void main(final String[] args) { - isHeadless = isHeadless(args); - if (isHeadless) { + setFlags(args); + + if (isHeadless()) { System.setProperty("java.awt.headless", Boolean.TRUE.toString()); } - else if (GraphicsEnvironment.isHeadless()) { - throw new HeadlessException("Unable to detect graphics environment"); - } + else { + if (GraphicsEnvironment.isHeadless()) { + throw new HeadlessException("Unable to detect graphics environment"); + } - if (!isHeadless) { try { installPatch(); } - catch (IOException e) { - e.printStackTrace(); - - File log = null; - try { - log = FileUtilRt.createTempFile("patch", ".log", false); - PrintWriter writer = new PrintWriter(log); - try { - e.printStackTrace(writer); - } - finally { - writer.close(); - } - } - catch (IOException ignore) { - ignore.printStackTrace(); - } - - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - catch (Throwable ignore) { - } - String message = e.getMessage() - + "\n" + (log == null ? "Log cannot be saved" : "Log is saved in " + log) - + "\n\nPlease download and install update manually" ; - JOptionPane.showMessageDialog(null, message, "Cannot Apply Patch", JOptionPane.ERROR_MESSAGE); + catch (Throwable t) { + showMessage("Update Failed", t); + System.exit(UPDATE_FAILED); } } - Bootstrap.main(args, Main.class.getName() + "Impl", "start"); - } - - public static boolean isHeadless(final String[] args) { - final Boolean forceEnabledHeadlessMode = Boolean.valueOf(System.getProperty("java.awt.headless")); - - @NonNls final String antAppCode = "ant"; - @NonNls final String duplocateCode = "duplocate"; - @NonNls final String traverseUI = "traverseUI"; - if (args.length == 0) { - return false; + try { + Bootstrap.main(args, Main.class.getName() + "Impl", "start"); + } + catch (Throwable t) { + showMessage("Start Failed", t); + System.exit(STARTUP_EXCEPTION); } - final String firstArg = args[0]; - return forceEnabledHeadlessMode || - Comparing.strEqual(firstArg, antAppCode) || - Comparing.strEqual(firstArg, duplocateCode) || - Comparing.strEqual(firstArg, traverseUI) || - (firstArg.length() < 20 && firstArg.endsWith("inspect")); - } - - public static boolean isUITraverser(final String[] args) { - return args.length > 0 && Comparing.strEqual(args[0], "traverseUI"); - } - - public static boolean isCommandLine(final String[] args) { - if (isHeadless(args)) return true; - @NonNls final String diffAppCode = "diff"; - return args.length > 0 && Comparing.strEqual(args[0], diffAppCode); } public static boolean isHeadless() { return isHeadless; } + public static boolean isCommandLine() { + return isCommandLine; + } + + public static void setFlags(String[] args) { + isHeadless = isHeadless(args); + isCommandLine = isCommandLine(args); + } + + private static boolean isHeadless(String[] args) { + if (GraphicsEnvironment.isHeadless()) { + return true; + } + + if (args.length == 0) { + return false; + } + + String firstArg = args[0]; + return Comparing.strEqual(firstArg, "ant") || + Comparing.strEqual(firstArg, "duplocate") || + Comparing.strEqual(firstArg, "traverseUI") || + (firstArg.length() < 20 && firstArg.endsWith("inspect")); + } + + private static boolean isCommandLine(String[] args) { + if (isHeadless()) return true; + return args.length > 0 && Comparing.strEqual(args[0], "diff"); + } + + public static boolean isUITraverser(final String[] args) { + return args.length > 0 && Comparing.strEqual(args[0], "traverseUI"); + } + private static void installPatch() throws IOException { String platform = System.getProperty("idea.platform.prefix", "idea"); String patchFileName = ("jetbrains.patch.jar." + platform).toLowerCase(); @@ -124,28 +120,67 @@ public class Main { File copyPatchFile = new File(System.getProperty("java.io.tmpdir"), patchFileName + "_copy"); // always delete previous patch copy - if (!FileUtilRt.delete(copyPatchFile)) throw new IOException("Cannot create temporary patch file"); + if (!FileUtilRt.delete(copyPatchFile)) { + throw new IOException("Cannot create temporary patch file"); + } - if (!originalPatchFile.exists()) return; + if (!originalPatchFile.exists()) { + return; + } if (!originalPatchFile.renameTo(copyPatchFile) || !FileUtilRt.delete(originalPatchFile)) { throw new IOException("Cannot create temporary patch file"); } - List args = new ArrayList(); - if (SystemInfo.isWindows) { - args.add(Restarter.createTempExecutable(new File(PathManager.getBinPath(), "vistalauncher.exe")).getPath()); + int status = 0; + if (Restarter.isSupported()) { + List args = new ArrayList(); + + if (SystemInfo.isWindows) { + File launcher = new File(PathManager.getBinPath(), "VistaLauncher.exe"); + args.add(Restarter.createTempExecutable(launcher).getPath()); + } + + Collections.addAll(args, + System.getProperty("java.home") + "/bin/java", + "-Xmx500m", + "-classpath", + copyPatchFile.getPath(), + "com.intellij.updater.Runner", + "install", + PathManager.getHomePath()); + + status = Restarter.scheduleRestart(ArrayUtilRt.toStringArray(args)); + } + else { + String message = "Patch update is not supported - please do it manually"; + showMessage("Update Error", message, true); } - Collections.addAll(args, - System.getProperty("java.home") + "/bin/java", - "-Xmx500m", - "-classpath", - copyPatchFile.getPath(), - "com.intellij.updater.Runner", - "install", - PathManager.getHomePath()); + System.exit(status); + } - System.exit(Restarter.scheduleRestart(args.toArray(new String[args.size()]))); + public static void showMessage(String title, Throwable t) { + String message = "Internal exception, please report to http://youtrack.jetbrains.com\n\n" + ExceptionUtil.getThrowableText(t); + showMessage(title, message, true); + } + + public static void showMessage(String title, String message, boolean error) { + if (isCommandLine()) { + PrintStream stream = error ? System.err : System.out; + stream.println(title + ": " + message); + } + else { + try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } + catch (Throwable ignore) { } + + JTextPane textPane = new JTextPane(); + textPane.setEditable(false); + textPane.setText(message.replaceAll("\t", " ")); + textPane.setBackground(UIManager.getColor("Panel.background")); + + int type = error ? JOptionPane.ERROR_MESSAGE : JOptionPane.INFORMATION_MESSAGE; + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), textPane, title, type); + } } } diff --git a/platform/core-api/src/com/intellij/diagnostic/PluginException.java b/platform/core-api/src/com/intellij/diagnostic/PluginException.java index 3d4e5da85f75..3a520ebc466c 100644 --- a/platform/core-api/src/com/intellij/diagnostic/PluginException.java +++ b/platform/core-api/src/com/intellij/diagnostic/PluginException.java @@ -19,11 +19,8 @@ import com.intellij.openapi.extensions.PluginId; import org.jetbrains.annotations.NonNls; /** - * Created by IntelliJ IDEA. - * User: stathik - * Date: Jan 8, 2004 - * Time: 3:06:43 PM - * To change this template use Options | File Templates. + * @author stathik + * @since Jan 8, 2004 */ public class PluginException extends RuntimeException { private final PluginId myPluginId; diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 83270ac75ea8..a33f22150dae 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -105,21 +105,10 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements try { myComponentsRegistry.loadClasses(); - final Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); + Class[] componentInterfaces = myComponentsRegistry.getComponentInterfaces(); for (Class componentInterface : componentInterfaces) { ProgressIndicatorProvider.checkCanceled(); - try { - createComponent(componentInterface); - } - catch (StateStorageException e) { - throw e; - } - catch (ProcessCanceledException e) { - throw e; - } - catch(Exception e) { - LOG.error(e); - } + createComponent(componentInterface); } } finally { @@ -209,35 +198,12 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return null; } - private void initComponent(Object component) { - final ProgressIndicator indicator = getProgressIndicator(); - if (indicator != null) { - indicator.checkCanceled(); - } - - try { - initializeComponent(component, false); - if (component instanceof BaseComponent) { - ((BaseComponent)component).initComponent(); - } - } - catch (StateStorageException e) { - throw e; - } - catch (ProcessCanceledException e) { - throw e; - } - catch (Throwable ex) { - handleInitComponentError(ex, false, component.getClass().getName(), null); - } - } - @Nullable protected static ProgressIndicator getProgressIndicator() { return ProgressIndicatorProvider.getGlobalProgressIndicator(); } - protected double getPercentageOfComponentsLoaded() { + protected float getPercentageOfComponentsLoaded() { return myComponentsRegistry.getPercentageOfComponentsLoaded(); } @@ -245,8 +211,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public void initializeComponent(Object component, boolean service) { } - - protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { + protected void handleInitComponentError(Throwable ex, String componentClassName, ComponentConfig config) { LOG.error(ex); } @@ -358,7 +323,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements getComponents(); } - protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable final PluginDescriptor descriptor, final boolean defaultProject) { + protected void loadComponentsConfiguration(ComponentConfig[] components, @Nullable PluginDescriptor descriptor, boolean defaultProject) { myConfigurator.loadComponentsConfiguration(components, descriptor, defaultProject); } @@ -426,7 +391,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements protected class ComponentsRegistry { private final Map myInterfaceToLockMap = new THashMap(); private final Map myInterfaceToClassMap = new THashMap(); - private final ArrayList myComponentInterfaces = new ArrayList(); // keeps order of component's registration + private final List myComponentInterfaces = new ArrayList(); // keeps order of component's registration private final Map myNameToComponent = new THashMap(); private final List myComponentConfigs = new ArrayList(); private final List myImplementations = new ArrayList(); @@ -452,7 +417,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements interfaceClass : Class.forName(config.getImplementationClass(), true, loader); if (myInterfaceToClassMap.get(interfaceClass) != null) { - throw new ComponentAlreadyRegisteredException(interfaceClass); + throw new RuntimeException("Component already registered: " + interfaceClass.getName()); } getPicoContainer().registerComponent(new ComponentConfigComponentAdapter(config, implementationClass)); @@ -460,17 +425,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements myComponentClassToConfig.put(implementationClass, config); myComponentInterfaces.add(interfaceClass); } - catch (ComponentAlreadyRegisteredException ex) { - throw new Error(ex); - } - catch (Throwable e) { - handleInitComponentError(e, false, null, config); - } - } - - private class ComponentAlreadyRegisteredException extends Exception { - private ComponentAlreadyRegisteredException(Class interfaceClass) { - super(interfaceClass.getName() + " component already registered"); + catch (Throwable t) { + handleInitComponentError(t, null, config); } } @@ -492,8 +448,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements return myInterfaceToClassMap.containsKey(interfaceClass); } - public double getPercentageOfComponentsLoaded() { - return ((double)myImplementations.size()) / myComponentConfigs.size(); + public float getPercentageOfComponentsLoaded() { + return ((float)myImplementations.size()) / myComponentConfigs.size(); } private void registerComponentInstance(final Object component) { @@ -565,57 +521,66 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements public ComponentConfigComponentAdapter(final ComponentConfig config, Class implementationClass) { myConfig = config; + final String componentKey = config.getInterfaceClass(); myDelegate = new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(componentKey, implementationClass, null, true)) { - @Override - public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { - Object componentInstance = null; - try { - long startTime = myInitialized ? 0 : System.nanoTime(); - componentInstance = super.getComponentInstance(picoContainer); - - if (!myInitialized) { - if (myInitializing) { - if (myConfig.pluginDescriptor != null) { - LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); - } - else { - LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); - } - } - - try { - myInitializing = true; - myComponentsRegistry.registerComponentInstance(componentInstance); - initComponent(componentInstance); - long endTime = System.nanoTime(); - long ms = (endTime - startTime) / 1000000; - if (ms > 10) { - if (logSlowComponents()) { - LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); - } - } - } - finally { - myInitializing = false; - } - - myInitialized = true; - } - } - catch (ProcessCanceledException e) { - throw e; - } - catch (StateStorageException e) { - throw e; - } - catch (Throwable t) { - handleInitComponentError(t, componentInstance == null, componentKey, config); - } - return componentInstance; + @Override + public Object getComponentInstance(PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException { + ProgressIndicator indicator = getProgressIndicator(); + if (indicator != null) { + indicator.checkCanceled(); } - }; + Object componentInstance = null; + try { + long startTime = myInitialized ? 0 : System.nanoTime(); + + componentInstance = super.getComponentInstance(picoContainer); + + if (!myInitialized) { + if (myInitializing) { + if (myConfig.pluginDescriptor != null) { + LOG.error(new PluginException("Cyclic component initialization: " + componentKey, myConfig.pluginDescriptor.getPluginId())); + } + else { + LOG.error(new Throwable("Cyclic component initialization: " + componentKey)); + } + } + + try { + myInitializing = true; + myComponentsRegistry.registerComponentInstance(componentInstance); + + initializeComponent(componentInstance, false); + if (componentInstance instanceof BaseComponent) { + ((BaseComponent)componentInstance).initComponent(); + } + + long ms = (System.nanoTime() - startTime) / 1000000; + if (ms > 10 && logSlowComponents()) { + LOG.info(componentInstance.getClass().getName() + " initialized in " + ms + " ms"); + } + } + finally { + myInitializing = false; + } + + myInitialized = true; + } + } + catch (ProcessCanceledException e) { + throw e; + } + catch (StateStorageException e) { + throw e; + } + catch (Throwable t) { + handleInitComponentError(t, componentKey, config); + } + + return componentInstance; + } + }; } @Override @@ -625,27 +590,23 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Override public Class getComponentImplementation() { - return getDelegate().getComponentImplementation(); + return myDelegate.getComponentImplementation(); } @Override public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { - return getDelegate().getComponentInstance(container); + return myDelegate.getComponentInstance(container); } @Override public void verify(final PicoContainer container) throws PicoIntrospectionException { - getDelegate().verify(container); + myDelegate.verify(container); } @Override public void accept(final PicoVisitor visitor) { visitor.visitComponentAdapter(this); - getDelegate().accept(visitor); - } - - private ComponentAdapter getDelegate() { - return myDelegate; + myDelegate.accept(visitor); } } } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java index 139d3eaa2e47..3488bce03487 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java @@ -16,7 +16,6 @@ package com.intellij.diagnostic; import com.intellij.notification.Notification; -import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; @@ -35,13 +34,14 @@ import java.lang.reflect.InvocationTargetException; * @author kir */ public class DefaultIdeaErrorLogger implements ErrorLogger { - private static boolean ourOomOccured = false; + private static boolean ourOomOccurred = false; private static boolean ourLoggerBroken = false; - private static boolean mappingFailedNotificationPosted = false; + private static boolean ourMappingFailedNotificationPosted = false; + @NonNls private static final String FATAL_ERROR_NOTIFICATION_PROPERTY = "idea.fatal.error.notification"; @NonNls private static final String DISABLED_VALUE = "disabled"; @NonNls private static final String ENABLED_VALUE = "enabled"; - @NonNls private static final String PARAM_PERMGEN = "PermGen"; + @NonNls private static final String PARAM_PERM_GEN = "PermGen"; public boolean canHandle(IdeaLoggingEvent event) { if (ourLoggerBroken) return false; @@ -56,7 +56,7 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal() || - isOOMError(event.getThrowable()) || + isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException; } catch (LinkageError e) { @@ -68,13 +68,8 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } } - /** - * @noinspection CallToPrintStackTrace - */ public void handle(IdeaLoggingEvent event) { - if (ourLoggerBroken) { - return; - } + if (ourLoggerBroken) return; try { Throwable throwable = event.getThrowable(); @@ -84,11 +79,11 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { else if (throwable instanceof MappingFailedException) { processMappingFailed(event); } - else if (!ourOomOccured) { + else if (!ourOomOccurred) { MessagePool messagePool = MessagePool.getInstance(); LogMessage message = messagePool.addIdeFatalMessage(event); if (message != null && ApplicationManager.getApplication() != null) { - notifyUi(messagePool, message); + ErrorNotifier.notifyUi(message, messagePool); } } } @@ -99,14 +94,9 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLoggerBroken = true; } - e.printStackTrace(); } } - private static void notifyUi(MessagePool messagePool, LogMessage message) { - ErrorNotifier.notifyUi(message, messagePool); - } - private static boolean isOOMError(Throwable throwable) { return throwable instanceof OutOfMemoryError || (throwable instanceof VirtualMachineError && @@ -114,17 +104,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { throwable.getMessage().contains("CodeCache")); } - /** - * @noinspection CallToPrintStackTrace - */ private static void processOOMError(final Throwable throwable) throws InterruptedException, InvocationTargetException { - ourOomOccured = true; - throwable.printStackTrace(); + ourOomOccurred = true; SwingUtilities.invokeAndWait(new Runnable() { public void run() { String message = throwable.getMessage(); - OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERMGEN) + OutOfMemoryDialog.MemoryKind k = message != null && message.contains(PARAM_PERM_GEN) ? OutOfMemoryDialog.MemoryKind.PERM_GEN : message != null && message.contains("CodeCache") ? OutOfMemoryDialog.MemoryKind.CODE_CACHE @@ -135,13 +121,13 @@ public class DefaultIdeaErrorLogger implements ErrorLogger { } private static void processMappingFailed(final IdeaLoggingEvent event) throws InterruptedException, InvocationTargetException { - if (!mappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { - mappingFailedNotificationPosted = true; - final String exceptionMessage = event.getThrowable().getMessage(); - final String text = exceptionMessage + - "
Possible cause: unable to allocate continuous memory chunk of necessary size.
Reducing JVM's maximum heap size (-Xmx) may help."; - Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), NotificationDisplayType.BALLOON, null); + if (!ourMappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) { + ourMappingFailedNotificationPosted = true; + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") String exceptionMessage = event.getThrowable().getMessage(); + String text = exceptionMessage + + "
Possible cause: unable to allocate continuous memory chunk of necessary size.
" + + "Reducing JVM maximum heap size (-Xmx) may help."; + Notifications.Bus.notify(new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), null); } } - } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 2ce3a3c4fe4f..5c9f61efba7d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.plugins; import com.intellij.ide.ClassUtilCore; import com.intellij.ide.IdeBundle; +import com.intellij.idea.Main; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.components.ComponentConfig; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.progress.ProcessCanceledException; @@ -30,7 +32,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.util.ArrayUtil; -import com.intellij.util.ExceptionUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,12 +41,11 @@ import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.io.IOException; import java.lang.reflect.Method; -import java.util.*; +import java.util.List; /** * @author mike */ -@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"}) // No logger is loaded at this time so we have to use these. public class PluginManager extends PluginManagerCore { @NonNls public static final String INSTALLED_TXT = "installed.txt"; @@ -55,93 +56,103 @@ public class PluginManager extends PluginManagerCore { /** * Called via reflection */ - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings({"UnusedDeclaration", "HardCodedStringLiteral", "finally"}) protected static void start(final String mainClass, final String methodName, final String[] args) { startupStart = System.nanoTime(); - try { - //noinspection HardCodedStringLiteral - ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { - @Override - public void uncaughtException(Thread t, Throwable e) { - if (!(e instanceof ProcessCanceledException)) { - PluginManagerCore.getLogger().error(e); - } - } - }; - Runnable runnable = new Runnable() { - @Override - public void run() { + Main.setFlags(args); + + if (!Main.isHeadless()) { + UIUtil.initDefaultLAF(); + } + + ThreadGroup threadGroup = new ThreadGroup("Idea Thread Group") { + @Override + public void uncaughtException(Thread t, Throwable e) { + if (e instanceof StartupAbortedException) { + StartupAbortedException se = (StartupAbortedException)e; try { - ClassUtilCore.clearJarURLCache(); - - Class aClass = Class.forName(mainClass); - Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); - method.setAccessible(true); - - //noinspection RedundantArrayCreation - method.invoke(null, new Object[]{args}); + if (se.logError()) { + if (Logger.isInitialized()) { + getLogger().error(e); + } + Main.showMessage("Start Failed", e); + } } - catch (Exception e) { - e.printStackTrace(System.err); - String message = "Error while accessing " + mainClass + "." + methodName + " with arguments: " + Arrays.asList(args); - if ("true".equals(System.getProperty("java.awt.headless"))) { - //noinspection UseOfSystemOutOrSystemErr - System.err.println(message); - } - else { - JOptionPane.showMessageDialog(null, message + ": " + e.getClass().getName() + ": " + e.getMessage() + "\n" + ExceptionUtil.getThrowableText(e), "Error starting IntelliJ Platform", JOptionPane.ERROR_MESSAGE); - } + finally { + System.exit(se.exitCode()); } } - }; - //noinspection HardCodedStringLiteral - new Thread(threadGroup, runnable, "Idea Main Thread").start(); - } - catch (Exception e) { - PluginManagerCore.getLogger().error(e); - } + if (!(e instanceof ProcessCanceledException)) { + getLogger().error(e); + } + } + }; + + Runnable runnable = new Runnable() { + @Override + public void run() { + try { + ClassUtilCore.clearJarURLCache(); + + Class aClass = Class.forName(mainClass); + Method method = aClass.getDeclaredMethod(methodName, ArrayUtil.EMPTY_STRING_ARRAY.getClass()); + method.setAccessible(true); + Object[] argsArray = {args}; + method.invoke(null, argsArray); + } + catch (Throwable t) { + throw new StartupAbortedException(t); + } + } + }; + + new Thread(threadGroup, runnable, "Idea Main Thread").start(); } public static void reportPluginError() { if (myPluginError != null) { - Notifications.Bus.notify(new Notification(IdeBundle.message("title.plugin.error"), IdeBundle.message("title.plugin.error"), - myPluginError, NotificationType.ERROR, new NotificationListener() { - @Override - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - notification.expire(); - final String description = event.getDescription(); - if (EDIT.equals(description)) { - final PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); - IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); - ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); - return; - } - final List disabledPlugins = PluginManagerCore.getDisabledPlugins(); - if (myPlugins2Disable != null && DISABLE.equals(description)) { - for (String pluginId : myPlugins2Disable) { - if (!disabledPlugins.contains(pluginId)) { - disabledPlugins.add(pluginId); - } - } - } else if (myPlugins2Enable != null && ENABLE.equals(description)) { - disabledPlugins.removeAll(myPlugins2Enable); - } - try { - PluginManagerCore.saveDisabledPlugins(disabledPlugins, false); - } - catch (IOException ignore) { - } - myPlugins2Enable = null; - myPlugins2Disable = null; + String message = IdeBundle.message("title.plugin.error"); + Notifications.Bus.notify(new Notification(message, message, myPluginError, NotificationType.ERROR, new NotificationListener() { + @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + notification.expire(); + + String description = event.getDescription(); + if (EDIT.equals(description)) { + PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance()); + IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null); + ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable); + return; } - })); + + List disabledPlugins = getDisabledPlugins(); + if (myPlugins2Disable != null && DISABLE.equals(description)) { + for (String pluginId : myPlugins2Disable) { + if (!disabledPlugins.contains(pluginId)) { + disabledPlugins.add(pluginId); + } + } + } + else if (myPlugins2Enable != null && ENABLE.equals(description)) { + disabledPlugins.removeAll(myPlugins2Enable); + } + + try { + saveDisabledPlugins(disabledPlugins, false); + } + catch (IOException ignore) { } + + myPlugins2Enable = null; + myPlugins2Disable = null; + } + })); myPluginError = null; } } - public static boolean isPluginInstalled(PluginId id) { return getPlugin(id) != null; } @@ -157,24 +168,59 @@ public class PluginManager extends PluginManagerCore { return null; } - public static void disableIncompatiblePlugin(final Object cause, final Throwable ex) { - final PluginId pluginId = getPluginByClassName(cause.getClass().getName()); - if (pluginId != null && !ApplicationManager.getApplication().isHeadlessEnvironment()) { - final boolean success = PluginManagerCore.disablePlugin(pluginId.getIdString()); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), - "Incompatible plugin detected: " + pluginId.getIdString() + - (success ? "\nThe plugin has been disabled" : ""), - "Plugin Manager", - JOptionPane.ERROR_MESSAGE); - } - }); + public static void handleComponentError(Throwable t, String componentClassName, ComponentConfig config) { + if (t instanceof StartupAbortedException) { + throw (StartupAbortedException)t; + } + + PluginId pluginId = config != null ? config.getPluginId() : getPluginByClassName(componentClassName); + + if (pluginId != null && !CORE_PLUGIN_ID.equals(pluginId.getIdString())) { + getLogger().warn(t); + + disablePlugin(pluginId.getIdString()); + + String message = + "Plugin '" + pluginId.getIdString() + "' failed to initialize and will be disabled\n" + + "(reason: " + t.getMessage() + ")\n\n" + + ApplicationNamesInfo.getInstance().getFullProductName() + " will be restarted."; + Main.showMessage("Plugin Error", message, false); + + throw new StartupAbortedException(t).exitCode(Main.PLUGIN_ERROR).logError(false); } else { - // should never happen - throw new RuntimeException(ex); + throw new StartupAbortedException("Fatal error initializing '" + componentClassName + "'", t); + } + } + + public static class StartupAbortedException extends RuntimeException { + private int exitCode = Main.STARTUP_EXCEPTION; + private boolean logError = true; + + public StartupAbortedException(Throwable cause) { + super(cause); + } + + public StartupAbortedException(String message, Throwable cause) { + super(message, cause); + } + + public int exitCode() { + return exitCode; + } + + public StartupAbortedException exitCode(int exitCode) { + this.exitCode = exitCode; + return this; + } + + public boolean logError() { + return logError; + } + + public StartupAbortedException logError(boolean logError) { + this.logError = logError; + return this; } } } diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 1641c8dd7838..4604d57a6777 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -18,12 +18,12 @@ package com.intellij.idea; import com.intellij.ExtensionPoints; import com.intellij.Patches; import com.intellij.concurrency.JobScheduler; -import com.intellij.diagnostic.PluginException; import com.intellij.ide.AppLifecycleListener; import com.intellij.ide.CommandLineProcessor; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.IdeRepaintManager; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationType; @@ -36,10 +36,12 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.updateSettings.impl.UpdateChecker; import com.intellij.openapi.updateSettings.impl.UpdateSettings; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.SystemDock; @@ -54,7 +56,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -79,14 +80,15 @@ public class IdeaApplication { myArgs = args; boolean isInternal = Boolean.valueOf(System.getProperty(IDEA_IS_INTERNAL_PROPERTY)).booleanValue(); - if (Main.isCommandLine(args)) { - boolean headless = Main.isHeadless(args); - if (!headless) patchSystem(); + boolean headless = Main.isHeadless(); + if (!headless) { + patchSystem(); + } + + if (Main.isCommandLine()) { new CommandLineApplication(isInternal, false, headless); } else { - patchSystem(); - Splash splash = null; if (myArgs.length == 0) { myStarter = getStarter(); @@ -159,15 +161,16 @@ public class IdeaApplication { protected ApplicationStarter getStarter() { if (myArgs.length > 0) { - PluginManager.getPlugins(); + PluginManagerCore.getPlugins(); ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.APPLICATION_STARTER); - final ApplicationStarter[] starters = point.getExtensions(); + ApplicationStarter[] starters = point.getExtensions(); String key = myArgs[0]; for (ApplicationStarter o : starters) { if (Comparing.equal(o.getCommandName(), key)) return o; } } + return new IdeStarter(); } @@ -175,17 +178,9 @@ public class IdeaApplication { return ourInstance; } - public void run() { + public void run() throws Exception { ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - try { - app.load(PathManager.getOptionsPath()); - } - catch (IOException e) { - e.printStackTrace(); - } - catch (InvalidDataException e) { - e.printStackTrace(); - } + app.load(PathManager.getOptionsPath()); myStarter.main(myArgs); myStarter = null; //GC it @@ -252,36 +247,28 @@ public class IdeaApplication { @Override public void main(String[] args) { - SystemDock.updateMenu(); + // Event queue should not be changed during initialization of application components. // It also cannot be changed before initialization of application components because IdeEventQueue uses other // application components. So it is proper to perform replacement only here. ApplicationEx app = ApplicationManagerEx.getApplicationEx(); - // app.setupIdeQueue(IdeEventQueue.getInstance()); WindowManagerImpl windowManager = (WindowManagerImpl)WindowManager.getInstance(); + IdeEventQueue.getInstance().setWindowManager(windowManager); - try { - IdeEventQueue.getInstance().setWindowManager(windowManager); + Ref willOpenProject = new Ref(Boolean.FALSE); + AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); + lifecyclePublisher.appFrameCreated(args, willOpenProject); - final Ref willOpenProject = new Ref(Boolean.FALSE); - final AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); - lifecyclePublisher.appFrameCreated(args, willOpenProject); - LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); - PluginManager.dumpPluginClassStatistics(); - if (!willOpenProject.get()) { - WelcomeFrame.showNow(); - lifecyclePublisher.welcomeScreenDisplayed(); - } - else { - windowManager.showFrame(); - } + LOG.info("App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); + PluginManagerCore.dumpPluginClassStatistics(); + + if (!willOpenProject.get()) { + WelcomeFrame.showNow(); + lifecyclePublisher.welcomeScreenDisplayed(); } - catch (PluginException e) { - Messages.showErrorDialog("Plugin " + e.getPluginId() + " couldn't be loaded, the IDE will now exit.\n" + - "See the full details in the log.\n" + - e.getMessage(), "Plugin Error"); - System.exit(-1); + else { + windowManager.showFrame(); } app.invokeLater(new Runnable() { @@ -321,7 +308,6 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); } - } private void loadProject() { diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java index 6f075573a6a2..17de69c30b7c 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaLogger.java @@ -44,7 +44,6 @@ public class IdeaLogger extends Logger { public static String ourLastActionId = ""; - private final org.apache.log4j.Logger myLogger; /** If not null - it means that errors occurred and it is the first of them. */ public static Exception ourErrorsOccurred; @@ -59,25 +58,24 @@ public class IdeaLogger extends Logger { static { InputStream stream = Logger.class.getResourceAsStream(COMPILATION_TIMESTAMP_RESOURCE_NAME); if (stream != null) { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); try { - String s = reader.readLine(); - if (s != null) { - ourCompilationTimestamp = s.trim(); - } - } - catch (IOException ignored) { - } - finally { + LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream)); try { - stream.close(); + String s = reader.readLine(); + if (s != null) { + ourCompilationTimestamp = s.trim(); + } } - catch (IOException ignored) { + finally { + reader.close(); } } + catch (IOException ignored) { } } } + private final org.apache.log4j.Logger myLogger; + IdeaLogger(org.apache.log4j.Logger logger) { myLogger = logger; } @@ -134,9 +132,6 @@ public class IdeaLogger extends Logger { myLogger.error(message + (!detailString.isEmpty() ? "\nDetails: " + detailString : ""), t); logErrorHeader(); - if (t != null && t.getCause() != null) { - myLogger.error("Original exception: ", t.getCause()); - } } private void logErrorHeader() { diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index d77b870c7112..d2b0fbf09b7d 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -88,7 +88,7 @@ public class SocketLock { if (mySocket == null) { if (!myIsDialogShown) { final String productName = ApplicationNamesInfo.getInstance().getProductName(); - if (StartupUtil.isHeadless()) { //team server inspections + if (Main.isHeadless()) { //team server inspections throw new RuntimeException("Only one instance of " + productName + " can be run at a time."); } @NonNls final String pathToLogFile = PathManager.getLogPath() + "/idea.log file".replace('/', File.separatorChar); diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index c05df8fdb349..28ee2fbfe8c2 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -15,10 +15,11 @@ */ package com.intellij.idea; -import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.ide.startupWizard.StartupWizard; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationNamesInfo; +import com.intellij.openapi.application.ConfigImportHelper; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.application.impl.ApplicationInfoImpl; @@ -28,6 +29,7 @@ import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.win32.IdeaWin32; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.AppUIUtil; import com.intellij.util.Consumer; import com.intellij.util.EnvironmentUtil; import com.intellij.util.SystemProperties; @@ -41,7 +43,6 @@ import javax.swing.*; import java.io.File; import java.io.InputStream; import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -54,8 +55,6 @@ public class StartupUtil { public static final boolean NO_SNAPPY = SystemProperties.getBooleanProperty("idea.no.snappy", false); - static boolean isHeadless; - private static SocketLock ourLock; private static String myDefaultLAF; @@ -73,17 +72,55 @@ public class StartupUtil { return !Arrays.asList(args).contains(NO_SPLASH); } + /** @deprecated use {@link Main#isHeadless()} (to remove in IDEA 14) */ + @SuppressWarnings("unused") public static boolean isHeadless() { - return isHeadless; + return Main.isHeadless(); } - private static void showError(final String title, final String message) { - if (isHeadless()) { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(message); + public synchronized static void addExternalInstanceListener(Consumer> consumer) { + ourLock.setActivateListener(consumer); + } + + interface AppStarter { + void start(boolean newConfigFolder); + } + + static void prepareAndStart(String[] args, AppStarter appStarter) { + boolean newConfigFolder = false; + + if (!Main.isHeadless()) { + AppUIUtil.updateFrameClass(); + AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); + AppUIUtil.registerBundledFonts(); + + newConfigFolder = PathManager.ensureConfigFolderExists(true); + if (newConfigFolder) { + ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); + } } - else { - JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, title, JOptionPane.ERROR_MESSAGE); + + boolean canStart = checkJdkVersion() && checkSystemFolders() && lockSystemFolders(args); // note: uses config folder! + if (!canStart) { + System.exit(Main.STARTUP_IMPOSSIBLE); + } + + Logger.setFactory(LoggerFactory.getInstance()); + Logger log = Logger.getInstance(Main.class); + startLogging(log); + fixProcessEnvironment(log); + loadSystemLibraries(log); + + appStarter.start(newConfigFolder); + } + + static void runStartupWizard() { + final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); + if (!pages.isEmpty()) { + final StartupWizard startupWizard = new StartupWizard(pages); + startupWizard.setCancelText("Skip"); + startupWizard.show(); + PluginManagerCore.invalidatePlugins(); } } @@ -97,17 +134,9 @@ public class StartupUtil { Class.forName("com.sun.jdi.Field"); } catch (ClassNotFoundException e) { - showError("Error", "'tools.jar' is not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + - "Please ensure JAVA_HOME points to JDK rather than JRE."); - return false; - } - } - - if (!"true".equals(System.getProperty("idea.no.jdk.check"))) { - final String version = System.getProperty("java.version"); - if (!SystemInfo.isJavaVersionAtLeast("1.6")) { - showError("Java Version Mismatch", "The JDK version is " + version + ".\n" + - ApplicationNamesInfo.getInstance().getProductName() + " requires JDK 1.6 or higher."); + String message = "'tools.jar' seems to be not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + + "Please ensure JAVA_HOME points to JDK rather than JRE."; + Main.showMessage("JDK Required", message, true); return false; } } @@ -117,18 +146,20 @@ public class StartupUtil { private synchronized static boolean checkSystemFolders() { final String configPath = PathManager.getConfigPath(); - if (configPath == null || !new File(configPath).isDirectory()) { - showError("Invalid config path", "Config path '" + configPath + "' is invalid.\n" + - "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."); + if (!new File(configPath).isDirectory()) { + String message = "Config path '" + configPath + "' is invalid.\n" + + "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."; + Main.showMessage("Invalid Config Path", message, true); return false; } final String systemPath = PathManager.getSystemPath(); if (systemPath == null || !new File(systemPath).isDirectory()) { - showError("Invalid system path", "System path '" + systemPath + "' is invalid.\n" + - "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + - "otherwise please re-install the IDE."); + String message = "System path '" + systemPath + "' is invalid.\n" + + "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + + "otherwise please re-install the IDE."; + Main.showMessage("Invalid System Path", message, true); return false; } @@ -146,8 +177,9 @@ public class StartupUtil { } if (activateStatus != SocketLock.ActivateStatus.NO_INSTANCE) { - if (isHeadless() || activateStatus == SocketLock.ActivateStatus.CANNOT_ACTIVATE) { - showError("Error", "Only one instance of " + ApplicationNamesInfo.getInstance().getFullProductName() + " can be run at a time."); + 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); } return false; } @@ -155,38 +187,16 @@ public class StartupUtil { return true; } - static boolean checkStartupPossible(String[] args) { - return checkJdkVersion() && - checkSystemFolders() && - lockSystemFolders(args); - } - - static void runStartupWizard() { - final List pages = ApplicationInfoImpl.getShadowInstance().getPluginChooserPages(); - if (!pages.isEmpty()) { - final StartupWizard startupWizard = new StartupWizard(pages); - startupWizard.setCancelText("Skip"); - startupWizard.show(); - PluginManager.invalidatePlugins(); - } - } - - public synchronized static void addExternalInstanceListener(Consumer> consumer) { - ourLock.setActivateListener(consumer); - } - - - static void fixProcessEnvironment(Logger log) { + private static void fixProcessEnvironment(Logger log) { boolean envReady = EnvironmentUtil.isEnvironmentReady(); // trigger environment loading if (!envReady) { log.info("initializing environment"); } } - private static final String JAVA_IO_TEMP_DIR = "java.io.tmpdir"; - static void loadSystemLibraries(final Logger log) { + private static void loadSystemLibraries(final Logger log) { // load JNA and Snappy in own temp directory - to avoid collisions and work around no-exec /tmp final File ideaTempDir = new File(PathManager.getSystemPath(), "tmp"); if (!(ideaTempDir.mkdirs() || ideaTempDir.exists())) { @@ -231,7 +241,7 @@ public class StartupUtil { IdeaWin32.isAvailable(); // logging is done there } - if (SystemInfo.isWin2kOrNewer && !isHeadless) { + if (SystemInfo.isWin2kOrNewer && !Main.isHeadless()) { try { System.loadLibrary(SystemInfo.isAMD64 ? "focusKiller64" : "focusKiller"); log.info("Using \"FocusKiller\" library to prevent focus stealing."); @@ -280,28 +290,25 @@ public class StartupUtil { loadNativeLibrary.invoke(null, loaderClass); } - public static void startLogging(final Logger log) { + private static void startLogging(final Logger log) { Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook - logging") { public void run() { - log.info( - "------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); + log.info("------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------"); } }); - log.info( - "------------------------------------------------------ IDE STARTED ------------------------------------------------------"); + log.info("------------------------------------------------------ IDE STARTED ------------------------------------------------------"); - final ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); - final ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); + ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance(); + ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance(); log.info("IDE: " + namesInfo.getFullProductName() + " (build #" + appInfo.getBuild() + ", " + DateFormatUtilRt.formatBuildDate(appInfo.getBuildDate()) + ")"); log.info("OS: " + SystemInfoRt.OS_NAME + " (" + SystemInfoRt.OS_VERSION + ")"); - log.info("JRE: " + System.getProperty("java.runtime.version", "-") + " (" + System.getProperty("java.vendor", "-") + ")"); log.info("JVM: " + System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.vendor", "-") + ")"); - RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); - List arguments = RuntimemxBean.getInputArguments(); - - if (arguments != null) log.info("JVM Args: " + StringUtil.join(arguments, " ")); + List arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); + if (arguments != null) { + log.info("JVM Args: " + StringUtil.join(arguments, " ")); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 48d8b85b133d..f092d21e0e43 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -22,6 +22,7 @@ import com.intellij.diagnostic.PluginException; import com.intellij.ide.*; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.idea.StartupUtil; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.*; @@ -37,7 +38,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProcessCanceledException; @@ -89,8 +89,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application private static final Logger LOG = Logger.getInstance("#com.intellij.application.impl.ApplicationImpl"); private final ModalityState MODALITY_STATE_NONE = ModalityState.NON_MODAL; - // about writer preference: the way the java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync is implemented, the - // writer thread will be always at the queue head and therefore, java.util.concurrent.locks.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() + // about writer preference: the way the j.u.c.l.ReentrantReadWriteLock.NonfairSync is implemented, the + // writer thread will be always at the queue head and therefore, j.u.c.l.ReentrantReadWriteLock.NonfairSync.readerShouldBlock() // will return true if the write action is pending, exactly as we need private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(false); @@ -361,55 +361,25 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } @Override - protected void handleInitComponentError(final Throwable ex, final boolean fatal, final String componentClassName, ComponentConfig config) { - if (myHandlingInitComponentError) { - return; - } - myHandlingInitComponentError = true; - try { - PluginId pluginId = config == null ? PluginManager.getPluginByClassName(componentClassName) : config.getPluginId(); - if (pluginId != null) { - LOG.warn(ex); - @NonNls final String errorMessage = - "Plugin " + pluginId.getIdString() + " failed to initialize and will be disabled:\n" + ex.getMessage() + - "\nPlease restart " + ApplicationNamesInfo.getInstance().getFullProductName() + "."; - PluginManager.disablePlugin(pluginId.getIdString()); - if (!myHeadlessMode) { - JOptionPane.showMessageDialog(null, errorMessage); - } - else if (!isUnitTestMode()) { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(errorMessage); - System.exit(1); - } - return; // do not call super + protected void handleInitComponentError(Throwable t, String componentClassName, ComponentConfig config) { + if (!myHandlingInitComponentError) { + myHandlingInitComponentError = true; + try { + PluginManager.handleComponentError(t, componentClassName, config); } - if (fatal) { - LOG.error(ex); - @NonNls final String errorMessage = "Fatal error initializing class " + componentClassName + ":\n" + - StringUtil.trimLog(ex.toString(), 239) + - "\nComplete error stacktrace was written to " + PathManager.getLogPath() + "/idea.log"; - if (!myHeadlessMode) { - JOptionPane.showMessageDialog(null, errorMessage); - } - else { - //noinspection UseOfSystemOutOrSystemErr - System.out.println(errorMessage); - } + finally { + myHandlingInitComponentError = false; } - super.handleInitComponentError(ex, fatal, componentClassName, config); - } - finally { - myHandlingInitComponentError = false; } } private void loadApplicationComponents() { - PluginManager.initPlugins(mySplash); - final IdeaPluginDescriptor[] plugins = PluginManager.getPlugins(); + PluginManagerCore.initPlugins(mySplash); + IdeaPluginDescriptor[] plugins = PluginManagerCore.getPlugins(); for (IdeaPluginDescriptor plugin : plugins) { - if (PluginManager.shouldSkipPlugin(plugin)) continue; - loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); + if (!PluginManagerCore.shouldSkipPlugin(plugin)) { + loadComponentsConfiguration(plugin.getAppComponents(), plugin, false); + } } } @@ -417,7 +387,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application protected synchronized Object createComponent(Class componentInterface) { Object component = super.createComponent(componentInterface); if (mySplash != null) { - mySplash.showProgress("", (float)(0.65f + getPercentageOfComponentsLoaded() * 0.35f)); + mySplash.showProgress("", 0.65f + getPercentageOfComponentsLoaded() * 0.35f); } return component; } @@ -1440,7 +1410,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application public void run() { if (ex instanceof PluginException) { final PluginException pluginException = (PluginException)ex; - PluginManager.disablePlugin(pluginException.getPluginId().getIdString()); + PluginManagerCore.disablePlugin(pluginException.getPluginId().getIdString()); Messages.showMessageDialog("The plugin " + pluginException.getPluginId() + " failed to save settings and has been disabled. Please restart " + diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index fd6e291e0b27..0ff8fe8b00fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -149,12 +149,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } }; - for (final FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { + for (FileTypeFactory factory : Extensions.getExtensions(FileTypeFactory.FILE_TYPE_FACTORY_EP)) { try { factory.createFileTypes(consumer); } - catch (final Error ex) { - PluginManager.disableIncompatiblePlugin(factory, ex); + catch (Throwable t) { + PluginManager.handleComponentError(t, factory.getClass().getName(), null); } } } @@ -191,7 +191,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return null; - } @Override @@ -218,7 +217,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements NamedJDOME } return new Document(root); - } @Override diff --git a/platform/platform-main/src/com/intellij/idea/MainImpl.java b/platform/platform-main/src/com/intellij/idea/MainImpl.java index 0faeeb706a0a..32660d97733a 100644 --- a/platform/platform-main/src/com/intellij/idea/MainImpl.java +++ b/platform/platform-main/src/com/intellij/idea/MainImpl.java @@ -15,77 +15,42 @@ */ package com.intellij.idea; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.application.ConfigImportHelper; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.impl.ApplicationInfoImpl; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.SystemInfoRt; -import com.intellij.ui.AppUIUtil; +import com.intellij.ide.plugins.PluginManager; import com.intellij.util.PlatformUtils; -import com.intellij.util.text.DateFormatUtilRt; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.PlatformUtilsCore; import javax.swing.*; -@SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "UnusedDeclaration"}) +@SuppressWarnings({"UnusedDeclaration"}) public class MainImpl { - private static final String LOG_CATEGORY = "#com.intellij.idea.Main"; - private MainImpl() { } /** * Called from PluginManager via reflection. */ protected static void start(final String[] args) { - System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); + System.setProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY, PlatformUtils.getPlatformPrefix(PlatformUtils.COMMUNITY_PREFIX)); - StartupUtil.isHeadless = Main.isHeadless(args); - if (!StartupUtil.isHeadless) { - AppUIUtil.updateFrameClass(); - AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame()); - AppUIUtil.registerBundledFonts(); - - UIUtil.initDefaultLAF(); - - final boolean isNewConfigFolder = PathManager.ensureConfigFolderExists(true); - if (isNewConfigFolder) { - ConfigImportHelper.importConfigsTo(PathManager.getConfigPath()); - } - } - - if (!StartupUtil.checkStartupPossible(args)) { // It uses config folder! - System.exit(-1); - } - - Logger.setFactory(LoggerFactory.getInstance()); - - final Logger LOG = Logger.getInstance(LOG_CATEGORY); - - StartupUtil.startLogging(LOG); - - _main(args); - } - - protected static void _main(final String[] args) { - // http://weblogs.java.net/blog/shan_man/archive/2005/06/improved_drag_g.html - System.setProperty("sun.swing.enableImprovedDragGesture", ""); - - Logger LOG = Logger.getInstance(LOG_CATEGORY); - StartupUtil.fixProcessEnvironment(LOG); - StartupUtil.loadSystemLibraries(LOG); - - startApplication(args); - } - - private static void startApplication(final String[] args) { - final IdeaApplication app = new IdeaApplication(args); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - public void run() { - app.run(); + StartupUtil.prepareAndStart(args, new StartupUtil.AppStarter() { + @Override + public void start(boolean newConfigFolder) { + final IdeaApplication app = new IdeaApplication(args); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + app.run(); + } + catch (PluginManager.StartupAbortedException e) { + throw e; + } + catch (Throwable t) { + throw new PluginManager.StartupAbortedException(t); + } + } + }); } }); } -} \ No newline at end of file +} diff --git a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java index 7a07bec9ae5e..bac5d8cab2cf 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java +++ b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java @@ -26,17 +26,23 @@ public abstract class Logger { Logger getLoggerInstance(String category); } - public static Factory ourFactory = new Factory() { + private static class DefaultFactory implements Factory { @Override public Logger getLoggerInstance(String category) { return new DefaultLogger(category); } - }; + } + + public static Factory ourFactory = new DefaultFactory(); public static void setFactory(Factory factory) { ourFactory = factory; } + public static boolean isInitialized() { + return !(ourFactory instanceof DefaultFactory); + } + public static Logger getInstance(@NonNls String category) { return ourFactory.getLoggerInstance(category); } @@ -48,9 +54,29 @@ public abstract class Logger { public abstract boolean isDebugEnabled(); public abstract void debug(@NonNls String message); + public abstract void debug(@Nullable Throwable t); + public abstract void debug(@NonNls String message, @Nullable Throwable t); + public void info(@NotNull Throwable t) { + info(t.getMessage(), t); + } + + public abstract void info(@NonNls String message); + + public abstract void info(@NonNls String message, @Nullable Throwable t); + + public void warn(@NonNls String message) { + warn(message, null); + } + + public void warn(@NotNull Throwable t) { + warn(t.getMessage(), t); + } + + public abstract void warn(@NonNls String message, @Nullable Throwable t); + public void error(@NonNls String message) { error(message, new Throwable(), ArrayUtil.EMPTY_STRING_ARRAY); } @@ -70,27 +96,8 @@ public abstract class Logger { error(t.getMessage(), t, ArrayUtil.EMPTY_STRING_ARRAY); } - public void warn(@NonNls String message) { - warn(message, null); - } - - public void warn(@NotNull Throwable t) { - warn(t.getMessage(), t); - } - - public abstract void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details); - public abstract void info(@NonNls String message); - - public abstract void info(@NonNls String message, @Nullable Throwable t); - - public abstract void warn(@NonNls String message, @Nullable Throwable t); - - public void info(@NotNull Throwable t) { - info(t.getMessage(), t); - } - public boolean assertTrue(boolean value, @NonNls Object message) { if (!value) { @NonNls StringBuilder resultMessage = new StringBuilder("Assertion failed"); @@ -107,5 +114,4 @@ public abstract class Logger { } public abstract void setLevel(Level level); - } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java index 10b65fe7f0e4..ed67161b6773 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomManagerImpl.java @@ -18,13 +18,10 @@ package com.intellij.util.xml.impl; import com.intellij.ide.highlighter.DomSupportEnabled; import com.intellij.ide.startup.StartupManagerEx; import com.intellij.openapi.Disposable; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; @@ -72,36 +69,44 @@ import java.util.Set; */ public final class DomManagerImpl extends DomManager { private static final Key MOCK = Key.create("MockElement"); + static final Key> CACHED_FILE_ELEMENT = Key.create("CACHED_FILE_ELEMENT"); static final Key MOCK_DESCRIPTION = Key.create("MockDescription"); - static final SemKey FILE_DESCRIPTION_KEY = SemKey.createKey("FILE_DESCRIPTION_KEY"); - public static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); + static final SemKey DOM_HANDLER_KEY = SemKey.createKey("DOM_HANDLER_KEY"); static final SemKey DOM_INDEXED_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_INDEXED_HANDLER_KEY"); static final SemKey DOM_COLLECTION_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_COLLECTION_HANDLER_KEY"); static final SemKey DOM_CUSTOM_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_CUSTOM_HANDLER_KEY"); static final SemKey DOM_ATTRIBUTE_HANDLER_KEY = DOM_HANDLER_KEY.subKey("DOM_ATTRIBUTE_HANDLER_KEY"); private final EventDispatcher myListeners = EventDispatcher.create(DomEventListener.class); - private final ConverterManagerImpl myConverterManager; - private final GenericValueReferenceProvider myGenericValueReferenceProvider = new GenericValueReferenceProvider(); private final Project myProject; + private final SemService mySemService; + private final ConverterManager myConverterManager; private final DomApplicationComponent myApplicationComponent; private final PsiFileFactory myFileFactory; + private final ProjectFileIndex myFileIndex; private long myModificationCount; private boolean myChanging; - private final ProjectFileIndex myFileIndex; - private final SemService mySemService; - public DomManagerImpl(final Project project, final XmlAspect xmlAspect) { + public DomManagerImpl(Project project, + final XmlAspect xmlAspect, + SemService semService, + ConverterManager converterManager, + DomApplicationComponent appComponent, + PsiFileFactory fileFactory, + ProjectFileIndex fileIndex) { myProject = project; - mySemService = SemService.getSemService(project); - myConverterManager = (ConverterManagerImpl)ServiceManager.getService(ConverterManager.class); - myApplicationComponent = DomApplicationComponent.getInstance(); - final PomModel pomModel = PomManager.getModel(project); + mySemService = semService; + myConverterManager = converterManager; + myApplicationComponent = appComponent; + myFileFactory = fileFactory; + myFileIndex = fileIndex; + + PomModel pomModel = PomManager.getModel(project); pomModel.addModelListener(new PomModelListener() { public void modelChanged(PomModelEvent event) { final XmlChangeSet changeSet = (XmlChangeSet)event.getChangeSet(xmlAspect); @@ -120,11 +125,7 @@ public final class DomManagerImpl extends DomManager { } }, project); - myFileFactory = PsiFileFactory.getInstance(project); - - final PsiManager psiManager = PsiManager.getInstance(project); - - final Runnable setupVfsListeners = new Runnable() { + Runnable setupVfsListeners = new Runnable() { public void run() { final VirtualFileAdapter listener = new VirtualFileAdapter() { private final List myDeletionEvents = new SmartList(); @@ -140,7 +141,7 @@ public final class DomManagerImpl extends DomManager { } public void beforeFileDeletion(final VirtualFileEvent event) { - if (!project.isDisposed()) { + if (!myProject.isDisposed()) { beforeFileDeletion(event.getFile()); } } @@ -163,7 +164,7 @@ public final class DomManagerImpl extends DomManager { public void fileDeleted(VirtualFileEvent event) { if (!myDeletionEvents.isEmpty()) { - if (!project.isDisposed()) { + if (!myProject.isDisposed()) { for (DomEvent domEvent : myDeletionEvents) { fireEvent(domEvent); } @@ -179,18 +180,17 @@ public final class DomManagerImpl extends DomManager { } } }; - VirtualFileManager.getInstance().addVirtualFileListener(listener, project); + VirtualFileManager.getInstance().addVirtualFileListener(listener, myProject); } }; - final StartupManager startupManager = StartupManager.getInstance(project); + StartupManager startupManager = StartupManager.getInstance(project); if (!((StartupManagerEx)startupManager).startupActivityPassed()) { startupManager.registerStartupActivity(setupVfsListeners); - } else { + } + else { setupVfsListeners.run(); } - - myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); } private void processVfsChange(final VirtualFile file) { @@ -522,7 +522,4 @@ public final class DomManagerImpl extends DomManager { public SemService getSemService() { return mySemService; } - - - private final static Logger LOG = Logger.getInstance(DomManagerImpl.class); } diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java index 298bf9ea9a16..49110e2c0f4a 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomAnnotationsTest.java @@ -23,13 +23,14 @@ import com.intellij.psi.PsiFileFactory; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.highlighting.*; +import com.intellij.util.xml.impl.DomTestCase; import java.util.Arrays; /** * @author peter */ -public class DomAnnotationsTest extends DomTestCase{ +public class DomAnnotationsTest extends DomTestCase { @Override protected T createElement(final String xml, final Class aClass) { diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java index ba33cf4ba00f..89229bf889c5 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomChildrenTest.java @@ -26,6 +26,7 @@ import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; import java.lang.reflect.Type; import java.util.ArrayList; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java index 8e78b570e9fb..4a94d0e5ba26 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java @@ -28,6 +28,7 @@ import com.intellij.semantic.SemService; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.Timings; import com.intellij.util.xml.impl.DomFileElementImpl; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomExtender; import com.intellij.util.xml.reflect.DomExtenderEP; import com.intellij.util.xml.reflect.DomExtensionsRegistrar; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java index e013091b79cf..5aa8c0b2255d 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomExtensionsTest.java @@ -21,6 +21,7 @@ import com.intellij.testFramework.IdeaTestUtil; import com.intellij.util.Consumer; import com.intellij.util.ParameterizedTypeImpl; import com.intellij.util.ReflectionUtil; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.*; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java index e4d6d65be887..c2f13f6368cb 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHardCoreTestCase.java @@ -26,8 +26,8 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.psi.xml.XmlTagValue; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomApplicationComponent; import com.intellij.util.xml.impl.DomManagerImpl; +import com.intellij.util.xml.impl.DomTestCase; /** * @author peter diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java index 8a57ba6d8d64..623b11616f59 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java @@ -34,6 +34,7 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.MockSchemesManagerFactory; import com.intellij.util.xml.highlighting.*; import com.intellij.util.xml.impl.DefaultDomAnnotator; +import com.intellij.util.xml.impl.DomTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java index f94d568c26d5..9efc125bb83c 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomModelMergingTest.java @@ -16,13 +16,17 @@ package com.intellij.util.xml; import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.util.xml.impl.DomTestCase; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * @author peter */ -public class DomModelMergingTest extends DomTestCase{ +public class DomModelMergingTest extends DomTestCase { private ModelMerger myMerger; @Override diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java index ae96a3b5062a..8d92c019129f 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomNamespacesTest.java @@ -20,6 +20,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.impl.DomFileElementImpl; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomGenericInfo; import java.util.List; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java index 5e42f0678f83..8911df1c22ac 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomSimpleValuesTest.java @@ -22,6 +22,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.ui.DomUIFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java index d85066b560d7..2a2bf1a4e2f3 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/SimpleValuesIncrementalUpdateTest.java @@ -17,11 +17,12 @@ package com.intellij.util.xml; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.events.DomEvent; +import com.intellij.util.xml.impl.DomTestCase; /** * @author peter */ -public class SimpleValuesIncrementalUpdateTest extends DomTestCase{ +public class SimpleValuesIncrementalUpdateTest extends DomTestCase { public void testAttributeChange() throws Throwable { final MyElement element = createElement(""); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java b/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java similarity index 92% rename from xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java rename to xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java index 16fedacfca67..37682943b3eb 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomTestCase.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/impl/DomTestCase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.util.xml; +package com.intellij.util.xml.impl; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; @@ -25,11 +25,8 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.xml.*; import com.intellij.util.xml.events.DomEvent; -import com.intellij.util.xml.impl.DomApplicationComponent; -import com.intellij.util.xml.impl.DomFileElementImpl; -import com.intellij.util.xml.impl.DomInvocationHandler; -import com.intellij.util.xml.impl.DomManagerImpl; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -87,7 +84,7 @@ public abstract class DomTestCase extends LightIdeaTestCase { return element; } - protected static T createElement(final DomManager domManager, final String xml, final Class aClass) + public static T createElement(final DomManager domManager, final String xml, final Class aClass) throws IncorrectOperationException { final String name = "a.xml"; final XmlFile file = (XmlFile)PsiFileFactory.getInstance(domManager.getProject()).createFileFromText(name, xml); diff --git a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java index e191e3eacfc0..2f7f2fefcd90 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/impl/IncrementalUpdateEventsTest.java @@ -19,7 +19,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import com.intellij.util.xml.DomElement; -import com.intellij.util.xml.DomTestCase; import com.intellij.util.xml.SubTag; import com.intellij.util.xml.events.DomEvent; From 0d8160ba85b32b4443b7fe29cc9606cf15f468c4 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 13:19:11 +0400 Subject: [PATCH 18/47] sm: workout all events before disposal --- .../sm/runner/GeneralTestEventsProcessor.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java index 305f42a2ba5e..23145d52702f 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java @@ -98,7 +98,16 @@ public abstract class GeneralTestEventsProcessor implements Disposable { public abstract void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider); @Override - public void dispose() {} + public void dispose() { + if (!ApplicationManager.getApplication().isUnitTestMode()) { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + myTransferToEDTQueue.drain(); + } + }); + } + } public Condition getDisposedCondition() { return Condition.FALSE; From 056c21941df6439bfeb371d189b26e6284112208 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Jun 2013 13:25:56 +0400 Subject: [PATCH 19/47] Cleanup (formatting) --- .../ide/ui/laf/darcula/DarculaLaf.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index a3c34041752b..54982d377f2a 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -23,7 +23,6 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ColorUtil; import com.intellij.util.containers.hash.HashMap; -import com.sun.jna.platform.unix.X11; import org.jetbrains.annotations.NotNull; import sun.awt.AppContext; @@ -49,6 +48,7 @@ import java.util.Properties; public final class DarculaLaf extends BasicLookAndFeel { public static final String NAME = "Darcula"; BasicLookAndFeel base; + public DarculaLaf() { try { if (SystemInfo.isWindows || SystemInfo.isLinux) { @@ -58,8 +58,8 @@ public final class DarculaLaf extends BasicLookAndFeel { base = (BasicLookAndFeel)Class.forName(name).newInstance(); } } - catch (Exception ignore) { - log(ignore); + catch (Exception e) { + log(e); } } @@ -69,8 +69,8 @@ public final class DarculaLaf extends BasicLookAndFeel { superMethod.setAccessible(true); superMethod.invoke(base, defaults); } - catch (Exception ignore) { - log(ignore); + catch (Exception e) { + log(e); } } @@ -85,8 +85,7 @@ public final class DarculaLaf extends BasicLookAndFeel { try { final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults"); superMethod.setAccessible(true); - final UIDefaults metalDefaults = - (UIDefaults)superMethod.invoke(new MetalLookAndFeel()); + final UIDefaults metalDefaults = (UIDefaults)superMethod.invoke(new MetalLookAndFeel()); final UIDefaults defaults = (UIDefaults)superMethod.invoke(base); if (SystemInfo.isLinux) { Font font = findFont("Ubuntu"); @@ -108,8 +107,8 @@ public final class DarculaLaf extends BasicLookAndFeel { MetalLookAndFeel.setCurrentTheme(new DarculaMetalTheme()); return defaults; } - catch (Exception ignore) { - log(ignore); + catch (Exception e) { + log(e); } return super.getDefaults(); } @@ -294,7 +293,6 @@ public final class DarculaLaf extends BasicLookAndFeel { } } - @Override public String getName() { return NAME; @@ -355,7 +353,6 @@ public final class DarculaLaf extends BasicLookAndFeel { } } - @Override public boolean getSupportsWindowDecorations() { return true; From f23bc89931a31e4562252139c60901c2417bab92 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Jun 2013 13:37:43 +0400 Subject: [PATCH 20/47] IDEA-108564 (really use system font) --- .../src/com/intellij/ide/ui/laf/IdeaLaf.java | 13 ++++++++++-- .../ide/ui/laf/darcula/DarculaLaf.java | 20 ------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java index 6fa170bab32f..47558feddc74 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -16,8 +16,10 @@ package com.intellij.ide.ui.laf; import com.intellij.icons.AllIcons; +import com.intellij.openapi.util.Pair; import com.intellij.ui.ColoredSideBorder; import com.intellij.ui.plaf.beg.*; +import com.intellij.util.ui.UIUtil; import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; import com.sun.java.swing.plaf.windows.WindowsTreeUI; @@ -38,7 +40,14 @@ public final class IdeaLaf extends MetalLookAndFeel { super.initComponentDefaults(defaults); LafManagerImpl.initInputMapDefaults(defaults); initIdeaDefaults(defaults); - LafManagerImpl.initFontDefaults(defaults, "Tahoma", 11); + + Pair systemFont = UIUtil.getSystemFontData(); + if (systemFont != null) { + LafManagerImpl.initFontDefaults(defaults, systemFont.first, systemFont.second); + } + else { + LafManagerImpl.initFontDefaults(defaults, "Tahoma", 11); + } } @SuppressWarnings({"HardCodedStringLiteral"}) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index 54982d377f2a..1e858edf612e 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -28,7 +28,6 @@ import sun.awt.AppContext; import javax.swing.*; import javax.swing.plaf.ColorUIResource; -import javax.swing.plaf.FontUIResource; import javax.swing.plaf.IconUIResource; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.basic.BasicLookAndFeel; @@ -87,16 +86,6 @@ public final class DarculaLaf extends BasicLookAndFeel { superMethod.setAccessible(true); final UIDefaults metalDefaults = (UIDefaults)superMethod.invoke(new MetalLookAndFeel()); final UIDefaults defaults = (UIDefaults)superMethod.invoke(base); - if (SystemInfo.isLinux) { - Font font = findFont("Ubuntu"); - if (font != null) { - for (Object key : defaults.keySet()) { - if (key instanceof String && ((String)key).endsWith(".font")) { - defaults.put(key, new FontUIResource(font.deriveFont(15f))); - } - } - } - } LafManagerImpl.initInputMapDefaults(defaults); initIdeaDefaults(defaults); @@ -113,15 +102,6 @@ public final class DarculaLaf extends BasicLookAndFeel { return super.getDefaults(); } - private static Font findFont(String name) { - for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) { - if (font.getName().equals(name)) { - return font; - } - } - return null; - } - private static void patchComboBox(UIDefaults metalDefaults, UIDefaults defaults) { defaults.remove("ComboBox.ancestorInputMap"); defaults.remove("ComboBox.actionMap"); From 155add571b2c48e5f6d95843a89aa3f68cd400bb Mon Sep 17 00:00:00 2001 From: Serega Vasiliev Date: Thu, 13 Jun 2013 11:38:05 +0200 Subject: [PATCH 21/47] jsf 2.2 : "contracts" feature --- xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java index dc6e626ad78b..e3a26e9fc055 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java @@ -143,7 +143,7 @@ public class XmlUtil { @NonNls public static final String NO_NAMESPACE_SCHEMA_LOCATION_ATT = "noNamespaceSchemaLocation"; @NonNls public static final String SCHEMA_LOCATION_ATT = "schemaLocation"; @NonNls public static final String[] WEB_XML_URIS = - {"http://java.sun.com/xml/ns/j2ee", "http://java.sun.com/xml/ns/javaee", "http://java.sun.com/dtd/web-app_2_3.dtd", + {"http://java.sun.com/xml/ns/j2ee", "http://java.sun.com/xml/ns/javaee", "http://xmlns.jcp.org/xml/ns/javaee", "http://java.sun.com/dtd/web-app_2_3.dtd", "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"}; @NonNls public static final String FACELETS_URI = "http://java.sun.com/jsf/facelets"; From 4b6ffae66537dd97aeb393fc499b81110297c6b6 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 14:02:28 +0400 Subject: [PATCH 22/47] sm statistics: sortable, exclude parent suite presentation from current view (IDEA-77380) --- .../runner/ui/statistics/ColumnDuration.java | 18 ++--------- .../sm/runner/ui/statistics/ColumnTest.java | 30 ++----------------- .../runner/ui/statistics/StatisticsPanel.java | 17 +++-------- .../ui/statistics/StatisticsTableModel.java | 4 +-- .../ui/statistics/ColumnDurationTest.java | 2 +- .../runner/ui/statistics/ColumnTestTest.java | 2 +- 6 files changed, 12 insertions(+), 61 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDuration.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDuration.java index e0cad807eba2..ba3998eb463f 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDuration.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDuration.java @@ -59,14 +59,12 @@ public class ColumnDuration extends BaseColumn implements Comparator{ @Override public TableCellRenderer getRenderer(final SMTestProxy proxy) { - return new TestsCellRenderer(proxy); + return new TestsCellRenderer(); } public static class TestsCellRenderer extends ColoredTableCellRenderer implements ColoredRenderer { - @NonNls private static final String TOTAL_TITLE = SMTestsRunnerBundle.message("sm.test.runner.ui.tabs.statistics.columns.test.total.title"); - @NonNls private static final String PARENT_TITLE = ".."; - - private final SMTestProxy myProxy; - - public TestsCellRenderer(final SMTestProxy proxy) { - myProxy = proxy; - } - public void customizeCellRenderer(final JTable table, final Object value, final boolean selected, @@ -72,24 +63,7 @@ public class ColumnTest extends BaseColumn implements Comparator{ final int column) { assert value != null; - final String title = value.toString(); - //Black bold for with caption "Total" for parent suite of items in statistics - if (myProxy.isSuite() && isFirstLine(row)) { - if (myProxy.getParent() == null) { - append(TOTAL_TITLE, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); - } - else { - append(PARENT_TITLE, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); - append(" (" + myProxy.getName() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES); - } - return; - } - //Black, regular for other suites and tests - append(title, SimpleTextAttributes.REGULAR_ATTRIBUTES); - } - - public static boolean isFirstLine(final int row) { - return row == 0; + append(value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java index 6debd74209bf..13260684f5d9 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java @@ -219,19 +219,10 @@ public class StatisticsPanel implements DataProvider { final int i = myStatisticsTableView.getSelectedRow(); assert i >= 0; //because something is selected - // If first line is selected we should go to parent suite - if (ColumnTest.TestsCellRenderer.isFirstLine(i)) { - final SMTestProxy parentSuite = selectedProxy.getParent(); - if (parentSuite != null) { - // go to parent and current suit in it - showInTableAndSelectRow(parentSuite, selectedProxy); - } - } else { - // if selected element is suite - we should expand it - if (selectedProxy.isSuite()) { - // expand and select first (Total) row - showInTableAndSelectRow(selectedProxy, selectedProxy); - } + // if selected element is suite - we should expand it + if (selectedProxy.isSuite()) { + // expand and select first (Total) row + showInTableAndSelectRow(selectedProxy, selectedProxy); } } }; diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsTableModel.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsTableModel.java index 34413801840e..edab544952d5 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsTableModel.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsTableModel.java @@ -37,7 +37,7 @@ public class StatisticsTableModel extends ListTableModel { public StatisticsTableModel() { super(new ColumnTest(), new ColumnDuration(), new ColumnResults()); - setSortable(false); // TODO: fix me + setSortable(true); } public void updateModelOnProxySelected(final SMTestProxy proxy) { @@ -95,8 +95,6 @@ public class StatisticsTableModel extends ListTableModel { } final List list = new ArrayList(); - // suite's total statistics - list.add(suite); // chiled's statistics list.addAll(suite.getChildren()); diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java index 7cbe913e2973..ee3cf79f6ed2 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java @@ -278,7 +278,7 @@ public class ColumnDurationTest extends BaseColumnRenderingTest { public MyRenderer(final SMTestProxy proxy, final UITestUtil.FragmentsContainer fragmentsContainer) { - super(proxy); + super(); myFragmentsContainer = fragmentsContainer; } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java index 793bec3f3147..0d577f622abb 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java @@ -120,7 +120,7 @@ public class ColumnTestTest extends BaseColumnRenderingTest { public MyRenderer(final SMTestProxy proxy, final UITestUtil.FragmentsContainer fragmentsContainer) { - super(proxy); + super(); myFragmentsContainer = fragmentsContainer; } From 28e87e29a5d314a3e0cd384f7b73a86c49abea35 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 13 Jun 2013 14:26:34 +0400 Subject: [PATCH 23/47] use SystemInfo.isApple/Oracle --- platform/util/src/com/intellij/util/ui/UIUtil.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 6274fd0f3f23..240a8ca584aa 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -220,13 +220,12 @@ public class UIUtil { if (ourRetina.isNull()) { ourRetina.set(false); // in case HiDPIScaledImage.drawIntoImage is not called for some reason - String vendor = SystemProperties.getJavaVmVendor(); - if (SystemInfo.isJavaVersionAtLeast("1.6.0_33") && vendor != null && StringUtil.containsIgnoreCase(vendor, "Apple")) { + if (SystemInfo.isJavaVersionAtLeast("1.6.0_33") && SystemInfo.isAppleJvm) { if (!"false".equals(System.getProperty("ide.mac.retina"))) { ourRetina.set(IsRetina.isRetina()); return ourRetina.get(); } - } else if (SystemInfo.isJavaVersionAtLeast("1.7.0_40") && vendor != null && StringUtil.containsIgnoreCase(vendor, "Oracle")) { + } else if (SystemInfo.isJavaVersionAtLeast("1.7.0_40") && SystemInfo.isOracleJvm) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice device = env.getDefaultScreenDevice(); try { @@ -1496,11 +1495,7 @@ public class UIUtil { public static BufferedImage createImage(int width, int height, int type) { if (isRetina()) { - if (SystemInfo.isAppleJvm) { - return RetinaImage.create(width, height, type); - } else if (SystemInfo.isOracleJvm) { - //todo[kb] provide some hidpi scaled image - } + return RetinaImage.create(width, height, type); } //noinspection UndesirableClassUsage return new BufferedImage(width, height, type); From 8650245c9558e74054f246acdc3012b593439c23 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 13 Jun 2013 14:27:08 +0400 Subject: [PATCH 24/47] fix white border --- .../src/com/intellij/openapi/wm/impl/InternalDecorator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index d37e976dfc22..6e73479e6d5f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -319,7 +319,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa add(contentPane, BorderLayout.CENTER); setBorder(new InnerPanelBorder(myToolWindow)); if (SystemInfo.isMac) { - setBackground(Gray._200); + setBackground(new JBColor(Gray._200, Gray._90)); } // Add listeners From d2e1f4909626e5e875bc7f8fa75f8495d5ce1db0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 14:32:09 +0400 Subject: [PATCH 25/47] plugins: install: suggest to restart if dialog was not closed yet --- .../src/com/intellij/ide/plugins/ActionInstallPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/ActionInstallPlugin.java b/platform/platform-impl/src/com/intellij/ide/plugins/ActionInstallPlugin.java index 29a113f9b3a7..212ade114677 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/ActionInstallPlugin.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/ActionInstallPlugin.java @@ -148,6 +148,7 @@ public class ActionInstallPlugin extends AnAction implements DumbAware { installedPluginsToModel(list); if (!installed.isDisposed()) { getPluginTable().updateUI(); + installed.setRequireShutdown(true); } else { boolean needToRestart = false; From 1fbe489730cfb0553e244b8513e6df84971b188a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 13:10:15 +0200 Subject: [PATCH 26/47] move lexer file to right place --- .../xml-psi-impl}/src/com/intellij/lexer/_HtmlLexer.flex | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {xml-psi-impl/impl => xml/xml-psi-impl}/src/com/intellij/lexer/_HtmlLexer.flex (100%) diff --git a/xml-psi-impl/impl/src/com/intellij/lexer/_HtmlLexer.flex b/xml/xml-psi-impl/src/com/intellij/lexer/_HtmlLexer.flex similarity index 100% rename from xml-psi-impl/impl/src/com/intellij/lexer/_HtmlLexer.flex rename to xml/xml-psi-impl/src/com/intellij/lexer/_HtmlLexer.flex From 8e3173382f3c3b4c7f863c6184af676cf83e91a9 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Jun 2013 15:35:57 +0400 Subject: [PATCH 27/47] NPE in Configuration Server Dialog --- .../platform-impl/src/com/intellij/ide/IdeEventQueue.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index fe8be3429f67..c21021478f06 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -903,11 +903,11 @@ public class IdeEventQueue extends EventQueue { myWaiterScheduled = false; } else { - Application app = ApplicationManager.getApplication(); - if (app == null || + if (ApplicationManager.getApplication() == null || + UISettings.getInstance() == null || !SystemInfo.isWindows || !Registry.is("actionSystem.win.suppressAlt") || - (!UISettings.getInstance().HIDE_TOOL_STRIPES && !UISettings.getInstance().PRESENTATION_MODE)) { + !(UISettings.getInstance().HIDE_TOOL_STRIPES || UISettings.getInstance().PRESENTATION_MODE)) { return !dispatch; } From 753a50e8900d5641c830b8d7f77d38c282f056b4 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 14:14:16 +0200 Subject: [PATCH 28/47] to avoid static initialization issues, extract extension point interface to top level --- .../src/com/intellij/lang/ant/AntParsingTest.java | 6 +++--- .../src/com/intellij/codeInsight/XmlParsingTest.java | 3 +-- .../com/intellij/psi/xml/StartTagEndTokenProvider.java | 10 ++++++++++ .../src/com/intellij/psi/xml/XmlChildRole.java | 10 +--------- .../src/com/intellij/xml/XmlCoreEnvironment.java | 4 ++-- 5 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 xml/xml-psi-impl/src/com/intellij/psi/xml/StartTagEndTokenProvider.java diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java index de266621e071..070b5611bb1b 100644 --- a/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java +++ b/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java @@ -23,7 +23,7 @@ import com.intellij.lang.xml.XmlASTFactory; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.util.SystemInfo; -import com.intellij.psi.xml.XmlChildRole; +import com.intellij.psi.xml.StartTagEndTokenProvider; import com.intellij.testFramework.ParsingTestCase; public class AntParsingTest extends ParsingTestCase { @@ -36,8 +36,8 @@ public class AntParsingTest extends ParsingTestCase { protected void setUp() throws Exception { super.setUp(); addExplicitExtension(LanguageASTFactory.INSTANCE, XMLLanguage.INSTANCE, new XmlASTFactory()); - registerExtensionPoint(new ExtensionPointName("com.intellij.xml.startTagEndToken"), - XmlChildRole.StartTagEndTokenProvider.class); + registerExtensionPoint(new ExtensionPointName("com.intellij.xml.startTagEndToken"), + StartTagEndTokenProvider.class); } @Override diff --git a/xml/tests/src/com/intellij/codeInsight/XmlParsingTest.java b/xml/tests/src/com/intellij/codeInsight/XmlParsingTest.java index 85f01c54b656..da3254a24815 100644 --- a/xml/tests/src/com/intellij/codeInsight/XmlParsingTest.java +++ b/xml/tests/src/com/intellij/codeInsight/XmlParsingTest.java @@ -49,8 +49,7 @@ public class XmlParsingTest extends ParsingTestCase { addExplicitExtension(LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition()); addExplicitExtension(LanguageASTFactory.INSTANCE, XMLLanguage.INSTANCE, new XmlASTFactory()); addExplicitExtension(LanguageASTFactory.INSTANCE, DTDLanguage.INSTANCE, new XmlASTFactory()); - registerExtensionPoint(new ExtensionPointName("com.intellij.xml.startTagEndToken"), - XmlChildRole.StartTagEndTokenProvider.class); + registerExtensionPoint(StartTagEndTokenProvider.EP_NAME, StartTagEndTokenProvider.class); } @Override diff --git a/xml/xml-psi-impl/src/com/intellij/psi/xml/StartTagEndTokenProvider.java b/xml/xml-psi-impl/src/com/intellij/psi/xml/StartTagEndTokenProvider.java new file mode 100644 index 000000000000..e81ea4ad23d1 --- /dev/null +++ b/xml/xml-psi-impl/src/com/intellij/psi/xml/StartTagEndTokenProvider.java @@ -0,0 +1,10 @@ +package com.intellij.psi.xml; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.psi.tree.IElementType; + +public interface StartTagEndTokenProvider { + ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.xml.startTagEndToken"); + + IElementType[] getTypes(); +} diff --git a/xml/xml-psi-impl/src/com/intellij/psi/xml/XmlChildRole.java b/xml/xml-psi-impl/src/com/intellij/psi/xml/XmlChildRole.java index 0e39ab22e2ab..02cb1fe03b5a 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/xml/XmlChildRole.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/xml/XmlChildRole.java @@ -16,11 +16,9 @@ package com.intellij.psi.xml; import com.intellij.lang.ASTNode; -import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.DefaultRoleFinder; -import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.RoleFinder; import com.intellij.util.ArrayUtil; import com.intellij.xml.util.XmlTagUtil; @@ -29,12 +27,6 @@ import org.jetbrains.annotations.Nullable; public interface XmlChildRole { - interface StartTagEndTokenProvider { - IElementType[] getTypes(); - } - - ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.xml.startTagEndToken"); - RoleFinder START_TAG_NAME_FINDER = new RoleFinder() { public ASTNode findChild(@NotNull ASTNode parent) { final PsiElement element = XmlTagUtil.getStartTagNameElement((XmlTag)parent.getPsi()); @@ -65,7 +57,7 @@ public interface XmlChildRole { RoleFinder ATTRIBUTE_VALUE_VALUE_FINDER = new DefaultRoleFinder(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN); RoleFinder START_TAG_END_FINDER = new DefaultRoleFinder(XmlTokenType.XML_TAG_END) { { - final StartTagEndTokenProvider[] tokenProviders = Extensions.getExtensions(EP_NAME); + final StartTagEndTokenProvider[] tokenProviders = Extensions.getExtensions(StartTagEndTokenProvider.EP_NAME); for (StartTagEndTokenProvider tokenProvider : tokenProviders) { myElementTypes = ArrayUtil.mergeArrays(myElementTypes, tokenProvider.getTypes()); } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java index 77852f097a34..2ae1d0d0db65 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java @@ -26,7 +26,7 @@ import com.intellij.psi.impl.cache.impl.id.IdIndexers; import com.intellij.psi.impl.cache.impl.idCache.XmlIdIndexer; import com.intellij.psi.impl.source.xml.XmlElementDescriptorProvider; import com.intellij.psi.meta.MetaDataContributor; -import com.intellij.psi.xml.XmlChildRole; +import com.intellij.psi.xml.StartTagEndTokenProvider; import com.intellij.psi.xml.XmlFileNSInfoProvider; import com.intellij.util.indexing.FileBasedIndexExtension; import com.intellij.xml.index.XmlNamespaceIndex; @@ -57,7 +57,7 @@ public class XmlCoreEnvironment { appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer()); - CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlChildRole.EP_NAME, XmlChildRole.StartTagEndTokenProvider.class); + CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StartTagEndTokenProvider.EP_NAME, StartTagEndTokenProvider.class); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlSuppressionProvider.EP_NAME, XmlSuppressionProvider.class); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlFileNSInfoProvider.EP_NAME, XmlFileNSInfoProvider.class); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlSchemaProvider.EP_NAME, XmlSchemaProvider.class); From 069b22c0ccbdaf9faa05e12f81a29545b75c2546 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Thu, 13 Jun 2013 16:16:41 +0400 Subject: [PATCH 29/47] IDEA-108320 Restart action is broken --- .../debugger/DefaultDebugUIEnvironment.java | 2 - .../intellij/execution/ExecutionManager.java | 7 ++ .../execution/impl/ExecutionManagerImpl.java | 73 +++++++++++++++---- .../execution/runners/RestartAction.java | 21 +----- .../execution/runners/RunContentBuilder.java | 3 +- .../xdebugger/impl/ui/XDebugSessionTab.java | 3 +- 6 files changed, 69 insertions(+), 40 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java b/java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java index 5c1b585391d4..bc7915f62a47 100644 --- a/java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java +++ b/java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java @@ -114,10 +114,8 @@ public class DefaultDebugUIEnvironment implements DebugUIEnvironment { @Override public void initActions(RunContentDescriptor content, DefaultActionGroup actionGroup) { - ProcessHandler processHandler = content.getProcessHandler(); RestartAction restartAction = new RestartAction(myExecutor, myRunner, - processHandler, content, myExecutionEnvironment); actionGroup.add(restartAction, Constraints.FIRST); diff --git a/platform/lang-api/src/com/intellij/execution/ExecutionManager.java b/platform/lang-api/src/com/intellij/execution/ExecutionManager.java index e51b46d73805..c8554e8a413f 100644 --- a/platform/lang-api/src/com/intellij/execution/ExecutionManager.java +++ b/platform/lang-api/src/com/intellij/execution/ExecutionManager.java @@ -18,6 +18,7 @@ package com.intellij.execution; import com.intellij.execution.configurations.RunProfileState; 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.execution.ui.RunContentManager; import com.intellij.openapi.project.Project; @@ -60,4 +61,10 @@ public abstract class ExecutionManager { @NotNull ExecutionTarget target, @Nullable RunnerAndConfigurationSettings configuration, @Nullable RunContentDescriptor currentDescriptor); + + public abstract void restartRunProfile(@NotNull Project project, + @NotNull Executor executor, + @Nullable ProgramRunner runner, + @NotNull ExecutionEnvironment environment, + @Nullable RunContentDescriptor currentDescriptor); } 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 e4fa66d6dc29..2cf5a48594a2 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java @@ -18,10 +18,7 @@ package com.intellij.execution.impl; import com.intellij.CommonBundle; import com.intellij.execution.*; -import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; -import com.intellij.execution.configurations.RunConfiguration; -import com.intellij.execution.configurations.RunProfile; -import com.intellij.execution.configurations.RunProfileState; +import com.intellij.execution.configurations.*; import com.intellij.execution.process.ProcessAdapter; import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.process.ProcessHandler; @@ -269,28 +266,55 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom for (RunContentDescriptor descriptor : getContentManager().getAllDescriptors()) { final ProcessHandler handler = descriptor.getProcessHandler(); if (handler == processHandler) { - restartRunProfile(project, executor, target, configuration, descriptor); + restartRunProfile(project, null, null, null, null, executor, target, configuration, descriptor); return; } } } - restartRunProfile(project, executor, target, configuration, (RunContentDescriptor)null); + restartRunProfile(project, null, null, null, null, executor, target, configuration, null); } @Override - public void restartRunProfile(@NotNull final Project project, + public void restartRunProfile(@NotNull Project project, + @NotNull Executor executor, + @NotNull ExecutionTarget target, + @Nullable RunnerAndConfigurationSettings configuration, + @Nullable RunContentDescriptor currentDescriptor) { + restartRunProfile(project, null, null, null, null, executor, target, configuration, currentDescriptor); + } + + @Override + public void restartRunProfile(@NotNull Project project, + @NotNull Executor executor, + @Nullable ProgramRunner runner, + @NotNull ExecutionEnvironment environment, + @Nullable RunContentDescriptor currentDescriptor) { + restartRunProfile(project, + runner, + environment.getRunProfile(), + environment.getRunnerSettings(), + environment.getConfigurationSettings(), + executor, + environment.getExecutionTarget(), + environment.getRunnerAndConfigurationSettings(), currentDescriptor); + } + + + private void restartRunProfile(@NotNull final Project project, + @Nullable ProgramRunner r, + @Nullable final RunProfile runProfile, + @Nullable final RunnerSettings runnerSettings, + @Nullable final ConfigurationPerRunnerSettings configurationPerRunnerSettings, @NotNull final Executor executor, @NotNull final ExecutionTarget target, @Nullable final RunnerAndConfigurationSettings configuration, @Nullable final RunContentDescriptor currentDescriptor) { - if (configuration != null && ProgramRunnerUtil.getRunner(executor.getId(), configuration) == null) { + final ProgramRunner runner = r != null ? r : ProgramRunnerUtil.getRunner(executor.getId(), configuration); + if (configuration != null && runner == null) { LOG.error("Cannot find runner for " + configuration.getName()); return; } - if (configuration == null && (currentDescriptor == null || currentDescriptor.getRestarter() == null)) { - LOG.error("Nothing to restart for descriptor ["+currentDescriptor+"]"); - return; - } + final List descriptorsToStop = new ArrayList(); if (configuration != null && configuration.isSingleton()) { descriptorsToStop.addAll(getRunningDescriptors(configuration)); @@ -312,7 +336,6 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom Runnable runnable = new Runnable() { @Override public void run() { - ProgramRunner runner = ProgramRunnerUtil.getRunner(executor.getId(), configuration); if (runner != null && ExecutorRegistry.getInstance().isStarting(project, executor.getId(), runner.getRunnerId())) { awaitingTerminationAlarm.addRequest(this, 100); return; @@ -324,19 +347,39 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom return; } } - start(project, configuration, executor, target, currentDescriptor); + start(project, runner, runProfile, runnerSettings, configurationPerRunnerSettings, configuration, executor, target, currentDescriptor); } }; awaitingTerminationAlarm.addRequest(runnable, 50); } private static void start(@NotNull Project project, + @Nullable ProgramRunner runner, + @Nullable RunProfile runProfile, + @Nullable RunnerSettings runnerSettings, + @Nullable ConfigurationPerRunnerSettings configurationPerRunnerSettings, @Nullable RunnerAndConfigurationSettings configuration, @NotNull Executor executor, @NotNull ExecutionTarget target, @Nullable RunContentDescriptor descriptor) { Runnable restarter = descriptor != null ? descriptor.getRestarter() : null; - if (configuration != null) { + if (runner != null && runProfile != null) { + try { + runner.execute(executor, new ExecutionEnvironment(runProfile, + target, + project, + runnerSettings, + configurationPerRunnerSettings, + descriptor, + configuration)); + } + catch (RunCanceledByUserException ignore) { + } + catch (ExecutionException e1) { + Messages.showErrorDialog(project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title")); + } + } + else if (configuration != null) { ProgramRunnerUtil.executeConfiguration(project, configuration, executor, target, descriptor, true); } else if (restarter != null) { diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java index 2d53816dd245..126aa490f172 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java @@ -43,7 +43,6 @@ import java.util.List; */ public class RestartAction extends FakeRerunAction implements DumbAware, AnAction.TransparentUpdate, Disposable { - private final ProcessHandler myProcessHandler; private final ProgramRunner myRunner; @NotNull private final RunContentDescriptor myDescriptor; @NotNull private final Executor myExecutor; @@ -51,7 +50,6 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio public RestartAction(@NotNull final Executor executor, final ProgramRunner runner, - final ProcessHandler processHandler,//todo kill ProcessHandler here, use descriptor.getProcessHandler() is need @NotNull final RunContentDescriptor descriptor, @NotNull final ExecutionEnvironment env) { Disposer.register(descriptor, this); @@ -59,7 +57,6 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio myEnvironment = env; getTemplatePresentation().setEnabled(false); - myProcessHandler = processHandler; myRunner = runner; myDescriptor = descriptor; myExecutor = executor; @@ -108,22 +105,8 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio public void restart() { Project project = myEnvironment.getProject(); - if (project == null) - return; - if (myProcessHandler != null) { - ExecutionManager.getInstance(project).restartRunProfile(project, - myExecutor, - myEnvironment.getExecutionTarget(), - myEnvironment.getRunnerAndConfigurationSettings(), - myProcessHandler); - } - else { - ExecutionManager.getInstance(project).restartRunProfile(project, - myExecutor, - myEnvironment.getExecutionTarget(), - myEnvironment.getRunnerAndConfigurationSettings(), - myDescriptor); - } + if (project != null && !ExecutorRegistry.getInstance().isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) + ExecutionManager.getInstance(project).restartRunProfile(project, myExecutor, myRunner, myEnvironment, myDescriptor); } @Override diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java b/platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java index 2600fa4f3268..ecea85eeff3d 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java @@ -205,8 +205,7 @@ public class RunContentBuilder extends LogConsoleManagerBase { private ActionGroup createActionToolbar(final RunContentDescriptor contentDescriptor, final JComponent component) { final DefaultActionGroup actionGroup = new DefaultActionGroup(); - final RestartAction restartAction = new RestartAction(myExecutor, myRunner, getProcessHandler(), - contentDescriptor, getEnvironment()); + final RestartAction restartAction = new RestartAction(myExecutor, myRunner, contentDescriptor, getEnvironment()); restartAction.registerShortcut(component); actionGroup.add(restartAction); contentDescriptor.setRestarter(new Runnable() { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java index 3fcadb528cba..68d56641c7a3 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java @@ -160,8 +160,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { DefaultActionGroup leftToolbar = new DefaultActionGroup(); final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance(); if (runner != null && env != null) { - RestartAction restartAction = new RestartAction(executor, runner, myRunContentDescriptor.getProcessHandler(), - myRunContentDescriptor, env); + RestartAction restartAction = new RestartAction(executor, runner, myRunContentDescriptor, env); leftToolbar.add(restartAction); restartAction.registerShortcut(myUi.getComponent()); } From b8e986fb164b5c5b10cae0c974dfb32c95c03ff0 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 13 Jun 2013 14:49:17 +0200 Subject: [PATCH 30/47] use interned id cache during indexstate rebuild --- .../roots/impl/DirectoryIndexImpl.java | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 4c439778edae..1b6fecf96ce7 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -224,22 +224,24 @@ public class DirectoryIndexImpl extends DirectoryIndex { state.fillMapWithModuleContent(file, module, (NewVirtualFile)parentContentRoot, null); String parentPackage = state.getPackageNameForDirectory(parent); + TObjectIntHashMap interned = new TObjectIntHashMap(); if (module != null) { if (parentInfo.isInModuleSource()) { String newDirPackageName = getPackageNameForSubdir(parentPackage, file.getName()); - state.fillMapWithModuleSource(module, (NewVirtualFile)parentContentRoot, file, newDirPackageName, (NewVirtualFile)parentInfo.getSourceRoot(), parentInfo.isTestSource(), null); + state.fillMapWithModuleSource(module, (NewVirtualFile)parentContentRoot, file, newDirPackageName, + (NewVirtualFile)parentInfo.getSourceRoot(), parentInfo.isTestSource(), null, interned); } } if (parentInfo.hasLibraryClassRoot()) { String newDirPackageName = getPackageNameForSubdir(parentPackage, file.getName()); - state.fillMapWithLibraryClasses(file, newDirPackageName, (NewVirtualFile)parentInfo.getLibraryClassRoot(), null); + state.fillMapWithLibraryClasses(file, newDirPackageName, (NewVirtualFile)parentInfo.getLibraryClassRoot(), null, interned); } if (parentInfo.isInLibrarySource()) { String newDirPackageName = getPackageNameForSubdir(parentPackage, file.getName()); - state.fillMapWithLibrarySources(file, newDirPackageName, (NewVirtualFile)parentInfo.getSourceRoot(), null); + state.fillMapWithLibrarySources(file, newDirPackageName, (NewVirtualFile)parentInfo.getSourceRoot(), null, interned); } OrderEntry[] entries = parentInfo.getOrderEntries(); @@ -365,7 +367,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { dispatchPendingEvents(); IndexState state = myState; - int[] allDirs = state.getDirsForPackage(internPackageName(packageName)); + int[] allDirs = state.getDirsForPackage(internPackageName(packageName, null)); if (allDirs == null) allDirs = ArrayUtil.EMPTY_INT_ARRAY; List files = new ArrayList(allDirs.length); @@ -511,7 +513,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { return result.toString(); } - private static int[] internPackageName(@Nullable String packageName) { + private static int[] internPackageName(@Nullable String packageName, @Nullable TObjectIntHashMap alreadyEnumerated) { if (packageName == null) { return null; } @@ -531,7 +533,13 @@ public class DirectoryIndexImpl extends DirectoryIndex { if (tokenEnd < 0) { tokenEnd = packageName.length(); } - result[tokenIndex + 1] = FileNameCache.storeName(packageName.substring(tokenStart, tokenEnd)); + String nextName = packageName.substring(tokenStart, tokenEnd); + int internedId = alreadyEnumerated != null ? alreadyEnumerated.get(nextName) : 0; + if (internedId == 0) { + internedId = FileNameCache.storeName(nextName); + if (alreadyEnumerated != null) alreadyEnumerated.put(nextName, internedId); + } + result[tokenIndex + 1] = internedId; tokenStart = tokenEnd + 1; tokenIndex++; } @@ -788,7 +796,8 @@ public class DirectoryIndexImpl extends DirectoryIndex { } } - private void initModuleSources(@NotNull Module module, boolean reverseAllSets, @NotNull ProgressIndicator progress) { + private void initModuleSources(@NotNull Module module, boolean reverseAllSets, @NotNull ProgressIndicator progress, + @Nullable TObjectIntHashMap interned) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.module.sources.progress", module.getName())); @@ -808,7 +817,8 @@ public class DirectoryIndexImpl extends DirectoryIndex { for (SourceFolder sourceFolder : sourceFolders) { VirtualFile dir = sourceFolder.getFile(); if (dir instanceof NewVirtualFile && contentRoot instanceof NewVirtualFile) { - fillMapWithModuleSource(module, (NewVirtualFile)contentRoot, (NewVirtualFile)dir, sourceFolder.getPackagePrefix(), (NewVirtualFile)dir, sourceFolder.isTestSource(), progress); + fillMapWithModuleSource(module, (NewVirtualFile)contentRoot, (NewVirtualFile)dir, sourceFolder.getPackagePrefix(), + (NewVirtualFile)dir, sourceFolder.isTestSource(), progress, interned); } } } @@ -820,7 +830,9 @@ public class DirectoryIndexImpl extends DirectoryIndex { @NotNull final String packageName, @NotNull final NewVirtualFile sourceRoot, final boolean isTestSource, - @Nullable final ProgressIndicator progress) { + @Nullable final ProgressIndicator progress, + final @Nullable TObjectIntHashMap interned + ) { assertWritable(); if (!isValid(dir)) return; assert VfsUtilCore.isAncestor(sourceRoot, dir, false) : "SourceRoot: "+sourceRoot+" ("+sourceRoot.getFileSystem()+"); dir: "+dir+" ("+dir.getFileSystem()+")"; @@ -850,7 +862,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { String currentPackage = myPackages.isEmpty() ? packageName : getPackageNameForSubdir(myPackages.peek(), file.getName()); myPackages.push(currentPackage); - setPackageName(id, internPackageName(currentPackage)); + setPackageName(id, internPackageName(currentPackage, interned)); return info; } @@ -866,7 +878,8 @@ public class DirectoryIndexImpl extends DirectoryIndex { return myDirToPackageName.get(id) == ArrayUtil.EMPTY_INT_ARRAY; } - private void initLibrarySources(@NotNull Module module, @NotNull ProgressIndicator progress) { + private void initLibrarySources(@NotNull Module module, @NotNull ProgressIndicator progress, + @Nullable TObjectIntHashMap interned) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.library.sources.progress", module.getName())); @@ -876,7 +889,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { VirtualFile[] sourceRoots = ((LibraryOrSdkOrderEntry)orderEntry).getRootFiles(OrderRootType.SOURCES); for (final VirtualFile sourceRoot : sourceRoots) { if (sourceRoot instanceof NewVirtualFile) { - fillMapWithLibrarySources((NewVirtualFile)sourceRoot, "", (NewVirtualFile)sourceRoot, progress); + fillMapWithLibrarySources((NewVirtualFile)sourceRoot, "", (NewVirtualFile)sourceRoot, progress, interned); } } } @@ -884,9 +897,10 @@ public class DirectoryIndexImpl extends DirectoryIndex { } private void fillMapWithLibrarySources(@NotNull final NewVirtualFile dir, - @Nullable final String packageName, - @NotNull final NewVirtualFile sourceRoot, - @Nullable final ProgressIndicator progress) { + @Nullable final String packageName, + @NotNull final NewVirtualFile sourceRoot, + @Nullable final ProgressIndicator progress, + @Nullable final TObjectIntHashMap interned) { assertWritable(); if (!isValid(dir)) return; VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() { @@ -908,7 +922,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { final String packageName = getCurrentValue(); final String newPackageName = Comparing.equal(file, dir) ? packageName : getPackageNameForSubdir(packageName, file.getName()); - setPackageName(dirId, internPackageName(newPackageName)); + setPackageName(dirId, internPackageName(newPackageName, interned)); setValueForChildren(newPackageName); return true; @@ -916,7 +930,8 @@ public class DirectoryIndexImpl extends DirectoryIndex { }); } - private void initLibraryClasses(@NotNull Module module, @NotNull ProgressIndicator progress) { + private void initLibraryClasses(@NotNull Module module, @NotNull ProgressIndicator progress, + @Nullable TObjectIntHashMap interned) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.library.classes.progress", module.getName())); @@ -926,7 +941,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { VirtualFile[] classRoots = ((LibraryOrSdkOrderEntry)orderEntry).getRootFiles(OrderRootType.CLASSES); for (final VirtualFile classRoot : classRoots) { if (classRoot instanceof NewVirtualFile) { - fillMapWithLibraryClasses((NewVirtualFile)classRoot, "", (NewVirtualFile)classRoot, progress); + fillMapWithLibraryClasses((NewVirtualFile)classRoot, "", (NewVirtualFile)classRoot, progress, interned); } } } @@ -936,7 +951,9 @@ public class DirectoryIndexImpl extends DirectoryIndex { private void fillMapWithLibraryClasses(@NotNull final NewVirtualFile dir, @NotNull final String packageName, @NotNull final NewVirtualFile classRoot, - @Nullable final ProgressIndicator progress) { + @Nullable final ProgressIndicator progress, + @Nullable final TObjectIntHashMap interned + ) { assertWritable(); if (!isValid(dir)) return; VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() { @@ -959,7 +976,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { final String packageName = getCurrentValue(); final String childPackageName = Comparing.equal(file, dir) ? packageName : getPackageNameForSubdir(packageName, file.getName()); if (!info.isInModuleSource() && !info.isInLibrarySource()) { - setPackageName(dirId, internPackageName(childPackageName)); + setPackageName(dirId, internPackageName(childPackageName, interned)); } setValueForChildren(childPackageName); @@ -1135,13 +1152,16 @@ public class DirectoryIndexImpl extends DirectoryIndex { for (Module module : modules) { initModuleContents(module, reverseAllSets, progress); } + + TObjectIntHashMap interned = new TObjectIntHashMap(100); + // Important! Because module's contents may overlap, // first modules should be marked and only after that sources markup // should be added. (src markup depends on module markup) for (Module module : modules) { - initModuleSources(module, reverseAllSets, progress); - initLibrarySources(module, progress); - initLibraryClasses(module, progress); + initModuleSources(module, reverseAllSets, progress, interned); + initLibrarySources(module, progress, interned); + initLibraryClasses(module, progress , interned); } progress.checkCanceled(); From 8c9d86c6221ae7acf6d1b1a2e8e86db3042dddcd Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 15:13:33 +0200 Subject: [PATCH 31/47] EP registration fixed --- platform/platform-resources/src/META-INF/XmlPlugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index 4ecf05c4b7bd..85757e808bb5 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -13,7 +13,7 @@ + interface="com.intellij.psi.xml.StartTagEndTokenProvider"/> Date: Thu, 13 Jun 2013 15:49:41 +0400 Subject: [PATCH 32/47] Cleanup (suppressions) --- .../extensions/impl/ExtensionPointImpl.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java index 9c6f782cbcc1..746857e8eb49 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -183,9 +183,9 @@ public class ExtensionPointImpl implements ExtensionPoint { result = myExtensionsCache; if (result == null) { processAdapters(); - final Class extensionClass = getExtensionClass(); - //noinspection unchecked - result = myExtensions.toArray((T[])Array.newInstance(extensionClass, myExtensions.size())); + Class extensionClass = getExtensionClass(); + @SuppressWarnings("unchecked") T[] a = (T[])Array.newInstance(extensionClass, myExtensions.size()); + result = myExtensions.toArray(a); for (int i = result.length - 1; i >= 0; i--) { T t = result[i]; @@ -237,8 +237,7 @@ public class ExtensionPointImpl implements ExtensionPoint { ExtensionComponentAdapter[] adapters = allAdapters.toArray(new ExtensionComponentAdapter[myExtensionAdapters.size()]); LoadingOrder.sort(adapters); for (ExtensionComponentAdapter adapter : adapters) { - //noinspection unchecked - T extension = (T)adapter.getExtension(); + @SuppressWarnings("unchecked") T extension = (T)adapter.getExtension(); assertClass(extension.getClass()); internalRegisterExtension(extension, adapter, myExtensions.size(), ArrayUtilRt.find(loadedAdapters, adapter) == -1); @@ -334,8 +333,8 @@ public class ExtensionPointImpl implements ExtensionPoint { if (myEPListeners.add(listener)) { for (ExtensionComponentAdapter componentAdapter : myLoadedAdapters.toArray(new ExtensionComponentAdapter[myLoadedAdapters.size()])) { try { - //noinspection unchecked - listener.extensionAdded((T)componentAdapter.getExtension(), componentAdapter.getPluginDescriptor()); + @SuppressWarnings("unchecked") T extension = (T)componentAdapter.getExtension(); + listener.extensionAdded(extension, componentAdapter.getPluginDescriptor()); } catch (Throwable e) { myLogger.error(e); @@ -348,8 +347,8 @@ public class ExtensionPointImpl implements ExtensionPoint { public synchronized void removeExtensionPointListener(@NotNull ExtensionPointListener listener) { for (ExtensionComponentAdapter componentAdapter : myLoadedAdapters.toArray(new ExtensionComponentAdapter[myLoadedAdapters.size()])) { try { - //noinspection unchecked - listener.extensionRemoved((T)componentAdapter.getExtension(), componentAdapter.getPluginDescriptor()); + @SuppressWarnings("unchecked") T extension = (T)componentAdapter.getExtension(); + listener.extensionRemoved(extension, componentAdapter.getPluginDescriptor()); } catch (Throwable e) { myLogger.error(e); @@ -379,10 +378,9 @@ public class ExtensionPointImpl implements ExtensionPoint { if (extensionClass == null) { try { ClassLoader pluginClassLoader = myDescriptor.getPluginClassLoader(); - //noinspection unchecked - myExtensionClass = extensionClass = pluginClassLoader == null - ? (Class)Class.forName(myClassName) - : (Class)Class.forName(myClassName, true, pluginClassLoader); + @SuppressWarnings("unchecked") Class extClass = pluginClassLoader == null + ? (Class)Class.forName(myClassName) : (Class)Class.forName(myClassName, true, pluginClassLoader); + myExtensionClass = extensionClass = extClass; } catch (ClassNotFoundException e) { throw new RuntimeException(e); @@ -422,8 +420,8 @@ public class ExtensionPointImpl implements ExtensionPoint { pluginContainer.unregisterComponent(componentKey); } - //noinspection unchecked - internalUnregisterExtension((T)componentAdapter.getExtension(), componentAdapter.getPluginDescriptor()); + @SuppressWarnings("unchecked") T extension = (T)componentAdapter.getExtension(); + internalUnregisterExtension(extension, componentAdapter.getPluginDescriptor()); return true; } return false; From 82551548ed4abe1180a3aaf16744ebf169fdc77d Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 13 Jun 2013 17:39:10 +0400 Subject: [PATCH 33/47] IDEA-104500 Gradle: Allow to reuse common logic for other external systems Use an utility method instead of manual processing --- .../project/manage/LibraryDataService.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java index 4c34b4ff0537..48777a134daa 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/LibraryDataService.java @@ -16,8 +16,10 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; -import com.intellij.openapi.util.io.FileUtilRt; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.JarFileSystem; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; @@ -130,14 +132,7 @@ public class LibraryDataService implements ProjectDataService Date: Thu, 13 Jun 2013 17:40:53 +0400 Subject: [PATCH 34/47] sm statistics tests fixed --- .../runner/ui/statistics/ColumnTestTest.java | 9 +- .../SMTRunnerStatisticsPanelTest.java | 88 +++++++------------ .../SMTRunnerStatisticsTableModelTest.java | 9 +- 3 files changed, 39 insertions(+), 67 deletions(-) diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java index 0d577f622abb..65a897b45cac 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnTestTest.java @@ -90,18 +90,13 @@ public class ColumnTestTest extends BaseColumnRenderingTest { final SMTestProxy newRootSuite = createSuiteProxy("root_suite"); mySuite.setParent(newRootSuite); doRender(mySuite, 0); - assertFragmentsSize(2); - assertEquals(SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES, myFragmentsContainer.getAttribsAt(0)); - assertEquals("..", myFragmentsContainer.getTextAt(0)); - assertEquals(SimpleTextAttributes.GRAYED_ATTRIBUTES, myFragmentsContainer.getAttribsAt(1)); - assertEquals(" (suite)", myFragmentsContainer.getTextAt(1)); + assertFragmentsSize(1); } public void testTotal_TotalRootSuite() { doRender(mySuite, 0); assertFragmentsSize(1); - assertEquals(SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES, myFragmentsContainer.getAttribsAt(0)); - assertEquals("Total:", myFragmentsContainer.getTextAt(0)); + assertEquals(SimpleTextAttributes.REGULAR_ATTRIBUTES, myFragmentsContainer.getAttribsAt(0)); } @Override diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsPanelTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsPanelTest.java index d2b8bf6c7d2b..586ac08e8bb3 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsPanelTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsPanelTest.java @@ -73,7 +73,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { // show suite in table myStatisticsPanel.selectProxy(suite1); // selects row that corresponds to test1 - myStatisticsPanel.selectRow(1); + myStatisticsPanel.selectRow(0); // Check that necessary row is selected assertEquals(test1, myStatisticsPanel.getSelectedItem()); @@ -84,7 +84,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { // Check that current suite in table wasn't changed. // For it let's select Total row and check selected object myStatisticsPanel.selectRow(0); - assertEquals(suite1, myStatisticsPanel.getSelectedItem()); + assertEquals(test1, myStatisticsPanel.getSelectedItem()); } public void testGotoSuite_OnSuite() { @@ -95,18 +95,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { // show root suite in table myStatisticsPanel.selectProxy(rootSuite); // selects row that corresponds to suite1 - myStatisticsPanel.selectRow(1); + myStatisticsPanel.selectRow(0); // Check that necessary row is selected assertEquals(suite1, myStatisticsPanel.getSelectedItem()); - // Perform action on suite - myStatisticsPanel.createGotoSuiteOrParentAction().run(); - - // Check that current suite in table was changed. - // For it let's select Total row and check selected object - myStatisticsPanel.selectRow(0); - assertEquals(suite1, myStatisticsPanel.getSelectedItem()); } public void testGotoParentSuite_Total() { @@ -117,24 +110,14 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { // show suite in table myStatisticsPanel.selectProxy(suite1); // selects Total row - myStatisticsPanel.selectRow(0); + assertEmpty(myStatisticsPanel.getTableItems()); - // Check that necessary row is selected - assertEquals(suite1, myStatisticsPanel.getSelectedItem()); - - // Perform action on suite - myStatisticsPanel.createGotoSuiteOrParentAction().run(); - - // Check that current suite in table was changed. - // For it let's select Total row and check selected object - myStatisticsPanel.selectRow(0); - assertEquals(rootSuite, myStatisticsPanel.getSelectedItem()); } public void testGotoParentSuite_TotalRoot() { // create test sturcure final SMTestProxy rootSuite = createSuiteProxy("rootSuite"); - createSuiteProxy("suite1", rootSuite); + final SMTestProxy suite1 = createSuiteProxy("suite1", rootSuite); // show root suite in table myStatisticsPanel.selectProxy(rootSuite); @@ -142,15 +125,8 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { myStatisticsPanel.selectRow(0); // Check that necessary row is selected - assertEquals(rootSuite, myStatisticsPanel.getSelectedItem()); + assertEquals(suite1, myStatisticsPanel.getSelectedItem()); - // Perform action on suite - myStatisticsPanel.createGotoSuiteOrParentAction().run(); - - // Check that current suite in table wasn't changed. - // For it let's select Total row and check selected object - myStatisticsPanel.selectRow(0); - assertEquals(rootSuite, myStatisticsPanel.getSelectedItem()); } public void testChangeSelectionListener() { @@ -165,7 +141,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { //suite myStatisticsPanel.selectProxy(suite1); - assertEquals(suite1, myStatisticsPanel.getSelectedItem()); + assertEquals(null, myStatisticsPanel.getSelectedItem()); } public void testChangeSelectionAction() { @@ -190,7 +166,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { //on test myStatisticsPanel.selectProxy(suite1); - myStatisticsPanel.selectRow(1); + myStatisticsPanel.selectRow(0); assertEquals(test1, myStatisticsPanel.getSelectedItem()); myStatisticsPanel.showSelectedProxyInTestsTree(); @@ -205,7 +181,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { focusRequestedRef.set(null); myStatisticsPanel.selectProxy(rootSuite); - myStatisticsPanel.selectRow(1); + myStatisticsPanel.selectRow(0); assertEquals(suite1, myStatisticsPanel.getSelectedItem()); myStatisticsPanel.showSelectedProxyInTestsTree(); @@ -221,11 +197,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { myStatisticsPanel.selectProxy(rootSuite); myStatisticsPanel.selectRow(0); - assertEquals(rootSuite, myStatisticsPanel.getSelectedItem()); + assertEquals(suite1, myStatisticsPanel.getSelectedItem()); myStatisticsPanel.showSelectedProxyInTestsTree(); assertTrue(onSelectedHappend.isSet()); - assertEquals(rootSuite, proxyRef.get()); + assertEquals(suite1, proxyRef.get()); assertTrue(focusRequestedRef.get()); } @@ -244,24 +220,24 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy suite = createSuiteProxy("suite1", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); final SMTestProxy test1 = createTestProxy("test1", suite); final SMTestProxy test2 = createTestProxy("test2", suite); myTestEventsListener.onSuiteStarted(suite); - assertSameElements(getItems(), suite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnSuiteStarted_Child() { final SMTestProxy suite = createSuiteProxy("suite1", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); final SMTestProxy test1 = createTestProxy("test1", suite); final SMTestProxy test2 = createTestProxy("test2", suite); myTestEventsListener.onSuiteStarted(test1); - assertSameElements(getItems(), suite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnSuiteStarted_Other() { @@ -269,12 +245,12 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy other_suite = createSuiteProxy("other_suite", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); createTestProxy("test1", suite); createTestProxy("test2", suite); myTestEventsListener.onSuiteStarted(other_suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); } public void testOnSuiteFinished_NoCurrent() { @@ -292,24 +268,24 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy suite = createSuiteProxy("suite1", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); final SMTestProxy test1 = createTestProxy("test1", suite); final SMTestProxy test2 = createTestProxy("test2", suite); myTestEventsListener.onSuiteFinished(suite); - assertSameElements(getItems(), suite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnSuiteFinished_Child() { final SMTestProxy suite = createSuiteProxy("suite1", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); final SMTestProxy test1 = createTestProxy("test1", suite); final SMTestProxy test2 = createTestProxy("test2", suite); myTestEventsListener.onSuiteFinished(test1); - assertSameElements(getItems(), suite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnSuiteFinished_Other() { @@ -317,12 +293,12 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy other_suite = createSuiteProxy("other_suite", myRootSuite); myStatisticsPanel.selectProxy(suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); createTestProxy("test1", suite); createTestProxy("test2", suite); myTestEventsListener.onSuiteFinished(other_suite); - assertSameElements(getItems(), suite); + assertSameElements(getItems()); } public void testOnTestStarted_NoCurrent() { @@ -340,11 +316,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy test1 = createTestProxy("test1", myRootSuite); myStatisticsPanel.selectProxy(test1); - assertSameElements(getItems(), myRootSuite, test1); + assertSameElements(getItems(),test1); final SMTestProxy test2 = createTestProxy("test2", myRootSuite); myTestEventsListener.onTestStarted(test1); - assertSameElements(getItems(), myRootSuite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnTestStarted_Other() { @@ -354,11 +330,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy other_test = createTestProxy("other_test", suite); myStatisticsPanel.selectProxy(test1); - assertSameElements(getItems(), myRootSuite, test1, suite); + assertSameElements(getItems(), test1, suite); createTestProxy("test2", myRootSuite); myTestEventsListener.onTestStarted(other_test); - assertSameElements(getItems(), myRootSuite, test1, suite); + assertSameElements(getItems(), test1, suite); } public void testOnTestFinished_NoCurrent() { @@ -377,11 +353,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy test1 = createTestProxy("test1", myRootSuite); myStatisticsPanel.selectProxy(test1); - assertSameElements(getItems(), myRootSuite, test1); + assertSameElements(getItems(), test1); final SMTestProxy test2 = createTestProxy("test2", myRootSuite); myTestEventsListener.onTestFinished(test1); - assertSameElements(getItems(), myRootSuite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnTestFinished_Other() { @@ -391,11 +367,11 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy other_test = createTestProxy("other_test", suite); myStatisticsPanel.selectProxy(test1); - assertSameElements(getItems(), myRootSuite, test1, suite); + assertSameElements(getItems(), test1, suite); createTestProxy("test2", myRootSuite); myTestEventsListener.onTestFinished(other_test); - assertSameElements(getItems(), myRootSuite, test1, suite); + assertSameElements(getItems(), test1, suite); } public void testSelectionRestoring_ForTest() { @@ -417,7 +393,7 @@ public class SMTRunnerStatisticsPanelTest extends BaseSMTRunnerTestCase { final SMTestProxy suite = createSuiteProxy("suite1", myRootSuite); myTestEventsListener.onSuiteStarted(suite); - assertEquals(myRootSuite, myStatisticsPanel.getSelectedItem()); + assertEquals(null, myStatisticsPanel.getSelectedItem()); } private List getItems() { diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsTableModelTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsTableModelTest.java index 547a2d45c8a8..2dce3dd9c097 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsTableModelTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/SMTRunnerStatisticsTableModelTest.java @@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner.ui.statistics; import com.intellij.execution.testframework.sm.runner.BaseSMTRunnerTestCase; import com.intellij.execution.testframework.sm.runner.SMTestProxy; +import java.util.ArrayList; import java.util.List; /** @@ -47,7 +48,7 @@ public class SMTRunnerStatisticsTableModelTest extends BaseSMTRunnerTestCase { final SMTestProxy test2 = createTestProxy("test2", myRootSuite); myStatisticsTableModel.updateModelOnProxySelected(test1); - assertSameElements(getItems(), myRootSuite, test1, test2); + assertSameElements(getItems(), test1, test2); } public void testOnSelected_Suite() { @@ -58,13 +59,13 @@ public class SMTRunnerStatisticsTableModelTest extends BaseSMTRunnerTestCase { final SMTestProxy suite2 = createSuiteProxy("suite2", myRootSuite); myStatisticsTableModel.updateModelOnProxySelected(suite1); - assertSameElements(getItems(), suite1, test1, test2); + assertSameElements(getItems(), test1, test2); myStatisticsTableModel.updateModelOnProxySelected(suite2); - assertSameElements(getItems(), suite2); + assertSameElements(getItems()); myStatisticsTableModel.updateModelOnProxySelected(myRootSuite); - assertSameElements(getItems(), myRootSuite, suite1, suite2); + assertSameElements(getItems(), suite1, suite2); } /* public void testSort_ColumnTest() { From e3e2cdbf5f5e76b7e45f19c98867be5eaf3c7627 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 15:59:12 +0200 Subject: [PATCH 35/47] don't depend on static initializer in Html5SchemaProvider --- .../htmlInspections/SwitchToHtml5Action.java | 2 +- ...DefaultHtmlDoctypeInitialConfigurator.java | 2 +- .../javaee/ExternalResourceManagerImpl.java | 4 +-- .../javaee/HtmlLanguageLevelForm.java | 4 +-- .../psi/impl/source/xml/XmlDocumentImpl.java | 4 +-- .../com/intellij/xml/Html5SchemaProvider.java | 36 ++++++++++++++----- .../src/com/intellij/xml/util/HtmlUtil.java | 2 +- .../src/com/intellij/xml/util/XmlUtil.java | 8 ++--- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java index cf6bee3dc81b..3aeb0ebf9fd0 100644 --- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java +++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java @@ -72,7 +72,7 @@ public class SwitchToHtml5Action implements LocalQuickFix, IntentionAction { } private static void applyFix(Project project) { - ExternalResourceManagerEx.getInstanceEx().setDefaultHtmlDoctype(Html5SchemaProvider.HTML5_SCHEMA_LOCATION, project); + ExternalResourceManagerEx.getInstanceEx().setDefaultHtmlDoctype(Html5SchemaProvider.getHtml5SchemaLocation(), project); DaemonCodeAnalyzer.getInstance(project).restart(); } } diff --git a/xml/impl/src/com/intellij/javaee/DefaultHtmlDoctypeInitialConfigurator.java b/xml/impl/src/com/intellij/javaee/DefaultHtmlDoctypeInitialConfigurator.java index 772dd1930d99..9ef5af47f311 100644 --- a/xml/impl/src/com/intellij/javaee/DefaultHtmlDoctypeInitialConfigurator.java +++ b/xml/impl/src/com/intellij/javaee/DefaultHtmlDoctypeInitialConfigurator.java @@ -14,7 +14,7 @@ public class DefaultHtmlDoctypeInitialConfigurator { if (!propertiesComponent.getBoolean("DefaultHtmlDoctype.MigrateToHtml5", false)) { propertiesComponent.setValue("DefaultHtmlDoctype.MigrateToHtml5", Boolean.TRUE.toString()); ExternalResourceManagerEx.getInstanceEx() - .setDefaultHtmlDoctype(Html5SchemaProvider.HTML5_SCHEMA_LOCATION, projectManager.getDefaultProject()); + .setDefaultHtmlDoctype(Html5SchemaProvider.getHtml5SchemaLocation(), projectManager.getDefaultProject()); } } } diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java index 56b9e70b4986..cd97d262957b 100644 --- a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java +++ b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java @@ -461,7 +461,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple return XmlUtil.XHTML4_SCHEMA_LOCATION; } else if (HTML5_DOCTYPE_ELEMENT.equals(doctype)) { - return Html5SchemaProvider.HTML5_SCHEMA_LOCATION; + return Html5SchemaProvider.getHtml5SchemaLocation(); } else { return doctype; @@ -496,7 +496,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple private void setDefaultHtmlDoctype(String defaultHtmlDoctype) { myModificationCount++; - if (Html5SchemaProvider.HTML5_SCHEMA_LOCATION.equals(defaultHtmlDoctype)) { + if (Html5SchemaProvider.getHtml5SchemaLocation().equals(defaultHtmlDoctype)) { myDefaultHtmlDoctype = HTML5_DOCTYPE_ELEMENT; } else { diff --git a/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java b/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java index ac828cbf5b88..5d4668a98ef2 100644 --- a/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java +++ b/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java @@ -75,7 +75,7 @@ public class HtmlLanguageLevelForm { return XmlUtil.XHTML_URI; } if (myHtml5RadioButton.isSelected()) { - return Html5SchemaProvider.HTML5_SCHEMA_LOCATION; + return Html5SchemaProvider.getHtml5SchemaLocation(); } return myDoctypeTextField.getText(); } @@ -85,7 +85,7 @@ public class HtmlLanguageLevelForm { myHtml4RadioButton.setSelected(true); myDoctypeTextField.setEnabled(false); } - else if (doctype.equals(Html5SchemaProvider.HTML5_SCHEMA_LOCATION)) { + else if (doctype.equals(Html5SchemaProvider.getHtml5SchemaLocation())) { myHtml5RadioButton.setSelected(true); myDoctypeTextField.setEnabled(false); } diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java index 3c4f2f4d8b2a..fea20095bc75 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java @@ -218,7 +218,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument { if (nsDescriptor == null) { String htmlns = ExternalResourceManagerEx.getInstanceEx().getDefaultHtmlDoctype(getProject()); if (htmlns.length() == 0) { - htmlns = Html5SchemaProvider.HTML5_SCHEMA_LOCATION; + htmlns = Html5SchemaProvider.getHtml5SchemaLocation(); } nsDescriptor = getDefaultNSDescriptor(htmlns, false); } @@ -227,7 +227,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument { else if (XmlUtil.XHTML_URI.equals(namespace)) { String xhtmlNamespace = XmlUtil.getDefaultXhtmlNamespace(getProject()); if (xhtmlNamespace == null || xhtmlNamespace.length() == 0) { - xhtmlNamespace = Html5SchemaProvider.XHTML5_SCHEMA_LOCATION; + xhtmlNamespace = Html5SchemaProvider.getXhtml5SchemaLocation(); } return getDefaultNSDescriptor(xhtmlNamespace, false); } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/Html5SchemaProvider.java b/xml/xml-psi-impl/src/com/intellij/xml/Html5SchemaProvider.java index b9ab906aa724..7d09b8780ab2 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/Html5SchemaProvider.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/Html5SchemaProvider.java @@ -17,16 +17,25 @@ public abstract class Html5SchemaProvider { public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.xml.html5SchemaProvider"); - public static final String HTML5_SCHEMA_LOCATION; - public static final String XHTML5_SCHEMA_LOCATION; + private static String HTML5_SCHEMA_LOCATION; + private static String XHTML5_SCHEMA_LOCATION; - @NotNull - public abstract URL getHtmlSchemaLocation(); + private static boolean ourInitialized; - @NotNull - public abstract URL getXhtmlSchemaLocation(); + public static String getHtml5SchemaLocation() { + ensureInitialized(); + return HTML5_SCHEMA_LOCATION; + } + + public static String getXhtml5SchemaLocation() { + ensureInitialized(); + return XHTML5_SCHEMA_LOCATION; + } + + private synchronized static void ensureInitialized() { + if (ourInitialized) return; + ourInitialized = true; - static { final Html5SchemaProvider[] providers = EP_NAME.getExtensions(); final URL htmlSchemaLocationURL; final URL xhtmlSchemaLocationURL; @@ -48,11 +57,20 @@ public abstract class Html5SchemaProvider { HTML5_SCHEMA_LOCATION = VfsUtilCore.urlToPath(VfsUtilCore.fixURLforIDEA( URLUtil.unescapePercentSequences(htmlSchemaLocationURL.toExternalForm()))); - LOG.info("HTML5_SCHEMA_LOCATION = " + HTML5_SCHEMA_LOCATION); + LOG.info("HTML5_SCHEMA_LOCATION = " + getHtml5SchemaLocation()); XHTML5_SCHEMA_LOCATION = VfsUtilCore.urlToPath(VfsUtilCore.fixURLforIDEA( URLUtil.unescapePercentSequences(xhtmlSchemaLocationURL.toExternalForm()))); - LOG.info("XHTML5_SCHEMA_LOCATION = " + XHTML5_SCHEMA_LOCATION); + LOG.info("XHTML5_SCHEMA_LOCATION = " + getXhtml5SchemaLocation()); + } + + @NotNull + public abstract URL getHtmlSchemaLocation(); + + @NotNull + public abstract URL getXhtmlSchemaLocation(); + + static { } private static String getClassesListString(T[] a) { diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java index 9dc54b0025da..e502a5ed00df 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java @@ -374,7 +374,7 @@ public class HtmlUtil { if (doctype == null) { LOG.debug("DOCTYPE for " + htmlFileFullName + " is null"); - return Html5SchemaProvider.HTML5_SCHEMA_LOCATION + return Html5SchemaProvider.getHtml5SchemaLocation() .equals(ExternalResourceManagerEx.getInstanceEx().getDefaultHtmlDoctype(doc.getProject())); } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java index e3a26e9fc055..09fa8ade43bb 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java @@ -613,8 +613,8 @@ public class XmlUtil { public static String getDefaultXhtmlNamespace(Project project) { final String doctype = ExternalResourceManagerEx.getInstanceEx().getDefaultHtmlDoctype(project); - return Html5SchemaProvider.HTML5_SCHEMA_LOCATION.equals(doctype) - ? Html5SchemaProvider.XHTML5_SCHEMA_LOCATION + return Html5SchemaProvider.getHtml5SchemaLocation().equals(doctype) + ? Html5SchemaProvider.getXhtml5SchemaLocation() : doctype; } @@ -782,8 +782,8 @@ public class XmlUtil { } else if (HtmlUtil.isHtml5Doctype(doctype)) { docType = doctype.getLanguage() instanceof HTMLLanguage - ? Html5SchemaProvider.HTML5_SCHEMA_LOCATION - : Html5SchemaProvider.XHTML5_SCHEMA_LOCATION; + ? Html5SchemaProvider.getHtml5SchemaLocation() + : Html5SchemaProvider.getXhtml5SchemaLocation(); } } return docType; From 12939e491638a7e8225dac1435a679391d712436 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 16:16:21 +0200 Subject: [PATCH 36/47] XmlResolveTest (which doesn't actually test resolve) fixed --- .../TagNameReferenceCompletionProvider.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java b/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java index 34e2a2082ab5..fa2f1609c3b9 100644 --- a/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java +++ b/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java @@ -25,12 +25,12 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.source.xml.TagNameReference; import com.intellij.psi.xml.XmlTag; +import com.intellij.util.Consumer; import com.intellij.util.ProcessingContext; import com.intellij.xml.XmlTagNameProvider; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -52,15 +52,21 @@ public class TagNameReferenceCompletionProvider extends CompletionProvider consumer) { + PsiElement element = tagNameReference.getElement(); + if (element instanceof XmlTag) { + if (!tagNameReference.isStartTagFlag()) { + consumer.consume(createClosingTagLookupElement((XmlTag)element, false, tagNameReference.getNameElement())); + } + else { + XmlTag tag = (XmlTag) element; + for(LookupElement variant: getTagNameVariants(tag, tag.getNamespacePrefix())) { + consumer.consume(variant); } } } From 60eee9f1ec18aa14663e580e9fddcb39409c2a30 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 18:36:07 +0400 Subject: [PATCH 37/47] scopes: do not create new panel on each selection --- .../intellij/ide/scopeView/ScopeViewPane.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewPane.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewPane.java index c8401174733b..8d1ebb5bed3d 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewPane.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewPane.java @@ -114,14 +114,16 @@ public class ScopeViewPane extends AbstractProjectViewPane { @Override public JComponent createComponent() { - myViewPanel = new ScopeTreeViewPanel(myProject); - Disposer.register(this, myViewPanel); - myViewPanel.initListeners(); - myViewPanel.selectScope(NamedScopesHolder.getScope(myProject, getSubId())); - myTree = myViewPanel.getTree(); - PopupHandler.installPopupHandler(myTree, IdeActions.GROUP_SCOPE_VIEW_POPUP, ActionPlaces.SCOPE_VIEW_POPUP); - enableDnD(); + if (myViewPanel == null) { + myViewPanel = new ScopeTreeViewPanel(myProject); + Disposer.register(this, myViewPanel); + myViewPanel.initListeners(); + myTree = myViewPanel.getTree(); + PopupHandler.installPopupHandler(myTree, IdeActions.GROUP_SCOPE_VIEW_POPUP, ActionPlaces.SCOPE_VIEW_POPUP); + enableDnD(); + } + myViewPanel.selectScope(NamedScopesHolder.getScope(myProject, getSubId())); return myViewPanel.getPanel(); } From d44d3ead973943014f258dc9406ea8894d13768e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 18:37:25 +0400 Subject: [PATCH 38/47] scopes: do not start refresh on directory rename which doesn't not belong to scope (IDEA-108614) --- .../src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java index 8ffe6acd5941..25bf410dc993 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeTreeViewPanel.java @@ -685,7 +685,10 @@ public class ScopeTreeViewPanel extends JPanel implements Disposable { }, false); } else if (propertyName.equals(PsiTreeChangeEvent.PROP_DIRECTORY_NAME)) { - queueRefreshScope(scope, (PsiDirectory)element); + final PackageSet value = getCurrentScope().getValue(); + if (!(value instanceof PackageSetBase) || ((PackageSetBase)value).contains(((PsiDirectory)element).getVirtualFile(), myProject, myDependencyValidationManager)) { + queueRefreshScope(scope, (PsiDirectory)element); + } } } } From 65fa555258d6fe0c88e8f0d0d500dfd36831449d Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 19:22:24 +0400 Subject: [PATCH 39/47] sm statistics tests fixed --- .../sm/runner/ui/statistics/ColumnDurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java index ee3cf79f6ed2..8e554be5b303 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/statistics/ColumnDurationTest.java @@ -258,7 +258,7 @@ public class ColumnDurationTest extends BaseColumnRenderingTest { public void testTotal_TotalSuite() { doRender(mySuite, 0); assertFragmentsSize(1); - assertEquals(SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES, myFragmentsContainer.getAttribsAt(0)); + assertEquals(SimpleTextAttributes.REGULAR_ATTRIBUTES, myFragmentsContainer.getAttribsAt(0)); assertEquals(myColumn.valueOf(mySuite), myFragmentsContainer.getTextAt(0)); } From 02ac139bf90f58ed9e2803b8f95ff2dc30ac6fb5 Mon Sep 17 00:00:00 2001 From: Evgeny Pasynkov Date: Thu, 13 Jun 2013 17:30:42 +0200 Subject: [PATCH 40/47] CoreFileTypeRegistry: allow to register multiple extensions in one call --- .../com/intellij/core/JavaCoreApplicationEnvironment.java | 3 +-- .../src/com/intellij/core/CoreFileTypeRegistry.java | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java index ba6b5f1dcf77..51ae457b4fc0 100644 --- a/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java @@ -51,8 +51,7 @@ public class JavaCoreApplicationEnvironment extends CoreApplicationEnvironment { registerFileType(JavaClassFileType.INSTANCE, "class"); registerFileType(JavaFileType.INSTANCE, "java"); - registerFileType(ArchiveFileType.INSTANCE, "jar"); - registerFileType(ArchiveFileType.INSTANCE, "zip"); + registerFileType(ArchiveFileType.INSTANCE, "jar;zip"); addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory()); addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder()); diff --git a/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java b/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java index 7efc8cca3b09..5427d88cc303 100644 --- a/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java +++ b/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java @@ -64,9 +64,11 @@ public class CoreFileTypeRegistry extends FileTypeRegistry { return result == null ? UnknownFileType.INSTANCE : result; } - public void registerFileType(FileType fileType, String extension) { + public void registerFileType(@NotNull FileType fileType, @NotNull @NonNls String extension) { myAllFileTypes.add(fileType); - myExtensionsMap.put(extension, fileType); + for (final String ext : extension.split(";")) { + myExtensionsMap.put(ext, fileType); + } } @NotNull From 6dbd9a1f64d87b4bb4e067d0fa12beeb2590c6df Mon Sep 17 00:00:00 2001 From: Evgeny Pasynkov Date: Thu, 13 Jun 2013 17:31:08 +0200 Subject: [PATCH 41/47] make stuff available in Upsource --- .../src/com/intellij/xml/XmlCoreEnvironment.java | 5 ++++- .../src/com/intellij/xml/index/XmlNamespaceIndex.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java index 2ae1d0d0db65..d76dbb5bac35 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java @@ -36,7 +36,7 @@ import com.intellij.xml.util.XmlApplicationComponent; * @author yole */ public class XmlCoreEnvironment { - public static void register(CoreApplicationEnvironment appEnvironment, CoreProjectEnvironment projectEnvironment) { + public static void registerApplication(CoreApplicationEnvironment appEnvironment) { appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml"); appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml"); appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt"); @@ -72,4 +72,7 @@ public class XmlCoreEnvironment { appEnvironment.registerApplicationService(ExternalResourceManager.class, new CoreExternalResourceManager()); } + + public static void registerProject(CoreProjectEnvironment projectEnvironment) { + } } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java b/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java index 62e66f46b247..efb006b587d9 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/index/XmlNamespaceIndex.java @@ -73,7 +73,7 @@ public class XmlNamespaceIndex extends XmlIndex { return IndexedRelevantResource.getAllResources(NAME, module, project, chooser); } - private static final ID NAME = ID.create("XmlNamespaces"); + public static final ID NAME = ID.create("XmlNamespaces"); @Override @NotNull From a941d8e05de128e05d0406718b6a37ccf3af9c9e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Jun 2013 17:50:38 +0200 Subject: [PATCH 42/47] move standard schemas to xml-psi-impl --- .../{src => resources}/messages/XmlErrorMessages.properties | 0 .../resources/standardSchemas/XMLSchema-instance.xsd | 0 .../resources/standardSchemas/XMLSchema.dtd | 0 .../resources/standardSchemas/XMLSchema.xsd | 0 xml/{impl => xml-psi-impl}/resources/standardSchemas/catalog.xsd | 0 .../resources/standardSchemas/datatypes.dtd | 0 .../resources/standardSchemas/html5/xhtml5.xsd | 0 .../resources/standardSchemas/plugin-repository.dtd | 0 xml/{impl => xml-psi-impl}/resources/standardSchemas/plugin.dtd | 0 .../resources/standardSchemas/xhtml-lat1.ent | 0 .../standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd | 0 .../standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod | 0 .../resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd | 0 .../standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod | 0 .../standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod | 0 .../resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd | 0 .../resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod | 0 .../resources/standardSchemas/xhtml-special.ent | 0 .../resources/standardSchemas/xhtml-symbol.ent | 0 xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml.dtd | 0 .../resources/standardSchemas/xhtml1-frameset.dtd | 0 .../resources/standardSchemas/xhtml1-frameset.xsd | 0 .../resources/standardSchemas/xhtml1-strict.dtd | 0 .../resources/standardSchemas/xhtml1-strict.xsd | 0 .../resources/standardSchemas/xhtml1-transitional.dtd | 0 .../resources/standardSchemas/xhtml1-transitional.xsd | 0 xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1.dtd | 0 .../resources/standardSchemas/xhtml11/xhtml-attribs-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-base-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-charent-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-csismap-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-edit-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-events-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-form-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-framework-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-image-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-lat1.ent | 0 .../resources/standardSchemas/xhtml11/xhtml-link-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-list-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-meta-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-object-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-param-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-pres-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-qname-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-ruby-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-script-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-special.ent | 0 .../resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-struct-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-style-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-symbol.ent | 0 .../resources/standardSchemas/xhtml11/xhtml-table-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-target-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml-text-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml11-model-1.mod | 0 .../resources/standardSchemas/xhtml11/xhtml11.dtd | 0 .../resources/standardSchemas/xinclude.xsd | 0 xml/{impl => xml-psi-impl}/resources/standardSchemas/xml.xsd | 0 .../resources/standardSchemas/xslt-1_0.xsd | 0 .../resources/standardSchemas/xslt-2_0.xsd | 0 xml/xml-psi-impl/xml-psi-impl.iml | 1 + 72 files changed, 1 insertion(+) rename xml/xml-psi-impl/{src => resources}/messages/XmlErrorMessages.properties (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/XMLSchema-instance.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/XMLSchema.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/XMLSchema.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/catalog.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/datatypes.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/html5/xhtml5.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/plugin-repository.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/plugin.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-lat1.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-special.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml-symbol.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-frameset.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-frameset.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-strict.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-strict.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-transitional.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1-transitional.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml1.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-attribs-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-base-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-charent-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-csismap-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-edit-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-events-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-form-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-framework-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-image-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-lat1.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-link-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-list-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-meta-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-object-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-param-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-pres-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-qname-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-ruby-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-script-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-special.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-struct-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-style-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-symbol.ent (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-table-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-target-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml-text-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml11-model-1.mod (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xhtml11/xhtml11.dtd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xinclude.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xml.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xslt-1_0.xsd (100%) rename xml/{impl => xml-psi-impl}/resources/standardSchemas/xslt-2_0.xsd (100%) diff --git a/xml/xml-psi-impl/src/messages/XmlErrorMessages.properties b/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties similarity index 100% rename from xml/xml-psi-impl/src/messages/XmlErrorMessages.properties rename to xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties diff --git a/xml/impl/resources/standardSchemas/XMLSchema-instance.xsd b/xml/xml-psi-impl/resources/standardSchemas/XMLSchema-instance.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/XMLSchema-instance.xsd rename to xml/xml-psi-impl/resources/standardSchemas/XMLSchema-instance.xsd diff --git a/xml/impl/resources/standardSchemas/XMLSchema.dtd b/xml/xml-psi-impl/resources/standardSchemas/XMLSchema.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/XMLSchema.dtd rename to xml/xml-psi-impl/resources/standardSchemas/XMLSchema.dtd diff --git a/xml/impl/resources/standardSchemas/XMLSchema.xsd b/xml/xml-psi-impl/resources/standardSchemas/XMLSchema.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/XMLSchema.xsd rename to xml/xml-psi-impl/resources/standardSchemas/XMLSchema.xsd diff --git a/xml/impl/resources/standardSchemas/catalog.xsd b/xml/xml-psi-impl/resources/standardSchemas/catalog.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/catalog.xsd rename to xml/xml-psi-impl/resources/standardSchemas/catalog.xsd diff --git a/xml/impl/resources/standardSchemas/datatypes.dtd b/xml/xml-psi-impl/resources/standardSchemas/datatypes.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/datatypes.dtd rename to xml/xml-psi-impl/resources/standardSchemas/datatypes.dtd diff --git a/xml/impl/resources/standardSchemas/html5/xhtml5.xsd b/xml/xml-psi-impl/resources/standardSchemas/html5/xhtml5.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/html5/xhtml5.xsd rename to xml/xml-psi-impl/resources/standardSchemas/html5/xhtml5.xsd diff --git a/xml/impl/resources/standardSchemas/plugin-repository.dtd b/xml/xml-psi-impl/resources/standardSchemas/plugin-repository.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/plugin-repository.dtd rename to xml/xml-psi-impl/resources/standardSchemas/plugin-repository.dtd diff --git a/xml/impl/resources/standardSchemas/plugin.dtd b/xml/xml-psi-impl/resources/standardSchemas/plugin.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/plugin.dtd rename to xml/xml-psi-impl/resources/standardSchemas/plugin.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml-lat1.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml-lat1.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-lat1.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-lat1.ent diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-flat.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10-model-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile10.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-form.mod diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12-model-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtml-mobile12.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-mobile/xhtmlmp12-form-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml-special.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml-special.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-special.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-special.ent diff --git a/xml/impl/resources/standardSchemas/xhtml-symbol.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml-symbol.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml-symbol.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml-symbol.ent diff --git a/xml/impl/resources/standardSchemas/xhtml.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml1-frameset.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-frameset.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-frameset.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-frameset.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml1-frameset.xsd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-frameset.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-frameset.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-frameset.xsd diff --git a/xml/impl/resources/standardSchemas/xhtml1-strict.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-strict.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-strict.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-strict.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml1-strict.xsd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-strict.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-strict.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-strict.xsd diff --git a/xml/impl/resources/standardSchemas/xhtml1-transitional.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-transitional.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-transitional.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-transitional.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml1-transitional.xsd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1-transitional.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1-transitional.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1-transitional.xsd diff --git a/xml/impl/resources/standardSchemas/xhtml1.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml1.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml1.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml1.dtd diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-attribs-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-attribs-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-attribs-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-attribs-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-base-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-base-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-base-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-base-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-basic-form-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-basic-table-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkphras-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkpres-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-blkstruct-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-charent-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-charent-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-charent-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-charent-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-csismap-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-csismap-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-csismap-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-csismap-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-datatypes-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-edit-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-edit-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-edit-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-edit-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-events-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-events-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-events-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-events-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-form-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-form-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-form-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-form-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-framework-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-framework-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-framework-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-framework-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-hypertext-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-image-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-image-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-image-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-image-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlphras-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlpres-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlstruct-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-inlstyle-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-lat1.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-lat1.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-lat1.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-lat1.ent diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-link-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-link-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-link-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-link-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-list-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-list-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-list-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-list-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-meta-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-meta-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-meta-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-meta-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-object-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-object-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-object-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-object-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-param-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-param-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-param-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-param-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-pres-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-pres-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-pres-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-pres-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-qname-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-qname-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-qname-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-qname-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-ruby-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-ruby-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-ruby-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-ruby-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-script-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-script-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-script-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-script-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-special.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-special.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-special.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-special.ent diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-ssismap-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-struct-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-struct-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-struct-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-struct-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-style-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-style-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-style-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-style-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-symbol.ent b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-symbol.ent similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-symbol.ent rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-symbol.ent diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-table-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-table-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-table-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-table-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-target-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-target-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-target-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-target-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml-text-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-text-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml-text-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml-text-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml11-model-1.mod b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml11-model-1.mod similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml11-model-1.mod rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml11-model-1.mod diff --git a/xml/impl/resources/standardSchemas/xhtml11/xhtml11.dtd b/xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml11.dtd similarity index 100% rename from xml/impl/resources/standardSchemas/xhtml11/xhtml11.dtd rename to xml/xml-psi-impl/resources/standardSchemas/xhtml11/xhtml11.dtd diff --git a/xml/impl/resources/standardSchemas/xinclude.xsd b/xml/xml-psi-impl/resources/standardSchemas/xinclude.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xinclude.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xinclude.xsd diff --git a/xml/impl/resources/standardSchemas/xml.xsd b/xml/xml-psi-impl/resources/standardSchemas/xml.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xml.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xml.xsd diff --git a/xml/impl/resources/standardSchemas/xslt-1_0.xsd b/xml/xml-psi-impl/resources/standardSchemas/xslt-1_0.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xslt-1_0.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xslt-1_0.xsd diff --git a/xml/impl/resources/standardSchemas/xslt-2_0.xsd b/xml/xml-psi-impl/resources/standardSchemas/xslt-2_0.xsd similarity index 100% rename from xml/impl/resources/standardSchemas/xslt-2_0.xsd rename to xml/xml-psi-impl/resources/standardSchemas/xslt-2_0.xsd diff --git a/xml/xml-psi-impl/xml-psi-impl.iml b/xml/xml-psi-impl/xml-psi-impl.iml index 1aa39410f34e..b12b84d69dcf 100644 --- a/xml/xml-psi-impl/xml-psi-impl.iml +++ b/xml/xml-psi-impl/xml-psi-impl.iml @@ -4,6 +4,7 @@ + From 3c39734cab0bb77999153420be9bd5427ae7adc7 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 20:11:38 +0400 Subject: [PATCH 43/47] include non started tests into rerun failed (IDEA-108509) --- .../actions/JavaRerunFailedTestsAction.java | 2 +- .../src/messages/ExecutionBundle.properties | 1 + .../testframework/TestConsoleProperties.java | 1 + .../AbstractRerunFailedTestsAction.java | 3 +++ .../junit2/ui/actions/JUnitToolbarPanel.java | 17 +++++++++++++++++ .../testng/ui/TestNGResults.java | 19 ++++++++++++++++++- 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java index 7bf07bf64518..76e7175b87ff 100644 --- a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java +++ b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java @@ -37,7 +37,7 @@ public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction { @NotNull @Override protected Filter getFilter(Project project, GlobalSearchScope searchScope) { - return Filter.FAILED_OR_INTERRUPTED.and(JavaAwareFilter.METHOD(project, searchScope)); + return super.getFilter(project, searchScope).and(JavaAwareFilter.METHOD(project, searchScope)); } } diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 041c4ff04c0a..ae6a49ac3e4d 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -145,6 +145,7 @@ junit.runing.info.track.test.action.description=Select currently running test in junit.runing.info.collapse.test.action.name=Collapse all test suites junit.runing.info.expand.test.action.name=Expand all test suites junit.runing.info.select.first.failed.action.name=Select First Failed Test When Finished +junit.runing.info.include.non.started.in.rerun.failed.action.name=Include Non-Started Tests into Rerun Failed junit.runing.info.scroll.to.stacktrace.action.name=Scroll to Stacktrace junit.runing.info.scroll.to.stacktrace.action.description=Scroll console to beginning of assertion or exception stacktrace junit.runing.info.open.source.at.exception.action.name=Open Source at Exception diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java index 58f3bbecad53..5d7fe60d2288 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java @@ -50,6 +50,7 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp public static final BooleanProperty OPEN_FAILURE_LINE = new BooleanProperty("openFailureLine", true); public static final BooleanProperty TRACK_CODE_COVERAGE = new BooleanProperty("trackCodeCoverage", false); public static final BooleanProperty SHOW_STATISTICS = new BooleanProperty("showStatistics", false); + public static final BooleanProperty INCLUDE_NON_STARTED_IN_RERUN_FAILED = new BooleanProperty("includeNonStarted", true); private final Project myProject; private final Executor myExecutor; diff --git a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java index dd61fbed941c..8b945eb9203a 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java @@ -150,6 +150,9 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction @NotNull protected Filter getFilter(Project project, GlobalSearchScope searchScope) { + if (TestConsoleProperties.INCLUDE_NON_STARTED_IN_RERUN_FAILED.value(myConsoleProperties)) { + return Filter.NOT_PASSED.or(Filter.FAILED_OR_INTERRUPTED); + } return Filter.FAILED_OR_INTERRUPTED; } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/JUnitToolbarPanel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/actions/JUnitToolbarPanel.java index 492778fc35d3..03c223eac4f6 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/JUnitToolbarPanel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/actions/JUnitToolbarPanel.java @@ -16,6 +16,7 @@ package com.intellij.execution.junit2.ui.actions; +import com.intellij.execution.ExecutionBundle; import com.intellij.execution.Location; import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; import com.intellij.execution.configurations.RunnerSettings; @@ -27,10 +28,12 @@ import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.TestsUIUtil; import com.intellij.execution.testframework.ToolbarPanel; import com.intellij.execution.testframework.actions.ScrollToTestSourceAction; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.project.Project; import com.intellij.pom.Navigatable; import com.intellij.psi.PsiClass; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.config.ToggleBooleanProperty; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -45,6 +48,20 @@ public class JUnitToolbarPanel extends ToolbarPanel { super(properties, runnerSettings, configurationSettings, parentComponent); } + @Override + protected void appendAdditionalActions(DefaultActionGroup actionGroup, + TestConsoleProperties properties, + RunnerSettings runnerSettings, + ConfigurationPerRunnerSettings configurationSettings, + JComponent parent) { + super.appendAdditionalActions(actionGroup, properties, runnerSettings, configurationSettings, parent); + actionGroup.addAction(new ToggleBooleanProperty( + ExecutionBundle.message("junit.runing.info.include.non.started.in.rerun.failed.action.name"), + null, + null, + properties, TestConsoleProperties.INCLUDE_NON_STARTED_IN_RERUN_FAILED)).setAsSecondary(true); + } + public void setModel(final TestFrameworkRunningModel model) { super.setModel(model); diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java index afbd12cbd32d..617d403f915d 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java @@ -23,11 +23,13 @@ package com.theoryinpractice.testng.ui; import com.intellij.codeInsight.AnnotationUtil; +import com.intellij.execution.ExecutionBundle; import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; import com.intellij.execution.configurations.RunnerSettings; import com.intellij.execution.testframework.*; import com.intellij.execution.testframework.actions.ScrollToTestSourceAction; import com.intellij.execution.testframework.ui.TestResultsPanel; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.util.ColorProgressBar; import com.intellij.openapi.project.Project; @@ -41,6 +43,7 @@ import com.intellij.ui.DoubleClickListener; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.table.TableView; import com.intellij.util.OpenSourceUtil; +import com.intellij.util.config.ToggleBooleanProperty; import com.theoryinpractice.testng.configuration.TestNGConfiguration; import com.theoryinpractice.testng.model.*; import com.theoryinpractice.testng.util.TestNGUtil; @@ -148,7 +151,21 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn @Override protected ToolbarPanel createToolbarPanel() { - final ToolbarPanel panel = new ToolbarPanel(getProperties(), myRunnerSettings, myConfigurationSettings, this); + final ToolbarPanel panel = new ToolbarPanel(getProperties(), myRunnerSettings, myConfigurationSettings, this){ + @Override + protected void appendAdditionalActions(DefaultActionGroup actionGroup, + TestConsoleProperties properties, + RunnerSettings runnerSettings, + ConfigurationPerRunnerSettings configurationSettings, + JComponent parent) { + super.appendAdditionalActions(actionGroup, properties, runnerSettings, configurationSettings, parent); + actionGroup.addAction(new ToggleBooleanProperty( + ExecutionBundle.message("junit.runing.info.include.non.started.in.rerun.failed.action.name"), + null, + null, + properties, TestConsoleProperties.INCLUDE_NON_STARTED_IN_RERUN_FAILED)).setAsSecondary(true); + } + }; panel.setModel(this); return panel; } From c56bc67cb6de12e011a3a953a05dcd00b775329f Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 13 Jun 2013 20:40:10 +0400 Subject: [PATCH 44/47] branch popup refactoring for Git and Mercurial *common RootAction and BranchActionGroupPopup moved to separate classes *static methods for getting repository names and relative paths moved from git specific class to DvcsUtil *action for creating new branch refactored as a separate base class for mercurial and git new branch classes --- .../dvcs/src/com/intellij/dvcs/DvcsUtil.java | 47 ++++++ .../dvcs/ui/BranchActionGroupPopup.java | 117 ++++++++++++++ .../com/intellij/dvcs/ui/NewBranchAction.java | 60 +++++++ .../src/com/intellij/dvcs/ui/RootAction.java | 85 ++++++++++ .../git4idea/branch/GitMergeOperation.java | 8 +- .../src/git4idea/push/GitPushLog.java | 4 +- .../git4idea/roots/GitIntegrationEnabler.java | 2 +- ...GitRepositoryComboboxListCellRenderer.java | 4 +- .../git4idea/ui/branch/GitBranchPopup.java | 152 ++---------------- .../ui/branch/GitBranchPopupActions.java | 35 +--- .../ui/branch/GitCompareBranchesDialog.java | 4 +- .../src/git4idea/update/GitFetcher.java | 3 +- .../git4idea/src/git4idea/util/GitUIUtil.java | 42 ----- .../zmlx/hg4idea/action/HgBranchPopup.java | 143 ++-------------- .../hg4idea/action/HgBranchPopupActions.java | 31 +--- 15 files changed, 359 insertions(+), 378 deletions(-) create mode 100644 platform/dvcs/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java create mode 100644 platform/dvcs/src/com/intellij/dvcs/ui/NewBranchAction.java create mode 100644 platform/dvcs/src/com/intellij/dvcs/ui/RootAction.java diff --git a/platform/dvcs/src/com/intellij/dvcs/DvcsUtil.java b/platform/dvcs/src/com/intellij/dvcs/DvcsUtil.java index f305321f15cd..c872f04a998b 100644 --- a/platform/dvcs/src/com/intellij/dvcs/DvcsUtil.java +++ b/platform/dvcs/src/com/intellij/dvcs/DvcsUtil.java @@ -15,13 +15,21 @@ */ package com.intellij.dvcs; +import com.intellij.dvcs.repo.Repository; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.StatusBarWidget; import com.intellij.openapi.wm.WindowManager; +import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; +import java.io.File; +import java.util.Collection; + /** * @author Kirill Likhodedov */ @@ -41,4 +49,43 @@ public class DvcsUtil { } } + @NotNull + public static String getShortRepositoryName(@NotNull Project project, @NotNull VirtualFile root) { + VirtualFile projectDir = project.getBaseDir(); + + String repositoryPath = root.getPresentableUrl(); + if (projectDir != null) { + String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar); + if (relativePath != null) { + repositoryPath = relativePath; + } + } + + return repositoryPath.isEmpty() ? root.getName() : repositoryPath; + } + + @NotNull + public static String getShortRepositoryName(@NotNull Repository repository) { + return getShortRepositoryName(repository.getProject(), repository.getRoot()); + } + + @NotNull + public static String getShortNames(@NotNull Collection repositories) { + return StringUtil.join(repositories, new Function() { + @Override + public String fun(Repository repository) { + return getShortRepositoryName(repository); + } + }, ", "); + } + + @NotNull + public static String joinRootsPaths(@NotNull Collection roots) { + return StringUtil.join(roots, new Function() { + @Override + public String fun(VirtualFile virtualFile) { + return virtualFile.getPresentableUrl(); + } + }, ", "); + } } diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java b/platform/dvcs/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java new file mode 100644 index 000000000000..3edd0c0768f8 --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java @@ -0,0 +1,117 @@ +/* + * Copyright 2000-2013 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.dvcs.ui; + +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.impl.SimpleDataContext; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.PopupStep; +import com.intellij.openapi.util.Condition; +import com.intellij.ui.ErrorLabel; +import com.intellij.ui.JBColor; +import com.intellij.ui.components.panels.OpaquePanel; +import com.intellij.ui.popup.PopupFactoryImpl; +import com.intellij.ui.popup.WizardPopup; +import com.intellij.ui.popup.list.PopupListElementRenderer; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Nadya Zabrodina + */ +public class BranchActionGroupPopup extends PopupFactoryImpl.ActionGroupPopup { + public BranchActionGroupPopup(@NotNull String title, @NotNull Project project, + @NotNull Condition preselectActionCondition, @NotNull ActionGroup actions) { + super(title, actions, SimpleDataContext.getProjectContext(project), false, false, false, true, null, -1, + preselectActionCondition, null); + } + + @Override + protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) { + WizardPopup popup = super.createPopup(parent, step, parentValue); + RootAction rootAction = getRootAction(parentValue); + if (rootAction != null) { + popup.setAdText((rootAction).getCaption()); + } + return popup; + } + + @Nullable + private static RootAction getRootAction(Object value) { + if (value instanceof PopupFactoryImpl.ActionItem) { + AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction(); + if (action instanceof RootAction) { + return (RootAction)action; + } + } + return null; + } + + @Override + protected ListCellRenderer getListElementRenderer() { + return new PopupListElementRenderer(this) { + + private ErrorLabel myBranchLabel; + + @Override + protected void customizeComponent(JList list, Object value, boolean isSelected) { + super.customizeComponent(list, value, isSelected); + + RootAction rootAction = getRootAction(value); + if (rootAction != null) { + myBranchLabel.setVisible(true); + myBranchLabel.setText(String.format("[%s]", rootAction.getBranch())); + + if (isSelected) { + setSelected(myBranchLabel); + } + else { + myBranchLabel.setBackground(getBackground()); + myBranchLabel.setForeground(JBColor.GRAY); // different foreground than for other elements + } + + adjustOpacity(myBranchLabel, isSelected); + } + else { + myBranchLabel.setVisible(false); + } + } + + @Override + protected JComponent createItemComponent() { + myTextLabel = new ErrorLabel(); + myTextLabel.setOpaque(true); + myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); + + myBranchLabel = new ErrorLabel(); + myBranchLabel.setOpaque(true); + myBranchLabel.setBorder(BorderFactory.createEmptyBorder(1, UIUtil.DEFAULT_HGAP, 1, 1)); + + JPanel compoundPanel = new OpaquePanel(new BorderLayout(), JBColor.WHITE); + compoundPanel.add(myTextLabel, BorderLayout.CENTER); + compoundPanel.add(myBranchLabel, BorderLayout.EAST); + + return layoutComponent(compoundPanel); + } + }; + } +} + diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/NewBranchAction.java b/platform/dvcs/src/com/intellij/dvcs/ui/NewBranchAction.java new file mode 100644 index 000000000000..19f1470c72d6 --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/NewBranchAction.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2013 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.dvcs.ui; + +import com.intellij.dvcs.repo.Repository; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; +import com.intellij.util.IconUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author Nadya Zabrodina + */ +public abstract class NewBranchAction extends DumbAwareAction { + protected final List myRepositories; + protected Project myProject; + + public NewBranchAction(@NotNull Project project, @NotNull List repositories) { + super("New Branch", "Create and checkout new branch", IconUtil.getAddIcon()); + myRepositories = repositories; + myProject = project; + } + + + @Override + public void update(AnActionEvent e) { + if (anyRepositoryIsFresh()) { + e.getPresentation().setEnabled(false); + e.getPresentation().setDescription("Checkout of a new branch is not possible before the first commit."); + } + } + + @Override + public abstract void actionPerformed(AnActionEvent e); + + private boolean anyRepositoryIsFresh() { + for (Repository repository : myRepositories) { + if (repository.isFresh()) { + return true; + } + } + return false; + } +} diff --git a/platform/dvcs/src/com/intellij/dvcs/ui/RootAction.java b/platform/dvcs/src/com/intellij/dvcs/ui/RootAction.java new file mode 100644 index 000000000000..a2a2f4961243 --- /dev/null +++ b/platform/dvcs/src/com/intellij/dvcs/ui/RootAction.java @@ -0,0 +1,85 @@ +/* + * Copyright 2000-2013 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.dvcs.ui; + +import com.intellij.dvcs.DvcsUtil; +import com.intellij.dvcs.repo.Repository; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Nadya Zabrodina + */ +public class RootAction extends ActionGroup { + + @NotNull protected final T myRepository; + @NotNull private ActionGroup myGroup; + @NotNull private String myBranchText; + @NotNull private String myBranchOrRev; + + + /** + * @param currentRepository Pass null in the case of common repositories - none repository will be highlighted then. + * @param actionsGroup + * @param branchText + * @param branchName + */ + public RootAction(@NotNull T repository, + @Nullable T currentRepository, + @NotNull ActionGroup actionsGroup, + @NotNull String branchText, + @NotNull String branchName) { + super(DvcsUtil.getShortRepositoryName(repository), true); + myRepository = repository; + myGroup = actionsGroup; + myBranchText = branchText; + myBranchOrRev = branchName; + if (repository.equals(currentRepository)) { + getTemplatePresentation().setIcon(PlatformIcons.CHECK_ICON); + } + } + + + @NotNull + public String getCaption() { + return "Current branch in " + DvcsUtil.getShortRepositoryName(myRepository) + ": " + + getDisplayableBranchText(); + } + + @NotNull + private String getDisplayableBranchText() { + return myBranchText; + } + + @NotNull + public String getBranch() { + return myBranchOrRev; + } + + @NotNull + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { + return myGroup.getChildren(e); + } +} + + + + diff --git a/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java b/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java index 306995b24135..fadba7dabc25 100644 --- a/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java +++ b/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java @@ -15,6 +15,7 @@ */ package git4idea.branch; +import com.intellij.dvcs.DvcsUtil; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; @@ -35,7 +36,6 @@ import git4idea.merge.GitMergeCommittingConflictResolver; import git4idea.merge.GitMerger; import git4idea.repo.GitRepository; import git4idea.util.GitPreservingProcess; -import git4idea.util.GitUIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.event.HyperlinkEvent; @@ -275,9 +275,9 @@ class GitMergeOperation extends GitBranchOperation { } } - LOG.info("for smart rollback: " + GitUIUtil.getShortNames(repositoriesForSmartRollback) + - "; for simple rollback: " + GitUIUtil.getShortNames(repositoriesForSimpleRollback) + - "; for merge rollback: " + GitUIUtil.getShortNames(repositoriesForMergeRollback)); + LOG.info("for smart rollback: " + DvcsUtil.getShortNames(repositoriesForSmartRollback) + + "; for simple rollback: " + DvcsUtil.getShortNames(repositoriesForSimpleRollback) + + "; for merge rollback: " + DvcsUtil.getShortNames(repositoriesForMergeRollback)); GitCompoundResult result = smartRollback(repositoriesForSmartRollback); for (GitRepository repository : repositoriesForSimpleRollback) { diff --git a/plugins/git4idea/src/git4idea/push/GitPushLog.java b/plugins/git4idea/src/git4idea/push/GitPushLog.java index a471eb40d15a..d8da16b1315d 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushLog.java +++ b/plugins/git4idea/src/git4idea/push/GitPushLog.java @@ -15,6 +15,7 @@ */ package git4idea.push; +import com.intellij.dvcs.DvcsUtil; import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.actionSystem.DataSink; @@ -34,7 +35,6 @@ import git4idea.GitBranch; import git4idea.GitCommit; import git4idea.GitUtil; import git4idea.repo.GitRepository; -import git4idea.util.GitUIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -362,7 +362,7 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider { renderer.setToolTipText(getHashString(commit) + " " + getDateString(commit)); } else if (userObject instanceof GitRepository) { - String repositoryPath = GitUIUtil.getShortRepositoryName((GitRepository)userObject); + String repositoryPath = DvcsUtil.getShortRepositoryName((GitRepository)userObject); renderer.append(repositoryPath, SimpleTextAttributes.GRAY_ATTRIBUTES); } else if (userObject instanceof GitPushBranchInfo) { diff --git a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java index 07da8828440f..32c3b686f578 100644 --- a/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java +++ b/plugins/git4idea/src/git4idea/roots/GitIntegrationEnabler.java @@ -31,8 +31,8 @@ import org.jetbrains.annotations.NotNull; import java.util.*; +import static com.intellij.dvcs.DvcsUtil.joinRootsPaths; import static com.intellij.openapi.util.text.StringUtil.pluralize; -import static git4idea.util.GitUIUtil.joinRootsPaths; /** * @author Kirill Likhodedov diff --git a/plugins/git4idea/src/git4idea/ui/GitRepositoryComboboxListCellRenderer.java b/plugins/git4idea/src/git4idea/ui/GitRepositoryComboboxListCellRenderer.java index 92532bfd78c1..822b90e58df4 100644 --- a/plugins/git4idea/src/git4idea/ui/GitRepositoryComboboxListCellRenderer.java +++ b/plugins/git4idea/src/git4idea/ui/GitRepositoryComboboxListCellRenderer.java @@ -15,9 +15,9 @@ */ package git4idea.ui; +import com.intellij.dvcs.DvcsUtil; import com.intellij.ui.ListCellRendererWrapper; import git4idea.repo.GitRepository; -import git4idea.util.GitUIUtil; import javax.swing.*; @@ -37,7 +37,7 @@ public class GitRepositoryComboboxListCellRenderer extends ListCellRendererWrapp @Override public void customize(JList list, GitRepository value, int index, boolean selected, boolean hasFocus) { - setText(GitUIUtil.getShortRepositoryName(value)); + setText(DvcsUtil.getShortRepositoryName(value)); } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java index d6c11a3f69eb..50e2e9622c36 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java @@ -15,54 +15,44 @@ */ package git4idea.ui.branch; +import com.intellij.dvcs.DvcsUtil; +import com.intellij.dvcs.ui.BranchActionGroupPopup; +import com.intellij.dvcs.ui.RootAction; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.openapi.actionSystem.ActionGroup; 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.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.util.Condition; -import com.intellij.ui.ErrorLabel; -import com.intellij.ui.JBColor; -import com.intellij.ui.components.panels.OpaquePanel; -import com.intellij.ui.popup.PopupFactoryImpl; -import com.intellij.ui.popup.WizardPopup; import com.intellij.ui.popup.list.ListPopupImpl; -import com.intellij.ui.popup.list.PopupListElementRenderer; -import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.UIUtil; import git4idea.GitUtil; import git4idea.GitVcs; import git4idea.branch.GitBranchUtil; import git4idea.config.GitVcsSettings; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; -import git4idea.util.GitUIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; -import java.awt.*; import java.util.List; /** *

- * The popup which allows to quickly switch and control Git branches. + * The popup which allows to quickly switch and control Git branches. *

*

- * Use {@link #asListPopup()} to achieve the {@link ListPopup} itself. + * Use {@link #asListPopup()} to achieve the {@link ListPopup} itself. *

- * + * * @author Kirill Likhodedov */ -class GitBranchPopup { +class GitBranchPopup { private final Project myProject; private final GitRepositoryManager myRepositoryManager; @@ -121,7 +111,7 @@ class GitBranchPopup { } }; - myPopup = new GitBranchActionGroupPopup(title, project, preselectActionCondition); + myPopup = new BranchActionGroupPopup(title, project, preselectActionCondition, createActions()); initBranchSyncPolicyIfNotInitialized(); setCurrentBranchInfo(); @@ -145,7 +135,7 @@ class GitBranchPopup { String title = "Git Branches"; if (myRepositoryManager.moreThanOneRoot() && (myMultiRootBranchConfig.diverged() || myVcsSettings.getSyncSetting() == GitBranchSyncSetting.DONT)) { - title += " in " + GitUIUtil.getShortRepositoryName(currentRepository); + title += " in " + DvcsUtil.getShortRepositoryName(currentRepository); } return title; } @@ -154,7 +144,7 @@ class GitBranchPopup { String currentBranchText = "Current branch"; if (myRepositoryManager.moreThanOneRoot()) { if (myMultiRootBranchConfig.diverged()) { - currentBranchText += " in " + GitUIUtil.getShortRepositoryName(myCurrentRepository) + ": " + + currentBranchText += " in " + DvcsUtil.getShortRepositoryName(myCurrentRepository) + ": " + GitBranchUtil.getDisplayableBranchText(myCurrentRepository); } else { @@ -196,7 +186,7 @@ class GitBranchPopup { else { fillPopupWithCurrentRepositoryActions(popupGroup, createRepositoriesActions()); } - } + } else { fillPopupWithCurrentRepositoryActions(popupGroup, null); } @@ -213,7 +203,7 @@ class GitBranchPopup { List repositories = repositoryManager.getRepositories(); String currentBranch = myMultiRootBranchConfig.getCurrentBranch(); assert currentBranch != null : "Current branch can't be null if branches have not diverged"; - popupGroup.add(new GitBranchPopupActions.NewBranchAction(myProject, repositories)); + popupGroup.add(new GitBranchPopupActions.GitNewBranchAction(myProject, repositories)); popupGroup.addAll(createRepositoriesActions()); @@ -240,7 +230,10 @@ class GitBranchPopup { DefaultActionGroup popupGroup = new DefaultActionGroup(null, false); popupGroup.addSeparator("Repositories"); for (GitRepository repository : myRepositoryManager.getRepositories()) { - popupGroup.add(new RootAction(repository, highlightCurrentRepo() ? myCurrentRepository : null)); + popupGroup.add(new RootAction(repository, highlightCurrentRepo() ? myCurrentRepository : null, + new GitBranchPopupActions(repository.getProject(), repository).createActions(null), + GitBranchUtil.getDisplayableBranchText(repository), + GitBranchUtil.getBranchNameOrRev(repository))); } return popupGroup; } @@ -252,117 +245,4 @@ class GitBranchPopup { private void fillPopupWithCurrentRepositoryActions(@NotNull DefaultActionGroup popupGroup, @Nullable DefaultActionGroup actions) { popupGroup.addAll(new GitBranchPopupActions(myCurrentRepository.getProject(), myCurrentRepository).createActions(actions)); } - - private static class RootAction extends ActionGroup { - - private final GitRepository myRepository; - - /** - * @param currentRepository Pass null in the case of common repositories - none repository will be highlighted then. - */ - RootAction(@NotNull GitRepository repository, @Nullable GitRepository currentRepository) { - super(GitUIUtil.getShortRepositoryName(repository), true); - myRepository = repository; - if (repository.equals(currentRepository)) { - getTemplatePresentation().setIcon(PlatformIcons.CHECK_ICON); - } - } - - @NotNull - @Override - public AnAction[] getChildren(@Nullable AnActionEvent e) { - ActionGroup group = new GitBranchPopupActions(myRepository.getProject(), myRepository).createActions(null); - return group.getChildren(e); - } - - @NotNull - public String getCaption() { - return "Current branch in " + GitUIUtil.getShortRepositoryName(myRepository) + ": " + - GitBranchUtil.getDisplayableBranchText(myRepository); - } - - @NotNull - public String getBranch() { - return GitBranchUtil.getBranchNameOrRev(myRepository); - } - } - - private class GitBranchActionGroupPopup extends PopupFactoryImpl.ActionGroupPopup { - public GitBranchActionGroupPopup(@NotNull String title, @NotNull Project project, - @NotNull Condition preselectActionCondition) { - super(title, GitBranchPopup.this.createActions(), SimpleDataContext.getProjectContext(project), false, false, false, true, null, -1, - preselectActionCondition, null); - } - - @Override - protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) { - WizardPopup popup = super.createPopup(parent, step, parentValue); - RootAction rootAction = getRootAction(parentValue); - if (rootAction != null) { - popup.setAdText((rootAction).getCaption()); - } - return popup; - } - - @Nullable - private RootAction getRootAction(Object value) { - if (value instanceof PopupFactoryImpl.ActionItem) { - AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction(); - if (action instanceof RootAction) { - return (RootAction)action; - } - } - return null; - } - - @Override - protected ListCellRenderer getListElementRenderer() { - return new PopupListElementRenderer(this) { - - private ErrorLabel myBranchLabel; - - @Override - protected void customizeComponent(JList list, Object value, boolean isSelected) { - super.customizeComponent(list, value, isSelected); - - RootAction rootAction = getRootAction(value); - if (rootAction != null) { - myBranchLabel.setVisible(true); - myBranchLabel.setText(String.format("[%s]", rootAction.getBranch())); - - if (isSelected) { - setSelected(myBranchLabel); - } - else { - myBranchLabel.setBackground(getBackground()); - myBranchLabel.setForeground(JBColor.GRAY); // different foreground than for other elements - } - - adjustOpacity(myBranchLabel, isSelected); - } - else { - myBranchLabel.setVisible(false); - } - } - - @Override - protected JComponent createItemComponent() { - myTextLabel = new ErrorLabel(); - myTextLabel.setOpaque(true); - myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - - myBranchLabel = new ErrorLabel(); - myBranchLabel.setOpaque(true); - myBranchLabel.setBorder(BorderFactory.createEmptyBorder(1, UIUtil.DEFAULT_HGAP, 1, 1)); - - JPanel compoundPanel = new OpaquePanel(new BorderLayout(), Color.white); - compoundPanel.add(myTextLabel, BorderLayout.CENTER); - compoundPanel.add(myBranchLabel, BorderLayout.EAST); - - return layoutComponent(compoundPanel); - } - - }; - } - } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java index 5d57ab1b4122..dbd3f8c902e5 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java @@ -15,16 +15,15 @@ */ package git4idea.ui.branch; +import com.intellij.dvcs.ui.NewBranchAction; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -import com.intellij.util.IconUtil; import git4idea.GitBranch; import git4idea.branch.GitBranchUtil; import git4idea.branch.GitBrancher; @@ -43,7 +42,6 @@ import java.util.List; */ class GitBranchPopupActions { - private static final Logger LOG = Logger.getInstance(GitBranchPopupActions.class); private final Project myProject; private final GitRepository myRepository; @@ -55,7 +53,7 @@ class GitBranchPopupActions { ActionGroup createActions(@Nullable DefaultActionGroup toInsert) { DefaultActionGroup popupGroup = new DefaultActionGroup(null, false); - popupGroup.addAction(new NewBranchAction(myProject, Collections.singletonList(myRepository))); + popupGroup.addAction(new GitNewBranchAction(myProject,Collections.singletonList(myRepository))); popupGroup.addAction(new CheckoutRevisionActions(myProject, myRepository)); if (toInsert != null) { @@ -80,15 +78,11 @@ class GitBranchPopupActions { return popupGroup; } - - static class NewBranchAction extends DumbAwareAction { - private final Project myProject; - private final List myRepositories; - NewBranchAction(@NotNull Project project, @NotNull List repositories) { - super("New Branch", "Create and checkout new branch", IconUtil.getAddIcon()); - myProject = project; - myRepositories = repositories; + public static class GitNewBranchAction extends NewBranchAction { + + public GitNewBranchAction(@NotNull Project project, @NotNull List repositories) { + super(project, repositories); } @Override @@ -99,23 +93,6 @@ class GitBranchPopupActions { brancher.checkoutNewBranch(name, myRepositories); } } - - @Override - public void update(AnActionEvent e) { - if (anyRepositoryIsFresh()) { - e.getPresentation().setEnabled(false); - e.getPresentation().setDescription("Checkout of a new branch is not possible before the first commit."); - } - } - - private boolean anyRepositoryIsFresh() { - for (GitRepository repository : myRepositories) { - if (repository.isFresh()) { - return true; - } - } - return false; - } } /** diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java index 06d6a8358b0c..d9cbbd781f1c 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitCompareBranchesDialog.java @@ -15,6 +15,7 @@ */ package git4idea.ui.branch; +import com.intellij.dvcs.DvcsUtil; import com.intellij.icons.AllIcons; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -22,7 +23,6 @@ import com.intellij.ui.TabbedPaneImpl; import git4idea.GitUtil; import git4idea.repo.GitRepository; import git4idea.util.GitCommitCompareInfo; -import git4idea.util.GitUIUtil; import icons.Git4ideaIcons; import org.jetbrains.annotations.NotNull; @@ -52,7 +52,7 @@ public class GitCompareBranchesDialog extends DialogWrapper { String rootString; if (compareInfo.getRepositories().size() == 1 && GitUtil.getRepositoryManager(myProject).moreThanOneRoot()) { - rootString = " in root " + GitUIUtil.getShortRepositoryName(initialRepo); + rootString = " in root " + DvcsUtil.getShortRepositoryName(initialRepo); } else { rootString = ""; diff --git a/plugins/git4idea/src/git4idea/update/GitFetcher.java b/plugins/git4idea/src/git4idea/update/GitFetcher.java index 7925ca720362..758797404008 100644 --- a/plugins/git4idea/src/git4idea/update/GitFetcher.java +++ b/plugins/git4idea/src/git4idea/update/GitFetcher.java @@ -15,6 +15,7 @@ */ package git4idea.update; +import com.intellij.dvcs.DvcsUtil; import com.intellij.notification.NotificationType; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -351,7 +352,7 @@ public class GitFetcher { StringBuilder info = new StringBuilder(); if (myRepositoryManager.moreThanOneRoot()) { for (Map.Entry entry : additionalInfo.entrySet()) { - info.append(entry.getValue()).append(" in ").append(GitUIUtil.getShortRepositoryName(myProject, entry.getKey())).append("
"); + info.append(entry.getValue()).append(" in ").append(DvcsUtil.getShortRepositoryName(myProject, entry.getKey())).append("
"); } } else { diff --git a/plugins/git4idea/src/git4idea/util/GitUIUtil.java b/plugins/git4idea/src/git4idea/util/GitUIUtil.java index 7ca621ae11c7..a9c88ee53ec5 100644 --- a/plugins/git4idea/src/git4idea/util/GitUIUtil.java +++ b/plugins/git4idea/src/git4idea/util/GitUIUtil.java @@ -23,10 +23,8 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ListCellRendererWrapper; -import com.intellij.util.Function; import git4idea.GitBranch; import git4idea.GitUtil; import git4idea.GitVcs; @@ -39,7 +37,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.File; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -393,43 +390,4 @@ public class GitUIUtil { return String.format("<%2$s>%1$s", s, tag); } - @NotNull - public static String getShortRepositoryName(@NotNull Project project, @NotNull VirtualFile root) { - VirtualFile projectDir = project.getBaseDir(); - - String repositoryPath = root.getPresentableUrl(); - if (projectDir != null) { - String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar); - if (relativePath != null) { - repositoryPath = relativePath; - } - } - - return repositoryPath.isEmpty() ? root.getName() : repositoryPath; - } - - @NotNull - public static String getShortRepositoryName(@NotNull GitRepository repository) { - return getShortRepositoryName(repository.getProject(), repository.getRoot()); - } - - @NotNull - public static String getShortNames(@NotNull Collection repositories) { - return StringUtil.join(repositories, new Function() { - @Override - public String fun(GitRepository repository) { - return getShortRepositoryName(repository); - } - }, ", "); - } - - @NotNull - public static String joinRootsPaths(@NotNull Collection roots) { - return StringUtil.join(roots, new Function() { - @Override - public String fun(VirtualFile virtualFile) { - return virtualFile.getPresentableUrl(); - } - }, ", "); - } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopup.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopup.java index 7975847b8435..87ba6f4555b2 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopup.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopup.java @@ -15,25 +15,17 @@ */ package org.zmlx.hg4idea.action; +import com.intellij.dvcs.DvcsUtil; +import com.intellij.dvcs.ui.BranchActionGroupPopup; +import com.intellij.dvcs.ui.RootAction; import com.intellij.openapi.actionSystem.ActionGroup; 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.project.Project; import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.ErrorLabel; -import com.intellij.ui.JBColor; -import com.intellij.ui.components.panels.OpaquePanel; -import com.intellij.ui.popup.PopupFactoryImpl; -import com.intellij.ui.popup.WizardPopup; import com.intellij.ui.popup.list.ListPopupImpl; -import com.intellij.ui.popup.list.PopupListElementRenderer; -import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.repo.HgRepository; @@ -41,7 +33,6 @@ import org.zmlx.hg4idea.repo.HgRepositoryImpl; import org.zmlx.hg4idea.util.HgUtil; import javax.swing.*; -import java.awt.*; /** *

@@ -82,9 +73,7 @@ public class HgBranchPopup { return false; } }; - - myPopup = new HgBranchActionGroupPopup(title, project, preselectActionCondition); - + myPopup = new BranchActionGroupPopup(title, project, preselectActionCondition, createActions()); setCurrentBranchInfo(); } @@ -92,9 +81,7 @@ public class HgBranchPopup { @NotNull private static String createPopupTitle(@NotNull HgRepository currentRepository) { String title = "Hg Branches"; - - title += " in " + currentRepository.getRoot().getName(); - + title += " in " + DvcsUtil.getShortRepositoryName(currentRepository); return title; } @@ -119,126 +106,16 @@ public class HgBranchPopup { popupGroup.addSeparator("Repositories"); for (VirtualFile repository : HgUtil.getHgRepositories(myProject)) { HgRepository repo = HgRepositoryImpl.getFullInstance(repository, myProject, myProject); - popupGroup.add(new RootAction(repo, null)); + popupGroup.add(new RootAction(repo, null, + new HgBranchPopupActions(repo.getProject(), repo).createActions(null), + HgUtil.getDisplayableBranchText(repo), + repo.getCurrentBranch())); } return popupGroup; } - - private void fillPopupWithCurrentRepositoryActions(@NotNull DefaultActionGroup popupGroup, @Nullable DefaultActionGroup actions) { + protected void fillPopupWithCurrentRepositoryActions(@NotNull DefaultActionGroup popupGroup, @Nullable DefaultActionGroup actions) { popupGroup.addAll(new HgBranchPopupActions(myProject, myCurrentRepository).createActions(actions)); } - - private static class RootAction extends ActionGroup { - - private final HgRepository myRepository; - - /** - * @param currentRepository Pass null in the case of common repositories - none repository will be highlighted then. - */ - RootAction(@NotNull HgRepository repository, @Nullable HgRepository currentRepository) { - super(repository.getRoot().getName(), true); - myRepository = repository; - if (repository.equals(currentRepository)) { - getTemplatePresentation().setIcon(PlatformIcons.CHECK_ICON); - } - } - - @NotNull - @Override - public AnAction[] getChildren(@Nullable AnActionEvent e) { - ActionGroup group = new HgBranchPopupActions(myRepository.getProject(), myRepository).createActions(null); - return group.getChildren(e); - } - - @NotNull - public String getCaption() { - String captionText = "Current branch in " + myRepository.getRoot().getName() + ": "; - return captionText + HgUtil.getDisplayableBranchText(myRepository); - } - - @NotNull - public String getBranch() { - return myRepository.getCurrentBranch(); - } - } - - private class HgBranchActionGroupPopup extends PopupFactoryImpl.ActionGroupPopup { - public HgBranchActionGroupPopup(@NotNull String title, @NotNull Project project, - @NotNull Condition preselectActionCondition) { - super(title, HgBranchPopup.this.createActions(), SimpleDataContext.getProjectContext(project), false, false, false, true, null, -1, - preselectActionCondition, null); - } - - @Override - protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) { - WizardPopup popup = super.createPopup(parent, step, parentValue); - RootAction rootAction = getRootAction(parentValue); - if (rootAction != null) { - popup.setAdText((rootAction).getCaption()); - } - return popup; - } - - @Nullable - private RootAction getRootAction(Object value) { - if (value instanceof PopupFactoryImpl.ActionItem) { - AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction(); - if (action instanceof RootAction) { - return (RootAction)action; - } - } - return null; - } - - @Override - protected ListCellRenderer getListElementRenderer() { - return new PopupListElementRenderer(this) { - - private ErrorLabel myBranchLabel; - - @Override - protected void customizeComponent(JList list, Object value, boolean isSelected) { - super.customizeComponent(list, value, isSelected); - - RootAction rootAction = getRootAction(value); - if (rootAction != null) { - myBranchLabel.setVisible(true); - myBranchLabel.setText(String.format("[%s]", rootAction.getBranch())); - - if (isSelected) { - setSelected(myBranchLabel); - } - else { - myBranchLabel.setBackground(getBackground()); - myBranchLabel.setForeground(JBColor.GRAY); // different foreground than for other elements - } - - adjustOpacity(myBranchLabel, isSelected); - } - else { - myBranchLabel.setVisible(false); - } - } - - @Override - protected JComponent createItemComponent() { - myTextLabel = new ErrorLabel(); - myTextLabel.setOpaque(true); - myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - - myBranchLabel = new ErrorLabel(); - myBranchLabel.setOpaque(true); - myBranchLabel.setBorder(BorderFactory.createEmptyBorder(1, UIUtil.DEFAULT_HGAP, 1, 1)); - - JPanel compoundPanel = new OpaquePanel(new BorderLayout(), Color.white); - compoundPanel.add(myTextLabel, BorderLayout.CENTER); - compoundPanel.add(myBranchLabel, BorderLayout.EAST); - - return layoutComponent(compoundPanel); - } - }; - } - } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java index 81eb20400cc8..79c3ca32bf3a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgBranchPopupActions.java @@ -15,6 +15,7 @@ */ package org.zmlx.hg4idea.action; +import com.intellij.dvcs.ui.NewBranchAction; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -23,7 +24,6 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.update.UpdatedFiles; -import com.intellij.util.IconUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgRevisionNumber; @@ -59,7 +59,7 @@ public class HgBranchPopupActions { ActionGroup createActions(@Nullable DefaultActionGroup toInsert) { DefaultActionGroup popupGroup = new DefaultActionGroup(null, false); - popupGroup.addAction(new NewBranchAction(myProject, Collections.singletonList(myRepository))); + popupGroup.addAction(new HgNewBranchAction(myProject, Collections.singletonList(myRepository))); if (toInsert != null) { popupGroup.addAll(toInsert); @@ -76,14 +76,10 @@ public class HgBranchPopupActions { return popupGroup; } - static class NewBranchAction extends DumbAwareAction { - private final Project myProject; - private final List myRepositories; + public static class HgNewBranchAction extends NewBranchAction { - NewBranchAction(@NotNull Project project, @NotNull List repositories) { - super("New Branch", "Create and checkout new branch", IconUtil.getAddIcon()); - myProject = project; - myRepositories = repositories; + HgNewBranchAction(@NotNull Project project, @NotNull List repositories) { + super(project, repositories); } @Override @@ -106,23 +102,6 @@ public class HgBranchPopupActions { HgAbstractGlobalAction.handleException(myProject, exception); } } - - @Override - public void update(AnActionEvent e) { - if (anyRepositoryIsFresh()) { - e.getPresentation().setEnabled(false); - e.getPresentation().setDescription("Checkout of a new branch is not possible before the first commit."); - } - } - - private boolean anyRepositoryIsFresh() { - for (HgRepository repository : myRepositories) { - if (repository.isFresh()) { - return true; - } - } - return false; - } } From c40eb56628d26e60c9bc0cbf7a9362c7131b5a1e Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 13 Jun 2013 18:43:50 +0200 Subject: [PATCH 45/47] test for IDEA-100439 --- .../pom/tree/events/impl/TreeChangeImpl.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeImpl.java b/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeImpl.java index 684fb56e7c0b..c3ac3b0c4e37 100644 --- a/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeImpl.java +++ b/platform/core-impl/src/com/intellij/pom/tree/events/impl/TreeChangeImpl.java @@ -122,17 +122,17 @@ public class TreeChangeImpl implements TreeChange { } myChanges.put(child, info); } - - private static boolean ourDoAddChangeAtOffsetChecks = ourDoChecks; + + private static boolean ourEnableAddChangeAtOffsetOptimization = true; private void addChangeAtOffset(final ASTNode child, final int nodeOffset) { int optimizedIndex = haveNotCalculated; - if (mySortedChanges.size() > 0) { // check adding at end + if (ourEnableAddChangeAtOffsetOptimization && mySortedChanges.size() > 0) { // check adding at end Pair pair = mySortedChanges.get(mySortedChanges.size() - 1); if (pair.getFirst() == child.getTreePrev() && pair.getSecond() <= nodeOffset) { optimizedIndex = mySortedChanges.size(); - if (!ourDoAddChangeAtOffsetChecks) { + if (!ourDoChecks) { mySortedChanges.add(new Pair(child, Integer.valueOf(nodeOffset))); return; } @@ -157,7 +157,7 @@ public class TreeChangeImpl implements TreeChange { ChangeInfo changeInfo = myChanges.get(child); ASTNode prev = child.getTreePrev(); LOG.error("Failed to calculate optimized index for add change at offset:"+changeInfo + "," + prev + "," + myChanges.get(prev)); - ourDoAddChangeAtOffsetChecks = false; + ourEnableAddChangeAtOffsetOptimization = false; } } } @@ -330,9 +330,11 @@ public class TreeChangeImpl implements TreeChange { private static final int haveNotCalculated = -1; - private static boolean ourDoOptimizedNodeOldOffsetChecks = ourDoChecks; + private static boolean ourEnableOptimizedNodeOldOffset = true; private int getOptimizedNodeOldOffset(ASTNode child, ChangeInfo changeInfo) { + if (!ourEnableOptimizedNodeOldOffset) return haveNotCalculated; + // we usually add / remove ranges so old offset can be tried to calculate from change with previous sibling ASTNode prevSibling = child.getTreePrev(); if (prevSibling != null) { @@ -349,11 +351,11 @@ public class TreeChangeImpl implements TreeChange { ) ) { int optimizedResult = pair.getSecond() + prevSiblingChange.getOldLength(); - if (ourDoOptimizedNodeOldOffsetChecks) { + if (ourDoChecks) { int oldOffset = calculateOldOffsetLinearly(child); if (optimizedResult != oldOffset) { LOG.error("Failed optimized node old offset check:"+changeInfo + ", previous:" + prevSibling + "," + prevSiblingChange); - ourDoOptimizedNodeOldOffsetChecks = false; + ourEnableOptimizedNodeOldOffset = false; optimizedResult = oldOffset; } } @@ -412,27 +414,30 @@ public class TreeChangeImpl implements TreeChange { private int myLastOffsetInNewTree; private ASTNode myLastNode; - private static boolean ourDoGetNewOffsetChecks = ourDoChecks; + private static boolean ourEnableGetNewOffset = true; private int getNewOffset(ASTNode node){ int optimizedResult = haveNotCalculated; - ASTNode prev = node.getTreePrev(); - if (myLastNode == prev) { - ChangeInfo prevChangeInfo = myChanges.get(prev); - ChangeInfo changeInfo = myChanges.get(node); + ASTNode prev = null; + if (ourEnableGetNewOffset) { + prev = node.getTreePrev(); + if (myLastNode == prev) { + ChangeInfo prevChangeInfo = myChanges.get(prev); + ChangeInfo changeInfo = myChanges.get(node); - // newoffset of removed element is the same of removed previous sibling - if (prevChangeInfo != null && - changeInfo != null && - prevChangeInfo.getChangeType() == ChangeInfo.REMOVED && - changeInfo.getChangeType() == ChangeInfo.REMOVED - ) { - optimizedResult = myLastOffsetInNewTree; + // newoffset of removed element is the same of removed previous sibling + if (prevChangeInfo != null && + changeInfo != null && + prevChangeInfo.getChangeType() == ChangeInfo.REMOVED && + changeInfo.getChangeType() == ChangeInfo.REMOVED + ) { + optimizedResult = myLastOffsetInNewTree; - myLastNode = node; - myLastOffsetInNewTree = optimizedResult; - if (!ourDoGetNewOffsetChecks) return optimizedResult; + myLastNode = node; + myLastOffsetInNewTree = optimizedResult; + if (!ourDoChecks) return optimizedResult; + } } } @@ -475,11 +480,10 @@ public class TreeChangeImpl implements TreeChange { } } finally { - if (ourDoGetNewOffsetChecks && - optimizedResult != haveNotCalculated && + if (optimizedResult != haveNotCalculated && optimizedResult != currentOffsetInNewTree) { LOG.error("Failed to calculate optimized getNewOffset:"+myChanges.get(node) + "," + prev + "," + myChanges.get(prev)); - ourDoGetNewOffsetChecks = false; + ourEnableGetNewOffset = false; } } From 519b18122e52d92958dbba9a447ba279f9f59a9e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Jun 2013 21:05:33 +0400 Subject: [PATCH 46/47] allow refs to inner classes inside anonymous classes in super/this calls (IDEA-108920) --- .../daemon/impl/analysis/HighlightUtil.java | 5 ++++ .../ReferenceMemberBeforeCtrCalled.java | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 5354932c4201..55055c93b83c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1936,6 +1936,11 @@ public class HighlightUtil extends HighlightUtilBase { !thisOrSuperReference(((PsiReferenceExpression)expression).getQualifierExpression(), aClass)) { return null; } + + if (expression instanceof PsiJavaCodeReferenceElement && !aClass.equals(PsiTreeUtil.getParentOfType(expression, PsiClass.class))) { + return null; + } + final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange()); if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(aClass)) { final String referenceName = ((PsiReferenceExpression)expression).getReferenceName(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java index fec91bc2dbb6..bafdc02117c7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java @@ -1,5 +1,7 @@ // reference before ctr called import java.io.*; +import java.lang.Override; +import java.lang.String; import java.net.*; class A { @@ -171,4 +173,32 @@ class WithAnonymous { } } +} + +class InnerClassRefInsideAnonymous { + static class Foo {} + static class SuperClass { + SuperClass(Foo foo) { + } + + SuperClass(String s, Foo foo) { + } + } + + static class Child extends SuperClass { + Child(Foo foo) { + super(new Foo() { + public String toString() { + AFoo afoo = null; + return super.toString(); + } + }); + } + + Child(String s, Foo foo) { + super(s, new AFoo()); + } + + class AFoo extends Foo {} + } } \ No newline at end of file From bc5c30ace2336bf3fe7c4c95971cc991101ea462 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 13 Jun 2013 19:26:48 +0200 Subject: [PATCH 47/47] if batch vfs update was large enough, rebuild the directoryindex from scratch --- .../impl/BulkVirtualFileListenerAdapter.java | 28 +++---- .../roots/impl/DirectoryIndexImpl.java | 75 +++++++++++++++++-- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java b/platform/core-api/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java index b695b651e51f..077fa0ffb2b9 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/impl/BulkVirtualFileListenerAdapter.java @@ -44,7 +44,7 @@ public class BulkVirtualFileListenerAdapter implements BulkFileListener { public void before(@NotNull final List events) { for (VFileEvent event : events) { if (myFileSystem == null || myFileSystem == event.getFileSystem()) { - fireBefore(event); + fireBefore(myAdapted, event); } } } @@ -53,16 +53,16 @@ public class BulkVirtualFileListenerAdapter implements BulkFileListener { public void after(@NotNull final List events) { for (VFileEvent event : events) { if (myFileSystem == null || myFileSystem == event.getFileSystem()) { - fireAfter(event); + fireAfter(myAdapted, event); } } } - private void fireAfter(final VFileEvent event) { + public static void fireAfter(VirtualFileListener adapted, final VFileEvent event) { if (event instanceof VFileContentChangeEvent) { final VFileContentChangeEvent ce = (VFileContentChangeEvent)event; final VirtualFile file = ce.getFile(); - myAdapted.contentsChanged( + adapted.contentsChanged( new VirtualFileEvent(event.getRequestor(), file, file.getParent(), ce.getOldModificationStamp(), ce.getModificationStamp())); } else if (event instanceof VFileCopyEvent) { @@ -70,49 +70,49 @@ public class BulkVirtualFileListenerAdapter implements BulkFileListener { final VirtualFile original = ce.getFile(); final VirtualFile copy = ce.getNewParent().findChild(ce.getNewChildName()); if (original != null && copy != null) { - myAdapted.fileCopied(new VirtualFileCopyEvent(event.getRequestor(), original, copy)); + adapted.fileCopied(new VirtualFileCopyEvent(event.getRequestor(), original, copy)); } } else if (event instanceof VFileCreateEvent) { final VFileCreateEvent ce = (VFileCreateEvent)event; final VirtualFile newChild = ce.getFile(); if (newChild != null) { - myAdapted.fileCreated(new VirtualFileEvent(event.getRequestor(), newChild, ce.getChildName(), ce.getParent())); + adapted.fileCreated(new VirtualFileEvent(event.getRequestor(), newChild, ce.getChildName(), ce.getParent())); } } else if (event instanceof VFileDeleteEvent) { final VFileDeleteEvent de = (VFileDeleteEvent)event; - myAdapted.fileDeleted(new VirtualFileEvent(event.getRequestor(), de.getFile(), de.getFile().getParent(), 0, 0)); + adapted.fileDeleted(new VirtualFileEvent(event.getRequestor(), de.getFile(), de.getFile().getParent(), 0, 0)); } else if (event instanceof VFileMoveEvent) { final VFileMoveEvent me = (VFileMoveEvent)event; - myAdapted.fileMoved(new VirtualFileMoveEvent(event.getRequestor(), me.getFile(), me.getOldParent(), me.getNewParent())); + adapted.fileMoved(new VirtualFileMoveEvent(event.getRequestor(), me.getFile(), me.getOldParent(), me.getNewParent())); } else if (event instanceof VFilePropertyChangeEvent) { final VFilePropertyChangeEvent pce = (VFilePropertyChangeEvent)event; - myAdapted.propertyChanged( + adapted.propertyChanged( new VirtualFilePropertyEvent(event.getRequestor(), pce.getFile(), pce.getPropertyName(), pce.getOldValue(), pce.getNewValue())); } } - private void fireBefore(final VFileEvent event) { + public static void fireBefore(VirtualFileListener adapted, final VFileEvent event) { if (event instanceof VFileContentChangeEvent) { final VFileContentChangeEvent ce = (VFileContentChangeEvent)event; final VirtualFile file = ce.getFile(); - myAdapted.beforeContentsChange( + adapted.beforeContentsChange( new VirtualFileEvent(event.getRequestor(), file, file.getParent(), ce.getOldModificationStamp(), ce.getModificationStamp())); } else if (event instanceof VFileDeleteEvent) { final VFileDeleteEvent de = (VFileDeleteEvent)event; - myAdapted.beforeFileDeletion(new VirtualFileEvent(event.getRequestor(), de.getFile(), de.getFile().getParent(), 0, 0)); + adapted.beforeFileDeletion(new VirtualFileEvent(event.getRequestor(), de.getFile(), de.getFile().getParent(), 0, 0)); } else if (event instanceof VFileMoveEvent) { final VFileMoveEvent me = (VFileMoveEvent)event; - myAdapted.beforeFileMovement(new VirtualFileMoveEvent(event.getRequestor(), me.getFile(), me.getOldParent(), me.getNewParent())); + adapted.beforeFileMovement(new VirtualFileMoveEvent(event.getRequestor(), me.getFile(), me.getOldParent(), me.getNewParent())); } else if (event instanceof VFilePropertyChangeEvent) { final VFilePropertyChangeEvent pce = (VFilePropertyChangeEvent)event; - myAdapted.beforePropertyChange( + adapted.beforePropertyChange( new VirtualFilePropertyEvent(event.getRequestor(), pce.getFile(), pce.getPropertyName(), pce.getOldValue(), pce.getNewValue())); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 1b6fecf96ce7..9e1fdb120992 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -38,8 +38,12 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; +import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent; +import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.impl.FileNameCache; import com.intellij.util.*; import com.intellij.util.containers.ContainerUtil; @@ -143,7 +147,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } }); - myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(new MyVirtualFileListener())); + myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyVirtualFileListener()); } private void markContentRootsForRefresh() { @@ -162,7 +166,10 @@ public class DirectoryIndexImpl extends DirectoryIndex { myConnection.deliverImmediately(); } - private class MyVirtualFileListener extends VirtualFileAdapter { + private class MyVirtualFileListener extends VirtualFileAdapter implements BulkFileListener { + private static final int MAX_DEPTH_TO_COUNT = 20; + private static final int DIRECTORIES_CHANGED_THRESHOLD = 50; + @Override public void fileCreated(VirtualFileEvent event) { VirtualFile file = event.getFile(); @@ -177,7 +184,6 @@ public class DirectoryIndexImpl extends DirectoryIndex { replaceState(newState); } - @NotNull private IndexState updateStateWithNewFile(@NotNull NewVirtualFile file, @NotNull NewVirtualFile parent) { final IndexState originalState = myState; @@ -305,11 +311,6 @@ public class DirectoryIndexImpl extends DirectoryIndex { myState.assertAncestorsConsistent(); } - @Override - public void beforeFileMovement(VirtualFileMoveEvent event) { - super.beforeFileMovement(event); - } - @Override public void fileMoved(VirtualFileMoveEvent event) { VirtualFile file = event.getFile(); @@ -329,6 +330,64 @@ public class DirectoryIndexImpl extends DirectoryIndex { } myState.assertAncestorsConsistent(); } + + private boolean myBatchChangePlanned; + private static final boolean ourCanHaveBatchUpdate = true; + + @Override + public void before(@NotNull List events) { + myBatchChangePlanned = false; + int directoriesRemoved = 0; + int directoriesCreated = 0; + + for(VFileEvent event:events) { + if (event instanceof VFileDeleteEvent) { + VirtualFile file = event.getFile(); + if (file != null && file.isDirectory()) { + directoriesRemoved += 1 + countDirectories(file, MAX_DEPTH_TO_COUNT); + } + } else if(event instanceof VFileCreateEvent) { + VirtualFile file = event.getFile(); + if (file != null && file.isDirectory()) directoriesCreated += 1 + countDirectories(file, MAX_DEPTH_TO_COUNT); + } + } + + final boolean willDoBatchUpdate = directoriesCreated + directoriesRemoved > DIRECTORIES_CHANGED_THRESHOLD; + + if (willDoBatchUpdate && ourCanHaveBatchUpdate) { + myBatchChangePlanned = true; + LOG.info("Too many directories created / deleted: " + directoriesCreated + "," + directoriesRemoved + ", will rebuild indexstate"); + } else { + for (VFileEvent event : events) { + BulkVirtualFileListenerAdapter.fireBefore(this, event); + } + } + } + + private int countDirectories(VirtualFile file, int depth) { + if (!(file instanceof NewVirtualFile)) return 0; + + int counter = 0; + for(VirtualFile child:((NewVirtualFile)file).iterInDbChildren()) { + if (child.isDirectory()) counter += 1 + (depth > 0 ? countDirectories(child, depth - 1):0); + } + return counter; + } + + @Override + public void after(@NotNull List events) { + if (myBatchChangePlanned) { + myBatchChangePlanned = false; + long started = System.currentTimeMillis(); + doInitialize(); + LOG.info("Rebuilt indexstate for " + (System.currentTimeMillis() - started)); + } + else { + for (VFileEvent event : events) { + BulkVirtualFileListenerAdapter.fireAfter(this, event); + } + } + } } private void replaceState(IndexState newState) {