@ -156,7 +156,7 @@ public class TryIt {
if ( ! new File ( localPath ) . delete ( ) ) {
if ( ! new File ( localPath ) . delete ( ) ) {
System . out . println ( "Delete " + localPath + " and try again" ) ;
System . out . println ( "Delete " + localPath + " and try again" ) ;
}
}
handleException ( "Download ing " + localPath + " failed." , e ) ;
handleException ( "Download failed for file : " + localPath , e ) ;
} finally {
} finally {
if ( in ! = null )
if ( in ! = null )
try {
try {
@ -193,7 +193,7 @@ public class TryIt {
String response = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) . next ( ) ;
String response = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) . next ( ) ;
String emulatorLocationPath = response + File . separator + "tools" + File . separator + "emulator" ;
String emulatorLocationPath = response + File . separator + "tools" + File . separator + "emulator" ;
if ( osSuffix . equals ( Constants . WINDOWS_OS ) ) {
if ( osSuffix . equals ( Constants . WINDOWS_OS ) ) {
emulatorLocationPath + = Constants . WINDOWS_EXTENSION_ BAT ;
emulatorLocationPath + = Constants . WINDOWS_EXTENSION_ EXE ;
}
}
if ( new File ( emulatorLocationPath ) . exists ( ) ) {
if ( new File ( emulatorLocationPath ) . exists ( ) ) {
androidSdkHome = response ;
androidSdkHome = response ;
@ -255,7 +255,7 @@ public class TryIt {
private void getTools ( String url , String folderName ) {
private void getTools ( String url , String folderName ) {
System . out . println ( "Downloading " + folderName ) ;
System . out . println ( "Downloading " + folderName ) ;
downloadArtifacts ( url , androidSdkHome + File . separator + folderName ) ;
downloadArtifacts ( url , androidSdkHome + File . separator + folderName ) ;
System . out . println ( "Configuring " + folderName ) ;
System . out . println ( "Configuring " + folderName + ", please wait" ) ;
extractFolder ( androidSdkHome + File . separator + folderName ) ;
extractFolder ( androidSdkHome + File . separator + folderName ) ;
}
}
@ -269,7 +269,7 @@ public class TryIt {
checkForSystemImages ( ) ;
checkForSystemImages ( ) ;
if ( ! new File ( wso2AvdLocation ) . isDirectory ( ) ) {
if ( ! new File ( wso2AvdLocation ) . isDirectory ( ) ) {
Scanner read = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) ;
Scanner read = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) ;
System . out . print ( "Do you want to create WSO2_AVD with default configs ( Y /n)?: ") ;
System . out . print ( "Do you want to create WSO2_AVD with default configs ( y /n)?: ") ;
if ( read . next ( ) . toLowerCase ( ) . matches ( "y" ) ) {
if ( read . next ( ) . toLowerCase ( ) . matches ( "y" ) ) {
createAVD ( ) ;
createAVD ( ) ;
return ;
return ;
@ -494,17 +494,29 @@ public class TryIt {
/ * *
/ * *
* This method gets the Android SDK location if available and sets the SDK path else downloads the SDK .
* This method gets the Android SDK location if available and sets the SDK path else downloads the SDK .
* /
* /
private int count = 0 ;
private void setAndroidSDK ( ) {
private void setAndroidSDK ( ) {
sdkConfigFile = new File ( "sdkConfigLocation" ) ;
sdkConfigFile = new File ( "sdkConfigLocation" ) ;
if ( ! ( sdkConfigFile . exists ( ) & & ! sdkConfigFile . isDirectory ( ) ) ) {
if ( ! ( sdkConfigFile . exists ( ) & & ! sdkConfigFile . isDirectory ( ) ) ) {
//TODO
//TODO
Scanner read = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) ;
Scanner read = new Scanner ( System . in , StandardCharsets . UTF_8 . toString ( ) ) ;
System . out . print ( "Do you have an Android SDK installed on your computer (y/ N ) ? : ") ;
System . out . print ( "Do you have an Android SDK installed on your computer (y/ n ) ? : ") ;
String response = read . next ( ) . toLowerCase ( ) ;
String response = read . next Line ( ) . toLowerCase ( ) ;
if ( response . matches ( "y" ) ) {
if ( response . matches ( "y" ) ) {
setSDKPath ( ) ;
setSDKPath ( ) ;
} else {
} else if ( response . matches ( "n" ) ) {
getAndroidSDK ( ) ;
getAndroidSDK ( ) ;
} else {
if ( count < 5 ) {
System . out . println ( "Please enter a valid parameter ." ) ;
count + + ;
setAndroidSDK ( ) ;
return ;
} else {
System . out . println ( "Terminating process" ) ;
System . exit ( 1 ) ;
}
}
}
} else {
} else {
Scanner scanner = null ;
Scanner scanner = null ;
@ -634,7 +646,7 @@ public class TryIt {
* /
* /
private void installAgent ( ) {
private void installAgent ( ) {
String androidAgentLocation = workingDirectory + Constants . APK_LOCATION ;
String androidAgentLocation = workingDirectory + Constants . APK_LOCATION ;
System . out . println ( "Installing agent ...") ;
System . out . println ( "Installing agent , please wait ...") ;
ProcessBuilder installAgentProcessBuilder = new ProcessBuilder ( adbLocation , "install" ,
ProcessBuilder installAgentProcessBuilder = new ProcessBuilder ( adbLocation , "install" ,
androidAgentLocation ) ;
androidAgentLocation ) ;
try {
try {
@ -722,19 +734,24 @@ public class TryIt {
if ( ! new File ( haxmLocation ) . mkdirs ( ) ) {
if ( ! new File ( haxmLocation ) . mkdirs ( ) ) {
makeDirectoryError ( haxmLocation , androidSdkHome ) ;
makeDirectoryError ( haxmLocation , androidSdkHome ) ;
}
}
String folderName = "_haxm.zip" ;
String haxmInstaller ;
getTools ( System . getProperty ( Constants . HAXM_URL ) , haxmLocation + File . separator
String folderName = "extras" + File . separator + "intel" + File . separator
+ folderName ) ;
+ "Hardware_Accelerated_Execution_Manager" + File . separator + "_haxm.zip" ;
String haxmInstaller = haxmLocation + File . separator + "silent_install" ;
getTools ( System . getProperty ( Constants . HAXM_URL ) , folderName ) ;
if ( osSuffix . equals ( Constants . WINDOWS_OS ) ) {
ProcessBuilder processBuilder ;
haxmInstaller + = Constants . WINDOWS_EXTENSION_BAT ;
if ( osSuffix . equals ( Constants . MAC_OS ) ) {
haxmInstaller = haxmLocation + File . separator + "silent_install.sh" ;
setExecutePermission ( haxmInstaller ) ;
processBuilder = new ProcessBuilder ( "sudo" , haxmInstaller , "-m" , "2048" , "-log" ,
androidSdkHome + File . separator + "haxmSilentRun.log" ) ;
} else {
} else {
haxmInstaller + = Constants . MAC_HAXM_EXTENSION ;
haxmInstaller = haxmLocation + File . separator + "silent_install.bat" ;
setExecutePermission ( haxmInstaller ) ;
processBuilder = new ProcessBuilder ( haxmInstaller , "-m" , "2048" , "-log" ,
androidSdkHome + File . separator + "haxmSilentRun.log" ) ;
}
}
setExecutePermission ( haxmInstaller ) ;
ProcessBuilder processBuilder = new ProcessBuilder ( haxmInstaller , "-m" , "2048" , "-log" ,
System . out . println ( "Installing intel HAXM, Please wait . . . " ) ;
workingDirectory + File . separator + "haxmSilentRun.log" ) ;
processBuilder . directory ( new File ( haxmLocation ) ) ;
processBuilder . directory ( new File ( haxmLocation ) ) ;
processBuilder . redirectInput ( ProcessBuilder . Redirect . INHERIT ) ;
processBuilder . redirectInput ( ProcessBuilder . Redirect . INHERIT ) ;
processBuilder . redirectOutput ( ProcessBuilder . Redirect . INHERIT ) ;
processBuilder . redirectOutput ( ProcessBuilder . Redirect . INHERIT ) ;
@ -818,6 +835,7 @@ public class TryIt {
private void checkCacheImg ( String deviceId ) {
private void checkCacheImg ( String deviceId ) {
File cacheImg = new File ( userHome + File . separator + ".android"
File cacheImg = new File ( userHome + File . separator + ".android"
+ File . separator + "avd" + File . separator + deviceId + ".avd" + File . separator + "cache.img" ) ;
+ File . separator + "avd" + File . separator + deviceId + ".avd" + File . separator + "cache.img" ) ;
System . out . print ( "Creating cache image, please wait " ) ;
while ( ! cacheImg . exists ( ) ) {
while ( ! cacheImg . exists ( ) ) {
System . out . print ( "." ) ;
System . out . print ( "." ) ;
delay ( 1000 ) ;
delay ( 1000 ) ;