/// <summary> /// Create Dot42.dll /// </summary> private static void CreateFrameworkAssembly(JarFile jf, DocModel xmlModel, SourceProperties sourceProperties, string folder) { // Initialize all MappedTypeBuilder.Initialize(CompositionContainer); // Create java type wrappers var module = new NetModule(AttributeConstants.Dot42Scope); var classLoader = new AssemblyClassLoader(null); var target = new TargetFramework(null, classLoader, xmlModel, LogMissingParamNamesType, true, false, Enumerable.Empty <string>()); List <TypeBuilder> typeBuilders; using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Create()", x.TotalMilliseconds))) { var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target)); var customTypeBuilder = CompositionContainer.GetExportedValues <ICustomTypeBuilder>() .OrderBy(x => x.CustomTypeName) .Select(x => x.AsTypeBuilder()); typeBuilders = classTypeBuilders.Concat(customTypeBuilder) .OrderBy(x => x.Priority) .ToList(); typeBuilders.ForEach(x => x.CreateType(null, module, target)); } // Create JavaRef attribute //JavaRefAttributeBuilder.Build(asm.MainModule); // Implement and finalize types using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Implement()", x.TotalMilliseconds))) { JarImporter.Implement(typeBuilders, target); } // Save using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Generate()", x.TotalMilliseconds))) { CodeGenerator.Generate(folder, module.Types, new List <NetCustomAttribute>(), target, new FrameworkCodeGeneratorContext(), target); } // Create layout.xml var doc = new XDocument(new XElement("layout")); typeBuilders.ForEach(x => x.FillLayoutXml(jf, doc.Root)); doc.Save(Path.Combine(folder, "layout.xml")); // create dot42.typemap doc = new XDocument(new XElement("typemap")); typeBuilders.ForEach(x => x.FillTypemapXml(jf, doc.Root)); doc.Save(Path.Combine(folder, "dot42.typemap")); //using (var s = new FileStream(Path.Combine(folder, "dot42.typemap"), FileMode.Create)) // CompressedXml.WriteTo(doc, s, Encoding.UTF8); }
/// <summary> /// Program main code /// </summary> /// <returns>true on success, false on usage due to invalid options</returns> internal static bool MainCode(CommandLineOptions options) { if (options.ShowHelp) { return(false); } // Detect target var target = Locations.SetTarget(options.Target); // Build APK/BAR? if (!string.IsNullOrEmpty(options.PackagePath)) { #if DEBUG //Debugger.Launch(); #endif // Build APK first var apkPath = options.PackagePath; if (target == Targets.BlackBerry) { // Put APK in TEMP folder apkPath = Path.GetTempFileName() + ".apk"; } var apkBuilder = new ApkBuilder.ApkBuilder(apkPath); apkBuilder.MapFilePath = Path.ChangeExtension(options.PackagePath, ".d42map"); apkBuilder.ManifestPath = options.ManifestFile; apkBuilder.DexFiles.AddRange(options.DexFiles); apkBuilder.MapFiles.AddRange(options.MapFiles); if (options.Assemblies.Any()) { apkBuilder.Assemblies.AddRange(options.Assemblies); } apkBuilder.ResourcesFolder = options.ResourcesFolder; apkBuilder.PfxFile = options.PfxFile; apkBuilder.PfxPassword = options.PfxPassword; apkBuilder.CertificateThumbprint = options.CertificateThumbprint; apkBuilder.FreeAppsKeyPath = options.FreeAppsKeyPath; apkBuilder.PackageName = options.PackageName; apkBuilder.NativeCodeLibraries.AddRange(options.NativeCodeLibs); apkBuilder.Build(); if (target == Targets.BlackBerry) { // Now build BAR var barBuilder = new BarBuilder.BarBuilder(options.PackagePath); barBuilder.ApkPath = apkPath; barBuilder.DebugTokenPath = options.DebugToken; barBuilder.Build(); } } else if (!string.IsNullOrEmpty(options.JarFile)) // Import jar file? { var module = new XModule(); var resolver = new AssemblyResolver(options.ReferenceFolders, new AssemblyClassLoader(module.OnClassLoaded), module.OnAssemblyLoaded); var jarImporter = new JarImporter(options.JarFile, options.LibName, options.ImportStubsOnly, false /*true*/, options.GeneratedCodeFolder, resolver, options.ExcludedPackages, options.UseAutoExcludedPackages); foreach (var path in options.References) { jarImporter.ImportAssembly(path); } jarImporter.ImportAssembliesCompleted(); jarImporter.Import(); } else if (options.WcfProxyInputAssemblies.Any()) // Generate WCF Proxy { var resolver = new AssemblyResolver(options.ReferenceFolders, null, null); var readerParameters = new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = resolver, SymbolReaderProvider = new SafeSymbolReaderProvider(), ReadSymbols = true }; var assemblies = options.WcfProxyInputAssemblies.Select(x => AssemblyDefinition.ReadAssembly(x, readerParameters)).ToList(); var proxyTool = new ProxyBuilderTool(assemblies, options.GeneratedProxySourcePath); proxyTool.Build(); } else { // Create namespace converter var nsConverter = new NameConverter(options.PackageName, options.RootNamespace); // Create manifest file? if (options.CreateManifest) { ManifestBuilder.CreateManifest(target, options.Assemblies.First(), options.ReferenceFolders, options.PackageName, nsConverter, options.DebugInfo, options.AppWidgetProviders, options.TargetSdkVersion, options.OutputFolder); } else { // Code compilation? if (options.Assemblies.Any()) { #if DEBUG //Debugger.Launch(); #endif CompileAssembly(options, nsConverter); } } // Xml compilation if (options.CompileResources) { if (!CompileResources(options)) { return(false); } } } return(true); }