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/06/27 14:15:41 UTC

[GitHub] [netbeans] sdedic opened a new pull request, #4287: Allow to find precise output folder for each language.

sdedic opened a new pull request, #4287:
URL: https://github.com/apache/netbeans/pull/4287

   In a mixed-language project, such as `micronaut-core/http`, each language produces the output typically to a separate folder, although the output is in form of .class files.
   
   Currently Gradle project knows the set of output folders, but does not know what language produces output in which particular one, so backwards mapping in `SourceForBinaryQuery` provides **all source folders**, which is not correct.
   
   In addition, the result of SFBQ query in Gradle/java says that sources should be always preferred. This is fine in theory, but java uses (exclusively) its cached indexed folders instead of the real output folders - so it is able to react on editing changes even before they are compiled. But other languages behave differently.
   
   These two things in effect lead to spurious "undersolved symbol" when Java code references some Groovy or Kotlin class:
   - the `build/groovy/main/classes`, or `build/kotlin/main/classes` is on the `classpath/compile` ClassPath; that's right
   - since `preferSources` is true, java support attempts of SFBQ to find sources. It gets a result. 
   - And to avoid **parsing**, it replaces the source folder with cache folder, under assumption that the sources are indexed into .sig files Java can process.
   
   The last thing is not true for groovy / kotlin, at least now. This could be improved in Java support if it did not entirely replace the output folder with the source, but used the output folder as a cache for the case the SFBQ result folder and its cache does not contain the desired type.
   
   
   ---
   **^Add meaningful description above**
   
   By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
   
    - are all your own work, and you have the right to contribute them.
    - are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
   
   Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
   
   If you're a first time contributor, see the Contributing guidelines for more information.
   
   


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


[GitHub] [netbeans] lbownik commented on a diff in pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4287:
URL: https://github.com/apache/netbeans/pull/4287#discussion_r908803029


##########
java/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java:
##########
@@ -365,6 +366,33 @@ public boolean outputContains(File f) {
     public Set<File> getOutputClassDirs() {
         return outputClassDirs != null ? outputClassDirs : Collections.<File>emptySet();
     }
+    
+    /**
+     * Represents an unknown value. This is different from a value that is not present,
+     * i.e. an output directory for a language that is not used in the project.
+     * @since 1.19
+     */
+    public static final File UNKNOWN = new File("");
+    
+    /**
+     * Returns output directories for the given source type in the sourceset. Returns
+     * null, if the source type has no output directories. Returns UNKNOWN, if the 
+     * output location is not known.
+     * 
+     * @param srcType language type
+     * @return location or {@code null}.
+     * @since 1.19
+     */
+    public File getOutputClassDir(SourceType srcType) {
+        File f = outputs.get(srcType);
+        if (f == null) {

Review Comment:
   this if seems redundant as UNKNOWN.equals(f) evaluates false it f == null
    so maybe
   
   return UNKNOWN.equals(f) ? UNKNOWN : f;
   
   will do?



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


[GitHub] [netbeans] sdedic merged pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
sdedic merged PR #4287:
URL: https://github.com/apache/netbeans/pull/4287


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


[GitHub] [netbeans] lbownik commented on a diff in pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
lbownik commented on code in PR #4287:
URL: https://github.com/apache/netbeans/pull/4287#discussion_r908805056


##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -307,6 +354,43 @@ private void detectSources(NbProjectInfoModel model) {
                             }
                             model.getInfo().put(propBase + lang + "_compiler_args", new ArrayList<>(compilerArgs));
                         }
+                        if (Boolean.TRUE.equals(available.get(langId))) {
+                            model.getInfo().put(propBase + lang, storeSet(getProperty(sourceSet, langId, "srcDirs")));
+                            DirectoryProperty dirProp = (DirectoryProperty)getProperty(sourceSet, langId, "classesDirectory");
+                            if (dirProp != null) {
+                                File outDir;
+                                
+                                if (dirProp.isPresent()) {
+                                    outDir = dirProp.get().getAsFile();
+                                } else {
+                                    // kotlin plugin uses some weird late binding, so it has the output item, but it cannot be resolved to a 
+                                    // concrete file path at this time. Let's make an approximation from 
+                                    Path candidate = null;
+                                    if (base != null) {
+                                        Path prefix = base.resolve(langId);
+                                        // assume the language has just one output dir in the source set:
+                                        for (int i = 0; i < outPaths.size(); i++) {
+                                            Path p = outPaths.get(i);
+                                            if (p.startsWith(prefix)) {
+                                                if (candidate != null) {
+                                                    candidate = null;
+                                                    break;
+                                                } else {
+                                                    candidate = p;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    if (candidate != null) {

Review Comment:
   how about ternary operator here?



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


[GitHub] [netbeans] sdedic commented on a diff in pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
sdedic commented on code in PR #4287:
URL: https://github.com/apache/netbeans/pull/4287#discussion_r909530753


##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -307,6 +354,43 @@ private void detectSources(NbProjectInfoModel model) {
                             }
                             model.getInfo().put(propBase + lang + "_compiler_args", new ArrayList<>(compilerArgs));
                         }
+                        if (Boolean.TRUE.equals(available.get(langId))) {
+                            model.getInfo().put(propBase + lang, storeSet(getProperty(sourceSet, langId, "srcDirs")));
+                            DirectoryProperty dirProp = (DirectoryProperty)getProperty(sourceSet, langId, "classesDirectory");
+                            if (dirProp != null) {
+                                File outDir;
+                                
+                                if (dirProp.isPresent()) {
+                                    outDir = dirProp.get().getAsFile();
+                                } else {
+                                    // kotlin plugin uses some weird late binding, so it has the output item, but it cannot be resolved to a 
+                                    // concrete file path at this time. Let's make an approximation from 
+                                    Path candidate = null;
+                                    if (base != null) {
+                                        Path prefix = base.resolve(langId);
+                                        // assume the language has just one output dir in the source set:
+                                        for (int i = 0; i < outPaths.size(); i++) {
+                                            Path p = outPaths.get(i);
+                                            if (p.startsWith(prefix)) {
+                                                if (candidate != null) {
+                                                    candidate = null;
+                                                    break;
+                                                } else {
+                                                    candidate = p;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    if (candidate != null) {

Review Comment:
   Fixed in 01cb17c54a



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


[GitHub] [netbeans] sdedic commented on a diff in pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
sdedic commented on code in PR #4287:
URL: https://github.com/apache/netbeans/pull/4287#discussion_r909530953


##########
java/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java:
##########
@@ -365,6 +366,33 @@ public boolean outputContains(File f) {
     public Set<File> getOutputClassDirs() {
         return outputClassDirs != null ? outputClassDirs : Collections.<File>emptySet();
     }
+    
+    /**
+     * Represents an unknown value. This is different from a value that is not present,
+     * i.e. an output directory for a language that is not used in the project.
+     * @since 1.19
+     */
+    public static final File UNKNOWN = new File("");
+    
+    /**
+     * Returns output directories for the given source type in the sourceset. Returns
+     * null, if the source type has no output directories. Returns UNKNOWN, if the 
+     * output location is not known.
+     * 
+     * @param srcType language type
+     * @return location or {@code null}.
+     * @since 1.19
+     */
+    public File getOutputClassDir(SourceType srcType) {
+        File f = outputs.get(srcType);
+        if (f == null) {

Review Comment:
   Fixed in 01cb17c54a



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


[GitHub] [netbeans] sdedic commented on pull request #4287: Allow to find precise output folder for each language.

Posted by GitBox <gi...@apache.org>.
sdedic commented on PR #4287:
URL: https://github.com/apache/netbeans/pull/4287#issuecomment-1169883853

   > 
   > So it would eventually force reloading projects.
   
   Fixed in 01cb17c54a


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