コード例 #1
0
        static Registry()
        {
            JNIEnv env = JNIEnv.ThreadEnv;

            RegisterType(typeof(Class), true, env);
            RegisterType(typeof(Object), true, env);
            RegisterType(typeof(String), true, env);
            initialized = true;

            BindJvm(knownCLR[typeof(Class)], env);
            BindJvm(knownCLR[typeof(Object)], env);
            BindJvm(knownCLR[typeof(String)], env);

            RegisterType(typeof(Boolean), true, env);
            RegisterType(typeof(Byte), true, env);
            RegisterType(typeof(Character), true, env);
            RegisterType(typeof(Short), true, env);
            RegisterType(typeof(Integer), true, env);
            RegisterType(typeof(Long), true, env);
            RegisterType(typeof(Float), true, env);
            RegisterType(typeof(Double), true, env);

            RegisterPrimitiveType("boolean", typeof(bool), typeof(Boolean));
            RegisterPrimitiveType("byte", typeof(byte), typeof(Byte));
            RegisterPrimitiveType("char", typeof(char), typeof(Character));
            RegisterPrimitiveType("short", typeof(short), typeof(Short));
            RegisterPrimitiveType("int", typeof(int), typeof(Integer));
            RegisterPrimitiveType("long", typeof(long), typeof(Long));
            RegisterPrimitiveType("float", typeof(float), typeof(Float));
            RegisterPrimitiveType("double", typeof(double), typeof(Double));
            RegisterPrimitiveType("void", typeof(void), null);

            Convertor.boolObject   = env.GetStaticMethodID(Boolean.staticClass, "valueOf", "(Z)Ljava/lang/Boolean;");
            Convertor.byteObject   = env.GetStaticMethodID(Byte.staticClass, "valueOf", "(B)Ljava/lang/Byte;");
            Convertor.charObject   = env.GetStaticMethodID(Character.staticClass, "valueOf", "(C)Ljava/lang/Character;");
            Convertor.shortObject  = env.GetStaticMethodID(Short.staticClass, "valueOf", "(S)Ljava/lang/Short;");
            Convertor.intObject    = env.GetStaticMethodID(Integer.staticClass, "valueOf", "(I)Ljava/lang/Integer;");
            Convertor.longObject   = env.GetStaticMethodID(Long.staticClass, "valueOf", "(J)Ljava/lang/Long;");
            Convertor.doubleObject = env.GetStaticMethodID(Double.staticClass, "valueOf", "(D)Ljava/lang/Double;");
            Convertor.floatObject  = env.GetStaticMethodID(Float.staticClass, "valueOf", "(F)Ljava/lang/Float;");

            Convertor.boolValue   = env.GetMethodID(Boolean.staticClass, "booleanValue", "()Z");
            Convertor.byteValue   = env.GetMethodID(Byte.staticClass, "byteValue", "()B");
            Convertor.charValue   = env.GetMethodID(Character.staticClass, "charValue", "()C");
            Convertor.shortValue  = env.GetMethodID(Short.staticClass, "shortValue", "()S");
            Convertor.intValue    = env.GetMethodID(Integer.staticClass, "intValue", "()I");
            Convertor.longValue   = env.GetMethodID(Long.staticClass, "longValue", "()J");
            Convertor.doubleValue = env.GetMethodID(Double.staticClass, "doubleValue", "()D");
            Convertor.floatValue  = env.GetMethodID(Float.staticClass, "floatValue", "()F");

            RegisterType(typeof(Throwable), true, env);
            RegisterType(typeof(ClassLoader), true, env);

            systemClassLoader = ClassLoader.getSystemClassLoader();
        }
コード例 #2
0
        private static void LoadClasspath()
        {
            BridgeSetup setup = new BridgeSetup(false);

            setup.BindNative = false;
            setup.BindStatic = true;

            if (config.ClassPath != null && config.ClassPath.Length > 0)
            {
                foreach (var classPath in config.ClassPath)
                {
                    setup.AddClassPath(Path.GetFullPath(classPath.Path));
                    if (classPath.Generate)
                    {
                        generateCp.Add(classPath.Path);
                    }
                }
            }
            setup.AddBridgeClassPath();
            Bridge.CreateJVM(setup);
            systemClassLoader = ClassLoader.getSystemClassLoader();
        }
コード例 #3
0
 public AssemblyClassLoader(Assembly asm, string packageName)
     : base(ClassLoader.getSystemClassLoader())
 {
     this.asm         = asm;
     this.packageName = packageName;
 }
コード例 #4
0
        public string execClass(string className)
        {
            if (TEST_IN_SAME_PROCESS)
            {
                try
                {
                    ClassLoader       loader       = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader());
                    Class             mainClass    = (Class)loader.loadClass(className);
                    Method            mainMethod   = mainClass.getDeclaredMethod("main", typeof(string[]));
                    PipedInputStream  stdoutIn     = new PipedInputStream();
                    PipedInputStream  stderrIn     = new PipedInputStream();
                    PipedOutputStream stdoutOut    = new PipedOutputStream(stdoutIn);
                    PipedOutputStream stderrOut    = new PipedOutputStream(stderrIn);
                    StreamVacuum      stdoutVacuum = new StreamVacuum(stdoutIn);
                    StreamVacuum      stderrVacuum = new StreamVacuum(stderrIn);

                    PrintStream originalOut = Console.Out;
                    System.setOut(new PrintStream(stdoutOut));
                    try
                    {
                        PrintStream originalErr = System.err;
                        try
                        {
                            System.setErr(new PrintStream(stderrOut));
                            stdoutVacuum.start();
                            stderrVacuum.start();
                            mainMethod.invoke(null, (Object) new string[] { new File(tmpdir, "input").getAbsolutePath() });
                        }
                        finally
                        {
                            System.setErr(originalErr);
                        }
                    }
                    finally
                    {
                        System.setOut(originalOut);
                    }

                    stdoutOut.close();
                    stderrOut.close();
                    stdoutVacuum.join();
                    stderrVacuum.join();
                    string output = stdoutVacuum.tostring();
                    if (stderrVacuum.tostring().length() > 0)
                    {
                        this.stderrDuringParse = stderrVacuum.tostring();
                        Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum);
                    }
                    return(output);
                }
                catch (MalformedURLException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (IOException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (InterruptedException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (IllegalAccessException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (IllegalArgumentException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (InvocationTargetException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (NoSuchMethodException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (SecurityException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
                catch (ClassNotFoundException ex)
                {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
            }

            try
            {
                string[] args = new string[] {
                    "java", "-classpath", tmpdir + pathSep + CLASSPATH,
                    className, new File(tmpdir, "input").getAbsolutePath()
                };
                //string cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir, "input").getAbsolutePath();
                //Console.WriteLine("execParser: "+cmdLine);
                Process process =
                    Runtime.getRuntime().exec(args, null, new File(tmpdir));
                StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
                StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
                stdoutVacuum.start();
                stderrVacuum.start();
                process.waitFor();
                stdoutVacuum.join();
                stderrVacuum.join();
                string output = stdoutVacuum.tostring();
                if (stderrVacuum.tostring().length() > 0)
                {
                    this.stderrDuringParse = stderrVacuum.tostring();
                    Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum);
                }
                return(output);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("can't exec recognizer");
                e.printStackTrace(System.err);
            }
            return(null);
        }
コード例 #5
0
ファイル: DriverReflection.cs プロジェクト: Dorokhov/NPhoenix
        internal static Method GetConnection()
        {
            Method getConnectionMethod = Class
                                         .forName(Constants.Classes.DriverManager, true, ClassLoader.getSystemClassLoader())
                                         .getDeclaredMethods()
                                         .Single(x => x.getName() == Constants.Methods.GetConnection &&
                                                 x.GetSignature() == Constants.MethodSignatures.GetConnection_String_Connection);

            return(getConnectionMethod);
        }
コード例 #6
0
        public static FileInfo GetDeclaringFile(this Class cls)
        {
            // Z:\jsc.svn\examples\java\hybrid\ubuntu\UbuntuBootExperiment\UbuntuBootExperiment\Program.cs
            //Console.WriteLine("enter BCLImplementationExtensions GetDeclaringFile");

            //Console.WriteLine("enter GetDeclaringFile");
            // for some reason void cannot be resolved...
            if (cls.getName() == "void")
            {
                cls = typeof(object).ToClass();
            }


            // http://stackoverflow.com/questions/5726930/location-of-javaagent-jar-in-bootclasspath

            //Console.WriteLine("GetDeclaringFile before Replace");
            var r0 = cls.getName();
            //Console.WriteLine(r0);

            var r = r0.Replace(".", "/") + ".class";

            //Console.WriteLine(r);

            //Console.WriteLine("GetDeclaringFile getClassLoader");
            var cl = cls.getClassLoader();

            if (cl == null)
            {
                cl = ClassLoader.getSystemClassLoader();
            }

            //http://stackoverflow.com/questions/1921238/getclass-getclassloader-is-null-why

            var loc = cl.getResource(r);

            if (loc == null)
            {
                //Console.WriteLine("cls: " + cls.getName());
                //Console.WriteLine("r: " + r);
                //Console.WriteLine("cl: " + cl);

                //return new FileInfo(@"c:\missing\missing-foo.jar");

                throw new InvalidOperationException();
            }

            //ProtectionDomain pDomain = cls.getProtectionDomain();

            //CodeSource cSource = pDomain.getCodeSource();

            //EnsureCodeSource(cSource);

            //URL loc = cSource.getLocation();



            // spaces are urlencoded?
            var ff0 = loc.getFile();
            //Console.WriteLine(ff0);

            //Console.WriteLine(" BCLImplementationExtensions GetDeclaringFile " + new { ff0 });


            var ff = ff0.Replace("%20", " ");

            //Console.WriteLine(ff);


            // keep it at root path, absolute

            //{
            //    var prefix = "file:/";

            //    if (prefix == ff.Substring(0, prefix.Length))
            //        ff = ff.Substring(prefix.Length);
            //}

            // sometimes the prefix is shorter?
            {
                var prefix = "file:";

                if (prefix == ff.Substring(0, prefix.Length))
                {
                    ff = ff.Substring(prefix.Length);
                }
            }


            // those jar loaders are adding !/ to the end?

            {
                var suffix = ff.IndexOf("!");

                if (suffix > 0)
                {
                    ff = ff.Substring(0, suffix);
                }
            }

            //global::System.Console.WriteLine("ff: " + ff);

            //Console.WriteLine(" BCLImplementationExtensions GetDeclaringFile " + new { ff });
            return(new FileInfo(ff));
        }
コード例 #7
0
 public static ClassLoader addJarToSystemClassLoader(this string pathToJar)
 {
     return(ClassLoader.getSystemClassLoader().loadJar(pathToJar));
 }
コード例 #8
0
 public static ClassLoader systemClassLoader(this  API_Jni4Net jni4Net)
 {
     return(ClassLoader.getSystemClassLoader());
 }
コード例 #9
0
        public static List <Class> java_From_ClassLoader_get_Loaded_Classes(this API_Jni4Net jni4Net)
        {
            var systemClassLoader = ClassLoader.getSystemClassLoader();

            return(jni4Net.java_From_ClassLoader_get_Loaded_Classes(systemClassLoader));
        }
コード例 #10
0
ファイル: Starter.cs プロジェクト: traien/Virtion.ApkTool
        public static int StartMain(string[] args)
        {
            Tracer.EnableTraceConsoleListener();
            Tracer.EnableTraceForDebug();
            Hashtable hashtable = new Hashtable();
            string    text      = Environment.GetEnvironmentVariable("CLASSPATH");

            if (text == null || text == "")
            {
                text = ".";
            }
            hashtable["java.class.path"] = text;
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            bool   flag5 = false;
            string text2 = null;
            int    num   = -1;
            bool   flag6 = false;
            string arg   = null;
            bool   flag7 = false;
            int    result;

            for (int i = 0; i < args.Length; i++)
            {
                string text3 = args[i];
                if (text3[0] != '-')
                {
                    text2 = text3;
                    num   = i + 1;
                    break;
                }
                if (text3 == "-help" || text3 == "-?")
                {
                    break;
                }
                if (text3 == "-Xsave")
                {
                    flag2 = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (text3 == "-XXsave")
                {
                    flag3 = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (text3 == "-Xtime")
                {
                    new IKVM.Helper.Starter.Timer();
                }
                else if (text3 == "-Xwait")
                {
                    flag4 = true;
                }
                else if (text3 == "-Xbreak")
                {
                    Debugger.Break();
                }
                else if (text3 == "-Xnoclassgc")
                {
                    IKVM.Internal.Starter.ClassUnloading = false;
                }
                else if (text3 == "-jar")
                {
                    flag = true;
                }
                else
                {
                    if (text3 == "-version")
                    {
                        Console.WriteLine(Startup.getVersionAndCopyrightInfo());
                        Console.WriteLine();
                        Console.WriteLine("CLR version: {0} ({1} bit)", Environment.Version, IntPtr.Size * 8);
                        System.Type type = System.Type.GetType("Mono.Runtime");
                        if (type != null)
                        {
                            Console.WriteLine("Mono version: {0}", type.InvokeMember("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[0]));
                        }
                        Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                        for (int j = 0; j < assemblies.Length; j++)
                        {
                            Assembly assembly = assemblies[j];
                            Console.WriteLine("{0}: {1}", assembly.GetName().Name, assembly.GetName().Version);
                        }
                        string property = java.lang.System.getProperty("openjdk.version");
                        if (property != null)
                        {
                            Console.WriteLine("OpenJDK version: {0}", property);
                        }
                        result = 0;
                        return(result);
                    }
                    if (text3 == "-showversion")
                    {
                        flag5 = true;
                    }
                    else if (text3.StartsWith("-D"))
                    {
                        text3 = text3.Substring(2);
                        string[] array = text3.Split(new char[]
                        {
                            '='
                        });
                        string value;
                        if (array.Length == 2)
                        {
                            value = array[1];
                        }
                        else if (array.Length == 1)
                        {
                            value = "";
                        }
                        else
                        {
                            value = text3.Substring(array[0].Length + 1);
                        }
                        hashtable[array[0]] = value;
                    }
                    else if (text3 == "-ea" || text3 == "-enableassertions")
                    {
                        Assertions.EnableAssertions();
                    }
                    else if (text3 == "-da" || text3 == "-disableassertions")
                    {
                        Assertions.DisableAssertions();
                    }
                    else if (text3 == "-esa" || text3 == "-enablesystemassertions")
                    {
                        Assertions.EnableSystemAssertions();
                    }
                    else if (text3 == "-dsa" || text3 == "-disablesystemassertions")
                    {
                        Assertions.DisableSystemAssertions();
                    }
                    else if (text3.StartsWith("-ea:") || text3.StartsWith("-enableassertions:"))
                    {
                        Assertions.EnableAssertions(text3.Substring(text3.IndexOf(':') + 1));
                    }
                    else if (text3.StartsWith("-da:") || text3.StartsWith("-disableassertions:"))
                    {
                        Assertions.DisableAssertions(text3.Substring(text3.IndexOf(':') + 1));
                    }
                    else if (text3 == "-cp" || text3 == "-classpath")
                    {
                        hashtable["java.class.path"] = args[++i];
                    }
                    else if (text3.StartsWith("-Xtrace:"))
                    {
                        Tracer.SetTraceLevel(text3.Substring(8));
                    }
                    else if (text3.StartsWith("-Xmethodtrace:"))
                    {
                        Tracer.HandleMethodTrace(text3.Substring(14));
                    }
                    else if (text3 == "-Xdebug")
                    {
                        flag6 = true;
                    }
                    else if (!(text3 == "-Xnoagent"))
                    {
                        if (text3.StartsWith("-Xrunjdwp") || text3.StartsWith("-agentlib:jdwp"))
                        {
                            arg   = text3;
                            flag6 = true;
                        }
                        else if (text3.StartsWith("-Xreference:"))
                        {
                            Startup.addBootClassPathAssemby(Assembly.LoadFrom(text3.Substring(12)));
                        }
                        else if (text3 == "-Xnoglobbing")
                        {
                            flag7 = true;
                        }
                        else
                        {
                            if (!text3.StartsWith("-Xms") && !text3.StartsWith("-Xmx") && !text3.StartsWith("-Xss") && !(text3 == "-Xmixed") && !(text3 == "-Xint") && !(text3 == "-Xnoclassgc") && !(text3 == "-Xincgc") && !(text3 == "-Xbatch") && !(text3 == "-Xfuture") && !(text3 == "-Xrs") && !(text3 == "-Xcheck:jni") && !(text3 == "-Xshare:off") && !(text3 == "-Xshare:auto") && !(text3 == "-Xshare:on"))
                            {
                                Console.Error.WriteLine("{0}: illegal argument", text3);
                                break;
                            }
                            Console.Error.WriteLine("Unsupported option ignored: {0}", text3);
                        }
                    }
                }
            }
            if (text2 == null || flag5)
            {
                Console.Error.WriteLine(Startup.getVersionAndCopyrightInfo());
                Console.Error.WriteLine();
            }
            if (text2 == null)
            {
                Console.Error.WriteLine("usage: ikvm [-options] <class> [args...]");
                Console.Error.WriteLine("          (to execute a class)");
                Console.Error.WriteLine("    or ikvm -jar [-options] <jarfile> [args...]");
                Console.Error.WriteLine("          (to execute a jar file)");
                Console.Error.WriteLine();
                Console.Error.WriteLine("where options include:");
                Console.Error.WriteLine("    -? -help          Display this message");
                Console.Error.WriteLine("    -version          Display IKVM and runtime version");
                Console.Error.WriteLine("    -showversion      Display version and continue running");
                Console.Error.WriteLine("    -cp -classpath <directories and zip/jar files separated by {0}>", Path.PathSeparator);
                Console.Error.WriteLine("                      Set search path for application classes and resources");
                Console.Error.WriteLine("    -D<name>=<value>  Set a system property");
                Console.Error.WriteLine("    -ea[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("    -enableassertions[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("                      Enable assertions.");
                Console.Error.WriteLine("    -da[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("    -disableassertions[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("                      Disable assertions");
                Console.Error.WriteLine("    -Xsave            Save the generated assembly (for debugging)");
                Console.Error.WriteLine("    -Xtime            Time the execution");
                Console.Error.WriteLine("    -Xtrace:<string>  Displays all tracepoints with the given name");
                Console.Error.WriteLine("    -Xmethodtrace:<string>");
                Console.Error.WriteLine("                      Builds method trace into the specified output methods");
                Console.Error.WriteLine("    -Xwait            Keep process hanging around after exit");
                Console.Error.WriteLine("    -Xbreak           Trigger a user defined breakpoint at startup");
                Console.Error.WriteLine("    -Xnoclassgc       Disable class garbage collection");
                Console.Error.WriteLine("    -Xnoglobbing      Disable argument globbing");
                result = 1;
                return(result);
            }
            try
            {
                if (flag6)
                {
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    string   text4    = arg + " -pid:" + System.Diagnostics.Process.GetCurrentProcess().Id;
                    string   text5    = new FileInfo(assembly.Location).DirectoryName + "\\debugger.exe";
                    try
                    {
                        ProcessStartInfo processStartInfo = new ProcessStartInfo(text5, text4);
                        processStartInfo.UseShellExecute = false;
                        new System.Diagnostics.Process
                        {
                            StartInfo = processStartInfo
                        }.Start();
                    }
                    catch (System.Exception ex)
                    {
                        Console.Error.WriteLine(text5 + " " + text4);
                        throw ex;
                    }
                }
                if (flag)
                {
                    hashtable["java.class.path"] = text2;
                }
                hashtable["sun.java.command"]  = string.Join(" ", args, num - 1, args.Length - (num - 1));
                hashtable["sun.java.launcher"] = "SUN_STANDARD";
                Startup.setProperties(hashtable);
                Startup.enterMainThread();
                string[] array2;
                if (flag7)
                {
                    array2 = new string[args.Length - num];
                    System.Array.Copy(args, num, array2, 0, array2.Length);
                }
                else
                {
                    array2 = Startup.glob(args, num);
                }
                if (flag)
                {
                    text2 = IKVM.Helper.Starter.GetMainClassFromJarManifest(text2);
                    if (text2 == null)
                    {
                        result = 1;
                        return(result);
                    }
                }
                Class clazz = Class.forName(text2, true, ClassLoader.getSystemClassLoader());
                try
                {
                    Method method = IKVM.Internal.Starter.FindMainMethod(clazz);
                    if (method == null)
                    {
                        throw new NoSuchMethodError("main");
                    }
                    if (!Modifier.isPublic(method.getModifiers()))
                    {
                        Console.Error.WriteLine("Main method not public.");
                    }
                    else
                    {
                        method.setAccessible(true);
                        if (flag2)
                        {
                            java.lang.Runtime.getRuntime().addShutdownHook(new IKVM.Helper.Starter.SaveAssemblyShutdownHook(clazz));
                        }
                        if (flag4)
                        {
                            java.lang.Runtime.getRuntime().addShutdownHook(new IKVM.Helper.Starter.WaitShutdownHook());
                        }
                        try
                        {
                            method.invoke(null, new object[]
                            {
                                array2
                            });
                            result = 0;
                            return(result);
                        }
                        catch (InvocationTargetException ex2)
                        {
                            throw ex2.getCause();
                        }
                    }
                }
                finally
                {
                    if (flag3)
                    {
                        IKVM.Internal.Starter.SaveDebugImage();
                    }
                }
            }
            catch (System.Exception t)
            {
                java.lang.Thread thread = java.lang.Thread.currentThread();
                thread.getThreadGroup().uncaughtException(thread, Util.mapException(t));
            }
            finally
            {
                Startup.exitMainThread();
            }
            result = 1;
            return(result);
        }