@@ -24,12 +24,24 @@ public LoadedModuleDependencies(Settings settings, List<ModuleDependency> depend
24
24
final ObjectMapper objectMapper = Utils .getObjectMapper ();
25
25
final Map <String , ModuleDependency > importFromMap = new LinkedHashMap <>();
26
26
final Map <String , ModuleDependency > importAsMap = new LinkedHashMap <>();
27
+ final Map <String , ModuleDependency > globalTypeNames = new LinkedHashMap <>();
27
28
for (ModuleDependency dependency : dependencies ) {
28
29
try {
29
30
final Function <String , String > reportNullParameter = parameterName ->
30
31
String .format ("Missing required configuration parameter '%s' in module dependency: %s" , parameterName , dependency );
31
- Objects .requireNonNull (dependency .importFrom , () -> reportNullParameter .apply ("importFrom" ));
32
- Objects .requireNonNull (dependency .importAs , () -> reportNullParameter .apply ("importAs" ));
32
+ if (dependency .global ) {
33
+ if (dependency .importFrom != null ) {
34
+ throw new RuntimeException (String .format (
35
+ "'importFrom' parameter is only applicable when 'global' is not set to 'true' (at module dependency %s)." , dependency ));
36
+ }
37
+ if (dependency .importAs != null ) {
38
+ throw new RuntimeException (String .format (
39
+ "'importAs' parameter is only applicable when 'global' is not set to 'true' (at module dependency %s)." , dependency ));
40
+ }
41
+ } else {
42
+ Objects .requireNonNull (dependency .importFrom , () -> reportNullParameter .apply ("importFrom" ));
43
+ Objects .requireNonNull (dependency .importAs , () -> reportNullParameter .apply ("importAs" ));
44
+ }
33
45
Objects .requireNonNull (dependency .infoJson , () -> reportNullParameter .apply ("infoJson" ));
34
46
if (settings .generateNpmPackageJson ) {
35
47
Objects .requireNonNull (dependency .npmPackageName , () -> reportNullParameter .apply ("npmPackageName" ));
@@ -46,27 +58,36 @@ public LoadedModuleDependencies(Settings settings, List<ModuleDependency> depend
46
58
}
47
59
48
60
TypeScriptGenerator .getLogger ().info (String .format (
49
- "Loading '%s' module info from: %s" , dependency .importFrom , dependency .infoJson ));
61
+ "Loading %s module info from: %s" , dependency .toShortString () , dependency .infoJson ));
50
62
51
- final ModuleDependency importFromConflict = importFromMap .put (dependency .importFrom , dependency );
52
- if (importFromConflict != null ) {
53
- throw new RuntimeException (String .format ("Duplicate module '%s'" , dependency .importFrom ));
54
- }
63
+ if (!dependency .global ) {
64
+ final ModuleDependency importFromConflict = importFromMap .put (dependency .importFrom , dependency );
65
+ if (importFromConflict != null ) {
66
+ throw new RuntimeException (String .format ("Duplicate module '%s'" , dependency .importFrom ));
67
+ }
55
68
56
- final ModuleDependency importAsConflict = importAsMap .put (dependency .importAs , dependency );
57
- if (importAsConflict != null ) {
58
- throw new RuntimeException (String .format ("Import identifier '%s' already used for module '%s'" , dependency .importAs , importAsConflict .importFrom ));
69
+ final ModuleDependency importAsConflict = importAsMap .put (dependency .importAs , dependency );
70
+ if (importAsConflict != null ) {
71
+ throw new RuntimeException (String .format ("Import identifier '%s' already used for module '%s'" , dependency .importAs , importAsConflict .importFrom ));
72
+ }
59
73
}
60
74
61
75
final InfoJson infoJson = objectMapper .readValue (dependency .infoJson , InfoJson .class );
62
76
for (InfoJson .ClassInfo classInfo : infoJson .classes ) {
63
77
final Pair <ModuleDependency , String > presentMapping = classMappings .get (classInfo .javaClass );
64
78
if (presentMapping != null ) {
65
79
TypeScriptGenerator .getLogger ().warning (String .format (
66
- "Java class '%s' already present in module '%s'" , classInfo .javaClass , presentMapping .getValue1 ().importFrom ));
80
+ "Java class '%s' already present in '%s'" , classInfo .javaClass , presentMapping .getValue1 ().infoJson ));
67
81
} else {
68
82
classMappings .put (classInfo .javaClass , Pair .of (dependency , classInfo .typeName ));
69
83
}
84
+ final ModuleDependency presentTypeName = globalTypeNames .get (classInfo .typeName );
85
+ if (presentTypeName != null ) {
86
+ throw new RuntimeException (String .format (
87
+ "Duplicate TypeScript global name '%s', declared in '%s' and also '%s'" , classInfo .typeName , presentTypeName .infoJson , dependency .infoJson ));
88
+ } else {
89
+ globalTypeNames .put (classInfo .typeName , dependency );
90
+ }
70
91
}
71
92
} catch (IOException e ) {
72
93
throw new RuntimeException (e );
0 commit comments