1
1
import { AndroidPluginBuildService } from "../../lib/services/android-plugin-build-service" ;
2
2
import { assert } from "chai" ;
3
- import { INCLUDE_GRADLE_NAME , AndroidBuildDefaults } from "../../lib/constants" ;
3
+ import { INCLUDE_GRADLE_NAME , AndroidBuildDefaults , PLUGIN_BUILD_DATA_FILENAME } from "../../lib/constants" ;
4
4
import { getShortPluginName } from "../../lib/common/helpers" ;
5
5
import * as FsLib from "../../lib/common/file-system" ;
6
6
import * as path from "path" ;
@@ -30,6 +30,8 @@ describe('androidPluginBuildService', () => {
30
30
latestRuntimeGradleAndroidVersion ?: string ,
31
31
projectRuntimeGradleVersion ?: string ,
32
32
projectRuntimeGradleAndroidVersion ?: string ,
33
+ addPreviousBuildInfo ?: boolean ,
34
+ hasChangesInShasums ?: boolean ,
33
35
} ) : IBuildOptions {
34
36
options = options || { } ;
35
37
spawnFromEventCalled = false ;
@@ -53,6 +55,7 @@ describe('androidPluginBuildService', () => {
53
55
latestRuntimeGradleAndroidVersion ?: string ,
54
56
projectRuntimeGradleVersion ?: string ,
55
57
projectRuntimeGradleAndroidVersion ?: string ,
58
+ hasChangesInShasums ?: boolean
56
59
} ) : void {
57
60
const testInjector : IInjector = new stubs . InjectorStub ( ) ;
58
61
testInjector . register ( "fs" , FsLib . FileSystem ) ;
@@ -71,6 +74,11 @@ describe('androidPluginBuildService', () => {
71
74
}
72
75
} ) ;
73
76
testInjector . register ( 'npm' , setupNpm ( options ) ) ;
77
+ testInjector . register ( 'filesHashService' , < IFilesHashService > {
78
+ generateHashes : async ( files : string [ ] ) : Promise < IStringDictionary > => ( { } ) ,
79
+ getChanges : async ( files : string [ ] , oldHashes : IStringDictionary ) : Promise < IStringDictionary > => ( { } ) ,
80
+ hasChangesInShasums : ( oldHashes : IStringDictionary , newHashes : IStringDictionary ) : boolean => ! ! options . hasChangesInShasums
81
+ } ) ;
74
82
75
83
fs = testInjector . resolve ( "fs" ) ;
76
84
androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
@@ -113,7 +121,8 @@ describe('androidPluginBuildService', () => {
113
121
addResFolder ?: boolean ,
114
122
addAssetsFolder ?: boolean ,
115
123
addIncludeGradle ?: boolean ,
116
- addLegacyIncludeGradle ?: boolean
124
+ addLegacyIncludeGradle ?: boolean ,
125
+ addPreviousBuildInfo ?: boolean ,
117
126
} ) {
118
127
const validAndroidManifestContent = `<?xml version="1.0" encoding="UTF-8"?>
119
128
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
@@ -125,8 +134,8 @@ describe('androidPluginBuildService', () => {
125
134
>text_string</string>
126
135
</resources>` ;
127
136
const validIncludeGradleContent =
128
- `android {` +
129
- ( options . addLegacyIncludeGradle ? `
137
+ `android {` +
138
+ ( options . addLegacyIncludeGradle ? `
130
139
productFlavors {
131
140
"nativescript-pro-ui" {
132
141
dimension "nativescript-pro-ui"
@@ -161,6 +170,13 @@ dependencies {
161
170
if ( options . addLegacyIncludeGradle || options . addIncludeGradle ) {
162
171
fs . writeFile ( path . join ( pluginFolder , INCLUDE_GRADLE_NAME ) , validIncludeGradleContent ) ;
163
172
}
173
+
174
+ if ( options . addPreviousBuildInfo ) {
175
+ const pluginBuildDir = path . join ( tempFolder , "my_plugin" ) ;
176
+ fs . ensureDirectoryExists ( pluginBuildDir ) ;
177
+ fs . writeFile ( path . join ( pluginBuildDir , PLUGIN_BUILD_DATA_FILENAME ) , "{}" ) ;
178
+ fs . writeFile ( path . join ( pluginFolder , "my_plugin.aar" ) , "{}" ) ;
179
+ }
164
180
}
165
181
166
182
describe ( 'buildAar' , ( ) => {
@@ -206,6 +222,29 @@ dependencies {
206
222
assert . isTrue ( spawnFromEventCalled ) ;
207
223
} ) ;
208
224
225
+ it ( 'builds aar when plugin is already build and source files have changed since last buid' , async ( ) => {
226
+ const config : IBuildOptions = setup ( {
227
+ addManifest : true ,
228
+ addPreviousBuildInfo : true ,
229
+ hasChangesInShasums : true
230
+ } ) ;
231
+
232
+ await androidBuildPluginService . buildAar ( config ) ;
233
+
234
+ assert . isTrue ( spawnFromEventCalled ) ;
235
+ } ) ;
236
+
237
+ it ( 'does not build aar when plugin is already build and source files have not changed' , async ( ) => {
238
+ const config : IBuildOptions = setup ( {
239
+ addManifest : true ,
240
+ addPreviousBuildInfo : true
241
+ } ) ;
242
+
243
+ await androidBuildPluginService . buildAar ( config ) ;
244
+
245
+ assert . isFalse ( spawnFromEventCalled ) ;
246
+ } ) ;
247
+
209
248
it ( 'builds aar with the latest runtime gradle versions when no project dir is specified' , async ( ) => {
210
249
const expectedGradleVersion = "1.2.3" ;
211
250
const expectedAndroidVersion = "4.5.6" ;
@@ -316,15 +355,15 @@ dependencies {
316
355
317
356
function getGradleAndroidPluginVersion ( ) {
318
357
const gradleWrappersContent = fs . readText ( path . join ( tempFolder , shortPluginName , "build.gradle" ) ) ;
319
- 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;
358
+ 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 \: ( .* ) \' \r ? \ n/ g;
320
359
const androidVersion = androidVersionRegex . exec ( gradleWrappersContent ) [ 1 ] ;
321
360
322
361
return androidVersion ;
323
362
}
324
363
325
364
function getGradleVersion ( ) {
326
365
const buildGradleContent = fs . readText ( path . join ( tempFolder , shortPluginName , "gradle" , "wrapper" , "gradle-wrapper.properties" ) ) ;
327
- const gradleVersionRegex = / g r a d l e \- ( .* ) \- b i n \. z i p \n / g;
366
+ const gradleVersionRegex = / g r a d l e \- ( .* ) \- b i n \. z i p \r ? \ n/ g;
328
367
const gradleVersion = gradleVersionRegex . exec ( buildGradleContent ) [ 1 ] ;
329
368
330
369
return gradleVersion ;
0 commit comments