From 91b97ed687327e29bd63bb524023df586da7248a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 1 Oct 2013 20:24:27 +0200 Subject: [PATCH] IDEA-113594 (OpenJDK notification refined) --- bin/scripts/unix/idea.sh | 18 ----- .../components/ApplicationComponent.java | 17 ++++- .../src/com/intellij/ide/OpenJdkNotifier.java | 68 ------------------- .../com/intellij/ide/SystemHealthMonitor.java | 66 ++++++++++++++++++ .../src/messages/IdeBundle.properties | 3 +- .../src/componentSets/Platform.xml | 4 ++ 6 files changed, 88 insertions(+), 88 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/ide/OpenJdkNotifier.java create mode 100644 platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index 42aec04781c8..2edf65a030f5 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -92,27 +92,9 @@ fi VERSION_LOG=`"$MKTEMP" -t java.version.log.XXXXXX` "$JDK/bin/java" -version 2> "$VERSION_LOG" -"$GREP" 'OpenJDK' "$VERSION_LOG" > /dev/null -OPEN_JDK=$? "$GREP" "64-Bit|x86_64" "$VERSION_LOG" > /dev/null BITS=$? "$RM" -f "$VERSION_LOG" -if [ $OPEN_JDK -eq 0 ]; then - echo "WARNING: You are launching the IDE using OpenJDK Java runtime." - echo - echo " ITS KNOWN TO HAVE PERFORMANCE AND GRAPHICS ISSUES!" - echo " SWITCH TO THE ORACLE(SUN) JDK BEFORE REPORTING PROBLEMS!" - echo - echo "NOTE: If you have both Oracle (Sun) JDK and OpenJDK installed" - echo " please validate either @@product_uc@@_JDK, JDK_HOME, or JAVA_HOME environment variable points to valid Oracle (Sun) JDK installation." - echo " See http://ow.ly/6TuKQ for more info on switching default JDK." - echo - echo "Press Enter to continue." -# --------------------------------------------------------------------- -# COMMENT LINE BELOW TO REMOVE PAUSE AFTER OPEN JDK WARNING -# --------------------------------------------------------------------- - read IGNORE -fi if [ $BITS -eq 0 ]; then BITS="64" else diff --git a/platform/core-api/src/com/intellij/openapi/components/ApplicationComponent.java b/platform/core-api/src/com/intellij/openapi/components/ApplicationComponent.java index 9fcdb5ece448..506800677f61 100644 --- a/platform/core-api/src/com/intellij/openapi/components/ApplicationComponent.java +++ b/platform/core-api/src/com/intellij/openapi/components/ApplicationComponent.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. @@ -15,10 +15,25 @@ */ package com.intellij.openapi.components; +import org.jetbrains.annotations.NotNull; + /** * Application-level component's implementation class may implement the ApplicationComponent interface.
* It may have constructor with parameters that are also application components. * See plugins.html for more information. */ public interface ApplicationComponent extends BaseComponent { + class Adapter implements ApplicationComponent { + @NotNull + @Override + public String getComponentName() { + return getClass().getSimpleName(); + } + + @Override + public void disposeComponent() { } + + @Override + public void initComponent() { } + } } diff --git a/platform/platform-impl/src/com/intellij/ide/OpenJdkNotifier.java b/platform/platform-impl/src/com/intellij/ide/OpenJdkNotifier.java deleted file mode 100644 index 2524af28cfe8..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/OpenJdkNotifier.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2000-2010 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.ide; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.ui.popup.Balloon; -import com.intellij.openapi.ui.popup.BalloonBuilder; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.wm.WindowManager; -import com.intellij.ui.awt.RelativePoint; -import com.intellij.util.messages.MessageBus; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.*; - -public class OpenJdkNotifier { - public static void checkJdk(MessageBus bus) { - final String vendor = System.getProperty("java.vendor").toLowerCase(); - if (!vendor.contains("sun") && !vendor.contains("apple") && !vendor.contains("oracle")) { - bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { - @Override - public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - showWrongJavaVersionBaloon(); - } - }); - } - }); - } - } - - private static void showWrongJavaVersionBaloon() { - // Just a copy paste from ChangesViewBaloonProblemNotifier - final JFrame frame = WindowManager.getInstance().findVisibleFrame(); - final JComponent component = frame.getRootPane(); - if (component == null) { - return; - } - final Rectangle rect = component.getVisibleRect(); - final Point p = new Point(rect.x + 30, rect.y + rect.height - 10); - final RelativePoint point = new RelativePoint(component, p); - - final MessageType messageType = MessageType.ERROR; - final BalloonBuilder builder = JBPopupFactory.getInstance() - .createHtmlTextBalloonBuilder(IdeBundle.message("use.sun.jdk.prompt"), messageType.getDefaultIcon(), messageType.getPopupBackground(), - null); - builder.setFadeoutTime(-1); - builder.createBalloon().show(point, Balloon.Position.above); - } - -} diff --git a/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java b/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java new file mode 100644 index 000000000000..8bae437f304e --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/SystemHealthMonitor.java @@ -0,0 +1,66 @@ +/* + * 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.ide; + +import com.intellij.openapi.application.Application; +import com.intellij.openapi.components.ApplicationComponent; +import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.ui.popup.Balloon; +import com.intellij.openapi.ui.popup.JBPopupFactory; +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.ui.awt.RelativePoint; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; + +public class SystemHealthMonitor extends ApplicationComponent.Adapter { + public SystemHealthMonitor(@NotNull Application application) { + checkJdk(application); + } + + private static void checkJdk(final Application app) { + String vmName = System.getProperty("java.vm.name"); + if (vmName != null && StringUtil.containsIgnoreCase(vmName, "OpenJDK") && !SystemInfo.isJavaVersionAtLeast("1.7")) { + app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + @Override + public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { + app.invokeLater(new Runnable() { + public void run() { + notifyWrongJavaVersion(); + } + }); + } + }); + } + } + + private static void notifyWrongJavaVersion() { + JComponent component = WindowManager.getInstance().findVisibleFrame().getRootPane(); + if (component != null) { + Rectangle rect = component.getVisibleRect(); + JBPopupFactory.getInstance() + .createHtmlTextBalloonBuilder(IdeBundle.message("unsupported.jdk.message"), MessageType.WARNING, null) + .setFadeoutTime(-1) + .setHideOnFrameResize(false) + .createBalloon() + .show(new RelativePoint(component, new Point(rect.x + 30, rect.y + rect.height - 10)), Balloon.Position.above); + } + } +} diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index da18754f23ff..0c6456252d4f 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -1074,7 +1074,8 @@ FileChooser.refreshActionLabelText=Refresh browsers.settings=Web Browsers updates.check.period.on.exit=On every exit -use.sun.jdk.prompt=Java version is not supported, please use Sun/Oracle JDK rather than OpenJDK +unsupported.jdk.message=OpenJDK 6 is not supported. Please use Oracle Java or newer OpenJDK. + prompt.goto.inspection.enter.name=Enter inspection name: goto.inspection.action.text=&Run Inspection by Name... label.no.inspections.found=No inspections found diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index 0a04f5117126..ea21c5040e80 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -128,6 +128,10 @@ com.intellij.util.net.HttpConfigurable + + com.intellij.ide.SystemHealthMonitor + +