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


##########
java/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java:
##########
@@ -162,7 +165,36 @@ public String getTargetCompatibility() {
      * @return the defined target compatibility
      */
     public String getTargetCompatibility(SourceType type) {
-        return targetCompatibility.getOrDefault(type, 
getSourcesCompatibility(type));
+        return fixCompatibility(type, 
targetCompatibility).orElse(getSourcesCompatibility(type));
+    }
+
+    /**
+     * Use compiler arguments to override source/target compatibility for JAVA.
+     * Look for something like "-flag" or "--flag" in args, the last occurence;
+     * return  it if found.
+     * <br>
+     * For example for source, flag is "-source", and args is
+     * "... --source 13 ..." then return "13". If not in args
+     * then don't change the compatibility, return the current value.
+     */
+    private Optional<String> fixCompatibility(SourceType sourceType, 
Map<SourceType, String> compatibilityMap) {
+        String compatibility = compatibilityMap.get(sourceType);
+        if(sourceType == SourceType.JAVA) { // only fixup for java
+            List<String> args = getCompilerArgs(sourceType);
+            if(args != null && !args.isEmpty()) {
+                String flag = compatibilityMap == sourcesCompatibility ? 
"-source" : "-target";

Review Comment:
   Nitpick: maybe pass the flag source/target explicitly rather than comparing 
Map instances ?



-- 
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-unsubscr...@netbeans.apache.org

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


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

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

Reply via email to