Example #1
0
        public override FilePath GitPrefix()
        {
            if (gitPrefixEvaluated)
            {
                return(gitPrefix);
            }
            string   path   = SystemReader.GetInstance().Getenv("PATH");
            FilePath gitExe = SearchPath(path, "git.exe", "git.cmd");

            if (gitExe != null)
            {
                gitPrefix = gitExe.GetParentFile().GetParentFile();
            }
            else
            {
                // This isn't likely to work, if bash is in $PATH, git should
                // also be in $PATH. But its worth trying.
                //
                string w = ReadPipe(UserHome(), new string[] { "bash", "--login", "-c", "which git" }, Encoding.Default.Name());
                //
                //
                if (w != null)
                {
                    gitPrefix = new FilePath(w).GetParentFile().GetParentFile();
                }
            }
            gitPrefixEvaluated = true;
            return(gitPrefix);
        }
Example #2
0
 /// <summary>
 /// Auto-detect the appropriate file system abstraction, taking into account
 /// the presence of a Cygwin installation on the system.
 /// </summary>
 /// <remarks>
 /// Auto-detect the appropriate file system abstraction, taking into account
 /// the presence of a Cygwin installation on the system. Using jgit in
 /// combination with Cygwin requires a more elaborate (and possibly slower)
 /// resolution of file system paths.
 /// </remarks>
 /// <param name="cygwinUsed">
 /// <ul>
 /// <li><code>Boolean.TRUE</code> to assume that Cygwin is used in
 /// combination with jgit</li>
 /// <li><code>Boolean.FALSE</code> to assume that Cygwin is
 /// <b>not</b> used with jgit</li>
 /// <li><code>null</code> to auto-detect whether a Cygwin
 /// installation is present on the system and in this case assume
 /// that Cygwin is used</li>
 /// </ul>
 /// Note: this parameter is only relevant on Windows.
 /// </param>
 /// <returns>detected file system abstraction</returns>
 public static NGit.Util.FS Detect(bool?cygwinUsed)
 {
     if (SystemReader.GetInstance().IsWindows())
     {
         if (cygwinUsed == null)
         {
             cygwinUsed = Sharpen.Extensions.ValueOf(FS_Win32_Cygwin.IsCygwin());
         }
         if (cygwinUsed.Value)
         {
             return(new FS_Win32_Cygwin());
         }
         else
         {
             return(new FS_Win32());
         }
     }
     else
     {
         if (FS_POSIX_Java6.HasExecute())
         {
             return(new FS_POSIX_Java6());
         }
         else
         {
             return(new FS_POSIX_Java5());
         }
     }
 }
 public virtual void SetUp()
 {
     mockSystemReader = new _MockSystemReader_62();
     SystemReader.SetInstance(mockSystemReader);
     ident = RawParseUtils.ParsePersonIdent("A U Thor <*****@*****.**> 1316560165 -0400"
                                            );
 }
        protected internal override FilePath DiscoverGitPrefix()
        {
            string   path   = SystemReader.GetInstance().Getenv("PATH");
            FilePath gitExe = SearchPath(path, "git.exe", "git.cmd");

            if (gitExe != null)
            {
                return(gitExe.GetParentFile().GetParentFile());
            }
            // This isn't likely to work, if bash is in $PATH, git should
            // also be in $PATH. But its worth trying.
            //
            string w = ReadPipe(UserHome(), new string[] { "bash", "--login", "-c", "which git" }, Encoding.Default.Name());

            //
            //
            if (w != null)
            {
                // The path may be in cygwin/msys notation so resolve it right away
                gitExe = Resolve(null, w);
                if (gitExe != null)
                {
                    return(gitExe.GetParentFile().GetParentFile());
                }
            }
            return(null);
        }
Example #5
0
        public override FilePath GitPrefix()
        {
            string   path   = SystemReader.GetInstance().Getenv("PATH");
            FilePath gitExe = SearchPath(path, "git");

            if (gitExe != null)
            {
                return(gitExe.GetParentFile().GetParentFile());
            }
            if (IsMacOS())
            {
                // On MacOSX, PATH is shorter when Eclipse is launched from the
                // Finder than from a terminal. Therefore try to launch bash as a
                // login shell and search using that.
                //
                string w = ReadPipe(UserHome(), new string[] { "bash", "--login", "-c", "which git" }, Encoding.Default.Name());
                //
                //
                if (w == null || w.Length == 0)
                {
                    return(null);
                }
                FilePath parentFile = new FilePath(w).GetParentFile();
                if (parentFile == null)
                {
                    return(null);
                }
                return(parentFile.GetParentFile());
            }
            return(null);
        }
        private void AssertFormat(long ageFromNow, long timeUnit, string expectedFormat)
        {
            DateTime d = Sharpen.Extensions.CreateDate(SystemReader.GetInstance().GetCurrentTime
                                                           () - ageFromNow * timeUnit);
            string s = RelativeDateFormatter.Format(d);

            NUnit.Framework.Assert.AreEqual(expectedFormat, s);
        }
Example #7
0
        /// <summary>Create a new Git oriented date formatter</summary>
        /// <param name="format"></param>
        public GitDateFormatter(GitDateFormatter.Format format)
        {
            this.format = format;
            switch (format)
            {
            default:
            {
                break;
                break;
            }

            case GitDateFormatter.Format.DEFAULT:
            {
                // Not default:
                dateTimeInstance = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy Z", CultureInfo
                                                        .InvariantCulture);
                break;
            }

            case GitDateFormatter.Format.ISO:
            {
                dateTimeInstance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", CultureInfo.InvariantCulture
                                                        );
                break;
            }

            case GitDateFormatter.Format.LOCAL:
            {
                dateTimeInstance = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture
                                                        );
                break;
            }

            case GitDateFormatter.Format.RFC:
            {
                dateTimeInstance = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", CultureInfo
                                                        .InvariantCulture);
                break;
            }

            case GitDateFormatter.Format.SHORT:
            {
                dateTimeInstance = new SimpleDateFormat("yyyy-MM-dd", CultureInfo.InvariantCulture
                                                        );
                break;
            }

            case GitDateFormatter.Format.LOCALE:
            case GitDateFormatter.Format.LOCALELOCAL:
            {
                SystemReader systemReader = SystemReader.GetInstance();
                dateTimeInstance = systemReader.GetDateTimeInstance(DateFormat.DEFAULT, DateFormat
                                                                    .DEFAULT);
                dateTimeInstance2 = systemReader.GetSimpleDateFormat("Z");
                break;
            }
            }
        }
Example #8
0
        public virtual void Iso()
        {
            string   dateStr = "2007-02-21 15:35:00 +0100";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"
                                                                              ).Parse(dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #9
0
        public virtual void Rfc()
        {
            string   dateStr = "Wed, 21 Feb 2007 15:35:00 +0100";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"
                                                                              ).Parse(dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #10
0
        public virtual void Local()
        {
            string   dateStr = "Wed Feb 21 15:35:00 2007";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("EEE MMM dd HH:mm:ss yyyy"
                                                                              ).Parse(dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #11
0
        public virtual void ShortWithDotsReverse()
        {
            string   dateStr = "21.02.2007";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("dd.MM.yyyy").Parse
                                   (dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #12
0
        public virtual void ShortWithSlash()
        {
            string   dateStr = "02/21/2007";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("MM/dd/yyyy").Parse
                                   (dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #13
0
        public virtual void ShortFmt()
        {
            string   dateStr = "2007-02-21";
            DateTime exp     = SystemReader.GetInstance().GetSimpleDateFormat("yyyy-MM-dd").Parse
                                   (dateStr);
            DateTime parse = GitDateParser.Parse(dateStr, null);

            NUnit.Framework.Assert.AreEqual(exp, parse);
        }
Example #14
0
        public virtual void Never()
        {
            GregorianCalendar cal = new GregorianCalendar(SystemReader.GetInstance().GetTimeZone
                                                              (), SystemReader.GetInstance().GetLocale());
            DateTime parse = GitDateParser.Parse("never", cal);

            NUnit.Framework.Assert.AreEqual(GitDateParser.NEVER, parse);
            parse = GitDateParser.Parse("never", null);
            NUnit.Framework.Assert.AreEqual(GitDateParser.NEVER, parse);
        }
Example #15
0
 /// <param name="newReader">the new instance to use when accessing properties.</param>
 public static void SetInstance(SystemReader newReader)
 {
     if (newReader == null)
     {
         INSTANCE = DEFAULT;
     }
     else
     {
         INSTANCE = newReader;
     }
 }
Example #16
0
        protected internal override FilePath DiscoverGitPrefix()
        {
            string   path   = SystemReader.GetInstance().Getenv("PATH");
            FilePath gitExe = SearchPath(path, "git.exe", "git.cmd");

            if (gitExe != null)
            {
                return(gitExe.GetParentFile().GetParentFile());
            }
            return(null);
        }
Example #17
0
        public virtual void WeeksAgo()
        {
            string           dateStr = "2007-02-21 15:35:00 +0100";
            SimpleDateFormat df      = SystemReader.GetInstance().GetSimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"
                                                                                      );
            DateTime          refDate = df.Parse(dateStr);
            GregorianCalendar cal     = new GregorianCalendar(SystemReader.GetInstance().GetTimeZone
                                                                  (), SystemReader.GetInstance().GetLocale());

            cal.SetTime(refDate);
            DateTime parse = GitDateParser.Parse("2 weeks ago", cal);

            NUnit.Framework.Assert.AreEqual(df.Parse("2007-02-07 15:35:00 +0100"), parse);
        }
Example #18
0
        public virtual void Yesterday()
        {
            GregorianCalendar cal = new GregorianCalendar(SystemReader.GetInstance().GetTimeZone
                                                              (), SystemReader.GetInstance().GetLocale());
            DateTime parse = GitDateParser.Parse("yesterday", cal);

            cal.Add(Calendar.DATE, -1);
            cal.Set(Calendar.HOUR_OF_DAY, 0);
            cal.Set(Calendar.MINUTE, 0);
            cal.Set(Calendar.SECOND, 0);
            cal.Set(Calendar.MILLISECOND, 0);
            cal.Set(Calendar.MILLISECOND, 0);
            NUnit.Framework.Assert.AreEqual(cal.GetTime(), parse);
        }
Example #19
0
        public virtual void BadlyFormattedWithExplicitRef()
        {
            Calendar @ref = new GregorianCalendar(SystemReader.GetInstance().GetTimeZone(), SystemReader
                                                  .GetInstance().GetLocale());

            try
            {
                GitDateParser.Parse(dateStr, @ref);
                NUnit.Framework.Assert.Fail("The expected ParseException while parsing '" + dateStr
                                            + "' did not occur.");
            }
            catch (ParseException)
            {
            }
        }
Example #20
0
        // Gets an instance of a SimpleDateFormat. If there is not already an
        // appropriate instance in the (ThreadLocal) cache the create one and put in
        // into the cache
        private static SimpleDateFormat GetDateFormat(GitDateParser.ParseableSimpleDateFormat
                                                      f)
        {
            IDictionary <GitDateParser.ParseableSimpleDateFormat, SimpleDateFormat> map = formatCache
                                                                                          .Value;
            SimpleDateFormat dateFormat = map.Get(f);

            if (dateFormat != null)
            {
                return(dateFormat);
            }
            SimpleDateFormat df = SystemReader.GetInstance().GetSimpleDateFormat(f.formatStr);

            map.Put(f, df);
            return(df);
        }
        // Gets an instance of a SimpleDateFormat. If there is not already an
        // appropriate instance in the (ThreadLocal) cache the create one and put in
        // into the cache
        private static SimpleDateFormat GetDateFormat(GitDateParser.ParseableSimpleDateFormat
                                                      f)
        {
            formatCache = formatCache ?? new Dictionary <GitDateParser.ParseableSimpleDateFormat
                                                         , SimpleDateFormat>();
            SimpleDateFormat dateFormat = formatCache.Get(f);

            if (dateFormat != null)
            {
                return(dateFormat);
            }
            SimpleDateFormat df = SystemReader.GetInstance().GetSimpleDateFormat(f.formatStr);

            formatCache.Put(f, df);
            return(df);
        }
Example #22
0
 /// <summary>Execute a command and return a single line of output as a String</summary>
 /// <param name="dir">Working directory for the command</param>
 /// <param name="command">as component array</param>
 /// <param name="encoding"></param>
 /// <returns>the one-line output of the command</returns>
 protected internal static string ReadPipe(FilePath dir, string[] command, string
                                           encoding)
 {
     try
     {
         SystemProcess  p        = Runtime.GetRuntime().Exec(command, null, dir);
         BufferedReader lineRead = new BufferedReader(new InputStreamReader(p.GetInputStream
                                                                                (), encoding));
         string r = null;
         try
         {
             r = lineRead.ReadLine();
         }
         finally
         {
             p.GetOutputStream().Close();
             p.GetErrorStream().Close();
             lineRead.Close();
         }
         for (; ;)
         {
             try
             {
                 if (p.WaitFor() == 0 && r != null && r.Length > 0)
                 {
                     return(r);
                 }
                 break;
             }
             catch (Exception)
             {
             }
         }
     }
     catch (IOException e)
     {
         // Stop bothering me, I have a zombie to reap.
         if (SystemReader.GetInstance().GetProperty("jgit.fs.debug") != null)
         {
             System.Console.Error.WriteLine(e);
         }
     }
     // Ignore error (but report)
     return(null);
 }
Example #23
0
 /// <returns>the $prefix directory C Git would use.</returns>
 public virtual FilePath GitPrefix()
 {
     FS.Holder <FilePath> p = gitPrefix;
     if (p == null)
     {
         string overrideGitPrefix = SystemReader.GetInstance().GetProperty("jgit.gitprefix"
                                                                           );
         if (overrideGitPrefix != null)
         {
             p = new FS.Holder <FilePath>(new FilePath(overrideGitPrefix));
         }
         else
         {
             p = new FS.Holder <FilePath>(DiscoverGitPrefix());
         }
         gitPrefix = p;
     }
     return(p.value);
 }
Example #24
0
        public virtual void Now()
        {
            string   dateStr = "2007-02-21 15:35:00 +0100";
            DateTime refDate = SystemReader.GetInstance().GetSimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"
                                                                              ).Parse(dateStr);
            GregorianCalendar cal = new GregorianCalendar(SystemReader.GetInstance().GetTimeZone
                                                              (), SystemReader.GetInstance().GetLocale());

            cal.SetTime(refDate);
            DateTime parse = GitDateParser.Parse("now", cal);

            NUnit.Framework.Assert.AreEqual(refDate, parse);
            long t1 = SystemReader.GetInstance().GetCurrentTime();

            parse = GitDateParser.Parse("now", null);
            long t2 = SystemReader.GetInstance().GetCurrentTime();

            NUnit.Framework.Assert.IsTrue(t2 >= parse.GetTime() && parse.GetTime() >= t1);
        }
Example #25
0
        protected internal override FilePath UserHomeImpl()
        {
            string home = SystemReader.GetInstance().Getenv("HOME");

            if (home != null)
            {
                return(Resolve(null, home));
            }
            string homeDrive = SystemReader.GetInstance().Getenv("HOMEDRIVE");

            if (homeDrive != null)
            {
                string homePath = SystemReader.GetInstance().Getenv("HOMEPATH");
                return(new FilePath(homeDrive, homePath));
            }
            string homeShare = SystemReader.GetInstance().Getenv("HOMESHARE");

            if (homeShare != null)
            {
                return(new FilePath(homeShare));
            }
            return(base.UserHomeImpl());
        }
Example #26
0
		/// <param name="newReader">the new instance to use when accessing properties.</param>
		public static void SetInstance(SystemReader newReader)
		{
			INSTANCE = newReader;
		}
Example #27
0
 public _PrivilegedAction_264(SystemReader _enclosing)
 {
     this._enclosing = _enclosing;
 }
        /// <param name="when">
        /// <see cref="System.DateTime">System.DateTime</see>
        /// to format
        /// </param>
        /// <returns>
        /// age of given
        /// <see cref="System.DateTime">System.DateTime</see>
        /// compared to now formatted in the same
        /// relative format as returned by
        /// <code>git log --relative-date</code>
        /// </returns>
        public static string Format(DateTime when)
        {
            long ageMillis = SystemReader.GetInstance().GetCurrentTime() - when.GetTime();

            // shouldn't happen in a perfect world
            if (ageMillis < 0)
            {
                return(JGitText.Get().inTheFuture);
            }
            // seconds
            if (ageMillis < UpperLimit(MINUTE_IN_MILLIS))
            {
                return(MessageFormat.Format(JGitText.Get().secondsAgo, Round(ageMillis, SECOND_IN_MILLIS
                                                                             )));
            }
            // minutes
            if (ageMillis < UpperLimit(HOUR_IN_MILLIS))
            {
                return(MessageFormat.Format(JGitText.Get().minutesAgo, Round(ageMillis, MINUTE_IN_MILLIS
                                                                             )));
            }
            // hours
            if (ageMillis < UpperLimit(DAY_IN_MILLIS))
            {
                return(MessageFormat.Format(JGitText.Get().hoursAgo, Round(ageMillis, HOUR_IN_MILLIS
                                                                           )));
            }
            // up to 14 days use days
            if (ageMillis < 14 * DAY_IN_MILLIS)
            {
                return(MessageFormat.Format(JGitText.Get().daysAgo, Round(ageMillis, DAY_IN_MILLIS
                                                                          )));
            }
            // up to 10 weeks use weeks
            if (ageMillis < 10 * WEEK_IN_MILLIS)
            {
                return(MessageFormat.Format(JGitText.Get().weeksAgo, Round(ageMillis, WEEK_IN_MILLIS
                                                                           )));
            }
            // months
            if (ageMillis < YEAR_IN_MILLIS)
            {
                return(MessageFormat.Format(JGitText.Get().monthsAgo, Round(ageMillis, MONTH_IN_MILLIS
                                                                            )));
            }
            // up to 5 years use "year, months" rounded to months
            if (ageMillis < 5 * YEAR_IN_MILLIS)
            {
                long   years     = ageMillis / YEAR_IN_MILLIS;
                string yearLabel = (years > 1) ? JGitText.Get().years : JGitText.Get().year;
                //
                long   months     = Round(ageMillis % YEAR_IN_MILLIS, MONTH_IN_MILLIS);
                string monthLabel = (months > 1) ? JGitText.Get().months : (months == 1 ? JGitText
                                                                            .Get().month : string.Empty);
                //
                return(MessageFormat.Format(months == 0 ? JGitText.Get().years0MonthsAgo : JGitText
                                            .Get().yearsMonthsAgo, new object[] { years, yearLabel, months, monthLabel }));
            }
            // years
            return(MessageFormat.Format(JGitText.Get().yearsAgo, Round(ageMillis, YEAR_IN_MILLIS
                                                                       )));
        }
Example #29
0
File: FS.cs Project: Gearset/ngit
        /// <summary>Execute a command and return a single line of output as a String</summary>
        /// <param name="dir">Working directory for the command</param>
        /// <param name="command">as component array</param>
        /// <param name="encoding"></param>
        /// <returns>the one-line output of the command</returns>
        protected internal static string ReadPipe(FilePath dir, string[] command, string
                                                  encoding)
        {
            bool debug = System.Boolean.Parse(SystemReader.GetInstance().GetProperty("jgit.fs.debug"
                                                                                     ));

            try
            {
                if (debug)
                {
                    System.Console.Error.WriteLine("readpipe " + Arrays.AsList(command) + "," + dir);
                }
                SystemProcess  p        = Runtime.GetRuntime().Exec(command, null, dir);
                BufferedReader lineRead = new BufferedReader(new InputStreamReader(p.GetInputStream
                                                                                       (), encoding));
                p.GetOutputStream().Close();
                AtomicBoolean  gooblerFail = new AtomicBoolean(false);
                Sharpen.Thread gobbler     = new _Thread_300(p, debug, gooblerFail);
                // ignore
                // Just print on stderr for debugging
                // Just print on stderr for debugging
                gobbler.Start();
                string r = null;
                try
                {
                    r = lineRead.ReadLine();
                    if (debug)
                    {
                        System.Console.Error.WriteLine("readpipe may return '" + r + "'");
                        System.Console.Error.WriteLine("(ignoring remaing output:");
                    }
                    string l;
                    while ((l = lineRead.ReadLine()) != null)
                    {
                        if (debug)
                        {
                            System.Console.Error.WriteLine(l);
                        }
                    }
                }
                finally
                {
                    p.GetErrorStream().Close();
                    lineRead.Close();
                }
                for (; ;)
                {
                    try
                    {
                        int rc = p.WaitFor();
                        gobbler.Join();
                        if (rc == 0 && r != null && r.Length > 0 && !gooblerFail.Get())
                        {
                            return(r);
                        }
                        if (debug)
                        {
                            System.Console.Error.WriteLine("readpipe rc=" + rc);
                        }
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (IOException e)
            {
                // Stop bothering me, I have a zombie to reap.
                if (debug)
                {
                    System.Console.Error.WriteLine(e);
                }
            }
            // Ignore error (but report)
            if (debug)
            {
                System.Console.Error.WriteLine("readpipe returns null");
            }
            return(null);
        }
Example #30
0
 public override bool IsCaseSensitive()
 {
     return(!SystemReader.GetInstance().IsMacOS());
 }
 public virtual void SetUp()
 {
     SystemReader.SetInstance(new MockSystemReader());
 }