]> source.dussan.org Git - aspectj.git/commitdiff
AjcTask: make version number arrays more generic
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 19 Feb 2024 07:03:31 +0000 (14:03 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 19 Feb 2024 07:55:06 +0000 (14:55 +0700)
SOURCE_INPUTS, TARGET_INPUTS, COMPLIANCE_INPUTS are now populated in a
'for' loop in a static initialiser block. I.e., adding support for a new
Java version is now as simple as incrementing field JAVA_VERSION_MAX. In
case ECJ raises the minimum supporter compiler source/target version,
field JAVA_VERSION_MIN needs to be incremented. But that should happen
less frequently.

This was done to make the 'AspectJ_JDK_Update' tasks as easy and as
little error-prone as possible.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java

index 0737127f91e9ca1c7144be341b2d1e9c55157e6d..777c765172b0c92f8c3f2f1ce15d8c5ad0ac7503 100644 (file)
@@ -250,21 +250,43 @@ public class AjcTask extends MatchingTask {
 
        public static final String COMMAND_EDITOR_NAME = AjcTask.class.getName() + ".COMMAND_EDITOR";
 
-       // AspectJ_JDK_Update
-       static final String[] TARGET_INPUTS = new String[] {
-               "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
-               "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"
-       };
-       // AspectJ_JDK_Update
-       static final String[] SOURCE_INPUTS = new String[] {
-               "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
-               "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"
-       };
-       // AspectJ_JDK_Update
-       static final String[] COMPLIANCE_INPUTS = new String[] {
-               "-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9",
-               "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19", "-20", "-21"
-       };
+       // AspectJ_JDK_Update: Check minimum supported ECJ version, currently 1.3
+       static final int JAVA_VERSION_MIN = 3;
+       // AspectJ_JDK_Update: Check maximum supported ECJ version
+       static final int JAVA_VERSION_MAX = 21;
+
+       static final String[] SOURCE_INPUTS;
+       static final String[] TARGET_INPUTS;
+       static final String[] COMPLIANCE_INPUTS;
+
+       static {
+               // 1.3 to 1.9
+               final int major1Versions = 10 - JAVA_VERSION_MIN;
+               // 5 to JAVA_VERSION_MAX
+               final int major5AndUpVersions = JAVA_VERSION_MAX - 4;
+
+               SOURCE_INPUTS = new String[major1Versions + major5AndUpVersions];
+               TARGET_INPUTS = new String[major1Versions + major5AndUpVersions];
+               COMPLIANCE_INPUTS = new String[major1Versions + major5AndUpVersions];
+
+               int arrayIndex = 0;
+               for (int i = 3; i <= JAVA_VERSION_MAX ; i++) {
+                       // Before Java 10, 1.x majors were supported by ECJ/AJC
+                       if (i < 10) {
+                               SOURCE_INPUTS[arrayIndex] = "1." + i;
+                               TARGET_INPUTS[arrayIndex] = "1." + i;
+                               COMPLIANCE_INPUTS[arrayIndex] = "-1." + i;
+                               arrayIndex++;
+                       }
+                       // Since Java 5, non-1 majors are supported by ECJ/AJC
+                       if (i >= 5) {
+                               SOURCE_INPUTS[arrayIndex] = "" + i;
+                               TARGET_INPUTS[arrayIndex] = "" + i;
+                               COMPLIANCE_INPUTS[arrayIndex] = "-" + i;
+                               arrayIndex++;
+                       }
+               }
+       }
 
        private static final ICommandEditor COMMAND_EDITOR;
 
index ae67012b9cba017bbcb16e2c95a5cc63ad580076..fd9834eb58dec396bdc46fea13bede039a79792a 100644 (file)
@@ -656,7 +656,7 @@ public class AjcTaskTest extends TestCase {
        }
 
        public void testVersions() {
-        String[] inputs = AjcTask.TARGET_INPUTS;
+               String[] inputs = AjcTask.TARGET_INPUTS;
                for (String value : inputs) {
                        AjcTask task = getTask(NOFILE);
                        task.setTarget(value);
@@ -665,7 +665,7 @@ public class AjcTaskTest extends TestCase {
                        checkContains(cmd, value, true);
                }
 
-        inputs = AjcTask.SOURCE_INPUTS;
+               inputs = AjcTask.SOURCE_INPUTS;
                for (String s : inputs) {
                        AjcTask task = getTask(NOFILE);
                        task.setSource(s);
@@ -674,7 +674,7 @@ public class AjcTaskTest extends TestCase {
                        checkContains(cmd, s, true);
                }
 
-        inputs = AjcTask.COMPLIANCE_INPUTS;
+               inputs = AjcTask.COMPLIANCE_INPUTS;
                for (String input : inputs) {
                        AjcTask task = getTask(NOFILE);
                        task.setCompliance(input);