This is an automated email from the ASF dual-hosted git repository.

jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new da71927247 Adding ability to safely enable/disable module fragments 
(requires restart, obviously), and tweaking nbjavac so that it can be 
enable/disabled.
     new 865b3f3171 Merge pull request #6743 from lahodaj/option-disable-nbjavac
da71927247 is described below

commit da719272474b35d9c736c3242f4f19fb0a529aeb
Author: Jan Lahoda <[email protected]>
AuthorDate: Wed Nov 15 13:14:37 2023 +0100

    Adding ability to safely enable/disable module fragments (requires restart, 
obviously), and tweaking nbjavac so that it can be enable/disabled.
---
 .../netbeans/api/debugger/jpda/JPDASupport.java    |  2 +-
 java/java.source.base/manifest.mf                  |  1 -
 .../autoupdate/ui/wizards/Bundle_nb.properties     |  2 +
 .../libsrc/org/netbeans/updater/Bundle.properties  |  1 +
 .../org/netbeans/updater/ModuleDeactivator.java    | 53 ++++++++++-----
 .../org/netbeans/updater/UpdaterDispatcher.java    | 20 +++++-
 ...l.java => ModuleEnableDisableDeleteHelper.java} | 31 ++++-----
 .../autoupdate/services/OperationSupportImpl.java  | 77 ++++++++++++++++------
 .../autoupdate/services/OperationValidator.java    |  6 +-
 .../modules/autoupdate/services/Utilities.java     |  8 ++-
 .../autoupdate/ui/wizards/UninstallStep.java       |  8 ++-
 .../src/org/netbeans/core/startup/NbInstaller.java | 12 +++-
 platform/o.n.bootstrap/launcher/unix/nbexec        |  4 +-
 .../src/org/netbeans/ModuleManager.java            | 20 +++---
 .../unit/src/org/netbeans/ModuleManagerTest.java   |  3 +-
 15 files changed, 169 insertions(+), 79 deletions(-)

diff --git 
a/java/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java
 
b/java/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java
index 28c45f5940..0a2112f469 100644
--- 
a/java/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java
+++ 
b/java/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java
@@ -90,7 +90,7 @@ public final class JPDASupport implements 
DebuggerManagerListener {
     
     public static Test createTestSuite(Class<? extends TestCase> clazz) {
         Configuration suiteConfiguration = 
NbModuleSuite.createConfiguration(clazz);
-        suiteConfiguration = 
suiteConfiguration.clusters(".*").enableModules(".*java.source.*").gui(false);
+        suiteConfiguration = 
suiteConfiguration.clusters(".*").enableModules(".*java.source.*").enableModules(".*libs.nbjavacapi.*").gui(false);
         if (!(ClassLoader.getSystemClassLoader() instanceof URLClassLoader)) {
             //when running on JDK 9+, to make the com.sun.jdi package 
dependency work, we need to make getPackage("com.sun.jdi") work
             //for system CL's parent (which otherwise happily loads the 
VirtualMachineManager class,
diff --git a/java/java.source.base/manifest.mf 
b/java/java.source.base/manifest.mf
index e47516a822..8e95ab8e59 100644
--- a/java/java.source.base/manifest.mf
+++ b/java/java.source.base/manifest.mf
@@ -3,4 +3,3 @@ OpenIDE-Module: org.netbeans.modules.java.source.base
 OpenIDE-Module-Implementation-Version: 6
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/java/source/base/Bundle.properties
 OpenIDE-Module-Layer: org/netbeans/modules/java/source/base/layer.xml
-OpenIDE-Module-Recommends: org.netbeans.libs.nbjavac
diff --git 
a/nb/ide.branding/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/Bundle_nb.properties
 
b/nb/ide.branding/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/Bundle_nb.properties
index c311ec410e..376d282d3b 100644
--- 
a/nb/ide.branding/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/Bundle_nb.properties
+++ 
b/nb/ide.branding/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/Bundle_nb.properties
@@ -24,6 +24,8 @@ InstallStep_Header_Restart_Head=Restart NetBeans IDE to 
complete installation.
 InstallStep_Header_Restart_Content=Restart NetBeans IDE to finish plugin 
installation.
 UninstallStep_Header_Restart_Head=Restart NetBeans IDE to complete 
deactivation.
 UninstallStep_Header_Restart_Content=Restart NetBeans IDE to finish plugin 
deactivation.
+UninstallStep_Activate_Header_Restart_Head=Restart NetBeans IDE to complete 
activation.
+UninstallStep_Activate_Header_Restart_Content=Restart NetBeans IDE to finish 
plugin activation.
 InstallUnitWizardModel_Buttons_RestartNow=&Restart IDE Now
 InstallUnitWizardModel_Buttons_RestartLater=Restart IDE &Later
 InstallStep_InstallDone_Text=The NetBeans IDE Installer has successfully \
diff --git 
a/platform/autoupdate.services/libsrc/org/netbeans/updater/Bundle.properties 
b/platform/autoupdate.services/libsrc/org/netbeans/updater/Bundle.properties
index 5afe441dd0..936ee3324c 100644
--- a/platform/autoupdate.services/libsrc/org/netbeans/updater/Bundle.properties
+++ b/platform/autoupdate.services/libsrc/org/netbeans/updater/Bundle.properties
@@ -20,6 +20,7 @@ CTL_UnpackingFile=Unpacking
 CTL_DownloadingFile=Downloading
 CTL_DeletingFiles=Uninstalling files...
 CTL_DisablingFiles=Deactivating files...
+CTL_EnablingFiles=Enabling files...
 UpdaterFrame.jTextArea1.text=Update is in progress.\n\nPlease wait...
 UpdaterFrame.textLabel.text=Preparing to Unpack
 UpdaterFrame.Form.title=Updater
diff --git 
a/platform/autoupdate.services/libsrc/org/netbeans/updater/ModuleDeactivator.java
 
b/platform/autoupdate.services/libsrc/org/netbeans/updater/ModuleDeactivator.java
index 4613e5d6c3..325858a864 100644
--- 
a/platform/autoupdate.services/libsrc/org/netbeans/updater/ModuleDeactivator.java
+++ 
b/platform/autoupdate.services/libsrc/org/netbeans/updater/ModuleDeactivator.java
@@ -31,6 +31,7 @@ public final class ModuleDeactivator extends Object {
 
     public static final String TO_UNINSTALL = "to_uninstall.txt"; // NOI18N
     public static final String TO_DISABLE = "to_disable.txt"; // NOI18N
+    public static final String TO_ENABLE = "to_enable.txt"; // NOI18N
     
     public static final String CONFIG = "config"; // NOI18N
     public static final String MODULES = "Modules"; // NOI18N
@@ -60,19 +61,22 @@ public final class ModuleDeactivator extends Object {
         }
     }
     
-    public void disable () {
+    public void enableDisable(boolean enable) {
         assert ! SwingUtilities.isEventDispatchThread () : "Cannot run in EQ";
-        context.setLabel (Localization.getBrandedString 
("CTL_DisablingFiles"));
+        context.setLabel (enable ? Localization.getBrandedString 
("CTL_EnablingFiles")
+                                 : Localization.getBrandedString 
("CTL_DisablingFiles"));
         Collection<File> allControlFiles = new HashSet<File> ();
         for (File cluster : UpdateTracking.clusters (true)) {
-            allControlFiles.addAll (readFilesMarkedForDisableInCluster 
(cluster));
-            doDelete (getControlFileForMarkedForDisable (cluster));
-            doDelete (getDeactivateLater (cluster));
+            allControlFiles.addAll 
(readFilesMarkedForEnableDisableInCluster(cluster, enable));
+            doDelete (getControlFileForMarkedForEnableDisable(cluster, 
enable));
+            if (!enable) {
+                doDelete (getDeactivateLater (cluster));
+            }
         }
         context.setProgressRange (0, allControlFiles.size ());
         int i = 0;
         for (File f : allControlFiles) {
-            doDisable (f);
+            doEnableDisable(f, enable);
             context.setProgressValue (i ++);
         }
     }
@@ -87,6 +91,11 @@ public final class ModuleDeactivator extends Object {
         return deactivateDir.exists () && deactivateDir.isDirectory () && 
Arrays.asList (deactivateDir.list ()).contains (TO_DISABLE);
     }
     
+    public static boolean hasModulesForEnable (File updateDir) {
+        File deactivateDir = new File (updateDir, 
UpdaterDispatcher.DEACTIVATE_DIR);
+        return deactivateDir.exists () && deactivateDir.isDirectory () && 
Arrays.asList (deactivateDir.list ()).contains (TO_ENABLE);
+    }
+
     public static File getDeactivateLater (File cluster) {
         File file = new File (cluster,
                 UpdaterDispatcher.UPDATE_DIR + // update
@@ -103,11 +112,13 @@ public final class ModuleDeactivator extends Object {
         return file;
     }
 
-    public static File getControlFileForMarkedForDisable (File cluster) {
+    public static File getControlFileForMarkedForEnableDisable (File cluster, 
boolean enable) {
+        String fileName = enable ? ModuleDeactivator.TO_ENABLE    // 
to_enable.txt
+                                 : ModuleDeactivator.TO_DISABLE;  // 
to_disable.txt
         File file = new File (cluster,
                 UpdaterDispatcher.UPDATE_DIR + // update
                 UpdateTracking.FILE_SEPARATOR + 
UpdaterDispatcher.DEACTIVATE_DIR + // update/deactivate
-                UpdateTracking.FILE_SEPARATOR + ModuleDeactivator.TO_DISABLE); 
// to_disable.txt
+                UpdateTracking.FILE_SEPARATOR + fileName);
         return file;
     }
 
@@ -219,9 +230,9 @@ public final class ModuleDeactivator extends Object {
         return toDelete;
     }
 
-    private static Set<File> readFilesMarkedForDisableInCluster (File cluster) 
{
+    private static Set<File> readFilesMarkedForEnableDisableInCluster (File 
cluster, boolean enable) {
         
-        File mark4disableFile = getControlFileForMarkedForDisable (cluster);
+        File mark4disableFile = 
getControlFileForMarkedForEnableDisable(cluster, enable);
         if (! mark4disableFile.exists ()) {
             return Collections.emptySet ();
         }
@@ -244,18 +255,24 @@ public final class ModuleDeactivator extends Object {
     private static String ENABLE_TAG = "<param name=\"enabled\">true</param>";
     private static String DISABLE_TAG = "<param 
name=\"enabled\">false</param>";
     
-    private static void doDisable (File f) {
+    private static void doEnableDisable (File f, boolean enable) {
+        String expected = enable ? DISABLE_TAG : ENABLE_TAG;
+        String target = enable ? ENABLE_TAG : DISABLE_TAG;
+
         String content = readStringFromFile (f);
-        int pos = content.indexOf (ENABLE_TAG);
-        assert pos != -1 : ENABLE_TAG + " must be contained in " + content;
-        int shift = ENABLE_TAG.length ();
-        String pre = content.substring (0, pos);
-        String post = content.substring (pos + shift);
-        String res = pre + DISABLE_TAG + post;
+        if (!content.contains(target)) {
+            int pos = content.indexOf(expected);
+            assert pos != -1 : expected + " must be contained in " + content;
+            int shift = expected.length ();
+            String pre = content.substring (0, pos);
+            String post = content.substring (pos + shift);
+
+            content = pre + target + post;
+        }
         File configDir = new File (new File (UpdateTracking.getUserDir (), 
CONFIG), MODULES);
         configDir.mkdirs ();
         File dest = new File (configDir, f.getName());
-        writeStringToFile (res, dest);
+        writeStringToFile (content, dest);
     }
 
 }
diff --git 
a/platform/autoupdate.services/libsrc/org/netbeans/updater/UpdaterDispatcher.java
 
b/platform/autoupdate.services/libsrc/org/netbeans/updater/UpdaterDispatcher.java
index 4fe0be9f21..22b3589803 100644
--- 
a/platform/autoupdate.services/libsrc/org/netbeans/updater/UpdaterDispatcher.java
+++ 
b/platform/autoupdate.services/libsrc/org/netbeans/updater/UpdaterDispatcher.java
@@ -29,6 +29,7 @@ import javax.swing.SwingUtilities;
  */
 public final class UpdaterDispatcher implements Runnable {
     private Boolean disable = null;
+    private Boolean enable = null;
     private Boolean install = null;
     private Boolean uninstall = null;
     
@@ -60,7 +61,12 @@ public final class UpdaterDispatcher implements Runnable {
 
             // then disable
             if (isDisableScheduled ()) {
-                new ModuleDeactivator(context).disable();
+                new ModuleDeactivator(context).enableDisable(false);
+            }
+
+            // then disable
+            if (isEnableScheduled()) {
+                new ModuleDeactivator(context).enableDisable(true);
             }
 
             // finally install/update
@@ -87,6 +93,13 @@ public final class UpdaterDispatcher implements Runnable {
         return disable;
     }
     
+    private boolean isEnableScheduled () {
+        if (enable == null) {
+            exploreUpdateDir ();
+        }
+        return enable;
+    }
+
     private boolean isUninstallScheduled () {
         if (uninstall == null) {
             exploreUpdateDir ();
@@ -106,6 +119,7 @@ public final class UpdaterDispatcher implements Runnable {
         install = false;
         uninstall = false;
         disable = false;
+        enable = false;
         
         // go over all clusters
         for (File cluster : UpdateTracking.clusters (true)) {
@@ -123,6 +137,10 @@ public final class UpdaterDispatcher implements Runnable {
                 if (disable == null || ! disable) {
                     disable = ModuleDeactivator.hasModulesForDisable 
(updateDir);
                 }
+                // enable
+                if (enable == null || ! enable) {
+                    enable = ModuleDeactivator.hasModulesForEnable (updateDir);
+                }
             }
         }
     }
diff --git 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleEnableDisableDeleteHelper.java
similarity index 94%
rename from 
platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
rename to 
platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleEnableDisableDeleteHelper.java
index babb7ff353..4d3cf7542c 100644
--- 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
+++ 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleEnableDisableDeleteHelper.java
@@ -59,18 +59,18 @@ import org.xml.sax.SAXException;
  *
  * @author  Jiri Rechtacek
  */
-public final class ModuleDeleterImpl  {
-    private static final ModuleDeleterImpl INSTANCE = new ModuleDeleterImpl();
+public final class ModuleEnableDisableDeleteHelper  {
+    private static final ModuleEnableDisableDeleteHelper INSTANCE = new 
ModuleEnableDisableDeleteHelper();
     private static final String ELEMENT_MODULE = "module"; // NOI18N
     private static final String ELEMENT_VERSION = "module_version"; // NOI18N
     private static final String ATTR_LAST = "last"; // NOI18N
     private static final String ATTR_FILE_NAME = "name"; // NOI18N
     
-    private static final Logger err = Logger.getLogger 
(ModuleDeleterImpl.class.getName ()); // NOI18N
+    private static final Logger err = Logger.getLogger 
(ModuleEnableDisableDeleteHelper.class.getName ()); // NOI18N
     
     private Set<File> storageFilesForDelete = null;
     
-    public static ModuleDeleterImpl getInstance() {
+    public static ModuleEnableDisableDeleteHelper getInstance() {
         return INSTANCE;
     }
     
@@ -88,7 +88,7 @@ public final class ModuleDeleterImpl  {
         }
     }
     
-    public Collection<File> markForDisable (Collection<ModuleInfo> modules, 
ProgressHandle handle) {
+    public Collection<File> findControlFiles(Collection<ModuleInfo> modules, 
ProgressHandle handle) {
         if (modules == null) {
             throw new IllegalArgumentException ("ModuleInfo argument cannot be 
null.");
         }
@@ -96,7 +96,11 @@ public final class ModuleDeleterImpl  {
         if (handle != null) {
             handle.switchToDeterminate (modules.size() + 1);
         }
-        
+
+        return doFindControlFiles(modules, handle);
+    }
+
+    private Collection<File> doFindControlFiles(Collection<ModuleInfo> 
modules, ProgressHandle handle) {
         Collection<File> configs = new HashSet<File> ();
         int i = 0;
         for (ModuleInfo moduleInfo : modules) {
@@ -125,18 +129,9 @@ public final class ModuleDeleterImpl  {
             handle.switchToDeterminate (modules.size () * 2 + 1);
         }
 
-        Collection<File> configFiles = new HashSet<File> ();
-        int i = 0;
-        for (ModuleInfo moduleInfo : modules) {
-            Collection<File> configs = locateAllConfigFiles (moduleInfo);
-            assert configs != null : "Located config files for " + 
moduleInfo.getCodeName ();
-            assert ! configs.isEmpty () : configs + " config files must exists 
for " + moduleInfo.getCodeName ();
-            configFiles.addAll (configs);
-            err.log(Level.FINE, "Locate config files of " + 
moduleInfo.getCodeNameBase () + ": " + configs);
-            if (handle != null) {
-                handle.progress (++i);
-            }
-        }
+        Collection<File> configFiles = doFindControlFiles(modules, handle);
+        int i = configFiles.size();
+
         getStorageFilesForDelete ().addAll (configFiles);
         
         for (ModuleInfo moduleInfo : modules) {
diff --git 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java
 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java
index f0225e29e5..590a545e06 100644
--- 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java
+++ 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationSupportImpl.java
@@ -95,6 +95,8 @@ public abstract class OperationSupportImpl {
     }
     
     private static class ForEnable extends OperationSupportImpl {
+        private Collection<File> controlFileForEnable = null;
+        private Collection<UpdateElement> affectedModules = null;
         @Override 
         public synchronized Boolean doOperation(ProgressHandle progress,
                 OperationContainer<?> container) throws OperationException {
@@ -128,21 +130,26 @@ public abstract class OperationSupportImpl {
                 assert mm != null;
                 
                 needsRestart = mm.hasToEnableCompatModules(modules);
-                
-                final ModuleManager fmm = mm;
-                try {
-                    fmm.mutex ().writeAccess (new ExceptionAction<Boolean> () {
-                        @Override
-                        public Boolean run () throws Exception {
-                            return enable(fmm, modules);
+
+                if (!needsRestart) {
+                    final ModuleManager fmm = mm;
+                    try {
+                        fmm.mutex ().writeAccess (new ExceptionAction<Boolean> 
() {
+                            @Override
+                            public Boolean run () throws Exception {
+                                return enable(fmm, modules);
+                            }
+                        });
+                    } catch (MutexException ex) {
+                        Exception x = ex.getException ();
+                        assert x instanceof OperationException : x + " is 
instanceof OperationException";
+                        if (x instanceof OperationException) {
+                            throw (OperationException) x;
                         }
-                    });
-                } catch (MutexException ex) {
-                    Exception x = ex.getException ();
-                    assert x instanceof OperationException : x + " is 
instanceof OperationException";
-                    if (x instanceof OperationException) {
-                        throw (OperationException) x;
                     }
+                } else {
+                    ModuleEnableDisableDeleteHelper helper = new 
ModuleEnableDisableDeleteHelper ();
+                    controlFileForEnable = 
helper.findControlFiles(moduleInfos, progress);
                 }
             } finally {
                 if (progress != null) {
@@ -155,7 +162,12 @@ public abstract class OperationSupportImpl {
         
         @Override
         public void doCancel () throws OperationException {
-            assert false : "Not supported yet";
+            if (controlFileForEnable != null) {
+                controlFileForEnable = null;
+            }
+            if (affectedModules != null) {
+                affectedModules = null;
+            }
         }
         
         private static boolean enable(ModuleManager mm, Set<Module> toRun) 
throws OperationException {
@@ -173,13 +185,36 @@ public abstract class OperationSupportImpl {
 
         @Override
         public void doRestart (Restarter restarter, ProgressHandle progress) 
throws OperationException {
-            LifecycleManager.getDefault().markForRestart();
-            LifecycleManager.getDefault().exit();
+            if (controlFileForEnable != null) {
+                // write files marked to enable into a temp file
+                // Updater will handle it
+                Utilities.writeFileMarkedForEnable(controlFileForEnable);
+
+                // restart IDE
+                Utilities.deleteAllDoLater ();
+                LifecycleManager.getDefault ().exit ();
+                // if exit&restart fails => use restart later as fallback
+                doRestartLater (restarter);
+            } else {
+                LifecycleManager.getDefault().markForRestart();
+                LifecycleManager.getDefault().exit();
+            }
         }
 
         @Override
         public void doRestartLater (Restarter restarter) {
-            LifecycleManager.getDefault().markForRestart();
+            if (controlFileForEnable != null) {
+                // write files marked to enable into a temp file
+                // Updater will handle it
+                Utilities.writeFileMarkedForEnable(controlFileForEnable);
+
+                // schedule module for restart
+                for (UpdateElement el : affectedModules) {
+                    UpdateUnitFactory.getDefault().scheduleForRestart (el);
+                }
+            } else {
+                LifecycleManager.getDefault().markForRestart();
+            }
         }        
     }
     
@@ -214,8 +249,8 @@ public abstract class OperationSupportImpl {
                     }
                 }
                 assert mm != null;
-                ModuleDeleterImpl deleter = new ModuleDeleterImpl ();
-                controlFileForDisable = deleter.markForDisable (modules, 
progress);
+                ModuleEnableDisableDeleteHelper deleter = new 
ModuleEnableDisableDeleteHelper ();
+                controlFileForDisable = deleter.findControlFiles(modules, 
progress);
             } finally {
                 if (progress != null) {
                     progress.finish();
@@ -354,7 +389,7 @@ public abstract class OperationSupportImpl {
                 if (progress != null) {
                     progress.start();
                 }
-                ModuleDeleterImpl deleter = new ModuleDeleterImpl();
+                ModuleEnableDisableDeleteHelper deleter = new 
ModuleEnableDisableDeleteHelper();
                 
                 List<? extends OperationInfo> infos = container.listAll ();
                 Set<ModuleInfo> moduleInfos = new HashSet<ModuleInfo> ();
@@ -446,7 +481,7 @@ public abstract class OperationSupportImpl {
                 if (progress != null) {
                     progress.start();
                 }
-                ModuleDeleterImpl deleter = new ModuleDeleterImpl();
+                ModuleEnableDisableDeleteHelper deleter = new 
ModuleEnableDisableDeleteHelper();
                 
                 List<? extends OperationInfo> infos = container.listAll ();
                 Set<ModuleInfo> moduleInfos = new HashSet<ModuleInfo> ();
diff --git 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationValidator.java
 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationValidator.java
index edce93edd5..71f16dd86d 100644
--- 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationValidator.java
+++ 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationValidator.java
@@ -218,13 +218,13 @@ abstract class OperationValidator {
             case KIT_MODULE :
             case MODULE :
                 Module m =  Utilities.toModule (((ModuleUpdateElementImpl) 
impl).getModuleInfo ());
-                res = ModuleDeleterImpl.getInstance ().canDelete (m);
+                res = ModuleEnableDisableDeleteHelper.getInstance ().canDelete 
(m);
                 break;
             case STANDALONE_MODULE :
             case FEATURE :
                 for (ModuleInfo info : ((FeatureUpdateElementImpl) 
impl).getModuleInfos ()) {
                     Module module = Utilities.toModule (info);
-                    res |= ModuleDeleterImpl.getInstance ().canDelete (module);
+                    res |= ModuleEnableDisableDeleteHelper.getInstance 
().canDelete (module);
                 }
                 break;
             case CUSTOM_HANDLED_COMPONENT :
@@ -261,7 +261,7 @@ abstract class OperationValidator {
                     if (Utilities.isEssentialModule (module)) {
                         LOGGER.log (Level.WARNING, "Essential module cannot be 
planned for uninstall but " + module);
                         continue;
-                    } else if (! ModuleDeleterImpl.getInstance ().canDelete 
(module)) {
+                    } else if (! ModuleEnableDisableDeleteHelper.getInstance 
().canDelete (module)) {
                         LOGGER.log (Level.WARNING, "The module " + module + " 
cannot be planned for uninstall because is read-only.");
                         continue;
                     }
diff --git 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
index 896897a946..1a08c8ea32 100644
--- 
a/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
+++ 
b/platform/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
@@ -511,9 +511,13 @@ public class Utilities {
     }
     
     public static void writeFileMarkedForDisable (Collection<File> files) {
-        writeMarkedFilesToFile (files, 
ModuleDeactivator.getControlFileForMarkedForDisable (InstallManager.getUserDir 
()));
+        writeMarkedFilesToFile (files, 
ModuleDeactivator.getControlFileForMarkedForEnableDisable(InstallManager.getUserDir
 (), false));
     }
-    
+
+    public static void writeFileMarkedForEnable (Collection<File> files) {
+        writeMarkedFilesToFile (files, 
ModuleDeactivator.getControlFileForMarkedForEnableDisable(InstallManager.getUserDir
 (), true));
+    }
+
     private static void writeMarkedFilesToFile (Collection<File> files, File 
dest) {
         // don't forget for content written before
         StringBuilder content = new StringBuilder();
diff --git 
a/platform/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/UninstallStep.java
 
b/platform/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/UninstallStep.java
index 77bf1a4d60..fb3150f8e5 100644
--- 
a/platform/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/UninstallStep.java
+++ 
b/platform/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/UninstallStep.java
@@ -278,11 +278,17 @@ public class UninstallStep implements 
WizardDescriptor.FinishablePanel<WizardDes
     @NbBundle.Messages({
         "UninstallStep_Header_Restart_Head=Restart application to complete 
deactivation",
         "UninstallStep_Header_Restart_Content=Restart application to finish 
plugin deactivation.",
+        "UninstallStep_Activate_Header_Restart_Head=Restart application to 
complete activation",
+        "UninstallStep_Activate_Header_Restart_Content=Restart application to 
finish plugin activation.",
         "UninstallStep_ActivateLater_Text=The Plugin Installer has 
successfully activated the following plugins:",
         "UninstallStep_UninstallLater_Text=The Plugin Installer has 
successfully uninstalled the following plugins:",
         "UninstallStep_DeactivateLater_Text=The Plugin Installer has 
successfully deactivated the following plugins:"})
     private void presentActionNeedsRestart (Restarter r) {
-        component.setHeadAndContent (UninstallStep_Header_Restart_Head(), 
UninstallStep_Header_Restart_Content());
+        if (model.getOperation() == OperationWizardModel.OperationType.ENABLE) 
{
+            component.setHeadAndContent 
(UninstallStep_Activate_Header_Restart_Head(), 
UninstallStep_Activate_Header_Restart_Content());
+        } else {
+            component.setHeadAndContent (UninstallStep_Header_Restart_Head(), 
UninstallStep_Header_Restart_Content());
+        }
         model.modifyOptionsForDoClose (wd, true);
         restarter = r;
         panel.setRestartButtonsVisible (true);
diff --git 
a/platform/core.startup/src/org/netbeans/core/startup/NbInstaller.java 
b/platform/core.startup/src/org/netbeans/core/startup/NbInstaller.java
index dcdecd07a8..7d9a115757 100644
--- a/platform/core.startup/src/org/netbeans/core/startup/NbInstaller.java
+++ b/platform/core.startup/src/org/netbeans/core/startup/NbInstaller.java
@@ -231,13 +231,13 @@ final class NbInstaller extends ModuleInstaller {
         List<Module> mWithDeps = new LinkedList<Module>();
         mWithDeps.add(m);
         if (mgr != null) {
-            mWithDeps.addAll(mgr.getAttachedFragments(m));
+            addEnabledFragments(m, mWithDeps);
             for (Dependency d : m.getDependencies()) {
                 if (d.getType() == Dependency.TYPE_MODULE) {
                     Module _m = mgr.get((String) 
Util.parseCodeName(d.getName())[0]);
                     assert _m != null : d;
                     mWithDeps.add(_m);
-                    mWithDeps.addAll(mgr.getAttachedFragments(_m));
+                    addEnabledFragments(_m, mWithDeps);
                 }
             }
         }
@@ -283,6 +283,14 @@ final class NbInstaller extends ModuleInstaller {
         }
     }
     
+    private void addEnabledFragments(Module forModule, List<Module> 
moduleWithDependencies) {
+        for (Module fragment : mgr.getAttachedFragments(forModule)) {
+            if (mgr.isOrWillEnable(fragment)) {
+                moduleWithDependencies.add(fragment);
+            }
+        }
+    }
+
     public void dispose(Module m) {
         Util.err.fine("dispose: " + m);
         // Events probably not needed here.
diff --git a/platform/o.n.bootstrap/launcher/unix/nbexec 
b/platform/o.n.bootstrap/launcher/unix/nbexec
index 0b5217845a..1d6ad6e530 100755
--- a/platform/o.n.bootstrap/launcher/unix/nbexec
+++ b/platform/o.n.bootstrap/launcher/unix/nbexec
@@ -291,7 +291,7 @@ look_for_pre_runs() {
         run_updater=yes
     else
         dir="${base}/update/deactivate"
-        if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" ] ; 
then
+        if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" -o -f 
"${dir}/to_enable.txt" ] ; then
             run_updater=yes
         fi
     fi
@@ -306,7 +306,7 @@ look_for_post_runs() {
     else
         dir="${base}/update/deactivate"
         if [ \! -f "${dir}/deactivate_later.txt" ] ; then
-            if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" ] 
; then
+            if [ -f "${dir}/to_disable.txt" -o -f "${dir}/to_uninstall.txt" -o 
-f "${dir}/to_enable.txt" ] ; then
                 run_updater=yes
             fi
         fi
diff --git a/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java 
b/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
index dd62e9eb15..a8d5facc6a 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java
@@ -1109,19 +1109,21 @@ public final class ModuleManager extends Modules {
     }
     
     /**
-     * Attaches a fragment to an existing module. The hosting module must NOT
-     * be already enabled, otherwise an exception will be thrown. Enabled 
module
-     * may have some classes already loaded, and they cannot be patched.
+     * Finds the host module for a given fragment.
      * 
+     * If assertNotEnabled, the hosting module must NOT be already enabled,
+     * otherwise an exception will be thrown. Enabled module may have some
+     * classes already loaded, and they cannot be patched.
+     *
      * @param m module to attach if it is a fragment
      */
-    private Module attachModuleFragment(Module m) {
+    private Module findHostModule(Module m, boolean assertNotEnabled) {
         String codeNameBase = m.getFragmentHostCodeName();
         if (codeNameBase == null) {
             return null;
         }
         Module host = modulesByName.get(codeNameBase);
-        if (host != null && host.isEnabled() && host.getClassLoader() != null) 
{
+        if (assertNotEnabled && host != null && host.isEnabled() && 
host.getClassLoader() != null) {
             throw new IllegalStateException("Host module " + host + " was 
enabled before, will not accept fragment " + m);
         }
         return host;
@@ -1294,7 +1296,7 @@ public final class ModuleManager extends Modules {
      * @param m module to check
      * @return true, if the module is/will enable.
      */
-    boolean isOrWillEnable(Module m) {
+    public boolean isOrWillEnable(Module m) {
         if (m.isEnabled()) {
             return true;
         }
@@ -1331,9 +1333,11 @@ public final class ModuleManager extends Modules {
                 throw new 
IllegalModuleException(IllegalModuleException.Reason.ENABLE_MISSING, errors);
             }
             for (Module m : testing) {
+                //lookup host here, to ensure enablement fails in the host is 
already enabled:
+                Module maybeHost =  findHostModule(m, true);
+
                 if (!modules.contains(m) && !m.isAutoload() && !m.isEager()) {
                     // it is acceptable if the module is a non-autoload host 
fragment, and its host enabled (thus enabled the fragment):
-                    Module maybeHost =  attachModuleFragment(m);
                     if (maybeHost == null && !testing.contains(maybeHost)) {
                         throw new 
IllegalModuleException(IllegalModuleException.Reason.ENABLE_TESTING, m);
                     }
@@ -1798,7 +1802,7 @@ public final class ModuleManager extends Modules {
             addedBecauseOfDependent = m;
             // need to register fragments eagerly, so they are available during
             // dependency sort
-            Module host = attachModuleFragment(m);
+            Module host = findHostModule(m, false);
             if (host != null && !host.isEnabled()) {
                 maybeAddToEnableList(willEnable, mightEnable, host, okToFail, 
"Fragment host");
             }
diff --git 
a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java 
b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
index 06813848cc..d60864328e 100644
--- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
+++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java
@@ -2879,8 +2879,9 @@ public class ModuleManagerTest extends SetupHid {
         mgr.enable(m1);
 
         Module m2 = mgr.create(new File(jars, "fragment-module.jar"), null, 
false, false, false);
+
         try {
-            mgr.simulateEnable(Collections.singleton(m2));
+            mgr.enable(Collections.singleton(m2));
             fail("Enabling fragment must fail if host is already live");
         } catch (IllegalStateException ex) {
             // ok


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Reply via email to