incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject svn commit: r1333232 [22/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 GMT
Added: incubator/flex/trunk/mustella/java/src/mustella/CousinPreCompile.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/CousinPreCompile.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/CousinPreCompile.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/CousinPreCompile.java Wed May  2 22:44:38 2012
@@ -0,0 +1,266 @@
+/*
+ *
+ * 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 org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import java.io.File;
+import java.util.*;
+
+public class CousinPreCompile extends Task {
+
+
+	/** 
+
+	Custom filtering mechanism. 
+
+	looks for a file ("pre_compile.sh") in SWF directories, given a list of files/directories
+
+	by decree, the only shell script that should get executed in the SWFs directory
+	is the pre_compile.sh script. If something else turns up, we remove it.
+
+
+	**/
+
+
+
+	// this is a variable, though it seems needless at this point:
+    	private String shellFile = "pre_compile.sh";
+
+
+    	private final String swfDir1 = "../SWFs/";
+    	private final String swfDir2 = "../swfs/";
+
+	public void setShellFile(String s) { 
+		this.shellFile = s;
+	}
+
+	public String getShellFile() { 
+		return shellFile;
+	}
+
+	private String property = null;
+
+	public String getProperty() { 
+		return property;
+	}
+
+	public void setProperty (String prop) { 
+		this.property = prop;
+	}
+
+
+	/// the contents of a fileset: 
+	private String files = null;
+
+	public void setFiles(String target) { 
+		this.files = target;
+	}
+
+	public String getFiles() { 
+		return files;
+	}
+
+
+	private String root = "";
+
+	public void setRoot(String target) { 
+		this.root = target;
+	}
+
+	public String getRoot() { 
+		return root;
+	}
+
+
+	private HashMap rez = new HashMap();
+
+
+	/// we need to take build, passed to us, and 
+	/// generate the id, setting that back in the project
+    	public void execute() {
+
+
+		/// split into pieces: 
+		String [] args = files.split(File.pathSeparator);
+		// System.out.println ("args length: " + args.length);
+		// System.out.println ("arg1: " + args[1]);
+
+		
+
+
+		ArrayList actuals = new ArrayList();
+
+		StringBuffer result = new StringBuffer();
+		result.append("");
+
+		Object obj = null;
+
+
+		File tmp = null;
+
+		String use = null;
+
+
+		for (int i=0;i<args.length;i++) {
+
+
+			use = args[i].trim();
+			// System.out.println ("result0: " + use);
+
+			if ( use.startsWith(","))
+				use=use.substring(1).trim();
+
+			// System.out.println ("result1: " + use);
+
+			tmp = new File (use);
+
+			if (use == null || use.equals (""))
+				 continue;
+
+
+			if (!tmp.isDirectory()) {
+				// if this is a file, see if we have to filter it
+				// if it lives in the SWFs directory, it can only be one name
+				if (tmp.getParent().toLowerCase().endsWith ("swfs")) {
+					// System.out.println ("NAME: " + tmp.getName());
+					if (!tmp.getName().equals ("pre_compile.sh")) {
+						// System.out.println ("SKIPPING " + tmp.getName());
+						continue;
+					} else { 
+				
+						try { 
+							obj = rez.put (tmp.getCanonicalPath(), "");
+							if (obj==null)
+								actuals.add(0, tmp.getCanonicalPath());
+						} catch (Exception e) {
+							e.printStackTrace();
+						}
+						continue;
+
+					}
+				} else { 
+					/// in this case, it's a file, 
+					/// so, we strip the file and will search it later
+					// System.out.println ("Adding: " + tmp);
+					try { 
+						obj = rez.put (tmp.getCanonicalPath(), "");
+						if (obj==null)
+							actuals.add(tmp.getCanonicalPath());
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+					// System.out.println ("working NOW with: " + tmp.getParent());
+					args[i] = tmp.getParent();
+				}
+			}
+
+			if (!tmp.exists()) {
+				args[i] = root + "/" + args[i];
+				// System.out.println ("morphed to: " + args[i]);
+			}
+
+
+			if (new File ( args[i] + "/" + swfDir1 + shellFile ).exists() ) {
+			
+				try { 	
+				obj = (Object) rez.put (new File ( args[i] + "/" + swfDir1 + shellFile).getCanonicalPath(), "");
+				if (obj==null)
+					actuals.add(0, new File ( args[i] + "/" + swfDir1 + shellFile).getCanonicalPath());
+				// System.out.println ("got one off: " + new File ( args[i] + "/" + swfDir1 + shellFile).getCanonicalPath());
+				}catch (Exception e) {}
+				continue;
+			} else if (new File ( args[i] + "/" + swfDir2 + shellFile ).exists() ) {
+				try { 	
+				obj = (Object)rez.put (new File ( args[i] + "/" + swfDir2 + shellFile).getCanonicalPath(), "");
+				if (obj==null)
+					actuals.add(0, new File ( args[i] + "/" + swfDir2 + shellFile).getCanonicalPath());
+				// System.out.println ("got one off: " + new File ( args[i] + "/" + swfDir2 + shellFile).getCanonicalPath());
+				}catch (Exception e) {}
+				continue;
+			} else if (new File (tmp.getParent() + "/" + swfDir1 + shellFile ).exists() ) {
+				try { 	
+				obj = (Object) rez.put (new File (tmp.getParent() + "/" + swfDir1 + shellFile ).getCanonicalPath(), "");
+				if (obj==null)
+					actuals.add(0, new File (tmp.getParent() + "/" + swfDir1 + shellFile ).getCanonicalPath());
+				// System.out.println ("got one off: " + new File (tmp.getParent() + "/" + swfDir1 + shellFile ).getCanonicalPath());
+				}catch (Exception e) {}
+				continue;
+			} else if (new File (tmp.getParent() + "/" + swfDir2 + shellFile ).exists() ) {
+				try { 	
+				obj = (Object) rez.put (new File (tmp.getParent() + "/" + swfDir2 + shellFile ).getCanonicalPath(), "");
+				if (obj==null)
+					actuals.add(0, new File (tmp.getParent() + "/" + swfDir2 + shellFile ).getCanonicalPath());
+				// System.out.println ("got one off: " + new File (tmp.getParent() + "/" + swfDir2 + shellFile ).getCanonicalPath());
+				}catch (Exception e) {}
+				continue;
+			}
+
+			// System.out.println ("bottom of loop");
+		}
+
+			
+
+		// System.out.println ("rez: " + rez.toString());
+
+		// Iterator it = actuals.iterator();
+
+
+		String tmp1 = null;
+
+		/// use CANONICAL!
+
+		for (int i=0;i<actuals.size();i++) {
+
+
+			tmp1 = (String)actuals.get(i);
+			if (tmp1.endsWith(".sh"))
+				result.append (tmp1);
+
+			if (i<(actuals.size()-1))
+				result.append (File.pathSeparator);
+				
+		}
+
+		// System.out.println ("result: " +  result.toString());
+
+		/* 
+		while (it.hasNext()) {
+			tmp1 = (String) it.next();
+			try { 
+			} catch (Exception e) {
+				e.printStackTrace();}
+			result.append (tmp1);
+			if (it.hasNext())
+				result.append (File.pathSeparator);
+			// System.out.println ("result: " +  tmp1.toString());
+		}
+		*/
+
+		Project project = getProject();
+		project.setProperty(property, result.toString());
+		   
+	 
+
+	}	
+
+
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/CousinPreCompile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/ExcludesAdjuster.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/ExcludesAdjuster.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/ExcludesAdjuster.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/ExcludesAdjuster.java Wed May  2 22:44:38 2012
@@ -0,0 +1,137 @@
+/*
+ *
+ * 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 java.util.ArrayList;
+
+
+
+/**
+ * Read in a local file to add to the list of excludes for a test run
+ * meant as a workaround for insurmountable configuration differences.
+ * details:
+ * 
+ * The file should reside in the qa/sdk/testsuites/mustella/tests directory.
+ * It's name should be "MachineSpecificExcludes.txt".  It should not be checked in.
+ * Its format should be one of two styles: 
+ * it can be in failures output format (from mini run), like this: 
+ *
+ *   gumbo/components/List/events/VItemRendRET_event_tester VRendRET_List_scrollPosition6
+ *
+ * or already in exclude format: 
+ * 
+ *   gumbo/components/List/events/VItemRendRET_event_tester$VRendRET_List_scrollPosition6
+
+ *
+ */
+public class ExcludesAdjuster {
+
+
+	/**
+	 * name of the file we'll read
+	 */
+	public static String excludesAdjustfile= "MachineSpecificExcludes.txt";
+
+	/**
+	 * Directory we'll read this from. This is ${sdk.mustella.dir}, 
+	 * so we get it pushed from the excludes task (which has the project)
+	 */
+	public static String testsDir = null;
+
+
+	public static void setDir (String dir) {
+		testsDir = dir;
+	}
+
+	public static String getDir (String dir) {
+		return testsDir;
+	}
+
+
+	public static ArrayList theExcludes = new ArrayList();
+
+
+	public static void readFile () {
+
+		if (testsDir == null) {
+			System.out.println ("Must feed a directory to the ExcludesAdjuster class!");
+			return;
+		}
+
+		BufferedReader br = null;
+
+		String tmp = null;
+
+
+		String lastTmp = null;
+		
+
+		try {
+
+			br = new  BufferedReader (new FileReader ( testsDir + File.separator + excludesAdjustfile ));
+
+			while ( (tmp=br.readLine()) != null) {
+
+				if (tmp.length() <= 1)
+					continue;
+
+				if (tmp.indexOf (" ") != -1)
+					tmp = tmp.replace (' ', '$');
+
+				/// our guys get inserted at the top of the excludes
+				/// so it's okay if they end with "," I guess
+				tmp = tmp + ",";
+
+				theExcludes.add (tmp);
+					
+			}	
+
+
+		} catch (Exception e) {
+			System.out.println ("No machine-based excludes");
+				
+			// e.printStackTrace();
+		}
+	}
+
+
+	public static ArrayList getExcludes () {
+
+		readFile();
+		
+		return theExcludes;
+
+
+	}
+
+
+	public static void main (String [] args) throws Exception {
+
+
+		ArrayList al = getExcludes();
+
+		for (int i=0;i<al.size();i++) { 
+
+			System.out.println ("ex+ " + al.get(i));
+
+		}	
+
+	}
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/ExcludesAdjuster.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/GetExcIncCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/GetExcIncCase.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/GetExcIncCase.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/GetExcIncCase.java Wed May  2 22:44:38 2012
@@ -0,0 +1,612 @@
+/*
+ *
+ * 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.sql.*;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class GetExcIncCase { 
+
+
+	/**
+
+		Write excludes.
+
+		type can be "class" or "text". If class, it wraps the list in a 
+		package & class structure.
+
+		text, just write the values
+
+	**/
+
+
+	public static String testcaseTableName = "test_cases";
+
+	public static String branch = null;
+	public static String browser = null;
+	public static String os = null;
+	public static String runtime = null;
+	public static String outfile = null;
+	public static String untilTime = null;
+	public static String type = "class";
+	public static String bugByPass = null;
+
+
+	public static String exclude_config_id_str;
+
+
+	public static void setPassedExcludeId (String s) { 
+
+		if (!s.equals("")) { 
+			exclude_config_id_str = s;
+		}
+	}
+
+	public static void setBranch (String b) { 
+		branch = b;
+	}
+
+	/// the cutoff for excludes in this run. a time stamp
+	public static void setUntilTime (String b) { 
+		untilTime = b;
+		System.out.println ("until time is: " + b);
+	}
+
+
+	public static void setBugByPass (String b) { 
+		bugByPass = b;
+	}
+
+	public static void setOs (String b) { 
+		os = b;
+	}
+
+	public static void setType (String b) { 
+		type = b;
+	}
+
+	public static void setRuntime (String b) { 
+		runtime = b;
+	}
+
+	public static void setExcludeConfigId (String s) { 
+		exclude_config_id_str = s;
+	}
+
+	public static void setBrowser (String b) { 
+		browser = b;
+		if (browser.indexOf ("/") != -1) { 
+			browser = browser.substring (browser.lastIndexOf ("/")+1);
+		} else if (browser.indexOf (File.separator) != -1) { 
+			browser = browser.substring (browser.lastIndexOf (File.separator)+1);
+		}
+
+		browser = browser.toLowerCase();
+	}
+
+	public static void createAndWrite (String filename, String branchl, String browserl, String runtimel, String osl) throws Exception {   
+
+		outfile = filename;
+		branch = branchl;
+		browser = browserl;
+		runtime = runtimel;
+		os = osl;
+
+
+		if (browser.indexOf ("/") != -1) { 
+			browser = browser.substring (browser.lastIndexOf ("/")+1);
+		} else if (browser.indexOf (File.separator) != -1) { 
+			browser = browser.substring (browser.lastIndexOf (File.separator)+1);
+		}
+
+		browser = browser.toLowerCase();
+
+	
+		// System.out.println ("resulting browser: " + browser);	
+
+	
+		/// set	
+		if (exclude_config_id_str == null) { 
+			// System.out.println ("---->>>>> Calling getExcludeConfigs");
+			exclude_config_id_str = getExcludeConfigs();
+		} 
+
+
+		ArrayList al = getExcludes();	
+		ArrayList al2 = ExcludesAdjuster.getExcludes();	
+		if (!al2.isEmpty())
+			al.addAll (0, al2);
+
+
+		System.out.println ("excludes count: " + (al.size()));
+
+		writeToFile (al, filename);
+
+		
+	}
+
+	public static void createAndWrite (String filename, String exclude_config) { 
+
+		exclude_config_id_str	= exclude_config;
+
+		try { 
+
+		ArrayList al = getExcludes();	
+		ArrayList al2 = ExcludesAdjuster.getExcludes();	
+
+		if (!al2.isEmpty())
+			al.addAll (0, al2);
+
+		writeToFile (al, filename);
+
+		} catch (Exception e) { 
+
+			e.printStackTrace();
+			
+		}
+
+
+	}
+
+
+
+	private static final String sep = "$";
+	private static final String comma = ",";
+	private static final String colon1 = ": 1";
+	private static final String tabs = "		";
+	private static final String newline = System.getProperties().getProperty ("line.separator");
+
+	public static ArrayList getExcludes() throws Exception { 
+		
+		System.err.println ("This should no longer be called");
+		
+		/* AJH
+		Connection con = null;
+
+		try { 
+			con = GetConnection.get();
+		} catch (Exception e) { 
+			System.err.println ("Could not make database connection, no fetch of excludes");
+			return new ArrayList();
+		}
+
+		Statement stmt = con.createStatement();
+		*/
+		
+		/* 
+			need to make this a transaction !!
+
+		*/
+
+		
+		ArrayList al = new ArrayList();
+		
+		/* AJH
+		ResultSet rs =stmt.executeQuery ( getExcludeStmt () );
+
+		String tmpdir = null;
+		String tmps = null;
+		String tmpt = null;
+
+		StringBuffer sb = new StringBuffer();
+
+		while (rs.next()) { 
+			tmpdir = rs.getString(1);	
+			tmps = rs.getString(2);	
+			tmpt = rs.getString(3);	
+			sb.append (tmpdir);
+			sb.append (tmps);
+			sb.append (sep);
+			sb.append (tmpt);
+			if (type.equals("class"))
+				sb.append (colon1);
+	
+			if (!rs.isLast())
+				sb.append (comma);
+
+			al.add (sb.toString());
+			sb.delete (0, sb.length());
+		}
+		*/
+
+		return al;
+
+	}
+
+	public static final String qt = "'";
+
+	public static String getExcludeCountStmt() { 
+
+
+		String s = "select count(test_file) from test_cases, excludes where test_cases.id = excludes.testcase_id and (excludes.date_end = '0000-00-00 00:00:00' or excludes.date_end > '" + untilTime +"' ) and excludes.exclude_config_id in " + exclude_config_id_str;
+		/// add untilTime
+	
+		return s;
+
+	}
+
+
+	/// neeed to check if the date_end  is > than some value we pass in; 
+	//  that would be a not-yet vetted exclude
+
+	public static String getExcludeStmt() { 
+
+		String s = null;
+
+		if (bugByPass != null && bugByPass.length() > 0) { 
+			// System.out.println ("Here's bug by pass: " + bugByPass + " length: " + bugByPass.length());
+			s = "select test_files.dir_name, test_file, test_id from test_cases, excludes, test_files where test_cases.id = excludes.testcase_id and test_files.id = test_cases.test_dir and (excludes.date_end = '0000-00-00 00:00:00' or excludes.date_end > '" + untilTime +"' ) and excludes.exclude_config_id in " + exclude_config_id_str  + " and (excludes.bug_id != '" + bugByPass + "' or excludes.bug_id is null)";
+		} else {
+			s = "select test_files.dir_name, test_file, test_id from test_cases, excludes, test_files where test_cases.id = excludes.testcase_id and test_files.id = test_cases.test_dir and (excludes.date_end = '0000-00-00 00:00:00' or excludes.date_end > '" + untilTime +"' ) and excludes.exclude_config_id in " + exclude_config_id_str;
+
+		}
+
+		// System.out.println (s);
+
+		return s;
+
+	}
+
+	public static String getExcludeConfigStmt() { 
+		String s = null;
+		if (!browser.equals ("")) { 
+
+			s = "select id from exclude_config where (os= '" +
+			os+"' or os= 'any' ) and (branch= '" +
+			branch+"' or branch= 'any' )and (runtime= '" +
+			runtime+"' or runtime= 'any' ) and (browser= '" +
+			browser+"' or browser= 'any') " ;
+		
+		} else { 
+
+			s = "select id from exclude_config where (os= '" +
+			os+"' or os= 'any' ) and (branch= '" +
+			branch+"' or branch= 'any' )and (runtime= '" +
+			runtime+"' or runtime= 'any' )";
+
+
+		}
+
+		// System.out.println (s);
+
+		return s;
+
+	}
+
+
+	public static String getExcludeConfigs() throws Exception { 
+		
+		System.err.println ("This should not be called");
+		
+		/* AJH
+		Connection con = null;
+
+		try { 
+			con = GetConnection.get();
+		} catch (Exception e) { 
+			System.err.println ("Could not make database connection, no fetch of excludes");
+			return null;
+		}
+
+		Statement stmt = con.createStatement();
+		*/
+
+		StringBuffer sb = new StringBuffer();
+
+		/* AJH
+		sb.append ("(");
+		
+		
+		ResultSet rs =stmt.executeQuery ( getExcludeConfigStmt () );
+
+		String tmps = null;
+		String tmpt = null;
+
+
+		while (rs.next()) { 
+			tmps = rs.getString(1);	
+
+			sb.append (tmps);
+
+			if (!rs.isLast())
+				sb.append (comma);
+
+		}
+
+		sb.append (")");
+
+		*/
+		
+		return sb.toString();
+
+
+	}
+
+	public static void close () { 
+
+		/* AJH
+		try { 
+			GetConnection.get().close();
+		} catch (Exception e) { 
+		}
+		*/
+	}
+
+
+	static String topFileExc1="package {\n\nimport flash.display.DisplayObject;\n\n[Mixin]\n\n/**\n\n*  A hash table of tests not to run. as of ";
+	static String topFileExc2= "\n*/\n\npublic class CurrentExcludeList\n\n {\n\n public static function init(root:DisplayObject):void\n\n {\n\n		UnitTester.excludeList = {\n\n";
+
+	static String topFileInc="package {\n\nimport flash.display.DisplayObject;\n\n[Mixin]\n\n/**\n\n*  A hash table of tests to run.\n*/\n\npublic class CurrentIncludeList\n\n {\n\n public static function init(root:DisplayObject):void\n\n {\n\n		UnitTester.includeList = {\n\n";
+
+	static String bottomFile = "                };\n\n}\n }\n}\n";
+
+
+	/** 
+	 * writes to an as file, to be compiled as a swc
+	 * writes the top, 
+	 * then the arraylist contents, then the bottom
+	 */
+	public static void writeToFile (ArrayList al, String filename) { 
+		writeToFile (al, filename, true);
+	}	
+
+
+	public static ResultSet doQuery (String s) {
+		/* AJH
+		Connection con = null;
+
+		try { 
+			con = GetConnection.get();
+		} catch (Exception e) { 
+			System.err.println ("Could not make database connection, no fetch of excludes");
+			return null;
+		}
+		*/
+		
+		ResultSet rs = null;
+		
+		/* AJH
+		try { 
+			Statement stmt = con.createStatement();
+
+			rs = stmt.executeQuery(s);
+
+		} catch (Exception e) { 
+			e.printStackTrace();
+			return null;
+		}
+		*/
+		
+		return rs;
+
+	}
+
+
+
+	public static void writeToFileTransform (ArrayList al, String filename, HashMap tellFiles) throws Exception {
+
+
+		FileOutputStream fos = null;
+
+		String tmp = null;
+		String last_tmp = null;
+
+		String file_portion = null;
+
+		try { 
+
+			fos = new FileOutputStream (filename);
+
+
+			if (type.equals ("class")) { 
+
+				fos.write (topFileInc.getBytes(), 0, topFileInc.length());
+			}
+
+
+
+			for (int i=0;i<al.size();i++) { 
+
+				tmp = (String) al.get (i);
+
+				file_portion = tmp.substring (0, tmp.indexOf ("$"));
+
+				file_portion = file_portion + qt;
+					
+		
+
+				if (!file_portion.equals (last_tmp)) { 
+
+			
+					fos.write (tabs.getBytes(), 0, tabs.length());
+					fos.write (file_portion.getBytes(), 0, file_portion.length());
+					fos.write (":1".getBytes(), 0, ":1".length());
+					fos.write (comma.getBytes(), 0, comma.length());
+					fos.write (newline.getBytes(), 0, newline.length());
+					last_tmp = file_portion;
+					tellFiles.put (file_portion, "1");
+				}
+
+				if (type.equals("class"))
+					fos.write (tabs.getBytes(), 0, tabs.length());
+				fos.write (tmp.getBytes(), 0, tmp.length());
+
+				if (i<al.size()-1)
+					fos.write (comma.getBytes(), 0, comma.length());
+
+				fos.write (newline.getBytes(), 0, newline.length());
+				fos.flush();
+			}
+
+			if (type.equals ("class")) 
+				fos.write (bottomFile.getBytes(), 0, bottomFile.length());
+				
+
+			fos.flush();
+			fos.close();
+
+		} catch (Exception e) { 
+
+			e.printStackTrace ();
+
+			try { 
+				fos.close();
+			} catch (Exception e2) { }
+
+			throw e;
+			
+		}
+	}
+
+	public static void writeToFile (ArrayList al, String filename, boolean exclude) { 
+
+
+		// System.out.println ("this is the file I'll write: " + filename);
+
+		/// (the unusual) case of nothing to write
+		/// skip out of here
+		/*
+		if (al.size()==0) { 
+			/// not sure the wisdom
+			System.out.println ("EMPTY SET FOR EXCLUDES. No write");
+			return;
+		}
+		*/
+
+		FileOutputStream fos = null;
+
+		String tmp = null;
+
+		try { 
+
+			fos = new FileOutputStream (filename);
+
+
+			if (type.equals ("class")) { 
+
+				if (exclude) { 
+					fos.write (topFileExc1.getBytes(), 0, topFileExc1.length());
+					fos.write (untilTime.getBytes(), 0, untilTime.length());
+					fos.write (topFileExc2.getBytes(), 0, topFileExc2.length());
+				} else
+					fos.write (topFileInc.getBytes(), 0, topFileInc.length());
+			}
+
+
+
+			for (int i=0;i<al.size();i++) { 
+
+				tmp = (String) al.get (i);
+				if (type.equals("class"))
+					fos.write (tabs.getBytes(), 0, tabs.length());
+				fos.write (tmp.getBytes(), 0, tmp.length());
+				fos.write (newline.getBytes(), 0, newline.length());
+				fos.flush();
+			}
+
+			if (type.equals ("class")) 
+				fos.write (bottomFile.getBytes(), 0, bottomFile.length());
+				
+
+			fos.flush();
+			fos.close();
+
+		} catch (Exception e) { 
+
+			e.printStackTrace ();
+
+			try { 
+				fos.close();
+			} catch (Exception e2) { }
+
+		}
+
+
+	}
+
+
+
+
+	public static void main (String [] args) throws Exception { 
+
+		// System.out.println (System.getProperties());
+
+		// String outfile = "tmp.run";
+
+		/* testing
+		ArrayList al = new ArrayList();
+
+		al.add ("CBTester$myButtonTest1: 1,");
+		al.add ("CBTester$myHeadTest1: 1");
+
+		writeToFile (al, "tmp1.test");
+		*/
+
+
+		if (args.length == 0) { 
+			System.err.println ("Required: NEED FILENAME TO WRITE EXCLUDES");
+		}
+
+
+		for (int i=0;i<args.length;i++)
+			System.out.println (i + " " +args[i]);
+
+
+		///kind of silly but it's all positional
+		/// 
+		String outfile = args[0];
+		String branch  = args[1];
+		String use_apollo = args[2];
+		String use_browser = args[3];
+		String browser = args[4];
+		String os      = args[5];
+		try { 
+			untilTime = args[6];
+		} catch (Exception e ) {
+			/// transform to now
+			untilTime = null;
+		}
+
+		String runtime = "";
+
+		if (use_apollo.equals("true"))
+			runtime = "apollo";
+		else if (use_browser.equals ("true"))
+			runtime = "browser";
+		else
+			runtime = "Standalone";
+
+		if (runtime.equals ("apollo"))
+			browser = "";
+
+
+		createAndWrite (outfile, branch, browser, runtime, os);
+
+
+		// System.out.println ("new run id: " + get ("999999"));
+
+
+
+	}
+
+
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/GetExcIncCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/GetUserArgs.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/GetUserArgs.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/GetUserArgs.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/GetUserArgs.java Wed May  2 22:44:38 2012
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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 utils.*;
+import utils.FileUtils;
+
+import java.io.File;
+import java.util.regex.*;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.*;
+
+/**
+ * User: bolaghlin
+ */
+public class GetUserArgs {
+
+    private static final String compile_arg_ending = ".compile";
+
+    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();
+
+
+		}
+	} 
+
+	return args;
+
+
+    }
+
+    public static String transformName (String mxml, String addition) { 
+
+	if (mxml.indexOf (".") != -1) {
+		return mxml.substring (0, mxml.lastIndexOf (".")) + addition;
+
+	}
+
+	return mxml;
+	
+    }
+
+
+    public static String transformName (String mxml) { 
+
+	return transformName (mxml, "");
+
+    }
+
+    public String doSubstitute (String line) { 
+
+	    	String sdk_dir=System.getProperty("sdk.dir");
+
+	    	String fwk_dir=System.getProperty("framework.dir");
+
+    		String mustella_dir = System.getProperty ("mustella.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 void main (String[] args) { 
+
+
+		GetUserArgs g = new GetUserArgs ();
+
+		String s = g.checkAndAddUserArgs(args[0], "");
+
+		System.out.println ("user args: " + s);
+	}
+
+
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/GetUserArgs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/HtmlTestAdapter.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/HtmlTestAdapter.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/HtmlTestAdapter.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/HtmlTestAdapter.java Wed May  2 22:44:38 2012
@@ -0,0 +1,484 @@
+/*
+ *
+ * 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 utils.*;
+import utils.FileUtils;
+
+import java.io.File;
+import java.util.regex.*;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.*;
+
+/**
+ * User: bolaghlin
+ * invoked by Runner when doing a browser run
+ * Writes the html file that will get invoked 
+ */
+public class HtmlTestAdapter { 
+
+
+	// These are the default dimensions. 
+	public static final String standard_height= "375";
+	public static final String standard_width= "500";
+
+   	private static final String property_arg_ending = ".htmlvars";
+
+	String real_mxml_file = null;
+
+	String html_file = null;
+
+	ParseMxmlHeader pml = null;
+
+	String extra_args = "";
+
+	ByteArrayOutputStream baos = null;
+
+	public static String sdk_dir=null;
+    	public static String htmlDir=null;
+    	// public static String htmlDirEnd = "/templates/client-side-detection-with-history/"; 
+    	public static String htmlDirEnd = "/templates/swfobject/";
+
+	static { 
+	try { 
+		if (System.getProperty ("sdk.dir")!=null && !System.getProperty ("sdk.dir").equals("")) 
+			sdk_dir = System.getProperty ("sdk.dir");
+	} catch (Exception e) { 
+	}
+
+	try { 
+		if (System.getProperty ("htmlDir")!=null && !System.getProperty ("htmlDir").equals("")) { 
+			htmlDir = System.getProperty ("htmlDir");
+			System.out.println ("incoming htmlDir: " + htmlDir);
+		} else {
+			htmlDir = sdk_dir + htmlDirEnd;
+			System.out.println ("non incoming htmlDir: " + htmlDir);
+		}
+
+		if (!htmlDir.endsWith("/"))
+			htmlDir = htmlDir + "/";	
+
+		System.out.println ("result htmlDir: " + htmlDir);
+	} catch (Exception e) { 
+	}
+	}
+
+
+	public HtmlTestAdapter (String swfFile, String loaderSwf) throws Exception {
+
+	
+		real_mxml_file = transformName(swfFile, ".mxml");
+		html_file = transformName(swfFile, ".html");
+
+
+		System.out.println ("Here is the real mxml file: " + real_mxml_file);
+
+
+		pml = new ParseMxmlHeader();
+		pml.setWidthAndHeight (real_mxml_file);
+
+		System.out.println ("here's the size: " + pml);
+
+		
+		GetUserArgs gu = new GetUserArgs();
+		extra_args = gu.checkAndAddUserArgs (real_mxml_file, extra_args);
+
+
+
+		createHtmlShell (html_file);
+
+	}
+
+
+	/// given the htmlvars file, 
+	public static String populateKeyValuePairs (String mxmlFile) { 
+
+
+		String fileName = transformName (mxmlFile, property_arg_ending);
+
+		String tmp = null;
+
+		Properties p = new Properties();
+
+		if (new File(fileName).exists()) { 
+
+			try { 
+
+				BufferedReader br = new BufferedReader (new FileReader(fileName));
+
+				while ( (tmp=br.readLine()) != null) { 
+
+					if (tmp.startsWith("flashvars="))
+						tmp = tmp.substring (10);
+
+					split (tmp, p);
+
+				}
+			
+				br.close();	
+			} catch (Exception e) { 
+	
+				e.printStackTrace();
+			}
+		}
+
+		// roll through these and make them flashvars.key=val; strings
+		Iterator it = p.entrySet().iterator();
+
+		Map.Entry me = null;
+
+		StringBuffer bs = new StringBuffer();
+
+		while (it.hasNext()) {
+
+			me = (Map.Entry) it.next();
+
+			bs.append ("flashvars.");
+			bs.append ((String)me.getKey());
+			bs.append ("=");
+			bs.append ("\"");
+			bs.append ((String)me.getValue());
+			bs.append ("\"");
+			bs.append (";");
+		}
+
+		return bs.toString();
+    	}
+
+
+	public static void split (String line, Properties  p) {
+
+		String key = null;
+		String entry = null;
+
+		String tmp = null;
+
+		// two way split, 
+		StringTokenizer st = new StringTokenizer(line, "&");
+
+		while (st.hasMoreTokens()) {
+
+			tmp = st.nextToken();
+
+			key = tmp.substring (0, tmp.indexOf ("="));
+			entry = tmp.substring (tmp.indexOf ("=")+1);
+			p.put (key, entry);
+		}
+
+
+	}	
+
+
+	public static Properties populatePropertiesFile (String mxmlFile) { 
+
+		Properties p = new Properties();
+
+		String fileName = transformName (mxmlFile, property_arg_ending);
+
+		if (new File(fileName).exists()) { 
+
+			try { 
+				p.load (new FileInputStream (fileName));
+
+			} catch (Exception e) { 
+	
+				e.printStackTrace();
+			}
+		}
+
+		return p;
+    	}
+
+    	public static String height = "375";
+    	public static String width = "500";
+
+
+	/*
+    	public void setWidthAndHeight(String mxml) {
+
+    	try {
+
+		String line = null;
+                BufferedReader br = new BufferedReader (new FileReader (mxml));
+                /// we will not go far into a file to get this
+                int count = 0 ;
+
+                int loc = -1;
+                int loc_end = -1;
+
+		boolean begun =  false;
+
+		boolean set1 = false;
+		boolean set2 = false;
+
+                while ( (line=br.readLine()) != null) {
+                	if ( (loc = line.indexOf("Application")) != -1) 
+				begun= true;
+
+						
+		
+			if (begun) { 
+				if (line.indexOf ("height=")!=-1) {
+					height = line.substring (line.indexOf ("height=")+8);
+					System.out.println ("inter h: " + height);
+					height = height.substring (0, height.indexOf ("\""));
+					set1 = true;
+		
+				}
+				
+				if (line.indexOf ("width=")!=-1) {
+					width = line.substring (line.indexOf ("width=")+7);
+					System.out.println ("inter w: " + width);
+					if (width.indexOf ("\"") != -1)
+						width = width.substring (0, width.indexOf ("\""));
+					set2 = true;
+				}
+                        }
+
+			if (set1 && set2) { 
+				br.close();
+				break;
+			}
+
+                	if ( begun && (loc_end = line.indexOf(">")) != -1)  { 
+				br.close();
+				break;
+			}
+		}
+
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+
+
+    	}
+
+	*/
+
+    public void createHtmlShell(String mxml) {
+
+	
+	System.out.println ("Creating the HTML files!!!! with " + mxml);
+
+
+        mxml=FileUtils.normalizeDir(mxml);
+
+	Properties p = populatePropertiesFile (mxml);
+	String pVals = populateKeyValuePairs (mxml);
+	System.out.println ("Properties file contained: " + pVals);
+
+	// ParseMxmlHeader pml = new ParseMxmlHeader();
+	// pml.setWidthAndHeight (mxml);
+
+        String dir=mxml.substring(0,mxml.lastIndexOf("/"));
+        String file=mxml.substring(mxml.lastIndexOf("/")+1);
+        String name=file.substring(0,file.lastIndexOf("."));
+        String swf=name+".swf";
+
+
+        try {
+            
+	    System.out.println ("Copying from: " + htmlDir + "history to: " + dir + "/history");
+	    FileUtils.copyDir(htmlDir + "history", dir + "/history");
+	    /// addded
+	    // was: AC_OETags.js
+	    System.out.println ("Copying from: " + htmlDir + "swfobject.js");
+	    FileUtils.copyFile( htmlDir + "swfobject.js", dir+"/swfobject.js" );
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+	try { 
+		// new load, edit, write.
+		BufferedInputStream bis = new BufferedInputStream (new FileInputStream ( htmlDir + "index.template.html"));
+
+		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);
+
+		}
+
+		contents = bos.toString();
+
+		// replace our targets. 
+		contents = contents.replaceAll ("\\$\\{useBrowserHistory\\}", "--");
+		contents = contents.replaceAll ("\\$\\{application\\}", name);
+		contents = contents.replaceAll ("\\$\\{title\\}", name);
+
+		// contents = contents.replaceAll ("\\$\\{height\\}", height);
+		// contents = contents.replaceAll ("\\$\\{width\\}", width);
+		System.out.println ("HTML SHELL, width and height: " + pml.width + " " + pml.height);
+		contents = contents.replaceAll ("\\$\\{height\\}", pml.height);
+		contents = contents.replaceAll ("\\$\\{width\\}", pml.width);
+		contents = contents.replaceAll ("\\$\\{bgcolor\\}", "0x000000");
+		contents = contents.replaceAll ("\\$\\{version_major\\}", "9");
+		contents = contents.replaceAll ("\\$\\{version_minor\\}", "0");
+		contents = contents.replaceAll ("\\$\\{version_revision\\}", "0");
+		contents = contents.replaceAll ("\\$\\{swf\\}", name );
+
+		/// push FlashVars if we've got any 
+		if (p.getProperty("flashvars") != null && (p.getProperty("flashvars").length() > 0)) { 
+			/// teh second one has an equals sign
+			contents = contents.replaceAll ("height=", "FlashVars=\"" + p.getProperty ("flashvars") + "\" " + "height=");
+			// the first one doesn't
+			contents = contents.replaceAll ("\"height\"", "\"FlashVars\", \"" + p.getProperty ("flashvars") + "\", " + "\"height\"");
+			contents = contents.replaceAll ("var flashvars = \\{\\};", "var flashvars = \\{\\}; " + pVals);
+
+		}
+
+		/// write it to our target html file.
+		String fileTo = dir + "/" + name + ".html";
+		System.out.println ("WRITING " +  fileTo);
+		BufferedOutputStream bus = new BufferedOutputStream (new FileOutputStream(fileTo));
+	
+		bus.write (contents.getBytes(), 0, contents.length());
+		bus.flush();
+		bus.close();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+	
+
+		
+			
+
+
+    }
+
+    private static final String compile_arg_ending = ".compile";
+
+    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();
+
+
+		}
+	}
+
+	return args;
+
+
+    }
+
+
+    public static String transformName (String file, String addition) { 
+
+	if (file.indexOf (".") != -1) {
+		return file.substring (0, file.lastIndexOf (".")) + addition;
+
+	}
+
+	return file;
+
+	
+    }
+
+    public String doSubstitute (String line) { 
+
+	    	String sdk_dir=System.getProperty("sdk.dir");
+
+	    	String fwk_dir=System.getProperty("framework.dir");
+
+    		String mustella_dir = System.getProperty ("mustella.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 void main (String[] args) throws Exception { 
+
+
+
+    }
+
+
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/HtmlTestAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/MobileConfigWriter.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/MobileConfigWriter.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/MobileConfigWriter.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/MobileConfigWriter.java Wed May  2 22:44:38 2012
@@ -0,0 +1,245 @@
+/*
+ *
+ * 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.awt.image.*;
+import java.io.*;
+import java.lang.reflect.*;
+import java.net.*;
+import java.util.*;
+import java.text.SimpleDateFormat;
+
+import javax.imageio.*;
+//import javax.mail.*;
+//import javax.mail.internet.*;
+
+import utils.MobileUtil;
+import utils.FileUtils;
+//import utils.HtmlNotify;
+import utils.StringUtils;
+import utils.P12Reader;
+import com.adobe.air.apk.APKPackager;
+import com.adobe.air.Listener;
+import com.adobe.air.Message;
+import com.adobe.air.SDK;
+
+public class MobileConfigWriter {
+
+	private static final String MOBILE_DIR = "mustella/tests/mobile";
+	private static final String AS_CLASS = "MobileConfig";
+	private static int adl_extras_XscreenDPI = -1;
+	private static String[] adl_extras = null;
+
+	static {
+		try {
+			adl_extras = System.getProperty( "adl_extras" ).split( " " );
+			
+			for( int i = 0; i < adl_extras.length; ++i ){
+				if( adl_extras[ i ].compareToIgnoreCase( "-XscreenDPI" ) == 0 ){
+					adl_extras_XscreenDPI = new Integer( adl_extras[ i + 1 ] ).intValue();
+				}
+			}
+			
+		} catch (Exception e) {
+			adl_extras_XscreenDPI = -1;
+			e.printStackTrace();
+		}
+		
+		//System.out.println("adl_extras_XscreenDPI: " + adl_extras_XscreenDPI);
+	}
+
+	public MobileConfigWriter(){
+	}
+
+
+	static public String write( String device_name, String target_os, String os_version, String frameworksDir, int run_id, String exclude_filename ){
+		File theFile = null;
+		File theDir = null;
+		File excludeFile = null;
+		File[] files = null;
+		String theClassString = null;
+		String theFileString = null;
+		String theDirString = null;
+		Calendar cal = null;
+		FileWriter fw = null;
+		String classContents = null;
+		String ret = null;
+		int i = 0;
+
+		try {
+			theClassString = AS_CLASS;
+			theFileString = theClassString + ".as";
+			theDirString = frameworksDir;
+
+			theFile = new File( theDirString + File.separator + theFileString);
+			theDir = new File( theDirString );
+
+			// Delete any old ones.
+			MobileConfigWriterFilter filter = new MobileConfigWriterFilter();
+			filter.fileToKeep = theFileString;
+			files = theDir.listFiles( filter );
+
+			if( files != null ){
+				for( i = 0; i < Array.getLength( files ); ++i ){
+					// System.out.println("deleting " + files[i].getCanonicalPath());
+					files[ i ].delete();
+				}
+			}
+
+			try{
+				excludeFile = new File( exclude_filename );
+			}catch(Exception e){
+				e.printStackTrace();
+			}
+
+			// Put the contents of the class to create in a string.
+			classContents = constructClass( device_name, target_os, os_version, theClassString, excludeFile, run_id );
+
+			// Write it.
+			fw = new FileWriter ( theFile );
+			fw.write ( classContents, 0, classContents.length());
+			fw.flush();
+			fw.close();
+			System.out.println ( "created " + theFile.toString() );
+
+			ret = theClassString;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		return ret;
+	}
+
+
+	/**
+	 * Returns a string which contains the text which will be written to the class.
+	 **/
+	static private String constructClass( String device_name, String target_os, String os_version, String className, File excludeFile, int run_id ){
+		int i = 0;
+
+		String ret = "package {\n";
+				ret += "import flash.display.DisplayObject;\n";
+				ret += "import flash.system.Capabilities;\n";
+
+				if( target_os.compareToIgnoreCase( MobileUtil.IOS ) == 0 ||
+					target_os.compareToIgnoreCase( MobileUtil.QNX ) == 0) {
+					ret += "import flash.filesystem.*;\n";
+				}
+
+				ret += "[Mixin]\n";
+				ret += "/**\n";
+				ret += "* By including this mixin via CompileMustellaSwfs, we\n";
+				ret += "* can set up some variables for UnitTester to use for\n";
+				ret += "* an Android run.\n";
+				ret += "*/\n";
+				ret += "public class " + className + "\n";
+				ret += "{\n";
+				ret += "	public static function init(root:DisplayObject):void\n";
+				ret += "	{\n";
+
+				// ConditionalValue stuff
+				ret += "		if( UnitTester.cv == null ){\n";
+				ret += "			UnitTester.cv = new ConditionalValue();\n";
+				ret += "		}";
+				ret += "		UnitTester.cv.device = \"" + device_name + "\";\n";
+				ret += "		UnitTester.cv.os = \"" + target_os + "\";\n";
+				ret += "		UnitTester.cv.osVersion = \"" + os_version + "\";\n";
+				// If device, get the proper dpi bucket (160/240/320) for the device.
+				if( (target_os.compareToIgnoreCase(MobileUtil.MAC) == 0) || (target_os.compareToIgnoreCase(MobileUtil.WIN) == 0) ){
+					if( adl_extras_XscreenDPI == -1 ){
+					ret += "		UnitTester.cv.deviceDensity = flash.system.Capabilities.screenDPI;\n";
+				}else{
+						ret += "		UnitTester.cv.deviceDensity = Util.roundDeviceDensity( flash.system.Capabilities.screenDPI );\n";
+					}
+				}else{
+					ret += "		UnitTester.cv.deviceDensity = " + Integer.toString(MobileUtil.getDeviceDensity(device_name)) + ";\n";
+				}
+
+				// Don't get this confused with the above.  Maybe the above needs to be changed.  The variable below always
+				// uses Capabilities.screenDPI.
+				ret += "		UnitTester.cv.screenDPI = flash.system.Capabilities.screenDPI;\n";
+
+				ret += "		//UnitTester.cv.deviceWidth = set by MultiResult;\n";
+				ret += "		//UnitTester.cv.deviceHeight = set by MultiResult;\n";
+				ret += "		//UnitTester.cv.color = this is not defined yet, but there are rumours it might be.\n";
+
+				// Other stuff
+				ret += "		UnitTester.run_id = \"" + run_id + "\";\n";
+				ret += "		UnitTester.excludeFile = \"" + excludeFile.getName() + "\";\n";
+
+				for( i = 0; i < Array.getLength( MobileUtil.DEVICES_USING_SDCARD ); ++i){
+					if( device_name.compareToIgnoreCase( MobileUtil.DEVICES_USING_SDCARD[ i ] ) == 0 ){
+						ret += "		UnitTester.mustellaWriteLocation = \"" + MobileUtil.SDCARD_DIR + "\";\n";
+						ret += "		UnitTester.writeBaselinesToDisk = true;\n";
+					}
+				}
+
+				if( target_os.compareToIgnoreCase( MobileUtil.IOS ) == 0 ){
+					ret += "		UnitTester.mustellaWriteLocation = File.documentsDirectory.nativePath;\n";
+					ret += "		UnitTester.writeBaselinesToDisk = true;\n";
+				}
+
+				if( target_os.compareToIgnoreCase( MobileUtil.QNX ) == 0 ){
+					ret += "		UnitTester.mustellaWriteLocation = File.applicationStorageDirectory.nativePath;\n";
+					ret += "		UnitTester.writeBaselinesToDisk = true;\n";
+				}
+
+				ret += "	}\n";
+				ret += "}\n";
+				ret += "}\n";
+
+		return ret;
+	}
+
+
+	/**
+	 * This is a filter which deletes extra .as files which this class creates.
+	 **/
+	public static class MobileConfigWriterFilter implements FilenameFilter{
+
+		/**
+		 *	SWF to test
+		 **/
+		public String fileToKeep = "";
+
+		/**
+		 * constructor
+		 **/
+		public void MobileConfigWriterFilter(){}
+
+		/**
+		 * This is the one method to implement for the interface.
+		 **/
+		public boolean accept( File dir, String name ){
+
+			File f = new File( dir, name );
+
+			if( (name.indexOf( AS_CLASS ) > -1)	&&
+			    (name.indexOf( ".as" ) > -1)	&&
+			    (name.compareToIgnoreCase( fileToKeep ) != 0 ) ){
+				return true;
+			}else{
+				return false;
+			}
+		}
+
+	} // end APKPackagerFilenameFilter class
+
+} // End MobileConfigWriter class
+

Propchange: incubator/flex/trunk/mustella/java/src/mustella/MobileConfigWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/NanoHTTPD.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/NanoHTTPD.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/NanoHTTPD.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/NanoHTTPD.java Wed May  2 22:44:38 2012
@@ -0,0 +1,805 @@
+package mustella;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URLEncoder;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
+
+/**
+ * A simple, tiny, nicely embeddable HTTP 1.0 server in Java
+ *
+ * <p> NanoHTTPD version 1.14,
+ * Copyright &copy; 2001,2005-2010 Jarno Elonen (elonen@iki.fi, http://iki.fi/elonen/)
+ *
+ * <p><b>Features + limitations: </b><ul>
+ *
+ *    <li> Only one Java file </li>
+ *    <li> Java 1.1 compatible </li>
+ *    <li> Released as open source, Modified BSD licence </li>
+ *    <li> No fixed config files, logging, authorization etc. (Implement yourself if you need them.) </li>
+ *    <li> Supports parameter parsing of GET and POST methods </li>
+ *    <li> Supports both dynamic content and file serving </li>
+ *    <li> Never caches anything </li>
+ *    <li> Doesn't limit bandwidth, request time or simultaneous connections </li>
+ *    <li> Default code serves files and shows all HTTP parameters and headers</li>
+ *    <li> File server supports directory listing, index.html and index.htm </li>
+ *    <li> File server does the 301 redirection trick for directories without '/'</li>
+ *    <li> File server supports simple skipping for files (continue download) </li>
+ *    <li> File server uses current directory as a web root </li>
+ *    <li> File server serves also very long files without memory overhead </li>
+ *    <li> Contains a built-in list of most common mime types </li>
+ *    <li> All header names are converted lowercase so they don't vary between browsers/clients </li>
+ *
+ * </ul>
+ *
+ * <p><b>Ways to use: </b><ul>
+ *
+ *    <li> Run as a standalone app, serves files from current directory and shows requests</li>
+ *    <li> Subclass serve() and embed to your own program </li>
+ *    <li> Call serveFile() from serve() with your own base directory </li>
+ *
+ * </ul>
+ *
+ * See the end of the source file for distribution license
+ * (Modified BSD licence)
+ */
+public class NanoHTTPD
+{
+	// ==================================================
+	// API parts
+	// ==================================================
+
+
+	public static String docroot = "c:/depot/flex/qa/sdk/testsuites/mustella/tests/";
+
+	public static boolean callExit = false;
+
+	public static void setRoot (String root) {
+		docroot = root;
+	}
+
+	static { 
+
+		try { 
+			String tmp = System.getProperty ("mustella.dir");	
+			if (tmp != null && !tmp.startsWith ("${"))
+				docroot = tmp + "/tests";
+
+		} catch (Exception e)  {
+			e.printStackTrace();
+		}
+
+
+
+
+	}
+
+	/**
+	 * Override this to customize the server.<p>
+	 *
+	 * (By default, this delegates to serveFile() and allows directory listing.)
+	 *
+	 * @parm uri	Percent-decoded URI without parameters, for example "/index.cgi"
+	 * @parm method	"GET", "POST" etc.
+	 * @parm parms	Parsed, percent decoded parameters from URI and, in case of POST, data.
+	 * @parm header	Header entries, percent decoded
+	 * @return HTTP response, see class Response for details
+	 */
+	public Response serve( String uri, String method, Properties header, Properties parms )
+	{
+		System.out.println( method + " '" + uri + "' " );
+
+		Enumeration e = header.propertyNames();
+		while ( e.hasMoreElements())
+		{
+			String value = (String)e.nextElement();
+			// System.out.println( "  HDR: '" + value + "' = '" + header.getProperty( value ) + "'" );
+		}
+		e = parms.propertyNames();
+		while ( e.hasMoreElements())
+		{
+			String value = (String)e.nextElement();
+			// System.out.println( "  PRM: '" + value + "' = '" + parms.getProperty( value ) + "'" );
+		}
+
+		// Fix this, always calling from here, call from 
+		// mustella.dir/tests
+		// take that as a static
+		return serveFile( uri, header, new File(docroot), true );
+	}
+
+	/**
+	 * HTTP response.
+	 * Return one of these from serve().
+	 */
+	public class Response
+	{
+		/**
+		 * Default constructor: response = HTTP_OK, data = mime = 'null'
+		 */
+		public Response()
+		{
+			this.status = HTTP_OK;
+		}
+
+		/**
+		 * Basic constructor.
+		 */
+		public Response( String status, String mimeType, InputStream data )
+		{
+			this.status = status;
+			this.mimeType = mimeType;
+			this.data = data;
+		}
+
+		/**
+		 * Convenience method that makes an InputStream out of
+		 * given text.
+		 */
+		public Response( String status, String mimeType, String txt )
+		{
+			this.status = status;
+			this.mimeType = mimeType;
+			this.data = new ByteArrayInputStream( txt.getBytes());
+		}
+
+		/**
+		 * Adds given line to the header.
+		 */
+		public void addHeader( String name, String value )
+		{
+			header.put( name, value );
+		}
+
+		/**
+		 * HTTP status code after processing, e.g. "200 OK", HTTP_OK
+		 */
+		public String status;
+
+		/**
+		 * MIME type of content, e.g. "text/html"
+		 */
+		public String mimeType;
+
+		/**
+		 * Data of the response, may be null.
+		 */
+		public InputStream data;
+
+		/**
+		 * Headers for the HTTP response. Use addHeader()
+		 * to add lines.
+		 */
+		public Properties header = new Properties();
+	}
+
+	/**
+	 * Some HTTP response status codes
+	 */
+	public static final String
+		HTTP_OK = "200 OK",
+		HTTP_REDIRECT = "301 Moved Permanently",
+		HTTP_FORBIDDEN = "403 Forbidden",
+		HTTP_NOTFOUND = "404 Not Found",
+		HTTP_BADREQUEST = "400 Bad Request",
+		HTTP_INTERNALERROR = "500 Internal Server Error",
+		HTTP_NOTIMPLEMENTED = "501 Not Implemented";
+
+	/**
+	 * Common mime types for dynamic content
+	 */
+	public static final String
+		MIME_PLAINTEXT = "text/plain",
+		MIME_HTML = "text/html",
+		MIME_DEFAULT_BINARY = "application/octet-stream";
+
+	// ==================================================
+	// Socket & server code
+	// ==================================================
+
+	public boolean running = true;
+	
+	/**
+	 * Starts a HTTP server to given port.<p>
+	 * Throws an IOException if the socket is already in use
+	 */
+	public NanoHTTPD( int port ) throws IOException
+	{
+		myTcpPort = port;
+		myServerSocket = new ServerSocket( myTcpPort );
+		System.out.println ("Server up on " + myTcpPort);
+		myThread = new Thread( new Runnable()
+
+		
+			{
+				public void run()
+				{
+					try
+					{
+						while( running  )
+							new HTTPSession( myServerSocket.accept());
+					}
+					catch ( IOException ioe )
+					{}
+				}
+			});
+		myThread.setDaemon( true );
+		myThread.start();
+	}
+
+	/**
+	 * Stops the server.
+	 */
+	public void stop()
+	{
+		running = false;
+		try
+		{ 
+			myServerSocket.close();
+			myThread.join();
+		}
+		catch ( Exception ioe ) {
+			ioe.printStackTrace();
+		}
+
+		/// force it to open the socket, just in case
+		System.out.println ("Server coming down on " + myTcpPort);
+		if (callExit)  {
+			System.out.println ("Calling exit");
+			System.exit (0);
+		}
+	}
+
+
+	/**
+	 * Starts as a standalone file server and waits for Enter.
+	 */
+	public static void main( String[] args )
+	{
+
+		callExit = true;
+		// System.out.println( "NanoHTTPD 1.14 (C) 2001,2005-2010 Jarno Elonen\n" + "(Command line options: [port] [--licence])\n" );
+
+		// Show licence if requested
+		int lopt = -1;
+		for ( int i=0; i<args.length; ++i )
+		if ( args[i].toLowerCase().endsWith( "licence" ))
+		{
+			lopt = i;
+			System.out.println( LICENCE + "\n" );
+		}
+
+		// Change port if requested
+		int port = 80;
+		if ( args.length > 0 && lopt != 0 )
+			port = Integer.parseInt( args[0] );
+
+		if ( args.length > 1 &&
+			 args[1].toLowerCase().endsWith( "licence" ))
+				System.out.println( LICENCE + "\n" );
+
+		NanoHTTPD nh = null;
+		try
+		{
+			nh = new NanoHTTPD( port );
+		}
+		catch( IOException ioe )
+		{
+			System.err.println( "Couldn't start server:\n" + ioe );
+			System.exit( -1 );
+		}
+		nh.myFileDir = new File("");
+
+		System.out.println( "Now serving files on port " + port + " from \"" + new File(docroot) + "\"" );
+		System.out.println( "Hit Enter to stop.\n" );
+
+		try { System.in.read(); } catch( Throwable t ) {};
+	}
+
+	/**
+	 * Handles one session, i.e. parses the HTTP request
+	 * and returns the response.
+	 */
+	private class HTTPSession implements Runnable
+	{
+		public HTTPSession( Socket s )
+		{
+			mySocket = s;
+			Thread t = new Thread( this );
+			t.setDaemon( true );
+			t.start();
+		}
+
+		public void run()
+		{
+			try
+			{
+				InputStream is = mySocket.getInputStream();
+				if ( is == null) return;
+				BufferedReader in = new BufferedReader( new InputStreamReader( is ));
+
+				// Read the request line
+				String inLine = in.readLine();
+				if (inLine == null) return;
+				StringTokenizer st = new StringTokenizer( inLine );
+				if ( !st.hasMoreTokens())
+					sendError( HTTP_BADREQUEST, "BAD REQUEST: Syntax error. Usage: GET /example/file.html" );
+
+				String method = st.nextToken();
+
+				if ( !st.hasMoreTokens())
+					sendError( HTTP_BADREQUEST, "BAD REQUEST: Missing URI. Usage: GET /example/file.html" );
+
+				String uri = st.nextToken();
+
+				// Decode parameters from the URI
+				Properties parms = new Properties();
+				int qmi = uri.indexOf( '?' );
+				if ( qmi >= 0 )
+				{
+					decodeParms( uri.substring( qmi+1 ), parms );
+					uri = decodePercent( uri.substring( 0, qmi ));
+				}
+				else uri = decodePercent(uri);
+
+
+				// If there's another token, it's protocol version,
+				// followed by HTTP headers. Ignore version but parse headers.
+				// NOTE: this now forces header names uppercase since they are
+				// case insensitive and vary by client.
+				Properties header = new Properties();
+				if ( st.hasMoreTokens())
+				{
+					String line = in.readLine();
+					while ( line.trim().length() > 0 )
+					{
+						int p = line.indexOf( ':' );
+						header.put( line.substring(0,p).trim().toLowerCase(), line.substring(p+1).trim());
+						line = in.readLine();
+					}
+				}
+
+				// If the method is POST, there may be parameters
+				// in data section, too, read it:
+				if ( method.equalsIgnoreCase( "POST" ))
+				{
+					long size = 0x7FFFFFFFFFFFFFFFl;
+					String contentLength = header.getProperty("content-length");
+					if (contentLength != null)
+					{
+						try { size = Integer.parseInt(contentLength); }
+						catch (NumberFormatException ex) {}
+					}
+					String postLine = "";
+					char buf[] = new char[512];
+					int read = in.read(buf);
+					while ( read >= 0 && size > 0 && !postLine.endsWith("\r\n") )
+					{
+						size -= read;
+						postLine += String.valueOf(buf, 0, read);
+						if ( size > 0 )
+							read = in.read(buf);
+					}
+					postLine = postLine.trim();
+					decodeParms( postLine, parms );
+				}
+
+				// Ok, now do the serve()
+				Response r = serve( uri, method, header, parms );
+				if ( r == null )
+					sendError( HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: Serve() returned a null response." );
+				else
+					sendResponse( r.status, r.mimeType, r.header, r.data );
+
+				in.close();
+			}
+			catch ( IOException ioe )
+			{
+				try
+				{
+					sendError( HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
+				}
+				catch ( Throwable t ) {}
+			}
+			catch ( InterruptedException ie )
+			{
+				// Thrown by sendError, ignore and exit the thread.
+			}
+		}
+
+		/**
+		 * Decodes the percent encoding scheme. <br/>
+		 * For example: "an+example%20string" -> "an example string"
+		 */
+		private String decodePercent( String str ) throws InterruptedException
+		{
+			try
+			{
+				StringBuffer sb = new StringBuffer();
+				for( int i=0; i<str.length(); i++ )
+				{
+				    char c = str.charAt( i );
+				    switch ( c )
+					{
+				        case '+':
+				            sb.append( ' ' );
+				            break;
+				        case '%':
+			                sb.append((char)Integer.parseInt( str.substring(i+1,i+3), 16 ));
+				            i += 2;
+				            break;
+				        default:
+				            sb.append( c );
+				            break;
+				    }
+				}
+				return new String( sb.toString().getBytes());
+			}
+			catch( Exception e )
+			{
+				sendError( HTTP_BADREQUEST, "BAD REQUEST: Bad percent-encoding." );
+				return null;
+			}
+		}
+
+		/**
+		 * Decodes parameters in percent-encoded URI-format
+		 * ( e.g. "name=Jack%20Daniels&pass=Single%20Malt" ) and
+		 * adds them to given Properties. NOTE: this doesn't support multiple
+		 * identical keys due to the simplicity of Properties -- if you need multiples,
+		 * you might want to replace the Properties with a Hastable of Vectors or such.
+		 */
+		private void decodeParms( String parms, Properties p )
+			throws InterruptedException
+		{
+			if ( parms == null )
+				return;
+
+			StringTokenizer st = new StringTokenizer( parms, "&" );
+			while ( st.hasMoreTokens())
+			{
+				String e = st.nextToken();
+				int sep = e.indexOf( '=' );
+				if ( sep >= 0 )
+					p.put( decodePercent( e.substring( 0, sep )).trim(),
+						   decodePercent( e.substring( sep+1 )));
+			}
+		}
+
+		/**
+		 * Returns an error message as a HTTP response and
+		 * throws InterruptedException to stop furhter request processing.
+		 */
+		private void sendError( String status, String msg ) throws InterruptedException
+		{
+			sendResponse( status, MIME_PLAINTEXT, null, new ByteArrayInputStream( msg.getBytes()));
+			throw new InterruptedException();
+		}
+
+		/**
+		 * Sends given response to the socket.
+		 */
+		private void sendResponse( String status, String mime, Properties header, InputStream data )
+		{
+			try
+			{
+				if ( status == null )
+					throw new Error( "sendResponse(): Status can't be null." );
+
+				OutputStream out = mySocket.getOutputStream();
+				PrintWriter pw = new PrintWriter( out );
+				pw.print("HTTP/1.0 " + status + " \r\n");
+
+				if ( mime != null )
+					pw.print("Content-Type: " + mime + "\r\n");
+
+				if ( header == null || header.getProperty( "Date" ) == null )
+					pw.print( "Date: " + gmtFrmt.format( new Date()) + "\r\n");
+
+				if ( header != null )
+				{
+					Enumeration e = header.keys();
+					while ( e.hasMoreElements())
+					{
+						String key = (String)e.nextElement();
+						String value = header.getProperty( key );
+						pw.print( key + ": " + value + "\r\n");
+					}
+				}
+
+				pw.print("\r\n");
+				pw.flush();
+
+				if ( data != null )
+				{
+					byte[] buff = new byte[2048];
+					while (true)
+					{
+						int read = data.read( buff, 0, 2048 );
+						if (read <= 0)
+							break;
+						out.write( buff, 0, read );
+					}
+				}
+				out.flush();
+				out.close();
+				if ( data != null )
+					data.close();
+			}
+			catch( IOException ioe )
+			{
+				// Couldn't write? No can do.
+				try { mySocket.close(); } catch( Throwable t ) {}
+			}
+		}
+
+		private Socket mySocket;
+	};
+
+	/**
+	 * URL-encodes everything between "/"-characters.
+	 * Encodes spaces as '%20' instead of '+'.
+	 */
+	private String encodeUri( String uri )
+	{
+		String newUri = "";
+		StringTokenizer st = new StringTokenizer( uri, "/ ", true );
+		while ( st.hasMoreTokens())
+		{
+			String tok = st.nextToken();
+			if ( tok.equals( "/" ))
+				newUri += "/";
+			else if ( tok.equals( " " ))
+				newUri += "%20";
+			else
+			{
+				newUri += URLEncoder.encode( tok );
+				// For Java 1.4 you'll want to use this instead:
+				// try { newUri += URLEncoder.encode( tok, "UTF-8" ); } catch ( UnsupportedEncodingException uee )
+			}
+		}
+		return newUri;
+	}
+
+	private int myTcpPort;
+	private final ServerSocket myServerSocket;
+	private Thread myThread; 
+	
+	File myFileDir;
+
+	// ==================================================
+	// File server code
+	// ==================================================
+
+	/**
+	 * Serves file from homeDir and its' subdirectories (only).
+	 * Uses only URI, ignores all headers and HTTP parameters.
+	 */
+	public Response serveFile( String uri, Properties header, File homeDir,
+							   boolean allowDirectoryListing )
+	{
+
+		if (uri.equals ("/shutdown")) {
+			callExit =true;
+			stop();
+		}
+
+		System.out.println ("serveFile with: " + homeDir);
+		// Make sure we won't die of an exception later
+		if ( !homeDir.isDirectory())
+			return new Response( HTTP_INTERNALERROR, MIME_PLAINTEXT,
+								 "INTERNAL ERRROR: serveFile(): given homeDir is not a directory." );
+
+		// Remove URL arguments
+		uri = uri.trim().replace( File.separatorChar, '/' );
+		if ( uri.indexOf( '?' ) >= 0 )
+			uri = uri.substring(0, uri.indexOf( '?' ));
+
+		// Prohibit getting out of current directory
+		if ( uri.startsWith( ".." ) || uri.endsWith( ".." ) || uri.indexOf( "../" ) >= 0 )
+			return new Response( HTTP_FORBIDDEN, MIME_PLAINTEXT,
+								 "FORBIDDEN: Won't serve ../ for security reasons." );
+
+		File f = new File( homeDir, uri );
+		if ( !f.exists())
+			return new Response( HTTP_NOTFOUND, MIME_PLAINTEXT,
+								 "Error 404, file not found." );
+
+		// List the directory, if necessary
+		if ( f.isDirectory())
+		{
+			// Browsers get confused without '/' after the
+			// directory, send a redirect.
+			if ( !uri.endsWith( "/" ))
+			{
+				uri += "/";
+				Response r = new Response( HTTP_REDIRECT, MIME_HTML,
+										   "<html><body>Redirected: <a href=\"" + uri + "\">" +
+										   uri + "</a></body></html>");
+				r.addHeader( "Location", uri );
+				return r;
+			}
+
+			// First try index.html and index.htm
+			if ( new File( f, "index.html" ).exists())
+				f = new File( homeDir, uri + "/index.html" );
+			else if ( new File( f, "index.htm" ).exists())
+				f = new File( homeDir, uri + "/index.htm" );
+
+			// No index file, list the directory
+			else if ( allowDirectoryListing )
+			{
+				String[] files = f.list();
+				String msg = "<html><body><h1>Directory " + uri + "</h1><br/>";
+
+				if ( uri.length() > 1 )
+				{
+					String u = uri.substring( 0, uri.length()-1 );
+					int slash = u.lastIndexOf( '/' );
+					if ( slash >= 0 && slash  < u.length())
+						msg += "<b><a href=\"" + uri.substring(0, slash+1) + "\">..</a></b><br/>";
+				}
+
+				for ( int i=0; i<files.length; ++i )
+				{
+					File curFile = new File( f, files[i] );
+					boolean dir = curFile.isDirectory();
+					if ( dir )
+					{
+						msg += "<b>";
+						files[i] += "/";
+					}
+
+					msg += "<a href=\"" + encodeUri( uri + files[i] ) + "\">" +
+						   files[i] + "</a>";
+
+					// Show file size
+					if ( curFile.isFile())
+					{
+						long len = curFile.length();
+						msg += " &nbsp;<font size=2>(";
+						if ( len < 1024 )
+							msg += curFile.length() + " bytes";
+						else if ( len < 1024 * 1024 )
+							msg += curFile.length()/1024 + "." + (curFile.length()%1024/10%100) + " KB";
+						else
+							msg += curFile.length()/(1024*1024) + "." + curFile.length()%(1024*1024)/10%100 + " MB";
+
+						msg += ")</font>";
+					}
+					msg += "<br/>";
+					if ( dir ) msg += "</b>";
+				}
+				return new Response( HTTP_OK, MIME_HTML, msg );
+			}
+			else
+			{
+				return new Response( HTTP_FORBIDDEN, MIME_PLAINTEXT,
+								 "FORBIDDEN: No directory listing." );
+			}
+		}
+
+		try
+		{
+			// Get MIME type from file name extension, if possible
+			String mime = null;
+			int dot = f.getCanonicalPath().lastIndexOf( '.' );
+			if ( dot >= 0 )
+				mime = (String)theMimeTypes.get( f.getCanonicalPath().substring( dot + 1 ).toLowerCase());
+			if ( mime == null )
+				mime = MIME_DEFAULT_BINARY;
+
+			// Support (simple) skipping:
+			long startFrom = 0;
+			String range = header.getProperty( "range" );
+			if ( range != null )
+			{
+				if ( range.startsWith( "bytes=" ))
+				{
+					range = range.substring( "bytes=".length());
+					int minus = range.indexOf( '-' );
+					if ( minus > 0 )
+						range = range.substring( 0, minus );
+					try	{
+						startFrom = Long.parseLong( range );
+					}
+					catch ( NumberFormatException nfe ) {}
+				}
+			}
+
+			FileInputStream fis = new FileInputStream( f );
+			fis.skip( startFrom );
+			Response r = new Response( HTTP_OK, mime, fis );
+			r.addHeader( "Content-length", "" + (f.length() - startFrom));
+			r.addHeader( "Content-range", "" + startFrom + "-" +
+						(f.length()-1) + "/" + f.length());
+			return r;
+		}
+		catch( IOException ioe )
+		{
+			return new Response( HTTP_FORBIDDEN, MIME_PLAINTEXT, "FORBIDDEN: Reading file failed." );
+		}
+	}
+
+	/**
+	 * Hashtable mapping (String)FILENAME_EXTENSION -> (String)MIME_TYPE
+	 */
+	private static Hashtable theMimeTypes = new Hashtable();
+	static
+	{
+		StringTokenizer st = new StringTokenizer(
+			"htm		text/html "+
+			"html		text/html "+
+			"txt		text/plain "+
+			"asc		text/plain "+
+			"gif		image/gif "+
+			"jpg		image/jpeg "+
+			"jpeg		image/jpeg "+
+			"png		image/png "+
+			"mp3		audio/mpeg "+
+			"m3u		audio/mpeg-url " +
+			"pdf		application/pdf "+
+			"doc		application/msword "+
+			"ogg		application/x-ogg "+
+			"zip		application/octet-stream "+
+			"exe		application/octet-stream "+
+			"class		application/octet-stream " );
+		while ( st.hasMoreTokens())
+			theMimeTypes.put( st.nextToken(), st.nextToken());
+	}
+
+	/**
+	 * GMT date formatter
+	 */
+    private static java.text.SimpleDateFormat gmtFrmt;
+	static
+	{
+		gmtFrmt = new java.text.SimpleDateFormat( "E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
+		gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));
+	}
+
+	/**
+	 * The distribution licence
+	 */
+	private static final String LICENCE =
+		"Copyright (C) 2001,2005-2010 by Jarno Elonen <elonen@iki.fi>\n"+
+		"\n"+
+		"Redistribution and use in source and binary forms, with or without\n"+
+		"modification, are permitted provided that the following conditions\n"+
+		"are met:\n"+
+		"\n"+
+		"Redistributions of source code must retain the above copyright notice,\n"+
+		"this list of conditions and the following disclaimer. Redistributions in\n"+
+		"binary form must reproduce the above copyright notice, this list of\n"+
+		"conditions and the following disclaimer in the documentation and/or other\n"+
+		"materials provided with the distribution. The name of the author may not\n"+
+		"be used to endorse or promote products derived from this software without\n"+
+		"specific prior written permission. \n"+
+		" \n"+
+		"THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n"+
+		"IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n"+
+		"OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n"+
+		"IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n"+
+		"INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n"+
+		"NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"+
+		"DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"+
+		"THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"+
+		"(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"+
+		"OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
+}
+

Propchange: incubator/flex/trunk/mustella/java/src/mustella/NanoHTTPD.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/trunk/mustella/java/src/mustella/ParseMxmlHeader.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/mustella/java/src/mustella/ParseMxmlHeader.java?rev=1333232&view=auto
==============================================================================
--- incubator/flex/trunk/mustella/java/src/mustella/ParseMxmlHeader.java (added)
+++ incubator/flex/trunk/mustella/java/src/mustella/ParseMxmlHeader.java Wed May  2 22:44:38 2012
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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 utils.*;
+import utils.FileUtils;
+
+import java.io.File;
+import java.util.regex.*;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.*;
+
+/**
+ * User: bolaghlin, 
+ */
+public class ParseMxmlHeader extends Thread {
+
+    public String height = "395";
+    public String width = "501";
+
+
+    public void setWidthAndHeight(String mxmlFile) {
+
+    	try {
+
+		String line = null;
+                BufferedReader br = new BufferedReader (new FileReader (mxmlFile));
+                /// we will not go far into a file to get this
+                int count = 0 ;
+
+                int loc = -1;
+                int loc_end = -1;
+
+		boolean begun =  false;
+
+		boolean setH = false;
+		boolean setW = false;
+
+                while ( (line=br.readLine()) != null) {
+                	if ( (loc = line.indexOf("Application")) != -1) 
+				begun= true;
+
+						
+		
+			if (begun) { 
+				if (line.indexOf ("height=")!=-1) {
+					height = line.substring (line.indexOf ("height=")+8);
+					System.out.println ("inter h: " + height);
+					height = height.substring (0, height.indexOf ("\""));
+					setH = true;
+		
+				}
+				
+				if (line.indexOf ("width=")!=-1) {
+					width = line.substring (line.indexOf ("width=")+7);
+					System.out.println ("inter w: " + width);
+					if (width.indexOf ("\"") != -1)
+						width = width.substring (0, width.indexOf ("\""));
+					setW = true;
+				}
+                        }
+
+			if (setH && setW) { 
+				br.close();
+				break;
+			}
+
+                	if ( begun && (loc_end = line.indexOf(">")) != -1)  { 
+				br.close();
+
+				if (!setH)
+					height=SwfLoaderTestAdapter.standard_height;
+				if (!setW)
+					width=SwfLoaderTestAdapter.standard_width;	
+				break;
+			}
+		}
+
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+
+
+    }
+
+
+    public static void main (String[] args) { 
+
+		ParseMxmlHeader p = new ParseMxmlHeader();
+		p.setWidthAndHeight(args[0]);
+
+		System.out.println ("width="+p.width + " height=" + p.height);
+	}
+
+
+}

Propchange: incubator/flex/trunk/mustella/java/src/mustella/ParseMxmlHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message