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 2022/04/08 15:28:44 UTC

[GitHub] [netbeans] lkishalmi commented on a diff in pull request #3942: Fix project load caching

lkishalmi commented on code in PR #3942:
URL: https://github.com/apache/netbeans/pull/3942#discussion_r846247015


##########
extide/gradle/src/org/netbeans/modules/gradle/loaders/LegacyProjectLoader.java:
##########
@@ -425,10 +439,95 @@ private static NbProjectInfo retrieveProjectInfo(NbGradleProjectImpl projectImpl
         
         BuildActionExecuter<NbProjectInfo> action = createInfoAction(pconn, online, token, pl);
         wasOnline.set(true);
-        ret = action.run();
-        return ret;
+        return runInfoAction(action);
+    }
+    
+
+    /**
+     * Makes a workaround for standard {@link PipedOutputStream} wait.
+     * <p>The {@link PipedInputStream#read()}, in case the receive buffer is
+     * empty at the time of the call, waits for up to 1000ms.
+     * {@link PipedOutputStream#write(int)} does call <code>sink.receive</code>,
+     * but does not <code>notify()</code> the sink object so that read's
+     * wait() terminates.
+     * <p>
+     * As a result, the read side of the pipe waits full 1000ms even though data
+     * become available during the wait.
+     * <p>
+     * The workaround is to simply {@link PipedOutputStream#flush} after write,
+     * which returns from wait()s immediately.
+     *
+     * @author Svata Dedic Copyright (C) 2020
+     */
+    static class ImmediatePipedOutputStream extends PipedOutputStream {
+        @Override
+        public void write(byte[] b, int off, int len) throws IOException {
+            super.write(b, off, len);
+            flush();
+        }
+
+        @Override
+        public void write(int b) throws IOException {
+            super.write(b);
+            flush();
+        }
     }
 
+    private static NbProjectInfo runInfoAction(BuildActionExecuter<NbProjectInfo> action) {
+        class LogDelegate implements Runnable {
+            final BufferedReader rdr;
+            
+            LogDelegate(InputStream is) throws IOException {
+                rdr = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            }
+            
+            public void run() {
+                boolean first = true;
+                try {
+                    String line;
+                    while ((line = rdr.readLine()) != null) {
+                        if (first) {
+                            LOG.log(Level.FINER, "[gradle] ---- daemon log starting");
+                            first = false;
+                        }
+                        LOG.log(Level.FINER, "[gradle] {0}", line);
+                    }
+                } catch (IOException ex) {
+                } finally {
+                    LOG.log(Level.FINER, "[gradle] ---- log terminated");
+                }
+            }
+        }
+        
+        OutputStream logStream = null;
+        try {
+            if (LOG.isLoggable(Level.FINER)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    action.addArguments("--debug"); // NOI18N
+                }
+                PipedOutputStream pos = new ImmediatePipedOutputStream();
+                try {
+                    logStream = pos;
+                    DAEMON_LOG_RP.post(new LogDelegate(new PipedInputStream(pos)));
+                } catch (IOException ex) {
+                    throw new IllegalStateException(ex);
+                }
+                action.setStandardOutput(pos);

Review Comment:
   Is this thing with the Piped streams necessary? I thought the Gradle out/err are attached to the system out/err which at the end ends up in the netbeans log. Though this way we have more control of this.



##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -172,7 +180,8 @@ private void detectProjectMetadata(NbProjectInfoModel model) {
         model.getInfo().put("project_buildDir", project.getBuildDir());
         model.getInfo().put("project_projectDir", project.getProjectDir());
         model.getInfo().put("project_rootDir", project.getRootDir());
-        model.getInfo().put("gradle_user_home", project.getGradle().getGradleHomeDir());
+        model.getInfo().put("gradle_user_home", project.getGradle().getGradleUserHomeDir());

Review Comment:
   Nice catch!



##########
extide/gradle/src/org/netbeans/modules/gradle/NbGradleProjectImpl.java:
##########
@@ -477,9 +477,10 @@ public boolean satisifes(LoadingCF other) {
                     this.loading = null;
                 }
             }
+            f.complete(prj);

Review Comment:
   Well I think this patch is reasonable. There might be better options we can come up out there, but right now it seems to be good enough. Just confirm that I'm reading it right. In this patch, we simply make the completable future completed before we are firing the notification events, so the event handlers can get the project in non-transient state?



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

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