You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/03/17 15:00:53 UTC

[GitHub] [netbeans] lkishalmi commented on a change in pull request #2765: [NETBEANS-5318] Prevent unnecessary Gradle model reloads

lkishalmi commented on a change in pull request #2765:
URL: https://github.com/apache/netbeans/pull/2765#discussion_r579757411



##########
File path: extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectImpl.java
##########
@@ -174,14 +174,76 @@ private Lookup createBasicLookup(ProjectState state, GradleAuxiliaryConfigImpl a
                 state
         );
     }
+    
+    GradleProject getProjectInternal() {
+        synchronized (this) {
+            return project;
+        }
+    }
 
     public GradleProject getGradleProject() {
-        if (project == null) {
-            project = loadProject();
+        GradleProject p = getProjectInternal();
+        if (p != null) {
+            return p;
+        }
+        p = loadProject();
+        synchronized (this) {
+            // avod unnecessary project replacements.
+            if (project != null) {
+                return project;
+            }
+            project = p;
         }
-        return project;
+        return p;
     }
-
+    
+    /**
+     * Records a reloaded project instance. Indicates whether the project was replaced.
+     * The method refuses to replace a project that has been changed since the reload procedure
+     * started. Will also not replace the project, if the original has a better quality
+     * than the reloaded one.
+     * <p>
+     * Pass {@code original = null} to just replace the project without checking.
+     * 
+     * @param original the original project data instance.
+     * @param reloaded the reloaded data.
+     * @param reloadIfMismatch will fire new reload if the project differs from original or quality is not satisfactory.
+     * @return {@code null}, if the project was accepted. {@code Boolean.TRUE}, if the project has
+     * been changed independently; {@code Boolean.FALSE}, if the reloaded project's quality is lower than
+     * the current.
+     */
+    Boolean recordOrReloadProject(GradleProject original, GradleProject reloaded, boolean reloadIfMismatch) {
+        Boolean result = null;

Review comment:
       Yes, tri-state looks bad, also, I do not understand the logic here, how does it fit in the picture. I feel I need more explanation. Maybe over some IM (Slack, Telegram, Zoom...)
   My use case in question would be: There is a good resolvable Gradle project loaded, the user tweaks something in it's build.gradle file, then saves it. There is a syntax error in the new file. The loader, would return the previous GradleProject, but decrease it's quality from FULL -> EVALUATED, marking, that we cannot completely trust our current state, but that's the best we know so far. As far as I see, this code would prevent that behavior.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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