1
1
import { AndroidPluginBuildService } from "../../lib/services/android-plugin-build-service" ;
2
2
import { Yok } from "../../lib/common/yok" ;
3
- // import * as stubs from "../stubs";
4
3
import { assert } from "chai" ;
5
- // import temp = require("temp");
6
4
import * as FsLib from "../../lib/common/file-system" ;
7
- // import * as path from "path";
5
+ import * as path from "path" ;
8
6
import { ChildProcess } from "../../lib/common/child-process" ;
9
7
import { HostInfo } from "../../lib/common/host-info" ;
10
8
import { AndroidToolsInfo } from "../../lib/android-tools-info" ;
11
9
import { Logger } from "../../lib/common/logger" ;
12
10
import * as ErrorsLib from "../../lib/common/errors" ;
11
+ import temp = require( "temp" ) ;
12
+ temp . track ( ) ;
13
13
14
14
describe ( 'androiPluginBuildService' , ( ) => {
15
15
@@ -32,26 +32,153 @@ describe('androiPluginBuildService', () => {
32
32
let testInjector : IInjector ;
33
33
let fs : IFileSystem ;
34
34
let androidBuildPluginService : AndroidPluginBuildService ;
35
+ let tempFolder : string ;
36
+ let pluginFolder : string ;
35
37
36
- beforeEach ( ( ) => {
37
- testInjector = createTestInjector ( ) ;
38
+ function setUpIncludeGradle ( ) {
39
+ fs = testInjector . resolve ( "fs" ) ;
40
+ pluginFolder = temp . mkdirSync ( "AndroidProjectPropertiesManager-temp" ) ;
38
41
39
- androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
42
+ const validIncludeGradleContent = `android {
43
+ productFlavors {
44
+ "nativescript-pro-ui" {
45
+ dimension "nativescript-pro-ui"
46
+ }
47
+ }
48
+ }
49
+
50
+ def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "23.3.0"
51
+
52
+ dependencies {
53
+ compile "com.android.support:appcompat-v7:$supportVersion"
54
+ compile "com.android.support:recyclerview-v7:$supportVersion"
55
+ compile "com.android.support:design:$supportVersion"
56
+ }` ;
57
+
58
+ fs . writeFile ( path . join ( pluginFolder , "include.gradle" ) , validIncludeGradleContent ) ;
59
+ }
60
+
61
+ function setUpPluginNativeFolder ( manifestFile : boolean , resFolder : boolean , assetsFolder : boolean ) {
40
62
fs = testInjector . resolve ( "fs" ) ;
63
+ tempFolder = temp . mkdirSync ( "AndroidProjectPropertiesManager" ) ;
64
+ pluginFolder = temp . mkdirSync ( "AndroidProjectPropertiesManager-temp" ) ;
65
+
66
+ const validAndroidManifestContent = `<?xml version="1.0" encoding="UTF-8"?>
67
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
68
+ </manifest>` ;
69
+ const validStringsXmlContent = `<?xml version="1.0" encoding="utf-8"?>
70
+ <resources>
71
+ <string
72
+ name="string_name"
73
+ >text_string</string>
74
+ </resources>` ;
75
+
76
+ if ( manifestFile ) {
77
+ fs . writeFile ( path . join ( tempFolder , "AndroidManifest.xml" ) , validAndroidManifestContent ) ;
78
+ }
79
+
80
+ if ( resFolder ) {
81
+ const valuesFolder = path . join ( tempFolder , "res" , "values" ) ;
82
+ fs . createDirectory ( valuesFolder ) ;
83
+ fs . writeFile ( path . join ( valuesFolder , "strings.xml" ) , validStringsXmlContent ) ;
84
+ }
85
+
86
+ if ( assetsFolder ) {
87
+ const imagesFolder = path . join ( tempFolder , "assets" , "images" ) ;
88
+ fs . createDirectory ( imagesFolder ) ;
89
+ fs . writeFile ( path . join ( imagesFolder , "myicon.png" ) , "123" ) ;
90
+ }
91
+ }
92
+
93
+ before ( ( ) => {
94
+ testInjector = createTestInjector ( ) ;
95
+ androidBuildPluginService = testInjector . resolve < AndroidPluginBuildService > ( AndroidPluginBuildService ) ;
41
96
} ) ;
42
97
43
98
describe ( 'builds aar' , ( ) => {
44
99
45
- it . only ( 'if supported files are in plugin' , ( ) => {
100
+ it ( 'if supported files are in plugin' , async ( ) => {
101
+ setUpPluginNativeFolder ( true , true , true ) ;
102
+ const config : IBuildOptions = {
103
+ platformsAndroidDirPath : tempFolder ,
104
+ pluginName : "my-plugin" ,
105
+ aarOutputDir : tempFolder ,
106
+ tempPluginDirPath : pluginFolder
107
+ } ;
108
+
109
+ const expectedAarName = "my_plugin.aar" ;
110
+ await androidBuildPluginService . buildAar ( config ) ;
111
+ const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
112
+
113
+ assert . equal ( hasGeneratedAar , true ) ;
114
+ } ) ;
115
+
116
+ it ( 'if android manifest is missing' , async ( ) => {
117
+ setUpPluginNativeFolder ( false , true , true ) ;
118
+ const config : IBuildOptions = {
119
+ platformsAndroidDirPath : tempFolder ,
120
+ pluginName : "my-plugin" ,
121
+ aarOutputDir : tempFolder ,
122
+ tempPluginDirPath : pluginFolder
123
+ } ;
124
+
125
+ const expectedAarName = "my_plugin.aar" ;
126
+ await androidBuildPluginService . buildAar ( config ) ;
127
+ const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
128
+
129
+ assert . equal ( hasGeneratedAar , true ) ;
130
+ } ) ;
131
+
132
+ it ( 'if there is only an android manifest file' , async ( ) => {
133
+ setUpPluginNativeFolder ( true , false , false ) ;
134
+ const config : IBuildOptions = {
135
+ platformsAndroidDirPath : tempFolder ,
136
+ pluginName : "my-plugin" ,
137
+ aarOutputDir : tempFolder ,
138
+ tempPluginDirPath : pluginFolder
139
+ } ;
140
+
141
+ const expectedAarName = "my_plugin.aar" ;
142
+ await androidBuildPluginService . buildAar ( config ) ;
143
+ const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
144
+
145
+ assert . equal ( hasGeneratedAar , true ) ;
146
+ } ) ;
147
+ } ) ;
148
+
149
+ describe ( `doesn't build aar ` , ( ) => {
150
+ it ( 'if there is only an android manifest file' , async ( ) => {
151
+ setUpPluginNativeFolder ( false , false , false ) ;
46
152
const config : IBuildOptions = {
47
- platformsAndroidDirPath : "string" ,
48
- pluginName : "string " ,
49
- aarOutputDir : "string" ,
50
- tempPluginDirPath : "string"
153
+ platformsAndroidDirPath : tempFolder ,
154
+ pluginName : "my-plugin " ,
155
+ aarOutputDir : tempFolder ,
156
+ tempPluginDirPath : pluginFolder
51
157
} ;
52
- androidBuildPluginService . buildAar ( config ) ;
158
+
53
159
const expectedAarName = "my_plugin.aar" ;
54
- assert . equal ( "asd" , expectedAarName ) ;
160
+ await androidBuildPluginService . buildAar ( config ) ;
161
+ const hasGeneratedAar = fs . exists ( path . join ( tempFolder , expectedAarName ) ) ;
162
+
163
+ assert . equal ( hasGeneratedAar , false ) ;
164
+ } ) ;
165
+ } ) ;
166
+
167
+ describe ( `handles include.gradle` , ( ) => {
168
+ it ( 'if there is a legacy include.gradle file' , async ( ) => {
169
+ setUpIncludeGradle ( ) ;
170
+ const config : IBuildOptions = {
171
+ platformsAndroidDirPath : pluginFolder ,
172
+ pluginName : "my-plugin" ,
173
+ aarOutputDir : pluginFolder ,
174
+ tempPluginDirPath : pluginFolder
175
+ } ;
176
+
177
+ const includeGradleName = "include.gradle" ;
178
+ await androidBuildPluginService . migrateIncludeGradle ( config ) ;
179
+ const includeGradleContent = fs . readText ( path . join ( pluginFolder , includeGradleName ) . toString ( ) ) ;
180
+ const productFlavorsAreRemoved = includeGradleContent . indexOf ( "productFlavors" ) === - 1 ;
181
+ assert . equal ( productFlavorsAreRemoved , true ) ;
55
182
} ) ;
56
183
} ) ;
57
184
} ) ;
0 commit comments