Example #1
0
 private static void ParseCp(string mainEntry, ToolConfig cfg, bool isCp, string swtch, string args)
 {
     if (swtch == "-cp")
     {
         int addcp = (isCp) ? 1 : 0;
         string[] cps = args.Split(';');
         cfg.ClassPath = new ClassPath[cps.Length+addcp];
         for (int i = 0; i < cps.Length; i++)
         {
             cfg.ClassPath[i] = new ClassPath() {Path = cps[i]};
         }
     }
 }
Example #2
0
        private static int Work(string[] args)
        {
            ToolConfig cfg;
            string mainEntry = args[0];
            string ext = Path.GetExtension(mainEntry).ToLowerInvariant();
            string workDir = null;
            string clr = null;
            string jvm = null;
            if (ext == ".xml")
            {
                var ser = new XmlSerializer(typeof(ToolConfig));
                using (var reader = new FileStream(mainEntry, FileMode.Open))
                {
                    cfg = ser.Deserialize(reader) as ToolConfig;
                }
            }
            else
            {
                bool isDll = ext == ".dll";
                bool isCp = ext == ".jar" || Directory.Exists(mainEntry);
                if (isDll || isCp)
                {
                    cfg = new ToolConfig();
                    workDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                    for (int i = 1; i < args.Length;i++ )
                    {
                        if (args.Length > i + 1)
                        {
                            ParseWd(ref workDir, args[i], args[i + 1]);
                            ParseCp(mainEntry, cfg, isCp, args[i], args[i + 1]);
                            ParseDl(mainEntry, cfg, isDll, args[i], args[i + 1]);
                        }
                    }
                    if (isDll)
                    {
                        if (cfg.AssemblyReference==null)
                        {
                            cfg.AssemblyReference=new AssemblyReference[1];
                        }
                        cfg.AssemblyReference[cfg.AssemblyReference.Length - 1] = new AssemblyReference() { Assembly = mainEntry, Generate = true };
                    }
                    if (isCp)
                    {
                        if (cfg.ClassPath == null)
                        {
                            cfg.ClassPath = new ClassPath[1];
                        }
                        cfg.ClassPath[cfg.ClassPath.Length - 1] = new ClassPath() { Path = mainEntry, Generate = true };
                    }

                    Directory.CreateDirectory(workDir);
                    clr = Path.Combine(workDir, "clr");
                    jvm = Path.Combine(workDir, "jvm");
                    Directory.CreateDirectory(clr);
                    Directory.CreateDirectory(jvm);
                    cfg.TargetDirClr = clr;
                    cfg.TargetDirJvm = jvm;
                }
                else
                {
                    return -1;
                }
            }

            Generator.config = cfg;
            Repository.config = cfg;
            Repository.Register();
            Repository.Analyze();
            Generator.GenerateAll();
            Console.WriteLine("proxygen done");

            if (workDir != null)
            {
                string fname = Path.GetFileNameWithoutExtension(mainEntry);
                WriteBuild(workDir, jvm, fname);

                var ser = new XmlSerializer(typeof (ToolConfig));
                using (var fs = new FileStream(Path.Combine(workDir, fname + ".proxygen.xml"), FileMode.Create))
                {
                    using (XmlWriter xw = XmlWriter.Create(fs, new XmlWriterSettings {Indent = true}))
                    {
                        ser.Serialize(xw, cfg);
                    }
                }
            }

            return 0;
        }
Example #3
0
        private static int Work(string[] args)
        {
            foreach (String arg in args)
            {
                if (arg == "-debug")
                {
                    Console.WriteLine("Execution in Debug Mode Started, Waiting for key press, Please attach to process now.");
                    Console.ReadKey();
                }
            }

            ToolConfig cfg;
            string mainEntry = args[0];
            string ext = Path.GetExtension(mainEntry).ToLowerInvariant();

            if (ext == ".xml")
            {
                var ser = new XmlSerializer(typeof(ToolConfig));
                using (var reader = new FileStream(mainEntry, FileMode.Open))
                {
                    cfg = ser.Deserialize(reader) as ToolConfig;
                }
            }
            else
            {
                bool isDll = ext == ".dll";
                bool isCp = ext == ".jar" || Directory.Exists(mainEntry);
                if (isDll || isCp)
                {
                    cfg = new ToolConfig();
                    //workDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                    for (int i = 1; i < args.Length;i++ )
                    {
                        if (args.Length > i + 1)
                        {
                            ParseWd(cfg, args[i], args[i + 1]);
                            ParseCp(cfg, isCp, args[i], args[i + 1]);
                            ParseDl(cfg, isDll, args[i], args[i + 1]);
                        }
                    }
                    if (isDll)
                    {
                        if (cfg.AssemblyReference==null)
                        {
                            cfg.AssemblyReference=new AssemblyReference[1];
                        }
                        cfg.AssemblyReference[cfg.AssemblyReference.Length - 1] = new AssemblyReference() { Assembly = mainEntry, Generate = true };
                    }
                    if (isCp)
                    {
                        if (cfg.ClassPath == null)
                        {
                            cfg.ClassPath = new ClassPath[1];
                        }
                        cfg.ClassPath[cfg.ClassPath.Length - 1] = new ClassPath() { Path = mainEntry, Generate = true };
                    }

                }
                else
                {
                    return -1;
                }
            }

            //Create Folders
            if (String.IsNullOrEmpty(cfg.WorkDir))
            {
                cfg.WorkDir = "work";
            }
            if(String.IsNullOrEmpty(cfg.TargetDirClr)){
                cfg.TargetDirClr = Path.Combine(cfg.WorkDir, "clr");
            }
            if(String.IsNullOrEmpty(cfg.TargetDirJvm)){
                cfg.TargetDirJvm = Path.Combine(cfg.WorkDir, "jvm"); ;
            }

            Directory.CreateDirectory(cfg.WorkDir);
            Directory.CreateDirectory(cfg.TargetDirClr);
            Directory.CreateDirectory(cfg.TargetDirJvm);

            Generator.config = cfg;
            Repository.config = cfg;
            Repository.Register();
            Repository.Analyze();
            Generator.GenerateAll();
            Console.WriteLine("proxygen done");

            if (cfg.WorkDir != null)
            {
                string fname = Path.GetFileNameWithoutExtension(mainEntry);
                WriteBuild(cfg.WorkDir, cfg.TargetDirJvm, fname);

                var ser = new XmlSerializer(typeof (ToolConfig));
                using (var fs = new FileStream(Path.Combine(cfg.WorkDir, fname + ".proxygen.xml"), FileMode.Create))
                {
                    using (XmlWriter xw = XmlWriter.Create(fs, new XmlWriterSettings {Indent = true}))
                    {
                        ser.Serialize(xw, cfg);
                    }
                }
            }

            return 0;
        }
Example #4
0
 private static void ParseDl(string mainEntry, ToolConfig cfg, bool isDll, string swtch, string args)
 {
     if (swtch == "-dp")
     {
         int adddp = isDll ? 1 : 0;
         string[] dps = args.Split(';');
         cfg.AssemblyReference = new AssemblyReference[dps.Length+adddp];
         for (int i = 0; i < dps.Length; i++)
         {
             cfg.AssemblyReference[i] = new AssemblyReference() { Assembly = dps[i] };
         }
     }
 }
Example #5
0
 private static void ParseWd(ToolConfig cfg, string swtch, string args)
 {
     if (swtch == "-wd")
     {
         cfg.WorkDir = args;
     }
 }