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/10/05 19:57:00 UTC

[GitHub] [netbeans] errael commented on a diff in pull request #4711: Override gradle's compiler version from compiler args.

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


##########
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:
   The first implementation did that (the one that was in the wrong place). I'll make that change after any other suggested changes have time to roll in. Thanks for the comment.



##########
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:
   I remember now why I compared to map instance; because -source/-target are/might-be specific to java. I'll change the method name to `fixJavaCompatibility`. I'd like to take out the souceType argument, but then the check for JAVA would, would have to be in the caller.



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