@@ -8,17 +8,28 @@ import { Logger } from "../../lib/common/logger";
88import * as ErrorsLib from "../../lib/common/errors" ;
99import temp = require( "temp" ) ;
1010import { INCLUDE_GRADLE_NAME } from "../../lib/constants" ;
11- temp . track ( ) ;
11+ import * as stubs from "../stubs" ;
12+ import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants" ;
13+ import { getShortPluginName } from "../../lib/common/helpers" ;
1214
13- describe ( 'androiPluginBuildService' , ( ) => {
15+ temp . track ( ) ;
1416
17+ describe . only ( 'androiPluginBuildService' , ( ) => {
1518 let spawnFromEventCalled = false ;
16- const createTestInjector = ( ) : IInjector => {
17- const testInjector = new Yok ( ) ;
19+ let testInjector : IInjector ;
20+ let fs : IFileSystem ;
21+ let androidBuildPluginService : AndroidPluginBuildService ;
22+ let tempFolder : string ;
23+ let pluginFolder : string ;
1824
25+ function setupTestInjector ( ) : IInjector {
26+ testInjector = new Yok ( ) ;
1927 testInjector . register ( "fs" , FsLib . FileSystem ) ;
2028 testInjector . register ( "childProcess" , {
2129 spawnFromEvent : async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
30+ const finalAarName = `${ getShortPluginName ( "my-plugin" ) } -release.aar` ;
31+ const aar = path . join ( pluginFolder , getShortPluginName ( "my-plugin" ) , "build" , "outputs" , "aar" , finalAarName ) ;
32+ fs . writeFile ( aar , "" ) ;
2233 spawnFromEventCalled = command . indexOf ( "gradlew" ) !== - 1 ;
2334 return null ;
2435 }
@@ -41,15 +52,44 @@ describe('androiPluginBuildService', () => {
4152 executeBeforeHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined ,
4253 executeAfterHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined
4354 } ) ;
55+ testInjector . register ( 'projectDataService' , stubs . ProjectDataService ) ;
56+ testInjector . register ( 'platformService' , {
57+ getCurrentPlatformVersion : ( platform : string , projectData : IProjectData ) : string => {
58+ console . log ( "here?" ) ;
59+ return "4.1.2" ;
60+ }
61+ } ) ;
62+ testInjector . register ( 'devicePlatformsConstants' , DevicePlatformsConstants ) ;
63+ setupNpm ( ) ;
4464
4565 return testInjector ;
46- } ;
66+ }
4767
48- let testInjector : IInjector ;
49- let fs : IFileSystem ;
50- let androidBuildPluginService : AndroidPluginBuildService ;
51- let tempFolder : string ;
52- let pluginFolder : string ;
68+ function setupNpm ( gradleVersion ?: string , gradleAndroidVersion ?: string ) : void {
69+ testInjector . register ( 'npm' , {
70+ getRegistryPackageData : async ( packageName : string ) : Promise < any > => {
71+ const result : any = [ ] ;
72+ result [ "dist-tags" ] = { latest : '1.0.0' } ;
73+ result . versions = [ ] ;
74+ result . versions [ '1.0.0' ] = {
75+ "name" : packageName ,
76+ "gradle" : {
77+ "version" : gradleVersion || "1.0.0" ,
78+ "android" : gradleAndroidVersion || "1.0.0"
79+ }
80+ } ;
81+ result . versions [ '4.1.2' ] = {
82+ "name" : packageName ,
83+ "gradle" : {
84+ "version" : "1.0.0" ,
85+ "android" : "1.0.0"
86+ }
87+ } ;
88+
89+ return result ;
90+ }
91+ } ) ;
92+ }
5393
5494 function setUpIncludeGradle ( ) {
5595 fs = testInjector . resolve ( "fs" ) ;
@@ -107,7 +147,7 @@ dependencies {
107147 }
108148
109149 before ( ( ) => {
110- testInjector = createTestInjector ( ) ;
150+ setupTestInjector ( ) ;
111151 androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
112152 } ) ;
113153
@@ -135,6 +175,65 @@ dependencies {
135175 assert . isTrue ( spawnFromEventCalled ) ;
136176 } ) ;
137177
178+ it ( 'should use the latest runtime gradle versions when no project dir specified' , async ( ) => {
179+ const gradleVersion = "1.2.3" ;
180+ const gradleAndroidPluginVersion = "4.5.6" ;
181+ setupNpm ( gradleVersion , gradleAndroidPluginVersion ) ;
182+ androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
183+ setUpPluginNativeFolder ( true , false , false ) ;
184+ const config : IBuildOptions = {
185+ platformsAndroidDirPath : tempFolder ,
186+ pluginName : "my-plugin" ,
187+ aarOutputDir : tempFolder ,
188+ tempPluginDirPath : pluginFolder
189+ } ;
190+
191+ await androidBuildPluginService . buildAar ( config ) ;
192+
193+ const gradleWrappersContent = fs . readText ( path . join ( pluginFolder , getShortPluginName ( "my-plugin" ) , "build.gradle" ) . toString ( ) ) ;
194+ const androidVersionRegex = / c o m \. a n d r o i d \. t o o l s \. b u i l d \: g r a d l e \: ( .* ) \' \n / g;
195+ const actualAndroidVersion = androidVersionRegex . exec ( gradleWrappersContent ) [ 1 ] ;
196+ assert . equal ( actualAndroidVersion , gradleAndroidPluginVersion ) ;
197+
198+ const buildGradleContent = fs . readText (
199+ path . join ( pluginFolder , getShortPluginName ( "my-plugin" ) , "gradle" , "wrapper" , "gradle-wrapper.properties" ) . toString ( ) ) ;
200+ const gradleVersionRegex = / g r a d l e \- ( .* ) \- b i n \. z i p \n / g;
201+ const actualGradleVersion = gradleVersionRegex . exec ( buildGradleContent ) [ 1 ] ;
202+ assert . equal ( actualGradleVersion , gradleVersion ) ;
203+
204+ assert . isTrue ( spawnFromEventCalled ) ;
205+ } ) ;
206+
207+ it . only ( 'should use specified runtime gradle versions from the project dir' , async ( ) => {
208+ const gradleVersion = "1.2.3" ;
209+ const gradleAndroidPluginVersion = "4.5.6" ;
210+ setupNpm ( gradleVersion , gradleAndroidPluginVersion ) ;
211+ androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
212+ setUpPluginNativeFolder ( true , false , false ) ;
213+ const config : IBuildOptions = {
214+ platformsAndroidDirPath : tempFolder ,
215+ pluginName : "my-plugin" ,
216+ aarOutputDir : tempFolder ,
217+ tempPluginDirPath : pluginFolder ,
218+ projectDir : tempFolder
219+ } ;
220+
221+ await androidBuildPluginService . buildAar ( config ) ;
222+
223+ const gradleWrappersContent = fs . readText ( path . join ( pluginFolder , getShortPluginName ( "my-plugin" ) , "build.gradle" ) . toString ( ) ) ;
224+ const androidVersionRegex = / c o m \. a n d r o i d \. t o o l s \. b u i l d \: g r a d l e \: ( .* ) \' \n / g;
225+ const actualAndroidVersion = androidVersionRegex . exec ( gradleWrappersContent ) [ 1 ] ;
226+ assert . equal ( actualAndroidVersion , "1.0.0" ) ;
227+
228+ const buildGradleContent = fs . readText (
229+ path . join ( pluginFolder , getShortPluginName ( "my-plugin" ) , "gradle" , "wrapper" , "gradle-wrapper.properties" ) . toString ( ) ) ;
230+ const gradleVersionRegex = / g r a d l e \- ( .* ) \- b i n \. z i p \n / g;
231+ const actualGradleVersion = gradleVersionRegex . exec ( buildGradleContent ) [ 1 ] ;
232+ assert . equal ( actualGradleVersion , "1.0.0" ) ;
233+
234+ assert . isTrue ( spawnFromEventCalled ) ;
235+ } ) ;
236+
138237 it ( 'if android manifest is missing' , async ( ) => {
139238 setUpPluginNativeFolder ( false , true , true ) ;
140239 const config : IBuildOptions = {
0 commit comments