Skip to content

Commit 6f59201

Browse files
committed
input now supports folders with jars
1 parent 244f77d commit 6f59201

File tree

6 files changed

+54
-65
lines changed

6 files changed

+54
-65
lines changed

Makefile

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,20 @@ android-platform-all: android-platform-17 android-platform-18 android-platform-1
4747

4848
android-support-17:
4949
java -jar dts-generator/build/libs/dts-generator.jar \
50-
-input libs/android-support/27.0.1/android-support-v4.jar \libs/android-support/27.0.1/android-support-design.jar \
51-
libs/android-support/27.0.1/android-support-v7-appcompat.jar libs/android-support/27.0.1/android-support-core-ui.jar \
52-
libs/android-support/27.0.1/android-support-recyclerview-v7.jar libs/android-support/27.0.1/android-support-transition.jar \
53-
libs/android-support/27.0.1/android-support-media-compat.jar libs/android-support/27.0.1/android-support-fragment.jar \
54-
libs/android-support/27.0.1/android-support-core-utils.jar libs/android-support/27.0.1/android-support-animated-vector-drawable.jar \
55-
libs/android-support/27.0.1/android-support-vector-drawable.jar libs/android-support/27.0.1/android-support-compat.jar \
56-
libs/android-support/27.0.1/android-support-annotations.jar libs/android-support/27.0.1/android-support-multidex.jar \
57-
-input-generics libs/generics.txt -super /Users/trifonov/Library/Android/sdk/platforms/android-17/android.jar -skip-declarations
50+
-input libs/android-support/27.0.1 -input-generics libs/generics.txt \
51+
-super /Users/trifonov/Library/Android/sdk/platforms/android-17/android.jar -skip-declarations
5852
mv out/android.d.ts out/android-support-17.d.ts
5953

6054
android-support-23:
6155
java -jar dts-generator/build/libs/dts-generator.jar \
62-
-input libs/android-support/27.0.1/android-support-v4.jar \libs/android-support/27.0.1/android-support-design.jar \
63-
libs/android-support/27.0.1/android-support-v7-appcompat.jar libs/android-support/27.0.1/android-support-core-ui.jar \
64-
libs/android-support/27.0.1/android-support-recyclerview-v7.jar libs/android-support/27.0.1/android-support-transition.jar \
65-
libs/android-support/27.0.1/android-support-media-compat.jar libs/android-support/27.0.1/android-support-fragment.jar \
66-
libs/android-support/27.0.1/android-support-core-utils.jar libs/android-support/27.0.1/android-support-animated-vector-drawable.jar \
67-
libs/android-support/27.0.1/android-support-vector-drawable.jar libs/android-support/27.0.1/android-support-compat.jar \
68-
libs/android-support/27.0.1/android-support-annotations.jar libs/android-support/27.0.1/android-support-multidex.jar \
69-
-input-generics libs/generics.txt -super /Users/trifonov/Library/Android/sdk/platforms/android-23/android.jar -skip-declarations
56+
-input libs/android-support/27.0.1 -input-generics libs/generics.txt \
57+
-super /Users/trifonov/Library/Android/sdk/platforms/android-23/android.jar -skip-declarations
7058
mv out/android.d.ts out/android-support-23.d.ts
7159

7260
android-support-26:
7361
java -jar dts-generator/build/libs/dts-generator.jar \
74-
-input libs/android-support/27.0.1/android-support-v4.jar \libs/android-support/27.0.1/android-support-design.jar \
75-
libs/android-support/27.0.1/android-support-v7-appcompat.jar libs/android-support/27.0.1/android-support-core-ui.jar \
76-
libs/android-support/27.0.1/android-support-recyclerview-v7.jar libs/android-support/27.0.1/android-support-transition.jar \
77-
libs/android-support/27.0.1/android-support-media-compat.jar libs/android-support/27.0.1/android-support-fragment.jar \
78-
libs/android-support/27.0.1/android-support-core-utils.jar libs/android-support/27.0.1/android-support-animated-vector-drawable.jar \
79-
libs/android-support/27.0.1/android-support-vector-drawable.jar libs/android-support/27.0.1/android-support-compat.jar \
80-
libs/android-support/27.0.1/android-support-annotations.jar libs/android-support/27.0.1/android-support-multidex.jar \
81-
-input-generics libs/generics.txt -super /Users/trifonov/Library/Android/sdk/platforms/android-26/android.jar -skip-declarations
62+
-input libs/android-support/27.0.1 -input-generics libs/generics.txt \
63+
-super /Users/trifonov/Library/Android/sdk/platforms/android-26/android.jar -skip-declarations
8264
mv out/android.d.ts out/android-support-26.d.ts
8365

8466
android-support-all: android-support-17 android-support-23 android-support-26

README.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,6 @@ There are two type of dependencies that can be passed:
6262
## Adding all implements for generic types
6363
There is an option **all-generic-implements** which is disabled by default which controls whether to add implements for all interfaces (if they are more than one) to generic type declarations. The problem is that in most of the cases one of those interfaces is actually an extend, so it should be manual reviewed and fixed after generation.
6464

65-
## Android support specifics
66-
One of the ways to get the android support jar files is to follow the steps bellow:
67-
68-
1. Create a NativeScript application - `tns create android-support-files`
69-
2. Add android platform - `tns platform add android`
70-
3. Open **platforms/android/app/build.graddle** file and locate the **explodeAar** task
71-
4. Add a print on the first line of the task `println "${compileDependency} copied to ${outputDir}"`
72-
5. Run `tns build android` and look for the lines from the output above
73-
6. Search for all files containing **android/support** or **android.support** in their path and get their corresponding jar files from the **platform/android/app/build/exploded-dependencies** folder
74-
7. To generate android support typings run the tool passing all the files from above
75-
8. You can find the **jar** files for android support 27.0.1 in [the current repository](libs/android-support/27.0.1)
76-
77-
As the android support needs the base android jar file to create its typings you need to pass the android.jar file as a **super** parameter to the generator. To avoid having typings for every different API level you can reuse typings built with API level 17 for all API levels until 23. It's quite easy to test this:
78-
79-
1. Run the typings generator for android support passing **android-17/android.jar** as a supper jar
80-
2. Add `/// <reference path="android-17.d.ts"/>` at the top of the generated typings file where android-17.d.ts is the typings file of the android API level 17
81-
3. Run `tsc` passing the generated typings file and there shouldn't be errors
82-
4. Now start replacing the reference file with the files from other API level while the `tsc` execution completes with no error
83-
5. If there's an error this means that you need to generate the android support typings with the same android API level super jar
84-
85-
By repeating the steps above we've found that:
86-
87-
- Android support 17 typings(built with supper jar from android API 17) can be reused until android API 22
88-
- Android support 23 typings(built with supper jar from android API 23) can be reused until android API 25
89-
- Android support 26 typings(built with supper jar from android API 26) can be reused for API 26 and 27
90-
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-
9365
## Finding package dependencies
9466
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:
9567

@@ -114,11 +86,29 @@ If you want to generate typings of a package but you are not sure how you can ge
11486
./gradlew extractAllJars
11587
```
11688
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
89+
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 (or you can optionaly pass another output folder `-PjarsOutput=another-folder`)
11890
6. You can run the following command to check what are the dependencies between the packages:
11991
12092
```
12193
./gradlew dependencies --configuration testCompileOnly
12294
```
12395
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
96+
7. Run the dts-generator tool passing as **input** arguments the path to the output jars folder
97+
98+
## Android support specifics
99+
To get all the jar files for android support follow the steps above. You can find the **jar** files for android support 27.0.1 in [the current repository](libs/android-support/27.0.1)
100+
As the android support needs the base android jar file to create its typings you need to pass the android.jar file as a **super** parameter to the generator. To avoid having typings for every different API level you can reuse typings built with API level 17 for all API levels until 23. It's quite easy to test this:
101+
102+
1. Run the typings generator for android support passing **android-17/android.jar** as a supper jar
103+
2. Add `/// <reference path="android-17.d.ts"/>` at the top of the generated typings file where android-17.d.ts is the typings file of the android API level 17
104+
3. Run `tsc` passing the generated typings file and there shouldn't be errors
105+
4. Now start replacing the reference file with the files from other API level while the `tsc` execution completes with no error
106+
5. If there's an error this means that you need to generate the android support typings with the same android API level super jar
107+
108+
By repeating the steps above we've found that:
109+
110+
- Android support 17 typings(built with supper jar from android API 17) can be reused until android API 22
111+
- Android support 23 typings(built with supper jar from android API 23) can be reused until android API 25
112+
- Android support 26 typings(built with supper jar from android API 26) can be reused for API 26 and 27
113+
114+
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

dts-generator/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ allprojects {
1919
}
2020

2121
dependencies {
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'
22+
compile 'org.apache.bcel:bcel:6.2'
23+
compile 'commons-io:commons-io:2.6'
24+
compile 'com.google.code.findbugs:findbugs:3.0.1'
2525

26-
// add your dependency here as the example bellow
26+
// add your dependency here as the example bellow, make sure you are using testCompileOnly
2727
// testCompileOnly "com.android.support:support-v4:27.0.1"
2828
}
2929

dts-generator/src/main/java/com/telerik/InputParameters.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ public class InputParameters {
1515
private File inputGenerics;
1616
private boolean allGenericImplements;
1717
private boolean skipDeclarations;
18+
private boolean classMode;
1819

1920
public InputParameters() {
2021
this.outputDir = new File("out");
2122
this.inputJars = new ArrayList<>();
2223
this.superJars = new ArrayList<>();
2324
this.allGenericImplements = false;
2425
this.skipDeclarations = false;
26+
this.classMode = false;
2527
}
2628

2729
public File getOutputDir() {
@@ -56,7 +58,9 @@ public boolean isAllGenericImplementsEnabled() {
5658

5759
public boolean getSkipDeclarations() { return skipDeclarations; }
5860

59-
public void setAllGenericImplements(boolean allGenericImplements) {
60-
this.allGenericImplements = allGenericImplements;
61-
}
61+
public void setAllGenericImplements(boolean allGenericImplements) { this.allGenericImplements = allGenericImplements; }
62+
63+
public boolean getClassMode() { return this.classMode; }
64+
65+
public void setClassMode(boolean classMode) { this.classMode = classMode; }
6266
}

dts-generator/src/main/java/com/telerik/Main.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Main {
1111
private static final String OUT_DIR = "-output";
1212
private static final String INPUT_JARS = "-input";
1313
private static final String SUPER_JARS = "-super";
14+
private static final String CLASS_MODE = "-class-mode";
1415

1516
// provide a file with rows in the following format - com.telerik.android.data.SelectionService:1
1617
// to know how many generic types uses a given generic
@@ -55,6 +56,10 @@ public static InputParameters parseCommand(String[] args) throws Exception {
5556
inputParameters.setSkipDeclarations(true);
5657
}
5758

59+
if (commandArg.equals(CLASS_MODE)) {
60+
inputParameters.setClassMode(true);
61+
}
62+
5863
if (commandArg.equals(OUT_DIR)) {
5964
if (i != (args.length - 1)) {
6065
String nextParam = args[i + 1];
@@ -105,13 +110,14 @@ private static void printHelpMessage() {
105110
helpMessage.appendln("usage: java -jar dts-generator.jar <flag> [<args>]");
106111
helpMessage.appendln("flags:\t\t");
107112
helpMessage.appendln("\t(Optional)");
108-
helpMessage.appendln("\t\t[-output <path>]:\tThe direcory the d.ts files will be generated in.");
113+
helpMessage.appendln("\t\t[-output <path>]:\t\tThe direcory the d.ts files will be generated in.");
109114
helpMessage.appendln("\t\t[-input]:\t\tThe input jars or class directories from which the d.ts files will be generated.");
110115
helpMessage.appendln("\t\t[-super]:\t\tProvide jar files from which to search for super classes.");
111116
helpMessage.appendln("\t\t[-input-generics]:\tProvide a file with information for number of generic types per given generic class name.");
112-
helpMessage.appendln("\t\t[-all-generic-implements]:\tAdd this flag to generate implements for all interfaces implemented by the generic types." +
117+
helpMessage.appendln("\t\t[-all-generic-implements]:\t\tAdd this flag to generate implements for all interfaces implemented by the generic types." +
113118
" It is not enabled by default as when there are more than one implementation most probably one of them needs to be changed to extends, but this have to be made manually");
114119
helpMessage.appendln("\t\t[-skip-declarations]:\t\tProvide this flag if you don't want android-declarations.d.ts file to be generated and referenced.");
120+
helpMessage.appendln("\t\t[--class-mode]:\t\tPass this argument if you want folders to be processed as class folders.");
115121
helpMessage.appendln("\t\t[-help]:\t\tPrints this help message.");
116122

117123
System.out.println(helpMessage);

dts-generator/src/main/java/com/telerik/dts/Generator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.nio.file.Files;
1010
import java.util.ArrayList;
11+
import java.util.Arrays;
1112
import java.util.List;
1213

1314
/**
@@ -20,13 +21,15 @@ public class Generator {
2021
private DtsApi dtsApi;
2122
private boolean allGenericImplements;
2223
private boolean skipDeclarations;
24+
private boolean classMode;
2325
private String outFileName;
2426
private String declarationsFileName;
2527

2628
public void start(InputParameters inputParameters) throws Exception {
2729
Generator.inputGenericsFile = inputParameters.getInputGenerics();
2830
this.allGenericImplements = inputParameters.isAllGenericImplementsEnabled();
2931
this.skipDeclarations = inputParameters.getSkipDeclarations();
32+
this.classMode = inputParameters.getClassMode();
3033
this.fileHelper = new FileHelper(inputParameters.getOutputDir());
3134
this.dtsApi = new DtsApi(allGenericImplements);
3235
this.outFileName = FileHelper.DEFAULT_DTS_FILE_NAME;
@@ -95,8 +98,12 @@ private void loadJavaClasses(List<File> jars) throws IOException {
9598
JarFile jar = JarFile.readJar(file.getAbsolutePath());
9699
ClassRepo.cacheJarFile(jar);
97100
} else if (file.isDirectory()) {
98-
ClassDirectrory dir = ClassDirectrory.readDirectory(file.getAbsolutePath());
99-
ClassRepo.cacheJarFile(dir);
101+
if(this.classMode) {
102+
ClassDirectrory dir = ClassDirectrory.readDirectory(file.getAbsolutePath());
103+
ClassRepo.cacheJarFile(dir);
104+
} else {
105+
loadJavaClasses(Arrays.asList(file.listFiles()));
106+
}
100107
}
101108
} else {
102109
throw new IOException(String.format("File %s does not exist", file.getName()));

0 commit comments

Comments
 (0)