Skip to content

Commit 244f77d

Browse files
committed
Add jar files retrieval functionality
1 parent e940335 commit 244f77d

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,37 @@ By repeating the steps above we've found that:
8888
- Android support 23 typings(built with supper jar from android API 23) can be reused until android API 25
8989
- Android support 26 typings(built with supper jar from android API 26) can be reused for API 26 and 27
9090

91-
The corresponding typings files can be found in the [tns-platform-declarations](https://github.com/NativeScript/NativeScript/tree/master/tns-platform-declarations) package. The repo's [Makefile](Makefile) can be used as a reference for creating these typings files
91+
The corresponding typings files can be found in the [tns-platform-declarations](https://github.com/NativeScript/NativeScript/tree/master/tns-platform-declarations) package. The repo's [Makefile](Makefile) can be used as a reference for creating these typings files
92+
93+
## Finding package dependencies
94+
If you want to generate typings of a package but you are not sure how you can get all the needed dependencies you can follow the steps bellow:
95+
96+
1. Open [dts-generator/build.gradle](dts-generator/build.gradle) file and locate `dependencies` part.
97+
2. Add as a `testCompileOnly` dependency the one that you want to generate typings for:
98+
99+
```groovy
100+
dependencies {
101+
implementation 'org.apache.bcel:bcel:6.2'
102+
implementation 'commons-io:commons-io:2.6'
103+
implementation 'com.google.code.findbugs:findbugs:3.0.1'
104+
105+
// add your dependency bellow
106+
testCompileOnly "com.android.support:support-v4:27.0.1"
107+
}
108+
```
109+
110+
3. Open the [dts-generator](dts-generator) folder in your terminal
111+
4. Run the following command:
112+
113+
```
114+
./gradlew extractAllJars
115+
```
116+
117+
5. The command above will get the needed jar files for your dependency and will output them in the [dts-generator/jar-files](dts-generator/jar-files) folder
118+
6. You can run the following command to check what are the dependencies between the packages:
119+
120+
```
121+
./gradlew dependencies --configuration testCompileOnly
122+
```
123+
124+
7. Run the dts-generator tool passing as **input** arguments the jar files for the needed package from the [dts-generator/jar-files](dts-generator/jar-files) folder

dts-generator/build.gradle

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
apply plugin: 'java'
22

3+
project.ext.extractedDependenciesDir = "jar-files"
4+
if(project.hasProperty("jarsOutput")) {
5+
project.ext.extractedDependenciesDir = project.ext.jarsOutput
6+
}
7+
38
repositories {
49
google()
510
jcenter()
@@ -14,9 +19,12 @@ allprojects {
1419
}
1520

1621
dependencies {
17-
compile 'org.apache.bcel:bcel:6.2'
18-
compile 'commons-io:commons-io:2.6'
19-
compile 'com.google.code.findbugs:findbugs:3.0.1'
22+
implementation 'org.apache.bcel:bcel:6.2'
23+
implementation 'commons-io:commons-io:2.6'
24+
implementation 'com.google.code.findbugs:findbugs:3.0.1'
25+
26+
// add your dependency here as the example bellow
27+
// testCompileOnly "com.android.support:support-v4:27.0.1"
2028
}
2129

2230
jar {
@@ -35,3 +43,51 @@ task copyJarToBuildTools (type: Copy) {
3543
}
3644

3745
jar.finalizedBy(copyJarToBuildTools)
46+
47+
task extractAllJars {
48+
49+
outputs.dir extractedDependenciesDir
50+
51+
doLast {
52+
def iter = configurations.testCompileOnly.resolvedConfiguration.resolvedArtifacts.iterator()
53+
def dependencyCounter = 0
54+
while (iter.hasNext()) {
55+
//declaring variable as specific class for getting code completion in Android Studio
56+
org.gradle.api.internal.artifacts.DefaultResolvedArtifact nextDependency = iter.next()
57+
58+
def outputDir = java.nio.file.Paths.get(extractedDependenciesDir, nextDependency.toString()).normalize().toString()
59+
explodeAar(nextDependency.file, outputDir)
60+
dependencyCounter++
61+
}
62+
}
63+
}
64+
65+
def explodeAar(File compileDependency, String outputDir) {
66+
if (compileDependency.name.endsWith(".aar")) {
67+
java.util.jar.JarFile jar = new java.util.jar.JarFile(compileDependency)
68+
Enumeration enumEntries = jar.entries()
69+
while (enumEntries.hasMoreElements()) {
70+
java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement()
71+
if (file.name.endsWith(".jar")) {
72+
def f = new File(outputDir, file.name)
73+
new File(f.parent).mkdirs()
74+
InputStream is = jar.getInputStream(file)
75+
FileOutputStream fos = new FileOutputStream(f)
76+
while (is.available() > 0) {
77+
fos.write(is.read())
78+
}
79+
fos.close()
80+
is.close()
81+
}
82+
if (file.isDirectory()) {
83+
continue
84+
}
85+
}
86+
jar.close()
87+
} else if (compileDependency.name.endsWith(".jar")) {
88+
copy {
89+
from compileDependency.absolutePath
90+
into outputDir
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)