incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r1401287 - in /incubator/flex/sdk/branches/develop/mustella/java/src: mustella/CompileMustellaSwfs.java utils/ArgRange.java utils/ArgumentParser.java utils/CompcUtils.java utils/CompileMxmlUtils.java
Date Tue, 23 Oct 2012 13:26:36 GMT
Author: pent
Date: Tue Oct 23 13:26:35 2012
New Revision: 1401287

URL: http://svn.apache.org/viewvc?rev=1401287&view=rev
Log:
Updated argument parser to work with argument values that contain spaces and dashes. Directories
may contain spaces as long the directories are not within the Mustella directory structure.
Directory paths may contain dashes as long as they are immediately preceeded by non-blank
characters.

Added:
    incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java   (with props)
    incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java   (with
props)
Modified:
    incubator/flex/sdk/branches/develop/mustella/java/src/mustella/CompileMustellaSwfs.java
    incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompcUtils.java
    incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompileMxmlUtils.java

Modified: incubator/flex/sdk/branches/develop/mustella/java/src/mustella/CompileMustellaSwfs.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/mustella/java/src/mustella/CompileMustellaSwfs.java?rev=1401287&r1=1401286&r2=1401287&view=diff
==============================================================================
--- incubator/flex/sdk/branches/develop/mustella/java/src/mustella/CompileMustellaSwfs.java
(original)
+++ incubator/flex/sdk/branches/develop/mustella/java/src/mustella/CompileMustellaSwfs.java
Tue Oct 23 13:26:35 2012
@@ -19,6 +19,7 @@
 package mustella; 
 import utils.*;
 import utils.FileUtils;
+import utils.ArgumentParser;
 
 import java.io.File;
 import java.util.regex.*;
@@ -55,8 +56,7 @@ public class CompileMustellaSwfs extends
 
     public static int hostId = 0;
 
-
-    private String[] defaultArgs;
+    private ArrayList defaultArgs;
 
 	private static String mobileConfigArg = null;
 	
@@ -991,7 +991,7 @@ public class CompileMustellaSwfs extends
 
 	args = checkAndAddUserArgs (mxml, args);
 
-	System.out.println ("ARGS: " + args);
+//	System.out.println ("ARGS: " + args);
 
 
 	/**
@@ -1003,8 +1003,15 @@ public class CompileMustellaSwfs extends
 		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);
+	
+	// ------- ArgumentParser -------------
+	ArgumentParser parser = new ArgumentParser(args);
+	defaultArgs = parser.parseArguments();
+	if( debugDump ) {
+		for(int i=0; i < defaultArgs.size(); i++) {
+			System.out.println("ARG "+i+": "+defaultArgs.get(i));
+		}
+	}
 
 	try {
 		// writeTag(mxml, "status=started");
@@ -1020,7 +1027,8 @@ public class CompileMustellaSwfs extends
 		String rsl = System.getProperty("rsl");
 		if (rsl != null && !rsl.equals("")) {
 			rsl(mxml);
-			defaultArgs = StringUtils.StringToArray(StringUtils.arrayToString(defaultArgs) + " +frameworks-dir
" + frameworks);
+			defaultArgs.add("+frameworks-dir");
+			defaultArgs.add(frameworks);
 		}
 
 		System.out.println ("okey doke, going to compile " + mxml);
@@ -1383,8 +1391,8 @@ public class CompileMustellaSwfs extends
         }
     }
 
-    public static String[] compc(String mxml, String[] mxmlArgs) throws Exception {
-        //System.out.println(">>>>> compc if necessary >>>>>>>
" + mxml);
+    public static ArrayList compc(String mxml, ArrayList mxmlArgs) throws Exception {
+        System.out.println(">>>>> compc if necessary >>>>>>>
" + mxml);
         CompcUtils compc = new CompcUtils();
         //compc.setPrintOut(true);
         File argFile = null;

Added: incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java?rev=1401287&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java (added)
+++ incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java Tue Oct 23 13:26:35
2012
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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 utils;
+
+/**
+ * Provides the start and end points for arguments in a string of
+ * arguments. The hasSpaces property is true if any spaces appear
+ * within the character range start-end.
+ */
+public class ArgRange {
+
+	public ArgRange( int start, int end, boolean spaces )
+	{
+		startIndex = start;
+		endIndex = end;
+		hasSpaces = spaces;
+	}
+	
+	public ArgRange()
+	{
+		startIndex = -1;
+		endIndex = -1;
+		hasSpaces = false;
+	}
+	
+	/**
+	 * The index of the first character in the range.
+	 */
+	public int startIndex;
+	
+	/**
+	 * The index of the last character in the range.
+	 */
+	public int endIndex;
+	
+	/**
+	 * True if there is at least one space character between
+	 * startIndex and endIndex, inclusive.
+	 */
+	public boolean hasSpaces;
+}

Propchange: incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgRange.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java?rev=1401287&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java (added)
+++ incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java Tue Oct
23 13:26:35 2012
@@ -0,0 +1,224 @@
+/*
+ *
+ * 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 utils;
+
+import java.util.ArrayList;
+
+/**
+ * Parses a string of arguments into an ArrayList of name=value pairs.
+ */
+public class ArgumentParser {
+
+	public ArgumentParser( String value )
+	{
+		_arguments = value;
+	}
+	
+	// ---------------------------------------------------------------------------
+	// arguments (to be parsed)
+	// ---------------------------------------------------------------------------
+	
+	private String _arguments;
+
+	/**
+	 * The argument string to be parsed. Valid arguments are those that may be passed
+	 * to compc or mxmlc.
+	 */
+	public String get_arguments() {
+		return _arguments;
+	}
+
+	public void set_arguments(String _arguments) {
+		this._arguments = _arguments;
+	}
+	
+	// ---------------------------------------------------------------------------
+	// result
+	// ---------------------------------------------------------------------------
+	
+	/**
+	 * The resultant ArrayList of arg=value pairs as String entries.
+	 */
+	public ArrayList result;
+	
+	// ---------------------------------------------------------------------------
+	// toArray
+	// ---------------------------------------------------------------------------
+	
+	/**
+	 * Converts the given ArrayList into an array of Strings.
+	 */
+	static public String[] toArray(ArrayList value)
+	{
+		String[] strArray = new String[value.size()];
+		for(int i=0; i < value.size(); i++ ) {
+			strArray[i] = (String)value.get(i);
+		}
+		return strArray;
+	}
+	
+	// ---------------------------------------------------------------------------
+	// toString
+	// ---------------------------------------------------------------------------
+	
+	/**
+	 * Converts an ArrayList into a String separated by spaces. The parser should
+	 * be able to re-create the ArrayList from this String.
+	 */
+	static public String toString(ArrayList value)
+	{
+		String str = "";
+		for(int i=0; i < value.size(); i++ ) {
+			if( i > 0 ) str += " ";
+			str += (String)value.get(i);
+		}
+		return str;
+	}
+	
+	// ---------------------------------------------------------------------------
+	// parseArguments
+	// ---------------------------------------------------------------------------
+	
+	/**
+	 * Arguments are identified with - or -- preceding them and separated from the previous
argument
+	 * by one or more spaces. The value of the argument, if present, is separated from the argument
name
+	 * using an equal-sign.
+	 * @return
+	 */
+	public ArrayList parseArguments()
+	{
+		// prefix the working copy with a space so that every argument is separated by one or more
spaces.
+		String working = " "+_arguments+" ";
+		int index = 0;
+		
+		result = new ArrayList();
+		
+		while( index < working.length() )
+		{
+			int next = findNextArg(index, working);
+			if( next < 0 ) break;
+			
+			int pos = extractArgName( next, working );
+			ArgRange range = extractArgValue( pos+1, working );
+			
+			if( range != null ) {
+				String argName = working.substring(next, pos);
+				String argValue = working.substring(range.startIndex,range.endIndex);
+
+// Places quotes around the file name just makes a file name with quotes in it and adversely
+// affects how the file name is interpreted. Better to leave off the quotes				
+//				result.add( argName+"="+(range.hasSpaces?"\"":"")+argValue+(range.hasSpaces?"\"":""));
+//debug			System.out.println("arg name=value: "+argName+"="+(range.hasSpaces?"'":"")+argValue+(range.hasSpaces?"'":""));
+
+				result.add( argName+"="+argValue );
+				
+				index = range.endIndex+1;
+			} else {
+				String argName = working.substring(next, pos);
+				result.add(argName);
+				
+				index = pos+1;
+			}
+			
+		}
+		
+		return result;
+	}
+	
+	/**
+	 * @private
+	 * Returns the index of the next argument in the sequence.
+	 */
+	private int findNextArg( int index, String working )
+	{
+		for(int i=index; i < working.length(); i++ )
+		{
+			char c = working.charAt(i);
+			if( c == ' ' ) continue;
+			if( c == '-' ) {
+				return i;
+			}
+		}
+		
+		return -1;
+	}
+	
+	/**
+	 * Find the index of the start of the argument name. The name must end with
+	 * either a - or a space.
+	 */
+	private int extractArgName( int index, String working )
+	{
+		for(int i=index; i < working.length(); i++ )
+		{
+			char c = working.charAt(i);
+			if( c == ' ' ) return i;
+			if( c == '=' ) return i;
+		}
+		
+		return -1;
+	}
+	
+	/**
+	 * Returns an ArgRange denoting the position of the argument value. The end of an
+	 * argument's value is either the end of the string or a hyphen that is proceeded
+	 * by at least one space. Should the argument value contain any spaces the ArgRange
+	 * hasSpaces property is set to true.
+	 */
+	private ArgRange extractArgValue( int index, String working )
+	{
+		int firstPos = index;
+		int lastPos = index;
+		boolean hasSpaces = false;
+		
+		for(int i=index; i < working.length(); i++ )
+		{
+			char c = working.charAt(i);
+			if( c == ' ' ) continue; // skip leading blanks.
+			firstPos = i;
+			break;
+		}
+		
+		if( working.charAt(firstPos) == '-' ) return null; // there is no argValue
+		
+		for(int i=index; i < working.length(); i++ )
+		{
+			char c = working.charAt(i);
+			
+			// the only thing that stops us at this point is - or the end of the string
+			if( c == '-' ) {
+				// look at the previous character: if it is a space, then the argument's end
+				// has been found. If not, consider the hyphen part of the argument value.
+				char prev = working.charAt(i-1);
+				if( prev == ' ' ) break;
+			}
+			else {
+				if( c != ' ' ) lastPos = i; // the last non-blank character
+			}
+		}
+		
+		// scan for any spaces between the first and last positions
+		for(int i=firstPos; !hasSpaces && i <= lastPos; i++) {
+			char c = working.charAt(i);
+			if( c == ' ' ) hasSpaces = true;
+		}
+		
+		return new ArgRange(firstPos,lastPos+1,hasSpaces);
+	}
+}

Propchange: incubator/flex/sdk/branches/develop/mustella/java/src/utils/ArgumentParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompcUtils.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompcUtils.java?rev=1401287&r1=1401286&r2=1401287&view=diff
==============================================================================
--- incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompcUtils.java (original)
+++ incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompcUtils.java Tue Oct 23
13:26:35 2012
@@ -24,6 +24,7 @@ import java.util.StringTokenizer;
 import java.util.List;
 import java.util.Vector;
 import java.util.Iterator;
+import java.util.ArrayList;
 
 import utils.FileUtils;
 import org.xml.sax.SAXException;
@@ -61,21 +62,15 @@ public class CompcUtils {
 
 
     public void compile(String args) throws Exception {
-        if (!args.equals("")) {
-            String[] aArgs;
-            StringTokenizer stok = new StringTokenizer(args, " ");
-            String[] tmp = new String[stok.countTokens()];
-            int count = 0;
-            while (stok.hasMoreTokens()) {
-                tmp[count] = stok.nextToken();
-                count++;
-            }
-            aArgs = tmp;
-            compile(aArgs);
-        } else {
-            throw new Exception("compc args are empty!");
-        }
-
+    	if( !args.equals("")) {
+    		ArgumentParser parser = new ArgumentParser(args);
+    		ArrayList result = parser.parseArguments();
+    		String a[] = new String[result.size()];
+        	for(int i=0; i < result.size(); i++) a[i] = (String)result.get(i);
+        	compc(a);
+    	} else {
+    		throw new Exception("compc args are empty!");
+    	}
     }
 
     //read args from file
@@ -313,34 +308,35 @@ public class CompcUtils {
 
 
 //    todo: I think this is the correct thing do to when compc will really be working?? -
kq
-    public String[] addSwcToClassPath(String[] mxmlArgs) {
+    public ArrayList addSwcToClassPath(ArrayList mxmlArgs) {
         //tack the swc onto the end of the --library-path
 
-        debug(">>>>>> original mxmlArgs >>> " + StringUtils.arrayToString(mxmlArgs));
+        //debug(">>>>>> original mxmlArgs >>> " + StringUtils.arrayToString(mxmlArgs));
 
         validateSwcs();
 
         boolean bFound = false;
         String sep = " ";
         int insertPos = 0;
-        List l = new Vector();
-        for (int i = 0; i < mxmlArgs.length; i++) {
-            if (mxmlArgs[i].trim().toLowerCase().indexOf("--library-path") > 0 || mxmlArgs[i].trim().toLowerCase().indexOf("-library-path")
> 0) {
+        ArrayList l = new ArrayList();
+        for (int i = 0; i < mxmlArgs.size(); i++) {
+        	String anArg = (String)mxmlArgs.get(i);
+            if (anArg.trim().toLowerCase().indexOf("--library-path") > 0 || anArg.trim().toLowerCase().indexOf("-library-path")
> 0) {
                 bFound = true;
                 insertPos = i;
                 debug("found library-path");
             }
             if (bFound) {
-                if ((mxmlArgs[i].startsWith("-") || mxmlArgs[i].startsWith("+")) &&
insertPos != i) {
+                if ((anArg.startsWith("-") || anArg.startsWith("+")) && insertPos
!= i) {
                     insertPos = i;
                     bFound = false;
                 }
-                if (mxmlArgs[i].indexOf("=") > 0) {
+                if (anArg.indexOf("=") > 0) {
                     sep = ",";
                     debug(">>> sepaprator is ',' ");
                 }
             }
-            l.add(mxmlArgs[i]);
+            l.add(anArg);
 
         }
         if (insertPos != 0) {
@@ -385,9 +381,7 @@ public class CompcUtils {
             }
         }
 
-        mxmlArgs = (String[]) l.toArray(new String[]{});
-        debug(">>>>>> new mxmlArgs >>> " + StringUtils.arrayToString(mxmlArgs));
-        return mxmlArgs;
+        return l;
 
     }
 

Modified: incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompileMxmlUtils.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompileMxmlUtils.java?rev=1401287&r1=1401286&r2=1401287&view=diff
==============================================================================
--- incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompileMxmlUtils.java (original)
+++ incubator/flex/sdk/branches/develop/mustella/java/src/utils/CompileMxmlUtils.java Tue
Oct 23 13:26:35 2012
@@ -19,6 +19,7 @@
 package utils;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Vector;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -38,10 +39,12 @@ public class CompileMxmlUtils {
     private RuntimeExecHelper reh;
     private String execArgs[];
     boolean printOut=false;
+    
     public void compile(String mxml) throws Exception {
-        compile(mxml,new String[]{});
+    	compile(mxml,new ArrayList());
     }
-    public void compile(String mxml,String[] optionalArgs) throws Exception {
+
+    public void compile(String mxml,ArrayList optionalArgs) throws Exception {
         boolean debug=false;
         debug=System.getProperty("debug")!=null && System.getProperty("debug").equals("true");
         String mxmlcdir=System.getProperty("mxmlcdir");
@@ -117,17 +120,9 @@ public class CompileMxmlUtils {
             }
         }
 
-
-        if (newArgs != null){
-            StringTokenizer stok = new StringTokenizer(newArgs, " ");
-            stok.countTokens();
-            String[] tmp = new String[stok.countTokens()];
-            int count=0;
-            while (stok.hasMoreTokens()) {
-                tmp[count]=stok.nextToken();
-                count++;
-            }
-            optionalArgs=tmp;
+        if( newArgs != null ) {
+        	ArgumentParser parser = new ArgumentParser(newArgs);
+        	optionalArgs = parser.parseArguments();
         }
 
         //String mxmldir=FileUtils.getDirectory(mxml);
@@ -155,24 +150,20 @@ public class CompileMxmlUtils {
         }
 
 		boolean hasLinkReport = false;
-		
-        List execArgsList=new Vector();
-        execArgsList.add(mxmlc);
-        for (int i=0;i<optionalArgs.length;i++) {
-			if (optionalArgs[i].indexOf("-link-report") != -1)
-				hasLinkReport = true;
-            execArgsList.add(optionalArgs[i]);
-        }
-		if (!hasLinkReport)
-		{
-			execArgsList.add("-link-report=" + linkReport);
-		}
-        execArgsList.add(mxml);
-        execArgs=(String[])execArgsList.toArray(new String[]{});
+        optionalArgs.add(0, mxmlc);
+        for (int i=0; i < optionalArgs.size(); i++) {
+        	String a = (String)optionalArgs.get(i);
+        	if( a.indexOf("-link-report") != -1 ) hasLinkReport = true;
+        }
+        if( !hasLinkReport ) {
+        	optionalArgs.add("-link-report=" + linkReport);
+        }
+        optionalArgs.add(mxml);
+        execArgs = ArgumentParser.toArray(optionalArgs);
 
         if (debug) {
         	System.out.println("cd "+dir);
-        	System.out.println(StringUtils.arrayToString(execArgs));
+            System.out.println("CompileMxmlUtils.compile: "+StringUtils.arrayToString(execArgs));
         }
 
         int timeout=300;
@@ -187,6 +178,7 @@ public class CompileMxmlUtils {
         reh.run();
         lastRunTime=System.currentTimeMillis()-startTime;
     }
+    
     public String getSwf() { return swf; }
     public long getLastRunTime() { return lastRunTime; }
     public RuntimeExecHelper getRuntimeExecHelper() { return reh; }



Mime
View raw message