Skip to content

Commit 53cc589

Browse files
committed
added message if two classes will be generated with the same name
this problem is explained in detail in issue #692 also did a clean of generated bindings
1 parent fdd37c2 commit 53cc589

File tree

3 files changed

+17
-9
lines changed
  • android-static-binding-generator/project/staticbindinggenerator/src/main/java/org/nativescript/staticbindinggenerator
  • build-artifacts/project-template-gradle

3 files changed

+17
-9
lines changed

android-static-binding-generator/project/staticbindinggenerator/src/main/java/org/nativescript/staticbindinggenerator/Generator.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ public Generator(String outputDir, String[] libs, boolean throwOnError) throws I
4747

4848
public void writeBindings(String filename) throws IOException {
4949
Binding[] bindings = generateBindings(filename);
50-
50+
List<File> writenFiles = new ArrayList<File>();
5151
for (Binding b : bindings) {
52-
try (PrintStream ps = new PrintStream(b.getFile())) {
53-
ps.append(b.getContent());
52+
if(!writenFiles.contains(b.getFile())) {
53+
writenFiles.add(b.getFile());
54+
try (PrintStream ps = new PrintStream(b.getFile())) {
55+
ps.append(b.getContent());
56+
}
57+
}
58+
else {
59+
throw new IOException("Trying to write already written file. Both files will have the same file name, which will lead to undefined behavior.\nPlease change the name of one of those classes.\n" + b.getFile());
5460
}
5561
}
5662
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.nativescript.staticbindinggenerator;
22

3+
import java.io.IOException;
34
import java.util.Arrays;
45

56
public class Main {
6-
public static void main(String[] args) {
7-
try {
7+
public static void main(String[] args) throws IOException {
88
if (args.length < 3) {
99
throw new IllegalArgumentException("Expects at least three arguments");
1010
}
@@ -13,8 +13,5 @@ public static void main(String[] args) {
1313
String[] libs = Arrays.copyOfRange(args, 2, args.length);
1414

1515
new Generator(outputDir, libs).writeBindings(inputBindingFilename);
16-
} catch (Exception e) {
17-
e.printStackTrace();
18-
}
1916
}
2017
}

build-artifacts/project-template-gradle/build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,12 @@ task deleteConfigurations (type: Delete) {
721721
delete "$projectDir/configurations"
722722
}
723723

724+
task deleteGeneratedBindings(type: Delete) {
725+
delete "$projectDir/src/main/java/com/tns/gen"
726+
}
727+
724728
deleteMetadata.dependsOn(":asbg:clean")
725729
deleteFlavors.dependsOn(deleteMetadata)
726730
deleteConfigurations.dependsOn(deleteFlavors)
727-
clean.dependsOn(deleteConfigurations)
731+
deleteGeneratedBindings.dependsOn(deleteConfigurations)
732+
clean.dependsOn(deleteGeneratedBindings)

0 commit comments

Comments
 (0)