This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5db27588d compiler: allow tests to be run with AIR ADL instead of 
Flash Player
5db27588d is described below

commit 5db27588dd9105848956571891909450999cf1c5
Author: Josh Tynjala <[email protected]>
AuthorDate: Tue Feb 3 14:06:36 2026 -0800

    compiler: allow tests to be run with AIR ADL instead of Flash Player
    
    Still uses FLASHPLAYER_DEBUGGER, if defined, but can fall back to ADL if 
AIR_HOME is defined instead
---
 .../org/apache/royale/utils/AntTestAdapter.java    |  38 +++++
 .../java/org/apache/royale/utils/ITestAdapter.java |   4 +
 .../org/apache/royale/utils/MavenTestAdapter.java  |  47 ++++++
 compiler/src/test/java/as/ASFeatureTestsBase.java  | 170 +++++++++++++++++++--
 .../java/mxml/tags/MXMLDefinitionTagTests.java     |  24 ++-
 .../test/java/mxml/tags/MXMLFeatureTestsBase.java  | 135 +++++++++++++++-
 .../java/mxml/tags/MXMLInstanceTagTestsBase.java   |  22 ++-
 .../test/java/mxml/tags/MXMLMetadataTagTests.java  |  22 ++-
 .../java/properties/MXMLPropertyTestsBase.java     |  22 ++-
 9 files changed, 460 insertions(+), 24 deletions(-)

diff --git 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/AntTestAdapter.java 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/AntTestAdapter.java
index fcb505045..73085e703 100644
--- 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/AntTestAdapter.java
+++ 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/AntTestAdapter.java
@@ -34,6 +34,8 @@ public class AntTestAdapter implements ITestAdapter {
     private static File PLAYERGLOBAL_SWC;
     // The Ant script for compiler.tests copies a standalone player to the 
temp directory.
     private static File FLASHPLAYER;
+    private static File ADL;
+    private static File ADT;
 
     private static File LIBS_ROOT;
     private static File RESOURCE_BUNDLES_ROOT;
@@ -81,6 +83,42 @@ public class AntTestAdapter implements ITestAdapter {
         return FLASHPLAYER;
     }
 
+    @Override
+    public File getAirDebugger() {
+       if (ADL == null && env.AIRSDK != null)
+        {
+               File airHome = new 
File(FilenameNormalization.normalize(env.AIRSDK));
+            if (airHome.exists() && airHome.isDirectory())
+            {
+                String adlExeName = "adl";
+                if 
(System.getProperty("os.name").toLowerCase().contains("windows"))
+                {
+                    adlExeName += ".exe";
+                }
+                ADL = new File(airHome, "bin" + File.separator + adlExeName);
+            }
+        }
+        return ADL;
+    }
+
+    @Override
+    public File getAirAdt() {
+       if (ADT == null && env.AIRSDK != null)
+        {
+               File airHome = new 
File(FilenameNormalization.normalize(env.AIRSDK));
+            if (airHome.exists() && airHome.isDirectory())
+            {
+                String adtExeName = "adt";
+                if 
(System.getProperty("os.name").toLowerCase().contains("windows"))
+                {
+                    adtExeName += ".bat";
+                }
+                ADT = new File(airHome, "bin" + File.separator + adtExeName);
+            }
+        }
+        return ADT;
+    }
+
     @Override
     public String getFlexManifestPath(String type) {
         return FilenameNormalization.normalize(env.SDK + "\\frameworks\\" + 
type + "-manifest.xml");
diff --git 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/ITestAdapter.java 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/ITestAdapter.java
index f3b516b2e..f9b529156 100644
--- 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/ITestAdapter.java
+++ 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/ITestAdapter.java
@@ -34,6 +34,10 @@ public interface ITestAdapter {
 
     File getFlashplayerDebugger();
 
+    File getAirDebugger();
+
+    File getAirAdt();
+
     String getFlexManifestPath(String type);
 
     File getFlexArtifact(String artifactName);
diff --git 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/MavenTestAdapter.java
 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/MavenTestAdapter.java
index 11441dfed..390395c86 100644
--- 
a/compiler-test-utils/src/main/java/org/apache/royale/utils/MavenTestAdapter.java
+++ 
b/compiler-test-utils/src/main/java/org/apache/royale/utils/MavenTestAdapter.java
@@ -98,6 +98,53 @@ public class MavenTestAdapter implements ITestAdapter {
         return new File(FLASHPLAYER_DEBUGGER);
     }
 
+    @Override
+    public File getAirDebugger() {
+        if(!optionWithSwfEnabled()) {
+            return null;
+        }
+        String AIR_HOME = System.getProperty("AIR_HOME", null);
+        if(AIR_HOME == null || AIR_HOME.length() == 0) {
+            System.out.println("AIR_HOME not specified");
+            return null;
+        }
+        File airHome = new File(AIR_HOME);
+        if (!airHome.exists() || !airHome.isDirectory())
+        {
+            System.out.println("AIR_HOME is invalid");
+            return null;
+        }
+        String adlExeName = "adl";
+        if (System.getProperty("os.name").toLowerCase().contains("windows"))
+        {
+            adlExeName += ".exe";
+        }
+        System.out.println("Using AIR");
+        return new File(airHome, "bin" + File.separator + adlExeName);
+    }
+
+    @Override
+    public File getAirAdt() {
+        if(!optionWithSwfEnabled()) {
+            return null;
+        }
+        String AIR_HOME = System.getProperty("AIR_HOME", null);
+        if(AIR_HOME == null || AIR_HOME.length() == 0) {
+            return null;
+        }
+        File airHome = new File(AIR_HOME);
+        if (!airHome.exists() || !airHome.isDirectory())
+        {
+            return null;
+        }
+        String adtExeName = "adt";
+        if (System.getProperty("os.name").toLowerCase().contains("windows"))
+        {
+            adtExeName += ".bat";
+        }
+        return new File(airHome, "bin" + File.separator + adtExeName);
+    }
+
     @Override
     public String getFlexManifestPath(String type) {
         File configsZip = getDependency("org.apache.flex.framework", 
"framework",
diff --git a/compiler/src/test/java/as/ASFeatureTestsBase.java 
b/compiler/src/test/java/as/ASFeatureTestsBase.java
index bc40aa8cb..5119ebe45 100644
--- a/compiler/src/test/java/as/ASFeatureTestsBase.java
+++ b/compiler/src/test/java/as/ASFeatureTestsBase.java
@@ -25,11 +25,13 @@ import org.apache.royale.swf.io.SWFDump;
 import org.apache.royale.utils.*;
 import utils.FlashplayerSecurityHandler;
 
+import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.MalformedURLException;
@@ -38,6 +40,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
@@ -52,6 +56,24 @@ import static org.junit.Assert.fail;
 public class ASFeatureTestsBase
 {
        private static boolean generateResultFile = false;
+
+       private static String APP_DESCRIPTOR_TEMPLATE = "<application 
xmlns=\"http://ns.adobe.com/air/application/@AIR_VERSION@\";>\n" +
+                                               "  <id>RoyaleAdlWrapper</id>\n" 
+
+                                               "  
<filename>RoyaleTestsAdlWrapper</filename>\n" +
+                                               "  <name>Royale Tests Adl 
Wrapper</name>\n" +
+                                               "  
<versionNumber>1.0.0</versionNumber>\n" +
+                                               "  <description>Wrapper 
application for use with the Royale compiler tests.</description>\n" +
+                                               "  <initialWindow>\n" +
+                                               "    <title>Royale Tests Adl 
Wrapper</title>\n" +
+                                               "    
<content>@SWF_NAME@</content>\n" +
+                                               "    
<visible>false</visible>\n" +
+                                               "    
<minimizable>true</minimizable>\n" +
+                                               "    
<maximizable>false</maximizable>\n" +
+                                               "    
<resizable>false</resizable>\n" +
+                                               "    <width>320</width>\n" +
+                                               "    <height>240</height>\n" +
+                                               "  </initialWindow>\n" +
+                                               "</application>";
        
        public ASFeatureTestsBase()
        {
@@ -64,27 +86,119 @@ public class ASFeatureTestsBase
                if(playerGlobal == null || !playerGlobal.isFile() || 
!playerGlobal.exists()) {
                        hasFlashPlayerGlobal = false;
                }
+               File adlExecutable = testAdapter.getAirDebugger();
+               if (adlExecutable == null || !adlExecutable.isFile() || 
!adlExecutable.exists()) {
+                       hasAdlExecutable = false;
+               }
 
-               if (hasFlashPlayerExecutable && !hasFlashPlayerGlobal)
+               if ((hasFlashPlayerExecutable || hasAdlExecutable) && 
!hasFlashPlayerGlobal)
                {
-                       String message = "Fatal Error: If FLASHPLAYER_DEBUGGER 
is defined, playerglobal must be available";
+                       String message = "Fatal Error: If FLASHPLAYER_DEBUGGER 
or AIR_HOME is defined, playerglobal must be available";
                        System.err.println(message);
                        fail(message);
                }
 
-               if (!hasFlashPlayerExecutable && hasFlashPlayerGlobal)
+               if (!hasFlashPlayerExecutable && !hasAdlExecutable && 
hasFlashPlayerGlobal)
                {
-                       String message = "Fatal Error: If playerglobal is 
available, FLASHPLAYER_DEBUGGER is required";
+                       String message = "Fatal Error: If playerglobal is 
available, FLASHPLAYER_DEBUGGER or AIR_HOME is required";
                        System.err.println(message);
                        fail(message);
                }
+
+               if (airVersion == null)
+               {
+                       File adtExecutable = testAdapter.getAirAdt();
+                       if (adtExecutable != null)
+                       {
+                               BufferedReader versionReader = null;
+                               String versionOutput = null;
+                               try
+                               {
+                                       Process process = 
Runtime.getRuntime().exec(new String[]{adtExecutable.getAbsolutePath(), 
"-version"});
+                                       int exitCode = process.waitFor();
+                                       if (exitCode == 0)
+                                       {
+                                               versionReader = new 
BufferedReader(new InputStreamReader(process.getInputStream()));
+                                               versionOutput = 
versionReader.readLine();
+                                       }
+                               }
+                               catch (Exception e)
+                               {
+                                       String message = "Fatal Error: Could 
not run ADT from AIR SDK to detect version";
+                                       System.err.println(message);
+                                       fail(message);
+                               }
+                               finally
+                               {
+                                       if (versionReader != null)
+                                       {
+                                               try
+                                               {
+                                                       versionReader.close();
+                                               }
+                                               catch (IOException e) {}
+                                       }
+                               }
+                               airVersion = 
parseAdtVersionNumber(versionOutput);
+                               if (airVersion == null)
+                               {
+                                       String message = "Fatal Error: Could 
not detect AIR SDK version";
+                                       System.err.println(message);
+                                       fail(message);
+                               }
+                       }
+               }
        }
 
        protected boolean hasFlashPlayerExecutable = true;
        protected boolean hasFlashPlayerGlobal = true;
+       protected boolean hasAdlExecutable = true;
+       private static String airVersion = null;
        
        private static final String NAMESPACE_2009 = 
"http://ns.adobe.com/mxml/2009";;
 
+       private static final Pattern AIR_VERSION_PATTERN = 
Pattern.compile("(\\d+\\.\\d+)(?:\\.\\d)+");
+
+    private String parseAdtVersionNumber(String versionString)
+    {
+               if (versionString == null)
+               {
+                       return null;
+               }
+               Matcher matcher = AIR_VERSION_PATTERN.matcher(versionString);
+               if (matcher.find())
+               {
+                       return matcher.group(1);
+               }
+               return null;
+    }
+
+       protected File generateTempAppDescriptorFile(String source, String 
swfFileName)
+       {
+        // Write the application descriptor into a temp file.
+        ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
+        String tempDir = testAdapter.getTempDir();
+        File tempDescriptorFile = null;
+        try
+        {
+            tempDescriptorFile = 
File.createTempFile(getClass().getSimpleName(), "-app.xml", new File(tempDir));
+            tempDescriptorFile.deleteOnExit();
+
+            BufferedWriter out = new BufferedWriter(new 
FileWriter(tempDescriptorFile));
+            
+            source = source.replaceAll("@SWF_NAME@", swfFileName);
+            source = source.replaceAll("@AIR_VERSION@", airVersion);
+            out.write(source);
+            out.close();
+        }
+        catch (IOException e1) 
+        {
+            e1.printStackTrace();
+            fail("Error generating test code");
+        }
+        return tempDescriptorFile;
+       }
+
        protected File generateTempFile(String source)
        {
         // Write the MXML into a temp file.
@@ -227,8 +341,8 @@ public class ASFeatureTestsBase
            File tempASFile = generateTempFile(source);
            compile(tempASFile, source, withFramework, withRPC, withSpark, 
otherOptions, true, false);
         ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
-               // Check the existence of the flashplayer executable
-               // Run the SWF in the standalone player amd wait until the SWF 
calls System.exit().
+               // Run the SWF in the standalone player or adl
+               // and wait until the SWF calls System.exit() or 
NativeApplication.nativeApplication.exit().
                String swf = 
FilenameNormalization.normalize(tempASFile.getAbsolutePath());
                swf = swf.replace(".as", ".swf");
                if (hasFlashPlayerExecutable)
@@ -254,6 +368,26 @@ public class ASFeatureTestsBase
                    // Check that the runtime exit code was 0, meaning that no 
asserts failed.
                        assertThat(exitCode, is(0));
                }
+               else if (hasAdlExecutable)
+               {
+                       File adlExecutable = testAdapter.getAirDebugger();
+                       File appDescriptorFile = 
generateTempAppDescriptorFile(APP_DESCRIPTOR_TEMPLATE, new File(swf).getName());
+                       String[] runArgs = new String[] { 
adlExecutable.getPath(), appDescriptorFile.getPath() };
+                       try
+                       {
+                               System.out.println("Executing test:\n" + 
Arrays.toString(runArgs));
+                               exitCode = executeCommandWithTimeout(runArgs, 
20);
+                       }
+                       catch (Exception e)
+                       {
+                               e.printStackTrace();
+                               // If we just print the stacktrace the exitCode 
is still 0 and the test will pass.
+                               fail("Got exception");
+                       }
+                       
+                   // Check that the runtime exit code was 0, meaning that no 
asserts failed.
+                       assertThat(exitCode, is(0));
+               }
                else
                {
                        StackTraceElement[] stackTraceElements = 
Thread.currentThread().getStackTrace();
@@ -377,7 +511,7 @@ public class ASFeatureTestsBase
 
        public static int executeCommandWithTimeout(String[] args, long 
timeoutInSeconds) throws Exception {
                ExecutorService service = Executors.newSingleThreadExecutor();
-               Process process = Runtime.getRuntime().exec(args);
+               Process process = new ProcessBuilder(args).inheritIO().start();
                try {
                        Callable<Integer> call = new CallableProcess(process);
                        Future<Integer> future = service.submit(call);
@@ -419,6 +553,7 @@ public class ASFeatureTestsBase
                    "import flash.display.Sprite;",
                    "import flash.events.Event;",
                    "import flash.system.System;",
+                   "import flash.utils.getDefinitionByName;",
                    "%1",
                    "public class %0 extends flash.display.Sprite",
                    "{",
@@ -430,16 +565,33 @@ public class ASFeatureTestsBase
                    "    private function 
initHandler(e:flash.events.Event):void",
                    "    {",
                    "        %3",
-                   "        System.exit(0);",            
+                   "        exitTests(0);",            
                    "    }",
                    "    private function assertEqual(message:String, 
actualValue:*, expectedValue:*):void",
                    "    {",
                    "        if (actualValue !== expectedValue)",
                    "        {",
                    "            trace(message, actualValue, expectedValue);",
-                   "            System.exit(1);",
+                   "            exitTests(1);",
                    "        }",
                    "    }",
+                               "    private function exitTests(code:int):void",
+                               "    {",
+                               "        var NativeApplication:Class = null;",
+                               "        try",
+                               "        {",
+                               "            NativeApplication = 
getDefinitionByName(\"flash.desktop.NativeApplication\") as Class;",
+                               "        }",
+                               "        catch (error:Error) {}",
+                               "        if (NativeApplication != null)",
+                               "        {",
+                               "            
NativeApplication.nativeApplication.exit(code);",
+                               "        }",
+                               "        else",
+                               "        {",
+                               "             System.exit(code);",
+                               "        }",
+                               "    }",
                    "}",
                    "}",
                    "%4"
diff --git a/compiler/src/test/java/mxml/tags/MXMLDefinitionTagTests.java 
b/compiler/src/test/java/mxml/tags/MXMLDefinitionTagTests.java
index 57655096a..baaef1b3f 100644
--- a/compiler/src/test/java/mxml/tags/MXMLDefinitionTagTests.java
+++ b/compiler/src/test/java/mxml/tags/MXMLDefinitionTagTests.java
@@ -49,20 +49,38 @@ public class MXMLDefinitionTagTests extends 
MXMLInstanceTagTestsBase
                    "    </fx:Declarations>",
                    "    <fx:Script>",
                    "    <![CDATA[",
-                   "        import custom.TestInstance;",                  
+                   "        import custom.TestInstance;",
+                   "        import flash.utils.getDefinitionByName;",
                    "        private function assertEqual(message:String, 
actualValue:*, expectedValue:*):void",
                    "        {",
                    "            if (actualValue !== expectedValue)",
                    "            {",
                    "                trace(message, actualValue, 
expectedValue);",
-                   "                System.exit(1);",
+                   "                exitTests(1);",
                    "            }",
                    "        }",
                    "        private function 
enterFrameHandler(event:Event):void",
                    "        {",
                    "            %3",
-                   "            System.exit(0);",
+                   "            exitTests(0);",
                    "        }",
+                               "        private function 
exitTests(code:int):void",
+                               "        {",
+                               "            var NativeApplication:Class = 
null;",
+                               "            try",
+                               "            {",
+                               "                NativeApplication = 
getDefinitionByName(\"flash.desktop.NativeApplication\") as Class;",
+                               "            }",
+                               "            catch (error:Error) {}",
+                               "            if (NativeApplication != null)",
+                               "            {",
+                               "                
NativeApplication.nativeApplication.exit(code);",
+                               "            }",
+                               "            else",
+                               "            {",
+                               "                System.exit(code);",
+                               "            }",
+                               "        }",
                    "    ]]>",
                    "    </fx:Script>",
                    "</d:Sprite>"
diff --git a/compiler/src/test/java/mxml/tags/MXMLFeatureTestsBase.java 
b/compiler/src/test/java/mxml/tags/MXMLFeatureTestsBase.java
index 8d4209946..57d56cea3 100644
--- a/compiler/src/test/java/mxml/tags/MXMLFeatureTestsBase.java
+++ b/compiler/src/test/java/mxml/tags/MXMLFeatureTestsBase.java
@@ -28,11 +28,13 @@ import as.ASFeatureTestsBase;
 
 import utils.FlashplayerSecurityHandler;
 
+import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.MalformedURLException;
@@ -41,6 +43,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
@@ -56,6 +60,24 @@ import static org.junit.Assert.fail;
 public class MXMLFeatureTestsBase
 {
        private static boolean generateResultFile = false;
+
+       private static String APP_DESCRIPTOR_TEMPLATE = "<application 
xmlns=\"http://ns.adobe.com/air/application/@AIR_VERSION@\";>\n" +
+                                               "  <id>RoyaleAdlWrapper</id>\n" 
+
+                                               "  
<filename>RoyaleTestsAdlWrapper</filename>\n" +
+                                               "  <name>Royale Tests Adl 
Wrapper</name>\n" +
+                                               "  
<versionNumber>1.0.0</versionNumber>\n" +
+                                               "  <description>Wrapper 
application for use with the Royale compiler tests.</description>\n" +
+                                               "  <initialWindow>\n" +
+                                               "    <title>Royale Tests Adl 
Wrapper</title>\n" +
+                                               "    
<content>@SWF_NAME@</content>\n" +
+                                               "    
<visible>false</visible>\n" +
+                                               "    
<minimizable>true</minimizable>\n" +
+                                               "    
<maximizable>false</maximizable>\n" +
+                                               "    
<resizable>false</resizable>\n" +
+                                               "    <width>320</width>\n" +
+                                               "    <height>240</height>\n" +
+                                               "  </initialWindow>\n" +
+                                               "</application>";
        
        private static final String NAMESPACE_2009 = 
"http://ns.adobe.com/mxml/2009";;
        private static final String NAMESPACE_TEST = 
"library://ns.apache.org/royale/test";
@@ -71,24 +93,104 @@ public class MXMLFeatureTestsBase
                if(playerGlobal == null || !playerGlobal.isFile() || 
!playerGlobal.exists()) {
                        hasFlashPlayerGlobal = false;
                }
+               File adlExecutable = testAdapter.getAirDebugger();
+               if (adlExecutable == null || !adlExecutable.isFile() || 
!adlExecutable.exists()) {
+                       hasAdlExecutable = false;
+               }
 
-               if (hasFlashPlayerExecutable && !hasFlashPlayerGlobal)
+               if ((hasFlashPlayerExecutable || hasAdlExecutable) && 
!hasFlashPlayerGlobal)
                {
-                       String message = "Fatal Error: If FLASHPLAYER_DEBUGGER 
is defined, playerglobal must be available";
+                       String message = "Fatal Error: If FLASHPLAYER_DEBUGGER 
or AIR_HOME is defined, playerglobal must be available";
                        System.err.println(message);
                        fail(message);
                }
 
-               if (!hasFlashPlayerExecutable && hasFlashPlayerGlobal)
+               if (!hasFlashPlayerExecutable && !hasAdlExecutable && 
hasFlashPlayerGlobal)
                {
-                       String message = "Fatal Error: If playerglobal is 
available, FLASHPLAYER_DEBUGGER is required";
+                       String message = "Fatal Error: If playerglobal is 
available, FLASHPLAYER_DEBUGGER or AIR_HOME is required";
                        System.err.println(message);
                        fail(message);
                }
+
+               if (airVersion == null)
+               {
+                       File adtExecutable = testAdapter.getAirAdt();
+                       if (adtExecutable != null)
+                       {
+                               String versionOutput = null;
+                               try
+                               {
+                                       Process process = 
Runtime.getRuntime().exec(new String[]{adtExecutable.getAbsolutePath(), 
"-version"});
+                                       int exitCode = process.waitFor();
+                                       if (exitCode == 0)
+                                       {
+                                               BufferedReader reader = new 
BufferedReader(new InputStreamReader(process.getInputStream()));
+                                               versionOutput = 
reader.readLine();
+                                       }
+                               }
+                               catch (Exception e)
+                               {
+                                       String message = "Fatal Error: Could 
not run ADT from AIR SDK to detect version";
+                                       System.err.println(message);
+                                       fail(message);
+                               }
+                               airVersion = 
parseAdtVersionNumber(versionOutput);
+                               if (airVersion == null)
+                               {
+                                       String message = "Fatal Error: Could 
not detect AIR SDK version";
+                                       System.err.println(message);
+                                       fail(message);
+                               }
+                       }
+               }
        }
 
        protected boolean hasFlashPlayerExecutable = true;
        protected boolean hasFlashPlayerGlobal = true;
+       protected boolean hasAdlExecutable = true;
+       private static String airVersion = null;
+
+       private static final Pattern AIR_VERSION_PATTERN = 
Pattern.compile("(\\d+\\.\\d+)(?:\\.\\d)+");
+
+    private String parseAdtVersionNumber(String versionString)
+    {
+               if (versionString == null)
+               {
+                       return null;
+               }
+               Matcher matcher = AIR_VERSION_PATTERN.matcher(versionString);
+               if (matcher.find())
+               {
+                       return matcher.group(1);
+               }
+               return null;
+    }
+
+       protected File generateTempAppDescriptorFile(String source, String 
swfFileName, String version)
+       {
+        // Write the application descriptor into a temp file.
+        ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
+        String tempDir = testAdapter.getTempDir();
+        File tempDescriptorFile = null;
+        try
+        {
+            tempDescriptorFile = 
File.createTempFile(getClass().getSimpleName(), "-app.xml", new File(tempDir));
+            tempDescriptorFile.deleteOnExit();
+
+            BufferedWriter out = new BufferedWriter(new 
FileWriter(tempDescriptorFile));
+            
+            source = source.replaceAll("@SWF_NAME@", swfFileName);
+            source = source.replaceAll("@AIR_VERSION@", version);
+            out.write(source);
+            out.close();
+        }
+        catch (IOException e1) 
+        {
+            e1.printStackTrace();
+            fail("Error generating test code");
+        }
+        return tempDescriptorFile;
+       }
        
        protected void compileAndRun(String mxml, boolean withFramework, 
boolean withRPC, boolean withSpark, String[] otherOptions)
        {
@@ -175,7 +277,8 @@ public class MXMLFeatureTestsBase
                }
                assertThat(sb.toString(), exitCode, is(0));
 
-               // Run the SWF in the standalone player amd wait until the SWF 
calls System.exit().
+               // Run the SWF in the standalone player or adl
+               // and wait until the SWF calls System.exit() or 
NativeApplication.nativeApplication.exit().
                String swf = 
FilenameNormalization.normalize(tempMXMLFile.getAbsolutePath());
                swf = swf.replace(".mxml", ".swf");
                if (hasFlashPlayerExecutable)
@@ -201,6 +304,26 @@ public class MXMLFeatureTestsBase
                    // Check that the runtime exit code was 0, meaning that no 
asserts failed.
                        assertThat(exitCode, is(0));
                }
+               else if (hasAdlExecutable)
+               {
+                       File adlExecutable = testAdapter.getAirDebugger();
+                       File appDescriptorFile = 
generateTempAppDescriptorFile(APP_DESCRIPTOR_TEMPLATE, new File(swf).getName(), 
"51.0");
+                       String[] runArgs = new String[] { 
adlExecutable.getPath(), appDescriptorFile.getPath() };
+                       try
+                       {
+                               System.out.println("Executing test:\n" + 
Arrays.toString(runArgs));
+                               exitCode = executeCommandWithTimeout(runArgs, 
20);
+                       }
+                       catch (Exception e)
+                       {
+                               e.printStackTrace();
+                               // If we just print the stacktrace the exitCode 
is still 0 and the test will pass.
+                               fail("Got exception");
+                       }
+                       
+                   // Check that the runtime exit code was 0, meaning that no 
asserts failed.
+                       assertThat(exitCode, is(0));
+               }
                else
                {
                        StackTraceElement[] stackTraceElements = 
Thread.currentThread().getStackTrace();
@@ -315,7 +438,7 @@ public class MXMLFeatureTestsBase
 
        public static int executeCommandWithTimeout(String[] args, long 
timeoutInSeconds) throws Exception {
                ExecutorService service = Executors.newSingleThreadExecutor();
-               Process process = Runtime.getRuntime().exec(args);
+               Process process = new ProcessBuilder(args).inheritIO().start();
                try {
                        Callable<Integer> call = new CallableProcess(process);
                        Future<Integer> future = service.submit(call);
diff --git a/compiler/src/test/java/mxml/tags/MXMLInstanceTagTestsBase.java 
b/compiler/src/test/java/mxml/tags/MXMLInstanceTagTestsBase.java
index 256d8c4be..f76486e8a 100644
--- a/compiler/src/test/java/mxml/tags/MXMLInstanceTagTestsBase.java
+++ b/compiler/src/test/java/mxml/tags/MXMLInstanceTagTestsBase.java
@@ -46,20 +46,38 @@ public class MXMLInstanceTagTestsBase extends 
MXMLFeatureTestsBase
                    "    <fx:Script>",
                    "    <![CDATA[",
                    "        import custom.TestInstance;",
+                   "        import flash.utils.getDefinitionByName;",
                    "        %2",
                    "        private function assertEqual(message:String, 
actualValue:*, expectedValue:*):void",
                    "        {",
                    "            if (actualValue !== expectedValue)",
                    "            {",
                    "                trace(message, actualValue, 
expectedValue);",
-                   "                System.exit(1);",
+                   "                exitTests(1);",
                    "            }",
                    "        }",
                    "        private function 
enterFrameHandler(event:Event):void",
                    "        {",
                    "            %3",
-                   "            System.exit(0);",
+                   "            exitTests(0);",
                    "        }",
+                               "        private function 
exitTests(code:int):void",
+                               "        {",
+                               "            var NativeApplication:Class = 
null;",
+                               "            try",
+                               "            {",
+                               "                NativeApplication = 
getDefinitionByName(\"flash.desktop.NativeApplication\") as Class;",
+                               "            }",
+                               "            catch (error:Error) {}",
+                               "            if (NativeApplication != null)",
+                               "            {",
+                               "                
NativeApplication.nativeApplication.exit(code);",
+                               "            }",
+                               "            else",
+                               "            {",
+                               "                System.exit(code);",
+                               "            }",
+                               "        }",
                    "    ]]>",
                    "    </fx:Script>",
                    "</d:Sprite>"
diff --git a/compiler/src/test/java/mxml/tags/MXMLMetadataTagTests.java 
b/compiler/src/test/java/mxml/tags/MXMLMetadataTagTests.java
index 58cd09a65..a1e639c36 100644
--- a/compiler/src/test/java/mxml/tags/MXMLMetadataTagTests.java
+++ b/compiler/src/test/java/mxml/tags/MXMLMetadataTagTests.java
@@ -45,19 +45,37 @@ public class MXMLMetadataTagTests extends 
MXMLFeatureTestsBase
                    "    <fx:Script>",
                    "    <![CDATA[",
                    "        import custom.TestInstance;",
+                   "        import flash.utils.getDefinitionByName;",
                    "        private function assertEqual(message:String, 
actualValue:*, expectedValue:*):void",
                    "        {",
                    "            if (actualValue !== expectedValue)",
                    "            {",
                    "                trace(message, actualValue, 
expectedValue);",
-                   "                System.exit(1);",
+                   "                exitTests(1);",
                    "            }",
                    "        }",
                    "        private function 
enterFrameHandler(event:Event):void",
                    "        {",
                    "            %3",
-                   "            System.exit(0);",
+                   "            exitTests(0);",
                    "        }",
+                               "        private function 
exitTests(code:int):void",
+                               "        {",
+                               "            var NativeApplication:Class = 
null;",
+                               "            try",
+                               "            {",
+                               "                NativeApplication = 
getDefinitionByName(\"flash.desktop.NativeApplication\") as Class;",
+                               "            }",
+                               "            catch (error:Error) {}",
+                               "            if (NativeApplication != null)",
+                               "            {",
+                               "                
NativeApplication.nativeApplication.exit(code);",
+                               "            }",
+                               "            else",
+                               "            {",
+                               "                System.exit(code);",
+                               "            }",
+                               "        }",
                    "    ]]>",
                    "    </fx:Script>",
                    "    %2",
diff --git a/compiler/src/test/java/properties/MXMLPropertyTestsBase.java 
b/compiler/src/test/java/properties/MXMLPropertyTestsBase.java
index 3627173e6..f6e67acf9 100644
--- a/compiler/src/test/java/properties/MXMLPropertyTestsBase.java
+++ b/compiler/src/test/java/properties/MXMLPropertyTestsBase.java
@@ -55,19 +55,37 @@ public abstract class MXMLPropertyTestsBase extends 
MXMLFeatureTestsBase
                    "    </fx:Declarations>",
                    "    <fx:Script>",
                    "    <![CDATA[",
+                   "        import flash.utils.getDefinitionByName;",
                    "        private function assertEqual(message:String, 
actualValue:*, expectedValue:*):void",
                    "        {",
                    "            if (actualValue !== expectedValue)",
                    "            {",
                    "                trace(message, actualValue, 
expectedValue);",
-                   "                System.exit(1);",
+                   "                exitTests(1);",
                    "            }",
                    "        }",
                    "        private function 
enterFrameHandler(event:Event):void",
                    "        {",
                    "            %3",
-                   "            System.exit(0);",
+                   "            exitTests(0);",
                    "        }",
+                               "        private function 
exitTests(code:int):void",
+                               "        {",
+                               "            var NativeApplication:Class = 
null;",
+                               "            try",
+                               "            {",
+                               "                NativeApplication = 
getDefinitionByName(\"flash.desktop.NativeApplication\") as Class;",
+                               "            }",
+                               "            catch (error:Error) {}",
+                               "            if (NativeApplication != null)",
+                               "            {",
+                               "                
NativeApplication.nativeApplication.exit(code);",
+                               "            }",
+                               "            else",
+                               "            {",
+                               "                System.exit(code);",
+                               "            }",
+                               "        }",
                    "    ]]>",
                    "    </fx:Script>",
                    "</d:Sprite>"

Reply via email to