--- a/derby/src/org/netbeans/modules/derby/RegisterDerby.java +++ a/derby/src/org/netbeans/modules/derby/RegisterDerby.java @@ -52,22 +52,28 @@ import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.prefs.Preferences; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.swing.Icon; import org.netbeans.api.db.explorer.ConnectionManager; import org.netbeans.api.db.explorer.DatabaseConnection; import org.netbeans.api.db.explorer.JDBCDriver; import org.netbeans.api.db.explorer.JDBCDriverManager; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; -import org.netbeans.api.progress.ProgressUtils; import org.netbeans.modules.derby.api.DerbyDatabases; import org.netbeans.spi.db.explorer.DatabaseRuntime; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.awt.NotificationDisplayer; import org.openide.execution.NbProcessDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Cancellable; +import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; +import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; import org.openide.windows.InputOutput; @@ -86,6 +92,10 @@ private static final Logger LOGGER = Logger.getLogger(RegisterDerby.class.getName()); private static final boolean LOG = LOGGER.isLoggable(Level.FINE); + private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile( + "(\\d+)\\.(\\d+)\\.\\d+(?:(?:-.*)|(?:_(\\d+)))?"); //NOI18N + private static final String DISABLED_SECURITY_MNGR_NOTIFIED + = "disabledSecurityManagerNotified"; //NOI18N private static final int START_TIMEOUT = 0; // seconds @@ -299,7 +309,7 @@ java, "-Dderby.system.home=\"" + getDerbySystemHome() + "\" " + "-classpath \"" + getNetworkServerClasspath() + "\"" + - " org.apache.derby.drda.NetworkServerControl start" + " org.apache.derby.drda.NetworkServerControl start" + jdkParams() ); if (LOG) { LOGGER.log(Level.FINE, "Running " + desc.getProcessName() + " " + desc.getArguments()); @@ -332,6 +342,78 @@ } } + /** + * Check whether some non-standard arguments are needed to start JavaDB. If + * so, a warning notification may be displayed to the user. Ugly workaround + * for bug 239962. + * + * @return String containing non-standard JDK params. Prefixed by a space + * character if not emtpy. + */ + @NbBundle.Messages({ + "TTL_NoSecurity=JavaDB - Security Manager Disabled", + "LBL_NoSecurity=JavaDB will be started with disabled security manager" + + " (i.e. with argument -noSecurityManager). Please ensure" + + " this cannot cause any security risks, and if so, start the" + + " JavaDB manually." + }) + private String jdkParams() { + + if (isDisablingOfSecurityManagerNeeded()) { + Preferences prefs = NbPreferences.forModule(RegisterDerby.class); + if (!prefs.getBoolean(DISABLED_SECURITY_MNGR_NOTIFIED, false)) { + NotificationDisplayer.getDefault().notify( + Bundle.TTL_NoSecurity(), + getDbIcon(), Bundle.LBL_NoSecurity(), null, + NotificationDisplayer.Priority.HIGH); + prefs.putBoolean(DISABLED_SECURITY_MNGR_NOTIFIED, true); + } + return " -noSecurityManager"; //NOI18N + } else { + return ""; //NOI18N + } + } + + private Icon getDbIcon() { + return ImageUtilities.loadImageIcon( + "org/netbeans/modules/derby/resources/database.gif", //NOI18N + false); + } + + /** + * JavaDB needs to be started with parameter "-noSecurityManager" on jdk + * 7u51 or newer or jdk8. + */ + private boolean isDisablingOfSecurityManagerNeeded() { + // 1.8.0-ea+ + // 1.7.0_51+ + String version = System.getProperty("java.version"); //NOI18N + Matcher m = JAVA_VERSION_PATTERN.matcher(version); + try { + if (m.matches()) { + int major = Integer.parseInt(m.group(1)); + int minor = Integer.parseInt(m.group(2)); + if (major == 1 && minor >= 8) { + return true; + } + String updateStr = m.group(3); + if (updateStr != null && !updateStr.isEmpty()) { + int update = Integer.parseInt(updateStr); + if (major == 1 && minor == 7 && update >= 51) { + return true; + } + } + } else { + LOGGER.log(Level.FINE, "Cannot parse java version {0}", //NOI18N + version); + } + } catch (NumberFormatException ex) { + LOGGER.log(Level.FINE, null, ex); + return false; + } + return false; + } + private boolean waitStart(final ExecSupport execSupport, int waitTime) { boolean started = false; String waitMessage = NbBundle.getMessage(RegisterDerby.class, "MSG_StartingDerby");