I have made an alternative patch, this one looks better and does not
contain a bug that results in a warning if target level "1.7" is
supplied instead of "7".
Description: Adjust the source/target level automatically for building with recent JDKs
Author: Emmanuel Bourg <[email protected]>
Forwarded: not-needed
--- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
+++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
@@ -208,6 +208,39 @@
         }
     }
 
+    private static final List<String> unsupportedLanguageLevels = getUnsupportedLanguageLevels();
+
+    private static List<String> getUnsupportedLanguageLevels()
+    {
+        if (isAtLeastJava21())
+        {
+            return Arrays.asList(new String[]{"1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6", "1.7", "7" });
+        }
+        return Arrays.asList(new String[]{"1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6" });
+    }
+
+    private static boolean isAtLeastJava21()
+    {
+        try
+        {
+            return Integer.parseInt(System.getProperty("java.specification.version")) >= 21;
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+    }
+
+    private static String getMinRelease()
+    {
+        return isAtLeastJava21() ? "8" : "7";
+    }
+
+    private static boolean isUnsupportedRelease(String version)
+    {
+        return unsupportedLanguageLevels.contains( version );
+    }
+
     public String[] createCommandLine( CompilerConfiguration config )
         throws CompilerException
     {
@@ -378,7 +411,15 @@
         if ( !StringUtils.isEmpty( config.getReleaseVersion() ) )
         {
             args.add( "--release" );
-            args.add( config.getReleaseVersion() );
+            if ( unsupportedLanguageLevels.contains( config.getReleaseVersion() ) )
+            {
+                System.err.println( "Use of release " + config.getReleaseVersion() + " is no longer supported, switching to " + getMinRelease() );
+                args.add( getMinRelease() );
+            }
+            else
+            {
+                args.add( config.getReleaseVersion() );
+            }
         }
         else
         {
@@ -387,7 +428,13 @@
             {
                 // Required, or it defaults to the target of your JDK (eg 1.5)
                 args.add( "-target" );
-                args.add( "1.1" );
+                args.add( getMinRelease() );
+            }
+            else if ( unsupportedLanguageLevels.contains( config.getTargetVersion() ) )
+            {
+                System.err.println( "Use of target " + config.getTargetVersion() + " is no longer supported, switching to " + getMinRelease() );
+                args.add( "-target" );
+                args.add( getMinRelease() );
             }
             else
             {
@@ -399,7 +446,13 @@
             {
                 // If omitted, later JDKs complain about a 1.1 target
                 args.add( "-source" );
-                args.add( "1.3" );
+                args.add( getMinRelease() );
+            }
+            else if ( !suppressSource( config ) && unsupportedLanguageLevels.contains( config.getSourceVersion() ) )
+            {
+                System.err.println( "Use of source " + config.getSourceVersion() + " is no longer supported, switching to " + getMinRelease() );
+                args.add( "-source" );
+                args.add( getMinRelease() );
             }
             else if ( !suppressSource( config ) )
             {
__
This is the maintainer address of Debian's Java team
<https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-java-maintainers>.
 Please use
[email protected] for discussions and questions.

Reply via email to