示例#1
0
 public override void close()
 {
     if (Out != null)
     {
         Out.close();
     }
     Out = null;
 }
示例#2
0
            public InternalLocalPushConnection(TransportLocal transport)
                : base(transport)
            {
                Repository dst;

                try
                {
                    dst = new Repository(transport.remoteGitDir);
                }
                catch (IOException)
                {
                    throw new TransportException(uri, "Not a Git directory");
                }

                PipedInputStream  in_r;
                PipedOutputStream in_w;

                PipedInputStream  out_r;
                PipedOutputStream out_w;

                try
                {
                    in_r = new PipedInputStream();
                    in_w = new PipedOutputStream(in_r);

                    out_r = new PipedInputStream();
                    out_w = new PipedOutputStream(out_r);
                }
                catch (IOException ex)
                {
                    dst.Close();
                    throw new TransportException(uri, "Cannot connect pipes", ex);
                }

                worker = new Thread(() =>
                {
                    try
                    {
                        ReceivePack rp = new ReceivePack(dst);
                        rp.receive(out_r, in_w, null);
                    }
                    catch (IOException)
                    {
                        // Client side of the pipes should report the problem.
                    }
                    catch (Exception)
                    {
                        // Clients side will notice we went away, and report.
                    }
                    finally
                    {
                        try
                        {
                            out_r.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        try
                        {
                            in_w.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        dst.Close();
                    }
                });
                worker.Name = "JGit-Receive-Pack";
                worker.Start();

                init(in_r, out_w);
                readAdvertisedRefs();
            }
示例#3
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);
        }
示例#4
0
 public void Close()
 {
     channel.disconnect();
     writer_po.close();
     reader.Close();
 }