sdedic commented on code in PR #6829:
URL: https://github.com/apache/netbeans/pull/6829#discussion_r1422036468


##########
extide/gradle/src/org/netbeans/modules/gradle/loaders/GradleDaemon.java:
##########
@@ -52,22 +52,45 @@ public final class GradleDaemon {
 
     private GradleDaemon() {}
 
-    public static String initScript() {
-        File initScript = Places.getCacheSubfile("gradle/nb-tooling.gradle"); 
//NOI18N
-        synchronized (initScriptReady) {
-            if (!initScriptReady.get()) {
-                File initTemplate = 
InstalledFileLocator.getDefault().locate(INIT_SCRIPT_NAME, 
NbGradleProject.CODENAME_BASE, false);
-                try (Stream<String> lines = 
Files.lines(initTemplate.toPath())) {
-                    List<String> script = lines.map(line -> 
line.replace(PROP_TOOLING_JAR, TOOLING_JAR)).collect(Collectors.toList());
-                    Files.write(initScript.toPath(), script);
-                    initScriptReady.set(true);
-                } catch(IOException ex) {
-                    // This one is unlikely
-                    LOG.log(Level.WARNING, "Can't create NetBeans Gradle init 
script", ex); //NOI18N
-                    // Let it pass trough. Gradle call will display some 
errors as well
+    public static String initScript(GradleRuntime rt) {
+        Path initScript = 
rt.rootDir.toPath().resolve(".gradle/nb-tooling.gradle"); //NOI18N
+        String onDisk = "";
+        try {
+            onDisk = Files.readString(initScript);
+        } catch (IOException ex) {}
+        String init = generateInitScript(rt);
+        if (!onDisk.equals(init)) {
+            try {
+                Files.createDirectories(initScript.getParent());
+                Files.writeString(initScript, init);
+            } catch (IOException ex) {}
+        }
+        return initScript.toString();
+    }
+    
+    private static String generateInitScript(GradleRuntime rt) {
+        var providers = 
Lookup.getDefault().lookupAll(GradlePluginProvider.class);
+        try (var wr = new StringWriter()) {
+            wr.append("initscript {\n");
+            wr.append("    dependencies {\n");
+            for (GradlePluginProvider pvd : providers) {

Review Comment:
   A suggestion: if a `GradlePluginProvider` had a method `boolean 
accepts(GradleRuntime r)`, then the providers can be filtered centrally. In the 
current state, each of the methods (classpath, plugins) need to accept 
`GradleRuntime and test for applicable version`. 
   Alternatively (future-compatible), suggest to have just 
   ```
   @CheckForNull GradlePluginDescriptor getPlugins(GradleRuntime r);
   
   public final class GradlePluginDescriptor {
       Collection<File> getClasspath(GradleRuntime runtime) {...}
       Collection<String> getPlugins(GradleRuntime runtime) {...}
   }
   ```
   which could eventually allow to compatibly add more information in the 
future, if needed.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to