Issue #168257: LifecycleManager.markForRestart. diff --git a/autoupdate.services/nbproject/project.xml b/autoupdate.services/nbproject/project.xml --- a/autoupdate.services/nbproject/project.xml +++ b/autoupdate.services/nbproject/project.xml @@ -53,7 +53,7 @@ - 7.5 + 7.25 diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java @@ -612,7 +612,7 @@ } public void doRestart (Restarter restarter, ProgressHandle progress) throws OperationException { - createRestartMarker(); + LifecycleManager.getDefault().markForRestart(); LifecycleManager.getDefault ().exit (); // if exit&restart fails => use restart later as fallback doRestartLater (restarter); @@ -620,24 +620,13 @@ public void doRestartLater (Restarter restarter) { // shedule module for restart - createRestartMarker(); + LifecycleManager.getDefault().markForRestart(); if(affectedModules!=null) { for (UpdateElement el : affectedModules) { UpdateUnitFactory.getDefault().scheduleForRestart (el); } } } - private void createRestartMarker() { - try { - File targetUserdir = new File(System.getProperty("netbeans.user")); // NOI18N - File restartFile = new File(targetUserdir, "var/restart");//NOI18N - if(!restartFile.exists()) { - restartFile.createNewFile(); - } - } catch (IOException ex) { - LOGGER.log(Level.INFO, "Can`t create restart file marker", ex); - } - } } private static class ForCustomUninstall extends OperationSupportImpl { @@ -691,7 +680,7 @@ } public void doRestart (Restarter restarter, ProgressHandle progress) throws OperationException { - createRestartMarker(); + LifecycleManager.getDefault().markForRestart(); LifecycleManager.getDefault ().exit (); // if exit&restart fails => use restart later as fallback doRestartLater (restarter); @@ -699,24 +688,12 @@ public void doRestartLater (Restarter restarter) { // shedule module for restart - createRestartMarker(); + LifecycleManager.getDefault().markForRestart(); if(affectedModules!=null) { for (UpdateElement el : affectedModules) { UpdateUnitFactory.getDefault().scheduleForRestart (el); } } } - private void createRestartMarker() { - try { - File targetUserdir = new File(System.getProperty("netbeans.user")); // NOI18N - File restartFile = new File(targetUserdir, "var/restart");//NOI18N - if(!restartFile.exists()) { - restartFile.createNewFile(); - } - } catch (IOException ex) { - LOGGER.log(Level.INFO, "Can`t create restart file marker", ex); - } - - } } } diff --git a/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java b/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java --- a/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java +++ b/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java @@ -39,6 +39,8 @@ package org.netbeans.core.startup; +import java.io.File; +import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import org.netbeans.CLIHandler; import org.netbeans.TopSecurityManager; @@ -89,4 +91,19 @@ } } + public @Override void markForRestart() throws UnsupportedOperationException { + String userdir = System.getProperty("netbeans.user"); // NOI18N + if (userdir == null) { + throw new UnsupportedOperationException("no userdir"); // NOI18N + } + File restartFile = new File(userdir, "var/restart"); // NOI18N + if (!restartFile.exists()) { + try { + restartFile.createNewFile(); + } catch (IOException x) { + throw new UnsupportedOperationException(x); + } + } + } + } diff --git a/o.n.core/nbproject/project.xml b/o.n.core/nbproject/project.xml --- a/o.n.core/nbproject/project.xml +++ b/o.n.core/nbproject/project.xml @@ -156,7 +156,7 @@ - 7.22 + 7.25 diff --git a/o.n.core/src/org/netbeans/core/NbTopManager.java b/o.n.core/src/org/netbeans/core/NbTopManager.java --- a/o.n.core/src/org/netbeans/core/NbTopManager.java +++ b/o.n.core/src/org/netbeans/core/NbTopManager.java @@ -61,6 +61,7 @@ import javax.swing.event.ChangeListener; import org.netbeans.TopSecurityManager; import org.netbeans.core.startup.MainLookup; +import org.netbeans.core.startup.ModuleLifecycleManager; import org.netbeans.core.startup.ModuleSystem; import org.netbeans.core.startup.layers.SessionManager; import org.netbeans.core.ui.SwingBrowser; @@ -389,7 +390,7 @@ for (int i = 0; i < modifs.length; i++) { try { dobj = modifs[i]; - SaveCookie sc = dobj.getCookie(SaveCookie.class); + SaveCookie sc = dobj.getLookup().lookup(SaveCookie.class); if (sc != null) { org.openide.awt.StatusDisplayer.getDefault().setStatusText( @@ -560,6 +561,9 @@ public void exit() { NbTopManager.exit(); } + public @Override void markForRestart() throws UnsupportedOperationException { + new ModuleLifecycleManager().markForRestart(); + } } /** Get the module subsystem. */ diff --git a/openide.util/apichanges.xml b/openide.util/apichanges.xml --- a/openide.util/apichanges.xml +++ b/openide.util/apichanges.xml @@ -49,6 +49,23 @@ Actions API + + + Added way to request that the platform restart. + + + + + +

+ Can now use LifecycleManager.markForRestart to cause + the application to restart after exiting. Formerly needed to + create special files in the userdir or use similar tricks. +

+
+ + +
Added diff --git a/openide.util/nbproject/project.properties b/openide.util/nbproject/project.properties --- a/openide.util/nbproject/project.properties +++ b/openide.util/nbproject/project.properties @@ -42,7 +42,7 @@ module.jar.dir=lib cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar -spec.version.base=7.24.0 +spec.version.base=7.25.0 # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4: diff --git a/openide.util/src/org/openide/LifecycleManager.java b/openide.util/src/org/openide/LifecycleManager.java --- a/openide.util/src/org/openide/LifecycleManager.java +++ b/openide.util/src/org/openide/LifecycleManager.java @@ -83,6 +83,16 @@ */ public abstract void exit(); + /** + * Request that the application restart immediately after next being shut down. + * You may want to then call {@link #exit} to go ahead and restart now. + * @throws UnsupportedOperationException if this request cannot be honored + * @since org.openide.util 7.25 + */ + public void markForRestart() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + /** Fallback instance. */ private static final class Trivial extends LifecycleManager { public Trivial() {