From flex-commits-return-530-apmail-incubator-flex-commits-archive=incubator.apache.org@incubator.apache.org Wed May 2 22:46:45 2012 Return-Path: X-Original-To: apmail-incubator-flex-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-flex-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82F64C637 for ; Wed, 2 May 2012 22:46:45 +0000 (UTC) Received: (qmail 44662 invoked by uid 500); 2 May 2012 22:46:45 -0000 Delivered-To: apmail-incubator-flex-commits-archive@incubator.apache.org Received: (qmail 44590 invoked by uid 500); 2 May 2012 22:46:45 -0000 Mailing-List: contact flex-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: flex-dev@incubator.apache.org Delivered-To: mailing list flex-commits@incubator.apache.org Received: (qmail 44454 invoked by uid 99); 2 May 2012 22:46:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2012 22:46:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2012 22:46:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F2C692388C7B; Wed, 2 May 2012 22:45:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1333232 [21/34] - in /incubator/flex/trunk: ./ frameworks/tests/ frameworks/tests/basicTests/ frameworks/tests/basicTests/dmv/ frameworks/tests/basicTests/dmv/scripts/ frameworks/tests/basicTests/dmv/views/ frameworks/tests/basicTests/fxg/... Date: Wed, 02 May 2012 22:45:08 -0000 To: flex-commits@incubator.apache.org From: aharui@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120502224526.F2C692388C7B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Propchange: incubator/flex/trunk/mustella/build.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/flex/trunk/mustella/clobber.awk URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/clobber.awk?rev=1333232&view=auto ============================================================================== --- incubator/flex/trunk/mustella/clobber.awk (added) +++ incubator/flex/trunk/mustella/clobber.awk Wed May 2 22:44:38 2012 @@ -0,0 +1,85 @@ +################################################################################ +## +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## +################################################################################ +BEGIN { FS="," + + MYLINE="" + + while ( (getline line < "local.properties") > 0) { + if (index(line, "extra_includes") == 1) { + MYLINE= substr(line, index(line, "=")+1) + } + } + + ## treat the entry as an array + n = split(MYLINE, arr) + + for (z in arr) + print "myline: " arr[z] + +} +{ + +reg=0;app=0; + +if ( (reg=index($1, "sdk.mustella.excludes")) > 0 || (app=index($1, "apollo_only_excludes")) > 0) { + + # print "found reg or app in " $1 "reg:"reg" app:" app; + + ## operate on this line + # clip $1 + + resultLine="" + + for (i=1;i<=NF;i++) { + + field=$i + + if (i==1) + field = substr($i, index($i, "=")+1) + + + ## loop through our list of extra_includes for a match. + sawmatch=0; + for (j in arr) { + if (field==arr[j]) { + sawmatch=1; + } + } + + if (!sawmatch) + resultLine=sprintf("%s,%s", field, resultLine); + + + } + + + +} +} + +END { + + + if (resultLine != "" && reg) + print "sdk.mustella.excludes="resultLine + if (resultLine != "" && app) + print "apollo_only_excludes="resultLine + +} + Propchange: incubator/flex/trunk/mustella/clobber.awk ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/flex/trunk/mustella/java/src/build.xml URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/build.xml?rev=1333232&view=auto ============================================================================== --- incubator/flex/trunk/mustella/java/src/build.xml (added) +++ incubator/flex/trunk/mustella/java/src/build.xml Wed May 2 22:44:38 2012 @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: incubator/flex/trunk/mustella/java/src/build.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/flex/trunk/mustella/java/src/mustella/ApolloAdjuster.java URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/ApolloAdjuster.java?rev=1333232&view=auto ============================================================================== --- incubator/flex/trunk/mustella/java/src/mustella/ApolloAdjuster.java (added) +++ incubator/flex/trunk/mustella/java/src/mustella/ApolloAdjuster.java Wed May 2 22:44:38 2012 @@ -0,0 +1,405 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package mustella; +import java.io.*; + +import javax.xml.parsers.*; +import javax.xml.transform.*; +import org.w3c.dom.*; +import javax.xml.transform.dom.*; +import javax.xml.transform.stream.StreamResult; + +import utils.*; + +/** + +Writes application descriptor files for AIR + + +*/ +public class ApolloAdjuster { + + + static String swffile = null; + static String xmlfile = null; + static String xmlfile2 = null; + static String delete_file = null; + static String deviceName = ""; + + /// the template file. + static String template_location = "/templates/air/descriptor-template.xml"; + static String model_file = System.getProperty ("sdk.dir") + template_location; + + + static String xmlnsVal = "http://ns.adobe.com/air/application/1.0"; + + static { + + try { + if (System.getProperty ("air_xmlns") != null) + xmlnsVal = System.getProperty ("air_xmlns"); + } catch (Exception e) { + + /// leave it + + } + + + try { + deviceName = System.getProperty( "device_name" ); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + /** + * use the template that's part of the distribution to create the + * application descriptor file. + * See code comments for details. + */ + public static String xmlTransformFromTemplate ( boolean includeSwfParent ) throws Exception { + + DocumentBuilder docb = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docb.parse (new File(model_file)); + + NodeList nl = null; + + String justSwf = getSwfName ( swffile, false ); + String appid = justSwf.substring( 0, justSwf.indexOf( ".swf" ) ).replace( "_", "" ); + String content = getSwfName ( swffile, includeSwfParent ); + + /// modify the pieces we need to: content: + nl = doc.getElementsByTagName("content"); + + if ( nl.item(0).getFirstChild() == null) { + Text t = doc.createTextNode (content); + nl.item(0).appendChild(t); + } else + nl.item(0).getFirstChild().setNodeValue(content); + + /// modify the pieces we need to: filename + // Note: The adt tool doesn't like filename to be exactly the same as the name of the swf. + nl = doc.getElementsByTagName("filename"); + + if ( nl.item(0).getFirstChild() == null) { + Text ft = doc.createTextNode (appid); + nl.item(0).appendChild (ft); + } else { + nl.item(0).getFirstChild().setNodeValue(appid); + } + + + /// modify the pieces we need to: id + nl = doc.getElementsByTagName("id"); + if ( nl.item(0).getFirstChild() == null) { + Text it = doc.createTextNode (appid); + nl.item(0).appendChild (it); + } else + nl.item(0).getFirstChild().setNodeValue(appid); + + nl = doc.getElementsByTagName("versionNumber"); + if ( nl != null && nl.item(0) != null ) { + if (nl.item(0).getFirstChild() == null) { + Text vit = doc.createTextNode ("1.0.0"); + nl.item(0).appendChild (vit); + } else { + nl.item(0).getFirstChild().setNodeValue("1.0.0"); + } + } + + /// modify the pieces we need to: android + if( deviceName != null ){ + if( MobileUtil.getOSForDevice( deviceName ).compareToIgnoreCase( MobileUtil.ANDROID_OS ) == 0 ){ + nl = doc.getElementsByTagName("application"); + Element el = doc.createElement("android"); + + Node el2 = el.appendChild( doc.createElement("manifestAdditions") ); + el2.appendChild( doc.createCDATASection("\n\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\t" + + "\n\t\n")); + nl.item(0).appendChild(el); + + // For namespace 3.1 and after, use 16 bit color for Android due to performance issues. + Element colorDepth = doc.createElement("colorDepth"); + Text colorDepthVal = doc.createTextNode ("16bit"); + colorDepth.appendChild(colorDepthVal); + el.appendChild(colorDepth); + + // Set the softKeyboardBehavior in initialWindow. This is only supported in Android right now, and + // this code can just be moved if it ends up being supported for other devices. + Element softKeyboardBehavior = doc.createElement("softKeyboardBehavior"); + Text softKeyboardBehaviorVal = doc.createTextNode ("none"); + softKeyboardBehavior.appendChild(softKeyboardBehaviorVal); + nl = doc.getElementsByTagName ("initialWindow"); + nl.item(0).appendChild (softKeyboardBehavior); + } + } + + /// modify the pieces we need to: iOS + if( deviceName != null ){ + if( MobileUtil.getOSForDevice( deviceName ).compareToIgnoreCase( MobileUtil.IOS ) == 0 ){ + + // Add fullScreen, autoOrients, aspectRatio, and renderMode to initialWindow. I'm not sure which of these + // are absolutely needed, but I do know that the file which works contains these items in addition to the above. + Element fullScreen = doc.createElement("fullScreen"); + Text fullScreenVal = doc.createTextNode ("true"); + fullScreen.appendChild (fullScreenVal); + + Element autoOrients = doc.createElement("autoOrients"); + Text autoOrientsVal = doc.createTextNode ("true"); + autoOrients.appendChild (autoOrientsVal); + + Element aspectRatio = doc.createElement("aspectRatio"); + Text aspectRatioVal = doc.createTextNode ("portrait"); + aspectRatio.appendChild (aspectRatioVal); + + Element renderMode = doc.createElement("renderMode"); + Text renderModeVal = doc.createTextNode ("cpu"); + renderMode.appendChild (renderModeVal); + + nl = doc.getElementsByTagName ("initialWindow"); + nl.item(0).appendChild(fullScreen); + nl.item(0).appendChild(autoOrients); + nl.item(0).appendChild(aspectRatio); + nl.item(0).appendChild(renderMode); + + // Run iOS tests in high resolution mode. Add these to the application node. + nl = doc.getElementsByTagName("application"); + Element el = doc.createElement("iPhone"); + Node el2 = el.appendChild( doc.createElement("InfoAdditions") ); + el2.appendChild( doc.createCDATASection("\n\tUIDeviceFamily" + + "\n\t\t" + + "\n\t\t\t1" + + "\n\t\t\t2" + + "\n\t\t" + + "\n\t\tUIStatusBarStyle" + + "\n\t\tUIStatusBarStyleBlackOpaque" + + "\n\t\tUIRequiresPersistentWiFi" + + "\n\t\tYES")); + nl.item(0).appendChild(el); + + nl = doc.getElementsByTagName("iPhone"); + Element reqDisplayRes = doc.createElement("requestedDisplayResolution"); + Text reqDisplayResVal = doc.createTextNode ("high"); + reqDisplayRes.appendChild(reqDisplayResVal); + nl.item(0).appendChild(reqDisplayRes); + } + } + + // modify the pieces we need to: name. Be sure it's no more than 25 characters (QNX restriction). + if( deviceName != null ){ + if( MobileUtil.getOSForDevice( deviceName ).compareToIgnoreCase( MobileUtil.QNX ) == 0 ){ + + String appName = appid; + if( appName.length() > 25 ){ + appName = appName.substring( 0, 25 ); + } + + nl = doc.getElementsByTagName( "name" ); + if ( nl.item(0).getFirstChild() == null ) { + Text nameNode = doc.createTextNode ( appName ); + nl.item(0).appendChild ( nameNode ); + } else + nl.item(0).getFirstChild().setNodeValue( appName ); + } + } + + /// modify the pieces we need to: systemChrome (we like 'none') + /// this is commented out in the template, so we just add it + Element sysChrome = doc.createElement("systemChrome"); + Text chrome = doc.createTextNode ("none"); + sysChrome.appendChild (chrome); + + /// modify the pieces we need to: transparent (we like 'true') + /// this is commented out in the template, so we just add it + Element trans = doc.createElement("transparent"); + Text transt = doc.createTextNode ("true"); + trans.appendChild (transt); + + /// modify the pieces we need to: visible (we like 'true') + /// this is commented out in the template, so we just add it + Element viz = doc.createElement("visible"); + Text transv = doc.createTextNode ("true"); + viz.appendChild (transv); + + /// put them in the InitialWindow section + nl = doc.getElementsByTagName ("initialWindow"); + nl.item(0).appendChild(sysChrome); + nl.item(0).appendChild(trans); + nl.item(0).appendChild(viz); + + /// output the result + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + //initialize StreamResult with File object to save to file + StreamResult result = new StreamResult(new StringWriter()); + DOMSource source = new DOMSource(doc); + transformer.transform(source, result); + String xmlString = result.getWriter().toString(); + + return xmlString; + } + + + public static String xmlWriter (String file) { + return xmlWriter (file, true); + + } + public static String xmlWriter (String file, boolean deleteIt) { + return xmlWriter (file, deleteIt, false); + } + + public static String xmlWriter (String file, boolean deleteIt, boolean includeSwfParent) { + + System.out.println ("apollo adj with : " + file); + + if (file.indexOf (".swf") != -1) { + + System.out.println ("apollo adj thinks it's a swf"); + swffile = file; + // builder's generated name + xmlfile = file.substring (0, file.indexOf (".swf")) + ".xml"; + if (deleteIt) + delete_file = file.substring (0, file.indexOf (".swf")) + ".delete"; + else + delete_file = null; + + } else if (file.indexOf (".xml") != -1) { + + xmlfile = file; + swffile = file.substring (0, file.indexOf (".xml")) + ".swf"; + if (deleteIt) + delete_file = file.substring (0, file.indexOf (".xml")) + ".delete"; + else + delete_file = null; + } + + /// check if it exists. + + if (new File(xmlfile).exists() && (delete_file == null || !new File(delete_file).exists())) { + System.out.println ("not writing Apollo file"); + return xmlfile; + } else { + System.out.println ("writing Apollo file!"); + createFile( includeSwfParent ); + } + + return xmlfile; + } + + + public static boolean didWrite () { + try { + return new File(delete_file).exists(); + } catch (Exception e) { + return false; + } + } + + + public static void delete () { + + System.out.println ("removing the xml app file"); + new File(delete_file).delete(); + new File(xmlfile).delete(); + + } + + public static String getSwfName (String file, boolean includeSwfParent) { + String ret = null; + String left = null; + String right = null; + + if (includeSwfParent){ + right = file.substring( file.lastIndexOf( File.separator ) + 1 ); // ButtonMain.swf + right = "/" + right; // /ButtonMain.swf, must be a /, cannot be a \. + left = file.substring( 0, file.lastIndexOf( File.separator ) ); // blah/blah/Button/swfs + left = left.substring( left.lastIndexOf( File.separator ) +1 ); // swfs + ret = left + right; // swfs/ButtonMain.swf + }else{ + if (file.indexOf("/") != -1) { + ret = file.substring (file.lastIndexOf("/")+1); + } else if (file.indexOf(File.separator) != -1) { + ret = file.substring (file.lastIndexOf(File.separator)+1); + } else { + ret = file; + } + } + + return ret; + } + + public static void createFile ( boolean includeSwfParent ) { + + System.out.println ("full swf is " + swffile); + + FileOutputStream bos = null; + FileOutputStream bos2 = null; + + try { + /// get the contents we'll write: + String xmlString = xmlTransformFromTemplate( includeSwfParent ); + + /// write a marker to delete the file we'll write + if (delete_file != null) { + bos2 = new FileOutputStream (delete_file); + bos2.write ("0".getBytes(), 0, 1); + bos2.flush(); + bos2.close(); + } + + /// write the xml file + bos = new FileOutputStream (xmlfile); + + bos.write (xmlString.getBytes(), 0, xmlString.length()); + + bos.flush(); + bos.close(); + + } catch (Exception e) { + e.printStackTrace(); + try { + bos.close(); + bos2.close(); + } catch (Exception e2) { + } + } + } + + + + public static void main (String [] args) throws Exception { + + xmlWriter (args[0]); + + + + } + + +} Propchange: incubator/flex/trunk/mustella/java/src/mustella/ApolloAdjuster.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/flex/trunk/mustella/java/src/mustella/ApolloAppToWindow.java URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/ApolloAppToWindow.java?rev=1333232&view=auto ============================================================================== --- incubator/flex/trunk/mustella/java/src/mustella/ApolloAppToWindow.java (added) +++ incubator/flex/trunk/mustella/java/src/mustella/ApolloAppToWindow.java Wed May 2 22:44:38 2012 @@ -0,0 +1,382 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package mustella; +import java.io.*; + +import javax.xml.parsers.*; +import javax.xml.transform.*; +import org.w3c.dom.*; +import javax.xml.transform.dom.*; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + + + +/** + +Utility for transforming a mustella test to apollo, by which is meant, +changing the test_swf from Application to Window, and popping that window up +from a WindowedApplication (provided as a template). + + + +*/ +public class ApolloAppToWindow { + + + /** + * given the mxml arg, get the testSwf's className + public static String getTestSwfName (String mxml) { + + return mxml; + } + */ + + + + /** + * return what will be the transformed name, given a test_swf filename + * and a directory + */ + public static String getNewMxmlName (String dir, String mxml, String transform_prefix) { + + if (mxml.indexOf ("\\apollo\\") != -1 || mxml.indexOf ("/apollo/") != -1) + return mxml; + + // System.out.println ("This is the getNewMxmlName with mxml="+ mxml); + + String className = getSwfClassName(mxml); + // System.out.println ("This is the getNewMxmlName className: " +className); + + // String subDir = getSwfSubDir(mxml); + // System.out.println ("This is the getNewMxmlName swf subdir: " +subDir); + + String newName = transform_prefix + className + ".mxml"; + // System.out.println ("This is the getNewMxmlName returning: " +dir+ "/" + newName); + return dir + "/" + newName; + + + } + + + /** + * The normal compile has a test_swf, and a bunch of args + * The Air transform introduces a new test_swf, based on a template. + * so we shift the args a bit: + * we make the test_swf an include and add its source path + * dir is the same as targetDir below + */ + public static String adjustArgList (String args, String mxml, String dir, String prefix) { + + String className = getSwfClassName (mxml); + + args += " -source-path="+dir; + args += " -includes="+prefix+className; + + return args; + + } + + public static final String app_string = " 0) { + insertPoint = fileContents.indexOf (script_start); + + StringBuffer sb = new StringBuffer(fileContents); + sb.insert ( (insertPoint-1), insertBlock); + + fileContents = sb.toString(); + } + + try { + writeStringToFile (fileContents, getNewMxmlName(swfDir, mxml, prefix)); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + + public static String doAll (String args, String prefix, String prefix2, String mxml, String templateFile, String targetDir) { + + + if (mxml.indexOf ("\\apollo\\") != -1 || mxml.indexOf ("/apollo/") != -1) + return args; + + + // System.out.println ("here is the dir AApp got; " + targetDir); + + /// need more from the Test swf + String insertBlock = getBlockFromTestSwf (mxml, "mx:Style"); + + /// do all, then return the adjusted Arg + transformDummyAndCopy (prefix, prefix2, mxml, templateFile, targetDir, insertBlock); + + transformTestSwfToWindow (mxml, targetDir, prefix2); + + + args += " -includes=WaitForWindow"; + return adjustArgList(args, mxml, targetDir, prefix2); + } + + private static void writeStringToFile (String str, String fileName) throws Exception { + + BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (fileName)); + + bos.write (str.getBytes(), 0, str.length()); + bos.flush(); + bos.close(); + + + } + + + public static String readFileIntoString (String mxml) { + + + try { + BufferedInputStream bis = new BufferedInputStream (new FileInputStream (mxml)); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + int av = 0; + byte [] b = null; + + String contents = null; + + while ((av = bis.available()) > 0) { + b = new byte[av]; + bis.read (b, 0, av); + bos.write (b, 0, av); + + } + + + bis.close(); + + return bos.toString(); + + + } catch (Exception e) { + e.printStackTrace(); + } + + return (String)null; + + } + + + + + + public static void main (String [] args) { + + + } + + + +} Propchange: incubator/flex/trunk/mustella/java/src/mustella/ApolloAppToWindow.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/flex/trunk/mustella/java/src/mustella/BaselineServer.java URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/BaselineServer.java?rev=1333232&view=auto ============================================================================== --- incubator/flex/trunk/mustella/java/src/mustella/BaselineServer.java (added) +++ incubator/flex/trunk/mustella/java/src/mustella/BaselineServer.java Wed May 2 22:44:38 2012 @@ -0,0 +1,127 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package mustella; + +import java.net.*; +import java.util.Date; +import java.util.ArrayList; + +/** + * BaselineServer + * + * Serve a given port, spawn BaselineWriters on whoever writes to it + */ +public class BaselineServer extends Thread { + + + int port = 9998; + + + public BaselineServer (int port) { + this.port = port; + } + + + public String dir = null; + + + /// this should be 1 above the swf + public void setDir (String dir) { + this.dir = dir.replaceAll("\\\\", "/"); + } + + + public static ArrayList threads = new ArrayList(); + + + ServerSocket ss = null; + + public void run () { + + System.out.println ("starting the baseline server: " + new Date()); + + /// launch server, dispatch sockets on new inlines + + try { + + ss = new ServerSocket (port); + + while (running) { + + try { + + Socket s = ss.accept (); + BaselineWriter bw = null; + if (dir != null) + bw = new BaselineWriter (s, dir); + else + bw = new BaselineWriter (s); + threads.add (bw); + bw.start(); + + } catch (Exception e) { + // System.out.println ("broke out of the socket loop"); + return; + } + + } + + } catch (Exception e) { + + e.printStackTrace (); + + } + + } + + + boolean running = true; + + public void end() { + running = false; + BaselineWriter bw = null; + for (int i=0;i 0) { + try { + Thread.sleep (1000); + // System.out.println ("Waiting for threads to finish: active " + threads.size()); + } catch (Exception e0) { + e0.printStackTrace(); + } + } + */ + + /// experiment, rather than waiting forever + if (threads.size() > 0) { + + Thread t = null; + + for (int i=0;i 0) + args+= " -library-path+="+mustellaswc; + } + + if (use_apollo) { + if (run_mobile_tests) + args+=" +configname=airmobile"; + else + args+=" +configname=air"; + } + + if (save_failures) { + if (!distributed && !pmd) { + System.out.println ("Choosing local runner bitmap save"); + args+=" -includes=SaveBitmapFailures"; + } else if (distributed || pmd) { + System.out.println ("Choosing the Dist server bitmap save"); + args+=" -includes=SaveBitmapFailuresDistServer"; + } + } + + /// adding + if (librarypath != null && librarypath.length() > 0) { + + args+=" -library-path+="+ librarypath; + + } + + String externallibrarypath=System.getProperty("external.librarypath",frameworks+"/libs/playerglobal.swc"); + + if (librarypath.indexOf(".swc")==-1) { + asclasspath+=","+frameworks; + } + + boolean strict=System.getProperty("strict")!=null && System.getProperty("strict").equals("true"); + + if (socket_mixin != null && !socket_mixin.equals("")) { + args+=socket_mixin; + } + + /// add mustella args to the arg string + // if somehow there are no ermine args, then there is no test to mixin; so no point in + // compiling it + if (ermineArgs.size() == 0) { + System.out.println ("Skipping compile on " + mxml + " no mustella includes survived"); + removeFromList(this); + return; + } + + for (int i=0;i 0) + args+=" -source-path="+pieces[i]; + } + + if (use_qa_framework_dir) { + + // System.out.println ("Adding qa fwk dir: " + qa_framework_dir); + + // If we're using android or iOS, use the CompareBitmap which handles file I/O. MXMLC will + // keep whichever CompareBitmap it encounters first. + if( target_os_name.equalsIgnoreCase( MobileUtil.ANDROID_OS ) || + target_os_name.equalsIgnoreCase( MobileUtil.IOS ) || + target_os_name.equalsIgnoreCase( MobileUtil.QNX ) ) + { + //System.out.println("AIR files will override."); + args+= " -source-path="+qa_framework_dir+File.separator+"AIR"; + } + + // Now add the rest. + args+= " -source-path="+qa_framework_dir; + } + + /// this is the include for the fwk to send stuff to the Runner + + String services = System.getProperty("services"); + if (services!= null && !services.equals("")) { + args+=" --services="+services; + } + String antArgs=System.getProperty("mxmlc.args"); + if (antArgs!=null && !antArgs.equals("")) { + args=antArgs+" "+args; + } + + args = checkAndAddUserArgs (mxml, args); + + System.out.println ("ARGS: " + args); + + + /** + * if this run is designated as an air_transform, do the dirty work here + * we save this for the end, because we need to shift the args. + */ + if (apollo_transform) { + mxml = FileUtils.normalizeDirOS(mxml); + args = ApolloAppToWindow.doAll (args, apollo_transform_prefix, apollo_transform_prefix2, mxml, apollo_transform_template, dir); + mxml = ApolloAppToWindow.getNewMxmlName (dir, mxml, apollo_transform_prefix); + } + + defaultArgs=StringUtils.StringToArray(args); + + try { + // writeTag(mxml, "status=started"); + // if compc is used to produce a swc, add it to the classpath + + String compc = System.getProperty("compc"); + + if (compc != null && !compc.equals("")) { + defaultArgs = compc(mxml, defaultArgs); + } + + // do a similar thing for rsl only do not put the rsl swc on the classpath + String rsl = System.getProperty("rsl"); + if (rsl != null && !rsl.equals("")) { + rsl(mxml); + defaultArgs = StringUtils.StringToArray(StringUtils.arrayToString(defaultArgs) + " +frameworks-dir " + frameworks); + } + + System.out.println ("okey doke, going to compile " + mxml); + + CompileMxmlUtils compiler = new CompileMxmlUtils(); + compiler.setPrintOut(true); + + compiler.setDir(dir); + + /** + System.out.println ("************"); + System.out.println ("************"); + + String defaultArgsDebugString = new String(); + + for(int i = 0; i < defaultArgs.length; ++i){ + defaultArgsDebugString += defaultArgs[i]; + } + + System.out.println ("mxml: " + mxml); + System.out.println ("defaultArgs: " + defaultArgsDebugString); + **/ + + compiler.compile(mxml, defaultArgs); + RuntimeExecHelper rh = compiler.getRuntimeExecHelper(); + + /// FIX collect these results / insert + + // writeTag(mxml, "mxmlc=" + StringUtils.arrayToString(compiler.getExecArgs()) + "\ncompile time=" + StringUtils.formatTime(compiler.getLastRunTime()) + "\nexitvalue=" + rh.getExitValue() + "\nstdout=" + rh.getOutputText() + "\nstderr=" + rh.getErrorText()); + // System.out.println("rh output: " + rh.getOutputText()); + // System.out.println("rh error out: " + rh.getErrorText()); + // System.out.println("exit value=" + rh.getExitValue()); + + String failedFile=null; + + // InsertErrorResult ier = null; + + if (rh.getExitValue() != 0) { + directory_result = 1; + failedFile = rh.getErrorText(); + System.out.println("here's the failedFile; " + failedFile); + + handleCompileError (mxml, args, failedFile); + + /// insert failure into the database here. + //ier = new InsertErrorResult (run_id, failedFile, rh.getErrorText()); + + removeFromList(this); + + /// don't bother retrying anymore. No more Mr. Nice Guy + /* + if (removeFromArgs (mxml, failedFile, ermineArgs) && retryCount < 4) { + System.out.println ("Compile: Calling again"); + compileMxml (mxml, ermineArgs); + } else { + System.out.println("!!compile failed, but could not fix cmd line, sorry"); + if (!exit_on_compile_error) { + System.out.println("Not set to exit on compile error, continue"); + removeFromList(this); + } else { + /// reachable? + System.out.println("getting out"); + System.exit(1); + + } + + } + */ + + } else { + // System.out.println ("that was just ducky"); + + /// if (System.getProperty("html")==null || System.getProperty("html").equals("false")==false) { + + removeFromList(this); + } + } catch (Exception e) { + e.printStackTrace(); + handleCompileError (mxml, args, e.toString()); + removeFromList(this); + } + } + + private static final String compile_arg_ending = ".compile"; + private static final String property_arg_ending = ".htmlvars"; + + + // private Hashtable htmlVars = new Hashtable(); + + public String checkAndAddUserArgs (String mxml, String args) { + + String comp_mxml = transformName(mxml, compile_arg_ending); + + Map.Entry me = null; + + if (new File(comp_mxml).exists()) { + // System.out.println ("Saw the .compile file"); + + Properties p = new Properties(); + try { + // Since we may get duplicate compile key directives, we + // have to combine them. + // can't really use load + + String line = null; + String key = null; + String val = null; + String tmp = null; + BufferedReader be = new BufferedReader (new FileReader (comp_mxml)); + + /// Simplified version: just throw the arg on there, as is + while ( (line=be.readLine()) != null) { + if (!line.startsWith ("#")) + args += " "+ doSubstitute(line); + } + + be.close(); + + + } catch (Exception e) { + System.err.println ("Exception on trying to load user .compile file, maybe ok"); + // e.printStackTrace(); + + + } + } + + if (args.indexOf ("-debug") == -1){ + args += " -debug"; + } + + return args; + } + + public String doSubstitute (String line) { + + String sdk_dir=System.getProperty("sdk.dir"); + + String fwk_dir=System.getProperty("framework.dir"); + + if (sdk_dir != null && !sdk_dir.equals("")) { + + if ( line.indexOf ("${sdk.dir}") != -1) { + line = line.replaceAll ("\\$\\{sdk.dir\\}", FileUtils.normalizeDir(sdk_dir)); + } + } + + + if (mustella_dir != null && !mustella_dir.equals("")) { + if ( line.indexOf ("${mustella.dir}") != -1) { + line = line.replaceAll ("\\$\\{mustella.dir\\}", FileUtils.normalizeDir(mustella_dir)); + } + + } + + if (fwk_dir != null && !fwk_dir.equals("")) { + if ( line.indexOf ("${framework.dir}") != -1) { + line = line.replaceAll ("\\$\\{framework.dir\\}", FileUtils.normalizeDir(fwk_dir)); + } + + } + + + return line; + + } + + + + public static String transformName (String mxml, String addition) { + + if (mxml.endsWith (".mxml")) { + mxml = mxml.substring (0, mxml.length()-5) + addition; + + } + + return mxml; + + + } + + // counter to see if there's progress. + private int retryCount = 0; + private int lastCount = 0; + private int currentCount = 0; + private String lastRemove = null; + + public boolean removeFromArgs (String mxml, String removeArg, ArrayList ermineArgs) { + + retryCount++; + HashMap theBroken = splitAndFix(removeArg); + + currentCount = ermineArgs.size(); + + if (currentCount < lastCount) { + lastCount = currentCount; + } else if (currentCount == lastCount) { + // we're making no headway, + return false; + } + + System.out.println ("broken files: " + theBroken); + + int countOfIncludes= countIncludes (ermineArgs); + + // note futility right away. + if (countOfIncludes == 1) { + System.out.println ("include count is 1. There's no hope, returning false"); + return false; + } + + System.out.println ("include count: " + countOfIncludes); + String fixed = null; + + + /// how do we know if there's a test left? + boolean others= false; + int count = 0; + String tmp = null; + boolean tookAction = false; + for (int i=0;i -1) { + tag = mxml.substring(0, mxml.lastIndexOf(".")) + ".output"; + } else { + tag = mxml + ".output"; + } + return tag; + } + + + public static void writeTag(String mxml, String msg) { + String build = System.getProperty("build", "workspace"); + String out = "hostname=" + StringUtils.getHostName() + "\n"; + out += "date=" + StringUtils.getDate() + "\n"; + out += "build=" + build + "\n"; + out += msg; + String name = getTagName(mxml); + try { + FileUtils.writeFile(name, out); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String[] compc(String mxml, String[] mxmlArgs) throws Exception { + //System.out.println(">>>>> compc if necessary >>>>>>> " + mxml); + CompcUtils compc = new CompcUtils(); + //compc.setPrintOut(true); + File argFile = null; + try { + argFile = compc.getCompcArgFile(mxml); + if (argFile.exists()) { + compc.compile(argFile); + RuntimeExecHelper rh = compc.getRuntimeExecHelper(); + mxmlArgs = compc.addSwcToClassPath(mxmlArgs); + // writeTag(mxml, "COMPC compile time=" + StringUtils.formatTime(compc.getLastRunTime()) + "\nexitvalue=" + rh.getExitValue() + "\nstdout=" + rh.getOutputText() + "\nstderr=" + rh.getErrorText()); + System.out.println("compc exit value=" + rh.getExitValue()); + } + } catch (Exception e) { + System.out.println("compc argfile doesn't exist...carry on."); + e.printStackTrace(); + } + + return mxmlArgs; + + } + + public static void rsl(String mxml) throws Exception { + System.out.println(">>>>> building rsl(s)"); + CompcUtils compc = new CompcUtils(); + //compc.setPrintOut(true); + File argFile = null; + try { + argFile = compc.getRSLArgFile(mxml); + if (argFile.exists()) { + compc.compile(argFile); + RuntimeExecHelper rh = compc.getRuntimeExecHelper(); + System.out.println("compc exit value=" + rh.getExitValue()); + } + } catch (Exception e) { + System.out.println("rsl argfile doesn't exist...carry on."); + e.printStackTrace(); + } + + } +} Propchange: incubator/flex/trunk/mustella/java/src/mustella/CompileMustellaSwfs.java ------------------------------------------------------------------------------ svn:eol-style = native