#221542: AWT blocked when PM is scanning updates release73_beta2
authorJiri Rechtacek <jrechtacek@netbeans.org>
Tue, 06 Nov 2012 22:42:35 +0100
branchrelease73_beta2
changeset 2461304b9ddecda013
parent 246022 cc8eca9f157b
child 246599 b50e87eb3471
#221542: AWT blocked when PM is scanning updates
(transplanted from 6af6f1a0b6509d553794465cbe660a73d7c883b3)
autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationContainerImpl.java
autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UpdateTableModel.java
autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java
autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/LazyOperationDescriptionStep.java
     1.1 --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationContainerImpl.java	Tue Nov 06 15:40:23 2012 +0100
     1.2 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/OperationContainerImpl.java	Tue Nov 06 22:42:35 2012 +0100
     1.3 @@ -227,9 +227,10 @@
     1.4          if ((type == OperationType.INSTALL || type == OperationType.UPDATE || type==OperationType.INTERNAL_UPDATE) && checkEagers) {
     1.5              Collection<UpdateElement> all = new HashSet<UpdateElement> (operations.size ());
     1.6              for (OperationInfo<?> i : operations) {
     1.7 -                all.add (i.getUpdateElement ());
     1.8 -                all.addAll (i.getRequiredElements());
     1.9 -                //TODO: what if elImpl instanceof FeatureUpdateElementImpl ?
    1.10 +                all.add(i.getUpdateElement());
    1.11 +            }
    1.12 +            for (OperationInfo<?> i : operations) {
    1.13 +                all.addAll(i.getRequiredElements());
    1.14              }
    1.15              for (UpdateElement eagerEl : UpdateManagerImpl.getInstance ().getAvailableEagers ()) {
    1.16                  if(eagerEl.getUpdateUnit().isPending() || eagerEl.getUpdateUnit().getAvailableUpdates().isEmpty()) {
    1.17 @@ -437,7 +438,11 @@
    1.18          public UpdateUnit/*or null*/ getUpdateUnit () {
    1.19              return uUnit;
    1.20          }
    1.21 +        private List<UpdateElement> requiredElements;
    1.22          public List<UpdateElement> getRequiredElements (){
    1.23 +            if (upToDate && requiredElements != null) {
    1.24 +                return requiredElements;
    1.25 +            }
    1.26              List<ModuleInfo> moduleInfos = new ArrayList<ModuleInfo>();
    1.27              for (OperationContainer.OperationInfo oii : listAll ()) {
    1.28                  UpdateElementImpl impl = Trampoline.API.impl (oii.getUpdateElement ());
    1.29 @@ -447,7 +452,7 @@
    1.30              }
    1.31              brokenDeps = new HashSet<String> ();
    1.32              Set<UpdateElement> recommeded = new HashSet<UpdateElement>();
    1.33 -            List<UpdateElement> requiredElements = OperationValidator.getRequiredElements (type, getUpdateElement (), moduleInfos, brokenDeps, recommeded);
    1.34 +            requiredElements = OperationValidator.getRequiredElements (type, getUpdateElement (), moduleInfos, brokenDeps, recommeded);
    1.35              if (! brokenDeps.isEmpty() && ! recommeded.isEmpty()) {
    1.36                  brokenDeps = new HashSet<String> ();
    1.37                  requiredElements = OperationValidator.getRequiredElements (type, getUpdateElement (), moduleInfos, brokenDeps, recommeded);
     2.1 --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java	Tue Nov 06 15:40:23 2012 +0100
     2.2 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java	Tue Nov 06 22:42:35 2012 +0100
     2.3 @@ -45,6 +45,8 @@
     2.4  package org.netbeans.modules.autoupdate.services;
     2.5  
     2.6  import java.io.*;
     2.7 +import java.lang.ref.Reference;
     2.8 +import java.lang.ref.WeakReference;
     2.9  import java.security.KeyStore;
    2.10  import java.security.KeyStoreException;
    2.11  import java.security.NoSuchAlgorithmException;
    2.12 @@ -556,7 +558,6 @@
    2.13                      brokenDependencies.addAll (moreBroken);
    2.14                      break;
    2.15                  }
    2.16 -                tmp = new HashSet<ModuleInfo> ();
    2.17                  for (UpdateElement e : more) {
    2.18                      //infos.addAll (Trampoline.API.impl (el).getModuleInfos ());
    2.19                      tmp.add (((ModuleUpdateElementImpl) Trampoline.API.impl (e)).getModuleInfo ());
    2.20 @@ -585,7 +586,17 @@
    2.21          return retval;
    2.22      }
    2.23      
    2.24 +    private static Reference<Set<ModuleInfo>> cachedInfosReference = null;            
    2.25 +    private static Reference<Set<UpdateElement>> cachedResultReference = null;
    2.26 +    
    2.27      public static Set<UpdateElement> handleBackwardCompatability (Set<ModuleInfo> forInstall, Set<Dependency> brokenDependencies, boolean aggressive) {
    2.28 +        if (cachedInfosReference != null && cachedInfosReference.get() != null && cachedInfosReference.get().equals(forInstall)) {
    2.29 +            if (cachedResultReference != null && cachedResultReference.get() != null) {
    2.30 +                return cachedResultReference.get();
    2.31 +            }
    2.32 +        }
    2.33 +        cachedInfosReference = new WeakReference<Set<ModuleInfo>>(forInstall);
    2.34 +        
    2.35          Set<UpdateElement> moreRequested = new HashSet<UpdateElement> ();
    2.36          // backward compatibility
    2.37          for (ModuleInfo mi : forInstall) {
    2.38 @@ -652,6 +663,8 @@
    2.39                      }
    2.40              }
    2.41          }
    2.42 +        cachedResultReference = new WeakReference<Set<UpdateElement>>(moreRequested);
    2.43 +
    2.44          return moreRequested;
    2.45      }
    2.46  
     3.1 --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UpdateTableModel.java	Tue Nov 06 15:40:23 2012 +0100
     3.2 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/UpdateTableModel.java	Tue Nov 06 22:42:35 2012 +0100
     3.3 @@ -220,8 +220,9 @@
     3.4          infos.addAll (containerCustom.listAll ());
     3.5          Set<UpdateElement> elements = new HashSet<UpdateElement> ();
     3.6          for (OperationInfo info : infos) {
     3.7 -            elements.add (info.getUpdateElement ());
     3.8 -            elements.addAll (info.getRequiredElements ());
     3.9 +            if (elements.add (info.getUpdateElement ())) {
    3.10 +                elements.addAll (info.getRequiredElements ());
    3.11 +            }
    3.12          }
    3.13          for (UpdateElement el : elements) {
    3.14              res += el.getDownloadSize ();
     4.1 --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java	Tue Nov 06 15:40:23 2012 +0100
     4.2 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/Utilities.java	Tue Nov 06 22:42:35 2012 +0100
     4.3 @@ -157,7 +157,7 @@
     4.4          logger.fine("License IDs - Stored: " + (sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1)));
     4.5      }
     4.6      
     4.7 -    public static void initAcceptedLicenseIDs() {
     4.8 +    public static synchronized void initAcceptedLicenseIDs() {
     4.9          assert ! SwingUtilities.isEventDispatchThread() : "Don't call in AWT queue";
    4.10          if (acceptedLicenseIDs == null) {
    4.11              acceptedLicenseIDs = new HashSet<String> ();
     5.1 --- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/LazyOperationDescriptionStep.java	Tue Nov 06 15:40:23 2012 +0100
     5.2 +++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/wizards/LazyOperationDescriptionStep.java	Tue Nov 06 22:42:35 2012 +0100
     5.3 @@ -174,6 +174,7 @@
     5.4                                  oc.add (el);
     5.5                              }
     5.6                          }
     5.7 +                        model.getBaseContainer().listAll();
     5.8                          final WizardDescriptor.Iterator<WizardDescriptor> panels = new InstallUnitWizardIterator (model, true);
     5.9                          SwingUtilities.invokeLater (new Runnable () {
    5.10                              @Override