diff --git a/InstallerSharedCore/src/actionScripts/managers/StartupHelper.as b/InstallerSharedCore/src/actionScripts/managers/StartupHelper.as index f6239a4..a3d8695 100644 --- a/InstallerSharedCore/src/actionScripts/managers/StartupHelper.as +++ b/InstallerSharedCore/src/actionScripts/managers/StartupHelper.as @@ -26,8 +26,8 @@ package actionScripts.managers } else { - // TODO: need to decide on download directory - trace(File.userDirectory.nativePath); + // Windows download directory + HelperConstants.DEFAULT_INSTALLATION_PATH = File.userDirectory.resolvePath("MoonshineSDKs"); } } diff --git a/InstallerSharedCore/src/actionScripts/utils/EnvironmentUtils.as b/InstallerSharedCore/src/actionScripts/utils/EnvironmentUtils.as index c43394d..da8e674 100644 --- a/InstallerSharedCore/src/actionScripts/utils/EnvironmentUtils.as +++ b/InstallerSharedCore/src/actionScripts/utils/EnvironmentUtils.as @@ -9,6 +9,7 @@ package actionScripts.utils import flash.filesystem.File; import flash.utils.IDataInput; + import actionScripts.valueObjects.EnvironmentVO; import actionScripts.valueObjects.HelperConstants; public class EnvironmentUtils extends EventDispatcher @@ -17,6 +18,12 @@ package actionScripts.utils private var customInfo:NativeProcessStartupInfo; private var isErrorClose:Boolean; + private var _environments:EnvironmentVO; + public function get environments():EnvironmentVO + { + return _environments; + } + public function readValues():void { // since mapping an environment variable won't work @@ -28,7 +35,7 @@ package actionScripts.utils customInfo = new NativeProcessStartupInfo(); customInfo.executable = new File("c:\\Windows\\System32\\cmd.exe"); - customInfo.arguments = new Vector.(["/c", "set"]); + customInfo.arguments = new ["/c", "set"]; startShell(true); } } @@ -74,8 +81,14 @@ package actionScripts.utils match = data.match(/fatal: .*/); if (match) { - + isErrorClose = true; + } + else if (data != "") + { + Parser.parseEnvironmentFrom(data, (_environments = new EnvironmentVO())); } + + startShell(false); } private function shellError(e:ProgressEvent):void diff --git a/InstallerSharedCore/src/actionScripts/utils/FileUtils.as b/InstallerSharedCore/src/actionScripts/utils/FileUtils.as index e167495..4c28117 100644 --- a/InstallerSharedCore/src/actionScripts/utils/FileUtils.as +++ b/InstallerSharedCore/src/actionScripts/utils/FileUtils.as @@ -119,6 +119,31 @@ package actionScripts.utils } } + /** + * Simple read to a given file/path + * @required + * target: File (read-destination) + * dataFormat: String (return data type after read) + * @return + * Object + */ + public static function readFromFile(target:File, dataFormat:String=DATA_FORMAT_STRING):Object + { + var loadedBytes:ByteArray; + var loadedString:String; + var fs:FileStream = new FileStream(); + fs.open(target, FileMode.READ); + if (dataFormat == DATA_FORMAT_STRING) loadedString = fs.readUTFBytes(fs.bytesAvailable); + else + { + loadedBytes = new ByteArray(); + fs.readBytes(loadedBytes); + } + fs.close(); + + return (loadedString || loadedBytes); + } + /** * Reads from file asynchronously * @required diff --git a/InstallerSharedCore/src/actionScripts/utils/HelperUtils.as b/InstallerSharedCore/src/actionScripts/utils/HelperUtils.as index 5035b7e..3e8fdf6 100644 --- a/InstallerSharedCore/src/actionScripts/utils/HelperUtils.as +++ b/InstallerSharedCore/src/actionScripts/utils/HelperUtils.as @@ -7,6 +7,7 @@ package actionScripts.utils import actionScripts.locator.HelperModel; import actionScripts.valueObjects.ComponentVO; import actionScripts.valueObjects.HelperConstants; + import actionScripts.valueObjects.HelperSDKVO; public class HelperUtils { @@ -47,5 +48,39 @@ package actionScripts.utils var process:NativeProcess = new NativeProcess(); process.start(npInfo); } + + public static function isSDKFolder(path:File):HelperSDKVO + { + var descriptor:File = path.resolvePath("royale-sdk-description.xml"); + if (!descriptor.exists) + { + descriptor = path.resolvePath("royale-asjs/royale-sdk-description.xml"); + } + if (!descriptor.exists) + { + descriptor = path.resolvePath("flex-sdk-description.xml"); + } + + if (descriptor.exists) + { + // read the xml value to get SDK name + var tmpXML:XML = XML(FileUtils.readFromFile(descriptor)); + var displayName:String = tmpXML["name"]; + if (descriptor.name.indexOf("royale") > -1) + { + displayName += " " + tmpXML.version; + } + + var tmpSDK:HelperSDKVO = new HelperSDKVO(); + tmpSDK.path = descriptor.parent; + tmpSDK.name = displayName; + tmpSDK.version = String(tmpXML.version); + tmpSDK.build = String(tmpXML.build); + + return tmpSDK; + } + + return null; + } } } \ No newline at end of file diff --git a/InstallerSharedCore/src/actionScripts/utils/Parser.as b/InstallerSharedCore/src/actionScripts/utils/Parser.as index 71ebaae..d281e79 100644 --- a/InstallerSharedCore/src/actionScripts/utils/Parser.as +++ b/InstallerSharedCore/src/actionScripts/utils/Parser.as @@ -1,16 +1,70 @@ package actionScripts.utils { + import flash.filesystem.File; + import mx.collections.ArrayCollection; import mx.collections.ArrayList; import actionScripts.locator.HelperModel; import actionScripts.valueObjects.ComponentTypes; import actionScripts.valueObjects.ComponentVO; + import actionScripts.valueObjects.EnvironmentVO; import actionScripts.valueObjects.HelperConstants; + import actionScripts.valueObjects.HelperSDKVO; import actionScripts.valueObjects.PackageVO; public class Parser { + public static function parseEnvironmentFrom(values:String, to:EnvironmentVO):void + { + var lines:Array = values.split("\r\n"); + var tmpPath:File; + for each (var line:String in lines) + { + if (line.indexOf("JAVA_HOME") != -1) + { + tmpPath = new File(line.split("=")[1]); + // validate the path against JDK + if (tmpPath.exists && tmpPath.resolvePath("bin/javac.exe").exists) + { + to.JAVA_HOME = tmpPath; + } + } + else if (line.indexOf("ANT_HOME") != -1) + { + tmpPath = new File(line.split("=")[1]); + if (tmpPath.exists) + { + to.ANT_HOME = tmpPath; + } + } + else if (line.indexOf("FLEX_HOME") != -1) + { + tmpPath = new File(line.split("=")[1]); + // validate if Flex SDK path + if (tmpPath.exists) + { + var tmpSDK:HelperSDKVO = HelperUtils.isSDKFolder(tmpPath); + if (tmpSDK && (tmpSDK.type == ComponentTypes.TYPE_FLEX || + tmpSDK.type == ComponentTypes.TYPE_FEATHERS || + tmpSDK.type == ComponentTypes.TYPE_ROYALE || + tmpSDK.type == ComponentTypes.TYPE_FLEXJS)) + { + to.FLEX_HOME = tmpSDK; + } + } + } + else if (line.indexOf("MAVEN_HOME") != -1) + { + tmpPath = new File(line.split("=")[1]); + if (tmpPath.exists) + { + to.MAVEN_HOME = tmpPath; + } + } + } + } + public static function parseHelperConfig(xmlData:XML):void { var model:HelperModel = HelperModel.getInstance(); diff --git a/InstallerSharedCore/src/actionScripts/valueObjects/EnvironmentVO.as b/InstallerSharedCore/src/actionScripts/valueObjects/EnvironmentVO.as new file mode 100644 index 0000000..945befb --- /dev/null +++ b/InstallerSharedCore/src/actionScripts/valueObjects/EnvironmentVO.as @@ -0,0 +1,12 @@ +package actionScripts.valueObjects +{ + import flash.filesystem.File; + + public class EnvironmentVO + { + public var ANT_HOME:File; + public var JAVA_HOME:File; + public var FLEX_HOME:HelperSDKVO; + public var MAVEN_HOME:File; + } +} \ No newline at end of file diff --git a/InstallerSharedCore/src/actionScripts/valueObjects/HelperSDKVO.as b/InstallerSharedCore/src/actionScripts/valueObjects/HelperSDKVO.as new file mode 100644 index 0000000..5ca88f4 --- /dev/null +++ b/InstallerSharedCore/src/actionScripts/valueObjects/HelperSDKVO.as @@ -0,0 +1,83 @@ +package actionScripts.valueObjects +{ + import flash.filesystem.File; + + public class HelperSDKVO + { + private static const JS_SDK_COMPILER_NEW:String = "js/bin/mxmlc"; + private static const JS_SDK_COMPILER_OLD:String = "bin/mxmlc"; + private static const FLEX_SDK_COMPILER:String = "bin/fcsh"; + + public function HelperSDKVO() + { + } + + //-------------------------------------------------------------------------- + // + // PUBLIC VARIABLES + // + //-------------------------------------------------------------------------- + + public var version:String; + public var build:String; + public var status:String; + public var path:File; + public var name:String; + + private var _type:String; + public function get type():String + { + if (!_type) _type = getType(); + return _type; + } + + //-------------------------------------------------------------------------- + // + // PRIVATE API + // + //-------------------------------------------------------------------------- + + private function getType():String + { + // flex + var compilerExtension:String = HelperConstants.IS_MACOS ? "" : ".bat"; + var compilerFile:File = path.resolvePath(FLEX_SDK_COMPILER + compilerExtension); + if (compilerFile.exists) + { + if (path.resolvePath("frameworks/libs/spark.swc").exists || + path.resolvePath("frameworks/libs/flex.swc").exists) return ComponentTypes.TYPE_FLEX; + } + + // royale + compilerFile = path.resolvePath(JS_SDK_COMPILER_NEW + compilerExtension); + if (compilerFile.exists) + { + if (path.resolvePath("frameworks/royale-config.xml").exists) return ComponentTypes.TYPE_ROYALE; + } + + // feathers + compilerFile = path.resolvePath(FLEX_SDK_COMPILER + compilerExtension); + if (compilerFile.exists) + { + if (path.resolvePath("frameworks/libs/feathers.swc").exists) return ComponentTypes.TYPE_FEATHERS; + } + + // flexjs + compilerFile = path.resolvePath(JS_SDK_COMPILER_NEW + compilerExtension); + if (compilerFile.exists) + { + if (name.toLowerCase().indexOf("flexjs") != -1) return ComponentTypes.TYPE_FLEXJS; + } + else + { + compilerFile = path.resolvePath(JS_SDK_COMPILER_OLD + compilerExtension); + if (compilerFile.exists) + { + if (name.toLowerCase().indexOf("flexjs") != -1) return ComponentTypes.TYPE_FLEXJS; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/InstallerSharedCore/src/components/HelperView.mxml b/InstallerSharedCore/src/components/HelperView.mxml index 7380f4b..353a646 100644 --- a/InstallerSharedCore/src/components/HelperView.mxml +++ b/InstallerSharedCore/src/components/HelperView.mxml @@ -82,6 +82,7 @@ { model.moonshineBridge = dependencyCheckUtil; + //environmentUtil.readValues(); attachStartupHelperListeners(true); startupHelper.setLocalPathConfig(); startupHelper.loadMoonshineConfig();