@@ -21,6 +21,7 @@ var PackageSource = require('./package-source.js');
21
21
var compiler = require ( './compiler.js' ) ;
22
22
var unipackage = require ( './unipackage.js' ) ;
23
23
var tropohouse = require ( './tropohouse.js' ) ;
24
+ var httpHelpers = require ( './http-helpers.js' ) ;
24
25
25
26
// XXX hard-coded the use of default tropohouse
26
27
var tropo = tropohouse . default ;
@@ -847,13 +848,70 @@ cordova.filterPackages = function (packages) {
847
848
return ret ;
848
849
} ;
849
850
851
+ var getTermsForPlatform = function ( platform ) {
852
+ var url = 'http://s3.amazonaws.com/android-bundle/license_cordova_' + platform + '.txt' ;
853
+ var result = httpHelpers . request ( {
854
+ url : url
855
+ } ) ;
856
+
857
+ var response = result . response ;
858
+ // S3 returns 403 if not found
859
+ if ( response . statusCode === 404 || response . statusCode === 403 ) {
860
+ verboseLog ( "License URL not found: " + url ) ;
861
+ process . stderr . write ( "No licensing file found for platform: " + platform + ".\n" ) ;
862
+ return null ;
863
+ }
864
+ if ( response . statusCode !== 200 ) {
865
+ throw new Error ( "Unexpected response code: " + response . statusCode ) ;
866
+ }
867
+ return response . body ;
868
+ } ;
869
+
870
+ var checkAgreePlatformTerms = function ( platform ) {
871
+ try {
872
+ var terms = getTermsForPlatform ( platform ) ;
873
+ } catch ( e ) {
874
+ verboseLog ( "Error while downloading license terms: " + e ) ;
875
+
876
+ // most likely we don't have a net connection
877
+ process . stderr . write ( "Unable to download license terms for platform: " + platform + ".\n" +
878
+ "Please make sure you are online.\n" )
879
+ throw new main . ExitWithCode ( 2 ) ;
880
+ }
881
+
882
+ if ( terms === null || terms . trim ( ) === "" ) {
883
+ // No terms required
884
+ return true ;
885
+ }
886
+
887
+ process . stdout . write ( "The following terms apply to the '" + platform + "' platform:\n\n" ) ;
888
+ process . stdout . write ( terms + "\n\n" ) ;
889
+ process . stdout . write ( "You must agree to the terms to proceed.\n" ) ;
890
+ process . stdout . write ( "Do you agree (Y/N)? " ) ;
891
+
892
+ var agreed = false ;
893
+
894
+ var line = utils . readLine ( { prompt : "Do you agree (Y/N)? " } ) ;
895
+ line = line . trim ( ) . toLowerCase ( ) ;
896
+ if ( line == "y" || line == "yes" ) {
897
+ agreed = true ;
898
+ }
899
+
900
+ return agreed ;
901
+ } ;
902
+
850
903
// add one or more Cordova platforms
851
904
main . registerCommand ( {
852
905
name : "add-platform" ,
906
+ options : {
907
+ verbose : { type : Boolean , short : "v" }
908
+ } ,
853
909
minArgs : 1 ,
854
910
maxArgs : Infinity ,
855
911
requiresApp : true
856
912
} , function ( options ) {
913
+ cordova . setVerboseness ( options . verbose ) ;
914
+
857
915
var platforms = options . args ;
858
916
859
917
try {
@@ -865,6 +923,18 @@ main.registerCommand({
865
923
return 1 ;
866
924
}
867
925
926
+ try {
927
+ var agreed = _ . every ( platforms , function ( platform , options ) {
928
+ return checkAgreePlatformTerms ( platform , options ) ;
929
+ } ) ;
930
+ if ( ! agreed ) {
931
+ return 2 ;
932
+ }
933
+ } catch ( err ) {
934
+ process . stderr . write ( err . message + "\n" ) ;
935
+ return 1 ;
936
+ }
937
+
868
938
project . addCordovaPlatforms ( platforms ) ;
869
939
870
940
if ( platforms . length ) {
0 commit comments