@Override
  public Sharability getSharability(URI uri) {
    Path queriedPath = tryConvertToPath(uri);
    if (queriedPath == null) {
      return Sharability.UNKNOWN;
    }

    NbGradleModel model = project.currentModel().getValue();
    Path rootProjectDir = model.getSettingsDir();

    if (isInBuildDir(model, queriedPath)) {
      return Sharability.NOT_SHARABLE;
    }
    if (isInDirectory(SettingsFiles.getSettingsDir(rootProjectDir), queriedPath)) {
      return Sharability.NOT_SHARABLE;
    }
    if (isInDirectory(SettingsFiles.getPrivateSettingsDir(rootProjectDir), queriedPath)) {
      return Sharability.NOT_SHARABLE;
    }

    Path projectDir = model.getProjectDir().toPath();
    if (isInDirectory(projectDir, queriedPath)) {
      return Sharability.SHARABLE;
    }

    return Sharability.UNKNOWN;
  }
    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();
    }
 public NbGradleModel getAvailableModel() {
   NbGradleModelRef resultRef = currentModelRef.get();
   NbGradleModel result = resultRef.model;
   // This is not a completely correct solution. The correct
   // solution would be to listen when the model becomes dirty (based on
   // the directory of the project). The problem is that there is no place
   // to unregister such listener.
   //
   // However this should work in most practical cases since
   // getAvailableModel() often gets called.
   if (result.isDirty() || !resultRef.isUpdateToDate()) {
     // Set a non-dirty to prevent many unnecessary project reload.
     currentModelRef.set(new NbGradleModelRef(result.createNonDirtyCopy()));
     reloadProject(true);
   }
   return result;
 }
 public static Path getRootDirectory(NbGradleProject project) {
   NbGradleModel model = project.currentModel().getValue();
   return model.getSettingsDir();
 }
 public boolean isUpdateToDate() {
   return stateID.equals(model.getStateID());
 }
 public NbGradleModelRef(NbGradleModel model) {
   this.model = model;
   this.stateID = model.getStateID();
 }
 private static boolean isInBuildDir(NbGradleModel model, Path queriedFile) {
   Path buildDir = model.getGenericInfo().getBuildDir().toPath();
   return isInDirectory(buildDir, queriedFile);
 }