@@ -8,17 +8,28 @@ import { Logger } from "../../lib/common/logger";
8
8
import * as ErrorsLib from "../../lib/common/errors" ;
9
9
import temp = require( "temp" ) ;
10
10
import { 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" ;
12
14
13
- describe ( 'androiPluginBuildService' , ( ) => {
15
+ temp . track ( ) ;
14
16
17
+ describe . only ( 'androiPluginBuildService' , ( ) => {
15
18
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 ;
18
24
25
+ function setupTestInjector ( ) : IInjector {
26
+ testInjector = new Yok ( ) ;
19
27
testInjector . register ( "fs" , FsLib . FileSystem ) ;
20
28
testInjector . register ( "childProcess" , {
21
29
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 , "" ) ;
22
33
spawnFromEventCalled = command . indexOf ( "gradlew" ) !== - 1 ;
23
34
return null ;
24
35
}
@@ -41,15 +52,44 @@ describe('androiPluginBuildService', () => {
41
52
executeBeforeHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined ,
42
53
executeAfterHooks : async ( commandName : string , hookArguments ?: IDictionary < any > ) : Promise < void > => undefined
43
54
} ) ;
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 ( ) ;
44
64
45
65
return testInjector ;
46
- } ;
66
+ }
47
67
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
+ }
53
93
54
94
function setUpIncludeGradle ( ) {
55
95
fs = testInjector . resolve ( "fs" ) ;
@@ -107,7 +147,7 @@ dependencies {
107
147
}
108
148
109
149
before ( ( ) => {
110
- testInjector = createTestInjector ( ) ;
150
+ setupTestInjector ( ) ;
111
151
androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
112
152
} ) ;
113
153
@@ -135,6 +175,65 @@ dependencies {
135
175
assert . isTrue ( spawnFromEventCalled ) ;
136
176
} ) ;
137
177
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
+
138
237
it ( 'if android manifest is missing' , async ( ) => {
139
238
setUpPluginNativeFolder ( false , true , true ) ;
140
239
const config : IBuildOptions = {
0 commit comments