/
importFlashBuilderProject.ts
1221 lines (1158 loc) · 35.5 KB
/
importFlashBuilderProject.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2016-2024 Bowler Hat LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as vscode from "vscode";
import * as fs from "fs";
import * as path from "path";
import { parseXml } from "@rgrove/parse-xml";
import validateFrameworkSDK from "../utils/validateFrameworkSDK";
const FILE_ASCONFIG_JSON = "asconfig.json";
const FILE_ACTIONSCRIPT_PROPERTIES = ".actionScriptProperties";
const FILE_FLEX_PROPERTIES = ".flexProperties";
const FILE_FLEX_LIB_PROPERTIES = ".flexLibProperties";
const PATH_FLASH_BUILDER_WORKSPACE_SDK_PREFS =
"../.metadata/.plugins/org.eclipse.core.runtime/.settings/com.adobe.flexbuilder.project.prefs";
const PATH_FLASH_BUILDER_WORKSPACE_RESOURCES_PREFS =
"../.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs";
const FILE_EXTENSION_SWF = ".swf";
const FILE_EXTENSION_SWC = ".swc";
const TOKEN_SDKS_PREF = "com.adobe.flexbuilder.project.flex_sdks=";
const TOKEN_PATHVARIABLE_PREF = "pathvariable.";
const MESSAGE_IMPORT_START = "🚀 Importing Adobe Flash Builder project...";
const MESSAGE_IMPORT_COMPLETE = "✅ Import complete.";
const MESSAGE_IMPORT_FAILED = "❌ Import failed.";
const ERROR_NO_FOLDER = "Workspace folder parameter is missing.";
const ERROR_NO_PROJECTS = "No Adobe Flash Builder projects found in workspace.";
const ERROR_FILE_READ = "Failed to read file: ";
const ERROR_XML_PARSE =
"Failed to parse Adobe Flash Builder project. Invalid XML in file: ";
const ERROR_PROJECT_PARSE = "Failed to parse Adobe Flash Builder project.";
const ERROR_CANNOT_FIND_SDKS =
"Failed to parse SDKs in Adobe Flash Builder workspace.";
const ERROR_ASCONFIG_JSON_EXISTS =
"Cannot migrate Adobe Flash Builder project because configuration file already exists... ";
const WARNING_CANNOT_FIND_LINKED_RESOURCES =
"Failed to parse linked resources in Adobe Flash Builder workspace. Result may contain path tokens that must be replaced.";
const WARNING_WORKER = "ActionScript workers are not supported. Skipping... ";
const WARNING_EXTERNAL_THEME =
"Themes from outside SDK are not supported. Skipping...";
const WARNING_BLACKBERRY =
"The BlackBerry platform is not supported. Skipping... ";
const CHANNEL_NAME_IMPORTER = "Flash Builder Importer";
interface FlashBuilderSDK {
name: string;
location: string;
flashSDK: boolean;
defaultSDK: boolean;
}
interface EclipseLinkedResource {
name: string;
path: string;
}
export function isFlashBuilderProject(folder: vscode.WorkspaceFolder) {
let asPropsPath = path.resolve(
folder.uri.fsPath,
FILE_ACTIONSCRIPT_PROPERTIES
);
return fs.existsSync(asPropsPath) && !fs.statSync(asPropsPath).isDirectory();
}
export function importFlashBuilderProject(
workspaceFolder: vscode.WorkspaceFolder
) {
getOutputChannel().clear();
getOutputChannel().appendLine(MESSAGE_IMPORT_START);
getOutputChannel().show(true);
let result = importFlashBuilderProjectInternal(workspaceFolder);
if (result) {
getOutputChannel().appendLine(MESSAGE_IMPORT_COMPLETE);
} else {
getOutputChannel().appendLine(MESSAGE_IMPORT_FAILED);
}
}
function findLinkedResources(
workspaceFolder: vscode.WorkspaceFolder
): EclipseLinkedResource[] {
let result: EclipseLinkedResource[] = [];
let resourcePrefsPath = path.resolve(
workspaceFolder.uri.fsPath,
PATH_FLASH_BUILDER_WORKSPACE_RESOURCES_PREFS
);
if (!fs.existsSync(resourcePrefsPath)) {
return result;
}
try {
let resourcesPrefsText = null;
try {
resourcesPrefsText = fs.readFileSync(resourcePrefsPath, "utf8");
} catch (error) {
addWarning(ERROR_FILE_READ + resourcePrefsPath);
return result;
}
let startIndex = resourcesPrefsText.indexOf(TOKEN_PATHVARIABLE_PREF);
if (startIndex === -1) {
return result;
}
do {
startIndex += TOKEN_PATHVARIABLE_PREF.length;
let endIndex = resourcesPrefsText.indexOf("\n", startIndex);
if (endIndex === -1) {
break;
}
let pathVar = resourcesPrefsText.substr(
startIndex,
endIndex - startIndex
);
let pathVarParts = pathVar.split("=");
if (pathVarParts.length != 2) {
//we couldn't parse this one for some reason
continue;
}
let pathVarName = pathVarParts[0];
let pathVarPath = pathVarParts[1];
pathVarPath = pathVarPath.replace(/\\:/g, ":");
pathVarPath = pathVarPath.replace(/\r/g, "");
if (pathVarName === "DOCUMENTS" && path.isAbsolute(pathVarPath)) {
//special case: it's better to make this one a relative path
//instead of leaving it as absolute
pathVarPath = path.relative(workspaceFolder.uri.fsPath, pathVarPath);
}
result.push({ name: pathVarName, path: pathVarPath });
startIndex = endIndex;
startIndex = resourcesPrefsText.indexOf(
TOKEN_PATHVARIABLE_PREF,
startIndex
);
} while (startIndex !== -1);
} catch (error) {
return [];
}
return result;
}
function findSDKs(workspaceFolder: vscode.WorkspaceFolder): FlashBuilderSDK[] {
let sdkPrefsPath = path.resolve(
workspaceFolder.uri.fsPath,
PATH_FLASH_BUILDER_WORKSPACE_SDK_PREFS
);
if (!fs.existsSync(sdkPrefsPath)) {
return [];
}
let sdksElement = null;
try {
let sdkPrefsText = null;
try {
sdkPrefsText = fs.readFileSync(sdkPrefsPath, "utf8");
} catch (error) {
addWarning(ERROR_FILE_READ + sdkPrefsPath);
return [];
}
let startIndex = sdkPrefsText.indexOf(TOKEN_SDKS_PREF);
if (startIndex === -1) {
return [];
}
startIndex += TOKEN_SDKS_PREF.length;
let endIndex = sdkPrefsText.indexOf("\n", startIndex);
if (endIndex === -1) {
return [];
}
sdkPrefsText = sdkPrefsText.substr(startIndex, endIndex - startIndex);
sdkPrefsText = sdkPrefsText.replace(/\\r/g, "\r");
sdkPrefsText = sdkPrefsText.replace(/\\n/g, "\n");
sdkPrefsText = sdkPrefsText.replace(/\\(.)/g, (match, p1) => {
return p1;
});
sdksElement = parseXml(sdkPrefsText);
} catch (error) {
return [];
}
let rootElement = sdksElement.children[0];
let rootChildren = rootElement.children;
return rootChildren
.filter((child) => {
if (child.type !== "element" || child.name !== "sdk") {
return false;
}
let attributes = child.attributes;
return (
"name" in attributes &&
"location" in attributes &&
"flashSDK" in attributes
);
})
.map((child) => {
let sdkAttributes = child.attributes;
return {
name: sdkAttributes.name,
location: sdkAttributes.location,
flashSDK: sdkAttributes.flashSDK === "true",
defaultSDK: sdkAttributes.defaultSDK === "true",
};
});
}
function importFlashBuilderProjectInternal(
workspaceFolder: vscode.WorkspaceFolder
): boolean {
if (!workspaceFolder) {
addError(ERROR_NO_FOLDER);
return false;
}
let folderPath = workspaceFolder.uri.fsPath;
let actionScriptPropertiesPath = path.resolve(
folderPath,
FILE_ACTIONSCRIPT_PROPERTIES
);
if (!fs.existsSync(actionScriptPropertiesPath)) {
addError(ERROR_NO_PROJECTS);
return false;
}
let asconfigPath = path.resolve(folderPath, FILE_ASCONFIG_JSON);
if (fs.existsSync(asconfigPath)) {
addError(ERROR_ASCONFIG_JSON_EXISTS + FILE_ASCONFIG_JSON);
return false;
}
let flexPropertiesPath = path.resolve(folderPath, FILE_FLEX_PROPERTIES);
let isFlexApp = fs.existsSync(flexPropertiesPath);
let flexLibPropertiesPath = path.resolve(
folderPath,
FILE_FLEX_LIB_PROPERTIES
);
let isFlexLibrary = fs.existsSync(flexLibPropertiesPath);
let actionScriptPropertiesText = null;
try {
actionScriptPropertiesText = fs.readFileSync(
actionScriptPropertiesPath,
"utf8"
);
} catch (error) {
addError(ERROR_FILE_READ + actionScriptPropertiesPath);
return false;
}
let actionScriptProperties = null;
try {
let parsedXML = parseXml(actionScriptPropertiesText);
actionScriptProperties = parsedXML.children[0];
} catch (error) {
addError(ERROR_XML_PARSE + actionScriptPropertiesPath);
return false;
}
let linkedResources = null;
try {
linkedResources = findLinkedResources(workspaceFolder);
} catch (error) {
addWarning(WARNING_CANNOT_FIND_LINKED_RESOURCES);
if (error instanceof Error) {
getOutputChannel().appendLine(error.stack);
}
linkedResources = [];
}
//these are built-in linked resources that cannot be configured by the user
linkedResources.push({ name: "PROJECT_FRAMEWORKS", path: "${flexlib}" });
linkedResources.push({ name: "SDK_THEMES_DIR", path: "${flexlib}/.." });
let sdks = null;
try {
sdks = findSDKs(workspaceFolder);
} catch (error) {
addError(ERROR_CANNOT_FIND_SDKS);
if (error instanceof Error) {
getOutputChannel().appendLine(error.stack);
}
return false;
}
try {
let result = createProjectFiles(
folderPath,
actionScriptProperties,
sdks,
linkedResources,
isFlexApp,
isFlexLibrary
);
if (!result) {
return false;
}
} catch (error) {
addError(ERROR_PROJECT_PARSE);
if (error instanceof Error) {
getOutputChannel().appendLine(error.stack);
}
return false;
}
return true;
}
let outputChannel: vscode.OutputChannel;
function getOutputChannel() {
if (!outputChannel) {
outputChannel = vscode.window.createOutputChannel(CHANNEL_NAME_IMPORTER);
}
return outputChannel;
}
function addWarning(message: string) {
getOutputChannel().appendLine("🚧 " + message);
}
function addError(message: string) {
getOutputChannel().appendLine("⛔ " + message);
}
function findApplications(actionScriptProperties: any) {
if (!actionScriptProperties) {
return [];
}
let rootChildren = actionScriptProperties.children as any[];
if (!rootChildren) {
return [];
}
let applicationsElement = findChildElementByName(
rootChildren,
"applications"
);
if (!applicationsElement) {
return [];
}
let appChildren = applicationsElement.children as any[];
if (!appChildren) {
return [];
}
return appChildren.filter((child) => {
return child.type === "element" && child.name === "application";
});
}
function findMainApplicationPath(actionScriptProperties: any) {
let attributes = actionScriptProperties.attributes;
if (!attributes) {
return null;
}
return attributes.mainApplicationPath;
}
function getApplicationNameFromPath(appPath: string) {
appPath = path.basename(appPath);
return appPath.substr(0, appPath.length - path.extname(appPath).length);
}
function createProjectFiles(
folderPath: string,
actionScriptProperties: any,
sdks: FlashBuilderSDK[],
linkedResources: EclipseLinkedResource[],
isFlexApp: boolean,
isFlexLibrary: boolean
) {
let mainAppPath = findMainApplicationPath(actionScriptProperties);
let applications = findApplications(actionScriptProperties);
return applications.every((application) => {
let appPath = application.attributes.path;
let appName = getApplicationNameFromPath(appPath);
let fileName = FILE_ASCONFIG_JSON;
if (appPath !== mainAppPath && applications.length > 1) {
fileName = "asconfig." + appName + ".json";
}
let asconfigPath = path.resolve(folderPath, fileName);
if (fs.existsSync(asconfigPath)) {
addError(ERROR_ASCONFIG_JSON_EXISTS + fileName);
return false;
}
let result: any = {
compilerOptions: {},
};
if (isFlexLibrary) {
result.type = "lib";
} else {
result.files = [];
}
migrateActionScriptProperties(
application,
actionScriptProperties,
isFlexApp,
isFlexLibrary,
sdks,
linkedResources,
result
);
if (isFlexLibrary) {
let flexLibPropertiesPath = path.resolve(
folderPath,
FILE_FLEX_LIB_PROPERTIES
);
let flexLibPropertiesText = null;
try {
flexLibPropertiesText = fs.readFileSync(flexLibPropertiesPath, "utf8");
} catch (error) {
addError(ERROR_FILE_READ + flexLibPropertiesPath);
return false;
}
let flexLibProperties = null;
try {
let parsedXML = parseXml(flexLibPropertiesText);
flexLibProperties = parsedXML.children[0];
} catch (error) {
addError(ERROR_PROJECT_PARSE);
if (error instanceof Error) {
getOutputChannel().appendLine(error.stack);
}
return false;
}
migrateFlexLibProperties(
flexLibProperties,
folderPath,
linkedResources,
result
);
}
let resultText = JSON.stringify(result, undefined, "\t");
fs.writeFileSync(asconfigPath, resultText);
vscode.workspace.openTextDocument(asconfigPath).then((document) => {
vscode.window.showTextDocument(document);
});
getOutputChannel().appendLine(appName + " ➡ " + fileName);
return true;
});
}
function migrateFlexLibProperties(
flexLibProperties: any,
folderPath: string,
linkedResources: EclipseLinkedResource[],
result: any
) {
let rootChildren = flexLibProperties.children as any[];
if (!rootChildren) {
return null;
}
let rootAttributes = flexLibProperties.attributes;
if (!rootAttributes) {
return null;
}
let includeAllClasses = false;
if (
"includeAllClasses" in rootAttributes &&
rootAttributes.includeAllClasses === "true"
) {
includeAllClasses = true;
let includeSources = result.compilerOptions["include-sources"] || [];
let sourcePaths = result.compilerOptions["source-path"] || [];
includeSources = includeSources.concat(sourcePaths);
if (includeSources.length > 0) {
result.compilerOptions["include-sources"] = includeSources;
}
}
if (!includeAllClasses) {
let includeClassesElement = findChildElementByName(
rootChildren,
"includeClasses"
);
if (includeClassesElement) {
migrateIncludeClassesElement(
includeClassesElement,
linkedResources,
result
);
}
}
let includeResourcesElement = findChildElementByName(
rootChildren,
"includeResources"
);
if (includeResourcesElement) {
migrateIncludeResourcesElement(includeResourcesElement, folderPath, result);
}
let namespaceManifestsElement = findChildElementByName(
rootChildren,
"namespaceManifests"
);
if (namespaceManifestsElement) {
migrateNamespaceManifestsElement(
namespaceManifestsElement,
folderPath,
result
);
}
}
function migrateActionScriptProperties(
application: any,
actionScriptProperties: any,
isFlexApp: boolean,
isFlexLibrary: boolean,
sdks: FlashBuilderSDK[],
linkedResources: EclipseLinkedResource[],
result: any
) {
let rootChildren = actionScriptProperties.children as any[];
if (!rootChildren) {
return null;
}
let rootAttributes = actionScriptProperties.attributes;
if (!rootAttributes) {
return null;
}
let appAttributes = application.attributes;
if (!appAttributes) {
return null;
}
let applicationPath = null;
if ("path" in appAttributes) {
applicationPath = appAttributes.path;
}
if (!applicationPath) {
applicationPath = isFlexApp ? "MyProject.mxml" : "MyProject.as";
}
let compilerElement = findChildElementByName(rootChildren, "compiler");
if (compilerElement) {
migrateCompilerElement(
compilerElement,
applicationPath,
isFlexLibrary,
sdks,
linkedResources,
result
);
}
if (!isFlexLibrary) {
let buildTargetsElement = findChildElementByName(
rootChildren,
"buildTargets"
);
if (buildTargetsElement) {
migrateBuildTargetsElement(
buildTargetsElement,
applicationPath,
linkedResources,
result
);
}
}
if (!isFlexLibrary) {
let modulesElement = findChildElementByName(rootChildren, "modules");
if (modulesElement) {
let moduleAppPath = applicationPath;
let moduleOutputFolderPath = "";
if (compilerElement) {
let attributes = compilerElement.attributes;
if ("sourceFolderPath" in attributes) {
moduleAppPath = path.posix.join(
attributes.sourceFolderPath,
moduleAppPath
);
}
if ("outputFolderPath" in attributes) {
moduleOutputFolderPath = attributes.outputFolderPath;
}
}
migrateModulesElement(
modulesElement,
moduleAppPath,
moduleOutputFolderPath,
result
);
}
}
if (!isFlexLibrary) {
let workersElement = findChildElementByName(rootChildren, "workers");
if (workersElement) {
let workerAppPath = applicationPath;
let workerOutputFolderPath = "";
if (compilerElement) {
let attributes = compilerElement.attributes;
if ("sourceFolderPath" in attributes) {
workerAppPath = path.posix.join(
attributes.sourceFolderPath,
workerAppPath
);
}
if ("outputFolderPath" in attributes) {
workerOutputFolderPath = attributes.outputFolderPath;
}
}
migrateWorkersElement(
workersElement,
workerAppPath,
workerOutputFolderPath,
result
);
}
}
if (!isFlexLibrary) {
let themeElement = findChildElementByName(rootChildren, "theme");
if (themeElement) {
migrateThemeElement(themeElement, linkedResources, result);
}
}
}
function findChildElementByName(children: any[], name: string) {
return children.find((child) => {
return child.type === "element" && child.name === name;
});
}
function migrateCompilerElement(
compilerElement: any,
appPath: string,
isFlexLibrary: boolean,
sdks: FlashBuilderSDK[],
linkedResources: EclipseLinkedResource[],
result: any
) {
let attributes = compilerElement.attributes;
let frameworkSDKConfig = vscode.workspace.getConfiguration("as3mxml");
let frameworkSDK = frameworkSDKConfig.inspect("sdk.framework").workspaceValue;
if (!frameworkSDK) {
let sdk: FlashBuilderSDK;
let useFlashSDK = false;
if ("useFlashSDK" in attributes) {
useFlashSDK = attributes.useFlashSDK === "true";
}
if (useFlashSDK) {
sdk = sdks.find((sdk) => {
return sdk.flashSDK;
});
} else if ("flexSDK" in attributes) {
let sdkName = attributes.flexSDK;
sdk = sdks.find((sdk) => {
return sdk.name === sdkName;
});
} else {
sdk = sdks.find((sdk) => {
return sdk.defaultSDK;
});
}
if (sdk) {
let validatedSDKPath = validateFrameworkSDK(sdk.location);
if (validatedSDKPath !== null) {
frameworkSDKConfig.update("sdk.framework", validatedSDKPath);
}
}
}
if (
!isFlexLibrary &&
"useApolloConfig" in attributes &&
attributes.useApolloConfig === "true"
) {
result.application = path.posix.join(
attributes.sourceFolderPath,
getApplicationNameFromPath(appPath) + "-app.xml"
);
}
if (
!isFlexLibrary &&
"copyDependentFiles" in attributes &&
attributes.copyDependentFiles === "true"
) {
result.copySourcePathAssets = true;
}
if (
!isFlexLibrary &&
"htmlGenerate" in attributes &&
attributes.htmlGenerate === "true"
) {
result.htmlTemplate = "html-template";
}
if ("outputFolderPath" in attributes) {
let fileExtension = isFlexLibrary ? FILE_EXTENSION_SWC : FILE_EXTENSION_SWF;
result.compilerOptions.output = path.posix.join(
attributes.outputFolderPath,
getApplicationNameFromPath(appPath) + fileExtension
);
}
if ("additionalCompilerArguments" in attributes) {
result.additionalOptions = attributes.additionalCompilerArguments;
}
if (
"generateAccessible" in attributes &&
attributes.generateAccessible === "true"
) {
result.compilerOptions.accessible = true;
}
if ("strict" in attributes && attributes.strict !== "true") {
result.compilerOptions.strict = false;
}
if ("warn" in attributes && attributes.warn !== "true") {
result.compilerOptions.warnings = false;
}
if ("verifyDigests" in attributes && attributes.verifyDigests !== "true") {
result.compilerOptions["verify-digests"] = false;
}
if (
"targetPlayerVersion" in attributes &&
attributes.targetPlayerVersion !== "0.0.0"
) {
result.compilerOptions["target-player"] = attributes.targetPlayerVersion;
}
let sourceFolderPath: string = null;
if ("sourceFolderPath" in attributes) {
sourceFolderPath = attributes.sourceFolderPath;
if (!isFlexLibrary) {
let mainFilePath = path.posix.join(attributes.sourceFolderPath, appPath);
result.files.push(mainFilePath);
}
}
let children = compilerElement.children as any[];
let compilerSourcePathElement = findChildElementByName(
children,
"compilerSourcePath"
);
if (compilerSourcePathElement) {
migrateCompilerSourcePathElement(
compilerSourcePathElement,
sourceFolderPath,
linkedResources,
result
);
}
let libraryPathElement = findChildElementByName(children, "libraryPath");
if (libraryPathElement) {
migrateCompilerLibraryPathElement(
libraryPathElement,
linkedResources,
result
);
}
}
function migrateCompilerSourcePathElement(
compilerSourcePathElement: any,
sourceFolderPath: string,
linkedResources: EclipseLinkedResource[],
result: any
) {
let sourcePaths = [];
if (sourceFolderPath) {
sourcePaths.push(sourceFolderPath);
}
let children = compilerSourcePathElement.children as any[];
children.forEach((child) => {
if (child.type !== "element" || child.name !== "compilerSourcePathEntry") {
return;
}
let attributes = child.attributes;
if ("path" in attributes && "kind" in attributes) {
let sourcePath = resolvePathWithTokens(
attributes.path as string,
linkedResources
);
let kind = attributes.kind as string;
if (kind !== "1") {
console.warn(
"Skipping sources with unknown kind " +
kind +
" at path " +
sourcePath
);
return;
}
sourcePaths.push(sourcePath);
}
});
if (sourcePaths.length > 0) {
result.compilerOptions["source-path"] = sourcePaths;
}
}
function resolvePathWithTokens(
pathWithTokens: string,
linkedResources: EclipseLinkedResource[]
) {
linkedResources.forEach((linkedResource) => {
let token = "${" + linkedResource.name + "}";
pathWithTokens = pathWithTokens.replace(token, linkedResource.path);
});
return pathWithTokens;
}
function findOnSourcePath(thePath: string, folderPath: string, result: any) {
if (path.isAbsolute(thePath)) {
//only search for relative paths on the source path
return thePath;
}
let sourcePath = result.compilerOptions["source-path"];
if (sourcePath) {
sourcePath.some((sourcePath) => {
let newPath = path.posix.join(sourcePath, thePath);
let absolutePath = newPath;
if (!path.isAbsolute(absolutePath)) {
absolutePath = path.resolve(folderPath, absolutePath);
}
if (fs.existsSync(absolutePath)) {
thePath = newPath;
return true;
}
return false;
});
}
return thePath;
}
function stripSourcePath(thePath: string, result: any) {
let sourcePath = result.compilerOptions["source-path"];
if (sourcePath) {
sourcePath.some((sourcePath) => {
if (thePath.startsWith(sourcePath + path.posix.sep)) {
thePath = thePath.substr(sourcePath.length + 1);
return true;
}
return false;
});
}
return thePath;
}
function migrateCompilerLibraryPathElement(
libraryPathElement: any,
linkedResources: EclipseLinkedResource[],
result: any
) {
let libraryPaths = [];
let externalLibraryPaths = [];
let defaultLinkType = "0";
let libraryPathAttributes = libraryPathElement.attributes;
if ("defaultLinkType" in libraryPathAttributes) {
defaultLinkType = libraryPathAttributes.defaultLinkType;
}
let children = libraryPathElement.children as any[];
children.forEach((child) => {
if (child.type !== "element" || child.name !== "libraryPathEntry") {
return;
}
let libraryPathEntryAttributes = child.attributes;
if (
"path" in libraryPathEntryAttributes &&
"kind" in libraryPathEntryAttributes &&
"linkType" in libraryPathEntryAttributes
) {
let libraryPath = resolvePathWithTokens(
libraryPathEntryAttributes.path as string,
linkedResources
);
//this path may not actually be absolute. in some cases, it should be
//resolved relative to parent folder instead.
if (libraryPath.startsWith("/")) {
//if on windows or if the absolute path does not exist
if (process.platform === "win32" || !fs.existsSync(libraryPath)) {
libraryPath = ".." + libraryPath;
}
}
let kind = libraryPathEntryAttributes.kind as string;
if (
kind !== "1" && //folder
kind !== "3" && //swc
kind !== "5"
) {
//ane
console.warn(
"Skipping library with unknown kind " +
kind +
" at path " +
libraryPath
);
return;
}
let useDefaultLinkType = false;
if ("useDefaultLinkType" in libraryPathEntryAttributes) {
useDefaultLinkType =
libraryPathEntryAttributes.useDefaultLinkType === "true";
}
let linkType = libraryPathEntryAttributes.linkType;
if (useDefaultLinkType && defaultLinkType !== "0") {
linkType = defaultLinkType;
}
if (linkType === "1") {
//library-path
libraryPaths.push(libraryPath);
} else if (linkType === "2") {
//external-ibrary-path
externalLibraryPaths.push(libraryPath);
} else if (linkType === "3") {
//runtime shared library
console.warn(
"Skipping library with linkType 3 (runtime shared library) located at path: " +
libraryPath
);
} else {
console.warn(
"Skipping library with unknown linkType " +
linkType +
" located at path: " +
libraryPath
);
}
}
});
if (libraryPaths.length > 0) {
result.compilerOptions["library-path"] = libraryPaths;
}
if (externalLibraryPaths.length > 0) {
result.compilerOptions["external-library-path"] = externalLibraryPaths;
}
}
function migrateBuildTargetsElement(
buildTargetsElement: any,
applicationFileName: string,
linkedResources: EclipseLinkedResource[],
result: any
) {
let children = buildTargetsElement.children as any[];
children.forEach((buildTarget) => {
if (buildTarget.type !== "element" || buildTarget.name !== "buildTarget") {
return;
}
let buildTargetAttributes = buildTarget.attributes;
if (!("platformId" in buildTargetAttributes)) {
return;
}
let platformId = buildTargetAttributes.platformId;
let isIOS = platformId === "com.adobe.flexide.multiplatform.ios.platform";
let isAndroid =
platformId === "com.adobe.flexide.multiplatform.android.platform";
let isBlackBerry =
platformId === "com.qnx.flexide.multiplatform.qnx.platform";
let isDefault = platformId === "default";
let buildTargetChildren = buildTarget.children;
let multiPlatformSettings = findChildElementByName(
children,
"multiPlatformSettings"
);
if (multiPlatformSettings) {
let multiPlatformSettingsAttributes = multiPlatformSettings.attributes;
if ("enabled" in multiPlatformSettingsAttributes) {
let enabled = multiPlatformSettingsAttributes.enabled === "true";
if (!enabled) {
//we can skip this one because it's not enabled
return;
}
}
}
result.airOptions = result.airOptions || {};
let platformOptions = null;
if (isIOS) {
platformOptions = result.airOptions.ios || {};
platformOptions.output = path.posix.join(
getApplicationNameFromPath(applicationFileName) + ".ipa"
);
if ("provisioningFile" in buildTargetAttributes) {
let provisioningFile = buildTargetAttributes.provisioningFile;
if (provisioningFile) {
provisioningFile = resolvePathWithTokens(
provisioningFile,
linkedResources
);
platformOptions.signingOptions = platformOptions.signingOptions || {};
platformOptions.signingOptions["provisioning-profile"] =
provisioningFile;
}
}
} else if (isAndroid) {
platformOptions = result.airOptions.android || {};
platformOptions.output = path.posix.join(
getApplicationNameFromPath(applicationFileName) + ".apk"
);