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(); }