private void notifyModelChange(NbGradleModel model) {
      int setSize = 2 * extensionRefs.size();
      Set<String> disabledExtensions = new HashSet<String>(setSize);
      Map<String, GradleProjectExtension> loadedExtensions =
          new HashMap<String, GradleProjectExtension>(setSize);

      for (ProjectExtensionRef extensionRef : extensionRefs) {
        GradleProjectExtension extension = extensionRef.getExtension();

        String name = extension.getExtensionName();
        if (disabledExtensions.contains(name)) {
          continue;
        }

        Set<String> conflicts =
            safelyLoadExtensions(extension, model.getModelsForExtension(extensionRef));
        disabledExtensions.addAll(conflicts);
        loadedExtensions.put(name, extension);
      }

      // TODO: What if an extension is disabled and so extensions
      //  conflicting with it can be enabled? Should we consider this case?

      for (String disabled : disabledExtensions) {
        GradleProjectExtension extension = loadedExtensions.get(disabled);
        if (extension != null) {
          safelyLoadExtensions(extension, Lookup.EMPTY);
        }
      }

      fireModelChangeEvent();
    }
    private Set<String> safelyLoadExtensions(GradleProjectExtension extension, Lookup lookup) {
      Set<String> conflicts = null;
      try {
        conflicts = extension.modelsLoaded(lookup);
      } catch (Throwable ex) {
        LOGGER.log(
            Level.SEVERE,
            "Extension has thrown an unexpected exception: " + extension.getExtensionName(),
            ex);
      }

      return conflicts != null ? conflicts : Collections.<String>emptySet();
    }
  private void setExtensions(List<GradleProjectExtension> extensions) {
    List<GradleProjectExtension> newExtensions =
        Collections.unmodifiableList(new ArrayList<GradleProjectExtension>(extensions));
    List<Lookup> allLookups = new ArrayList<Lookup>(newExtensions.size() + 1);
    List<ProjectExtensionRef> newExtensionRefs =
        new ArrayList<ProjectExtensionRef>(newExtensions.size());

    allLookups.add(getDefaultLookup());
    for (final GradleProjectExtension extension : newExtensions) {
      allLookups.add(extension.getExtensionLookup());
      newExtensionRefs.add(new ProjectExtensionRef(extension));
    }

    this.extensionsOnLookup = Lookups.fixed(newExtensions.toArray());
    this.extensionRefs = Collections.unmodifiableList(newExtensionRefs);
    getMainLookup().replaceLookups(allLookups);
  }