Skip to content

Commit

Permalink
- Path finalized on Windows to download SDKs
Browse files Browse the repository at this point in the history
- Environment variable procedure updated to work independently in SDK Installer application (reference Moonshine-IDE/Moonshine-IDE#449)
  • Loading branch information
rat-moonshine committed Feb 27, 2019
1 parent 59c21e7 commit e71d97f
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
17 changes: 15 additions & 2 deletions InstallerSharedCore/src/actionScripts/utils/EnvironmentUtils.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -28,7 +35,7 @@ package actionScripts.utils
customInfo = new NativeProcessStartupInfo();
customInfo.executable = new File("c:\\Windows\\System32\\cmd.exe");

customInfo.arguments = new Vector.<Object>(["/c", "set"]);
customInfo.arguments = new <String>["/c", "set"];
startShell(true);
}
}
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions InstallerSharedCore/src/actionScripts/utils/FileUtils.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions InstallerSharedCore/src/actionScripts/utils/HelperUtils.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
}
54 changes: 54 additions & 0 deletions InstallerSharedCore/src/actionScripts/utils/Parser.as
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
83 changes: 83 additions & 0 deletions InstallerSharedCore/src/actionScripts/valueObjects/HelperSDKVO.as
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions InstallerSharedCore/src/components/HelperView.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
{
model.moonshineBridge = dependencyCheckUtil;
//environmentUtil.readValues();
attachStartupHelperListeners(true);
startupHelper.setLocalPathConfig();
startupHelper.loadMoonshineConfig();
Expand Down

0 comments on commit e71d97f

Please sign in to comment.