Browse Source

Integrated extraction of android.jar from Android SDK based on the implementation of the WALA gradle setup.

master
Achim D. Brucker 7 months ago
parent
commit
cee54c801c

+ 6
- 0
build.gradle View File

@@ -1,3 +1,9 @@
1
+plugins {
2
+	id 'de.undercouch.download'
3
+}
4
+
5
+
6
+
1 7
 allprojects  {
2 8
   apply plugin: 'maven'
3 9
 

+ 1
- 0
buildSrc/.gitignore View File

@@ -0,0 +1 @@
1
+/.gradle/

+ 7
- 0
buildSrc/build.gradle View File

@@ -0,0 +1,7 @@
1
+repositories {
2
+	mavenCentral()
3
+}
4
+
5
+dependencies {
6
+	compile 'de.undercouch:gradle-download-task:3.4.3'
7
+}

+ 31
- 0
buildSrc/src/main/groovy/package-list.groovy View File

@@ -0,0 +1,31 @@
1
+import org.gradle.api.tasks.*
2
+
3
+
4
+////////////////////////////////////////////////////////////////////////
5
+//
6
+//  create a Javadoc-style "package-list" file
7
+//
8
+
9
+@CacheableTask
10
+class CreatePackageList extends org.gradle.api.DefaultTask {
11
+
12
+	@PathSensitive(PathSensitivity.RELATIVE)
13
+	@Input Object sourceSet
14
+
15
+	@OutputFile File packageList = new File("$temporaryDir/package-list")
16
+
17
+	@TaskAction
18
+	def create() {
19
+		sourceSet.sourceCollections.collect { collection ->
20
+			def sourceRoot = collection.tree.dir.toPath()
21
+			collection.collect { source ->
22
+				def javaSourceFilePath = source.toPath()
23
+				def parentPath = javaSourceFilePath.parent
24
+				def relativePath = sourceRoot.relativize(parentPath)
25
+				relativePath.toString().replace(File.separator, '.')
26
+			}
27
+		}.flatten().sort().unique().each {
28
+			packageList << "$it\n"
29
+		}
30
+	}
31
+}

+ 53
- 0
buildSrc/src/main/groovy/verified-download.groovy View File

@@ -0,0 +1,53 @@
1
+import org.gradle.api.tasks.*
2
+
3
+
4
+////////////////////////////////////////////////////////////////////////
5
+//
6
+//  download and use checksum to verify that we got what we expected
7
+//
8
+
9
+@CacheableTask
10
+class VerifiedDownload extends org.gradle.api.DefaultTask {
11
+
12
+	// URL of resource to download
13
+	def @Input src
14
+
15
+	// expected checksum of resource as hex digits
16
+	def @Input checksum
17
+
18
+	// algorithm to use for computing checksum
19
+	def @Input algorithm = 'MD5'
20
+
21
+	// whether to use ETag for selective downloading
22
+	def @Input useETag = true
23
+
24
+	// local file into which resource should be saved
25
+	def @OutputFile dest
26
+
27
+	File getDest() {
28
+		return project.file(dest)
29
+	}
30
+
31
+	VerifiedDownload() {
32
+		outputs.upToDateWhen {
33
+			getDest().exists()
34
+		}
35
+	}
36
+
37
+	@TaskAction
38
+	downloadAndVerify() {
39
+		def destFile = getDest()
40
+		project.download {
41
+			src this.src
42
+			dest destFile
43
+			overwrite true
44
+			onlyIfModified true
45
+			useETag this.useETag
46
+		}
47
+		project.verifyChecksum {
48
+			src destFile
49
+			algorithm this.algorithm
50
+			checksum this.checksum
51
+		}
52
+	}
53
+}

+ 76
- 0
com.logicalhacking.dasca.crosslanguage.test/build.gradle View File

@@ -1,6 +1,80 @@
1 1
 apply plugin: 'scala'
2 2
 
3 3
 description = 'com.logicalhacking.dasca.crosslanguage.test'
4
+
5
+def osName = System.getProperty('os.name')
6
+ext.isWindows = osName.startsWith('Windows ')
7
+
8
+task downloadAndroidSdk(type: VerifiedDownload) {
9
+	def sdkOs
10
+	switch (osName) {
11
+		case ~/Linux/:
12
+			sdkOs = 'linux'
13
+			checksum '444e22ce8ca0f67353bda4b85175ed3731cae3ffa695ca18119cbacef1c1bea0'
14
+			break
15
+		case ~/Mac OS X/:
16
+			sdkOs = 'darwin'
17
+			checksum '4a81754a760fce88cba74d69c364b05b31c53d57b26f9f82355c61d5fe4b9df9'
18
+			break
19
+		case ~/Windows.*/:
20
+			sdkOs = 'windows'
21
+			checksum '7f6037d3a7d6789b4fdc06ee7af041e071e9860c51f66f7a4eb5913df9871fd2'
22
+			break
23
+	}
24
+	def archive = "sdk-tools-$sdkOs-3859397.zip"
25
+	src "https://dl.google.com/android/repository/$archive"
26
+	dest "$temporaryDir/$archive"
27
+	algorithm 'SHA-256'
28
+}
29
+
30
+task installAndroidSdk(type: Sync, dependsOn: downloadAndroidSdk) {
31
+	from zipTree(downloadAndroidSdk.dest)
32
+	into temporaryDir
33
+
34
+	def buildToolsVersion = '26.0.2'
35
+	ext {
36
+		components = [
37
+			'build-tools': buildToolsVersion,
38
+			'platforms': "android-${buildToolsVersion.tokenize('.')[0]}"
39
+		]
40
+	}
41
+
42
+	doLast {
43
+		exec {
44
+			def shell, shellFlags, yes, semicolon, discard
45
+			if (project.isWindows) {
46
+				shell = 'PowerShell'
47
+				shellFlags = '-Command'
48
+				yes = 'echo y'
49
+				semicolon = '`;'
50
+				discard = '$null'
51
+			} else {
52
+				shell = 'sh'
53
+				shellFlags = '-ceu'
54
+				yes = 'yes 2>/dev/null'
55
+				semicolon = /\;/
56
+				discard = '/dev/null'
57
+			}
58
+
59
+			def componentArgs = components.collect { "$it.key$semicolon$it.value" }.join ' '
60
+			commandLine shell, shellFlags, "$yes | $temporaryDir/tools/bin/sdkmanager $componentArgs >$discard"
61
+		}
62
+	}
63
+	outputs.cacheIf { true }
64
+}
65
+
66
+task copyAndroidJar(type: Sync, dependsOn: installAndroidSdk) {
67
+	from "${installAndroidSdk.destinationDir}/platforms/${installAndroidSdk.components['platforms']}/android.jar"
68
+        into temporaryDir
69
+}
70
+
71
+processResources {
72
+    with copySpec {
73
+        from copyAndroidJar
74
+        rename { "android-dasca.jar" }
75
+    }
76
+}
77
+
4 78
 dependencies {
5 79
     implementation group: 'org.scala-lang', name: 'scala-library', version:'2.12.3'
6 80
     implementation group: 'junit', name: 'junit', version: '4.12'
@@ -22,3 +96,5 @@ dependencies {
22 96
     testRuntime group: 'com.typesafe.scala-logging', name: 'scala-logging_2.12', version: '3.5.0'
23 97
     testRuntime group: 'apktool', name: 'apktool', version:'2.3.0'
24 98
 }
99
+
100
+

+ 6
- 5
com.logicalhacking.dasca.crosslanguage/src/main/scala/com/logicalhacking/dasca/crosslanguage/builder/CordovaCGBuilder.scala View File

@@ -159,13 +159,14 @@ class CordovaCGBuilder(val apk: File, val apkUnzipDir: File) {
159 159
   }
160 160
 
161 161
   private def createJavaCallGraph = {
162
-    val tmpAndroidJar = File.createTempFile("android", "jar")
162
+    val tmpAndroidJar = File.createTempFile("android-dasca", ".jar")
163 163
     tmpAndroidJar.deleteOnExit()
164
-    if (null != getClass.getClassLoader.getResource("android19.jar")){
165
-      TemporaryFile.urlToFile(tmpAndroidJar, getClass.getClassLoader.getResource("android19.jar"))
164
+    if (null != getClass.getClassLoader.getResource("android-dasca.jar")){
165
+      TemporaryFile.urlToFile(tmpAndroidJar, getClass.getClassLoader.getResource("android-dasca.jar"))
166 166
     }else{
167
-       logger.error("Please install android19.jar.");
168
-       throw new FileNotFoundException("Please install android19.jar.");
167
+       val msg = "Please install android-dasca.jar in resources directory."
168
+       logger.error(msg);
169
+       throw new FileNotFoundException(msg);
169 170
     }
170 171
     val scope = AndroidAnalysisScope.setUpAndroidAnalysisScope(apk.toURI(), getClass.getClassLoader.getResource("javaexclusions.txt").getFile, CordovaCGBuilder.getClass.getClassLoader())
171 172
     scope.addToScope(ClassLoaderReference.Primordial, new JarFileModule(new JarFile(tmpAndroidJar)))

Loading…
Cancel
Save