Ejemplo n.º 1
0
        /// <summary>
        /// Searches file in load directories and then appends extensions.
        /// </summary>
        private ResolvedFile FindFile(string /*!*/ path, bool appendExtensions, string[] sourceFileExtensions)
        {
            Assert.NotNull(path);
            bool isAbsolutePath;

#if SILVERLIGHT
            {
#else
            if (path.StartsWith("~/", StringComparison.Ordinal) || path.StartsWith("~\\", StringComparison.Ordinal))
            {
                path           = RubyUtils.ExpandPath(_context.Platform, path);
                isAbsolutePath = true;
            }
            else
            {
#endif
                try {
                    isAbsolutePath = Platform.IsAbsolutePath(path);
                } catch (ArgumentException e) {
                    throw RubyExceptions.CreateLoadError(e);
                }
            }

            string extension = RubyUtils.GetExtension(path);

            // Absolute path -> load paths not consulted.
            if (isAbsolutePath)
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            string[] loadPaths = GetLoadPathStrings();

            if (loadPaths.Length == 0)
            {
                return(null);
            }

            // If load paths are non-empty and the path starts with .\ or ..\ then MRI also ignores the load paths.
            if (path.StartsWith("./", StringComparison.Ordinal) ||
                path.StartsWith("../", StringComparison.Ordinal) ||
                path.StartsWith(".\\", StringComparison.Ordinal) ||
                path.StartsWith("..\\", StringComparison.Ordinal))
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            foreach (var dir in loadPaths)
            {
                ResolvedFile result = ResolveFile(RubyUtils.CombinePaths(dir, path), extension, appendExtensions, sourceFileExtensions);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void AddStandardLibraryPath(RubyArray /*!*/ loadPaths, string path, string applicationBaseDir)
        {
#if FEATURE_FILESYSTEM
            bool isFullPath;
            if (path != null)
            {
                try {
                    isFullPath = Platform.IsAbsolutePath(path);
                } catch {
                    loadPaths.Add(_context.EncodePath(path));
                    return;
                }
            }
            else
            {
#if DEBUG
                // For developer use, add Src/StdLib
                string devStdLib = "../../Src/StdLib";
                if (Directory.Exists(devStdLib))
                {
                    path = devStdLib;
                }
#else
                path = "../Lib";
#endif
                isFullPath = false;
            }

            if (!isFullPath)
            {
                try {
                    if (String.IsNullOrEmpty(applicationBaseDir))
                    {
                        applicationBaseDir = _context.Platform.GetEnvironmentVariable(RubyContext.BinDirEnvironmentVariable);
                        if (!Directory.Exists(applicationBaseDir))
                        {
                            applicationBaseDir = AppDomain.CurrentDomain.BaseDirectory;
                        }
                    }
                } catch (SecurityException) {
                    applicationBaseDir = null;
                }

                try {
                    path = Platform.GetFullPath(RubyUtils.CombinePaths(applicationBaseDir, path));
                } catch {
                    loadPaths.Add(_context.EncodePath(path));
                    return;
                }
            }

            path = path.Replace('\\', '/');
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ironruby")));
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ruby/site_ruby/" + _context.StandardLibraryVersion)));
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ruby/" + _context.StandardLibraryVersion)));
#endif
        }
Ejemplo n.º 3
0
        private void AddStandardLibraryPath(RubyArray /*!*/ loadPaths, string path, string applicationBaseDir)
        {
#if !SILVERLIGHT // no library paths on Silverlight
            bool isFullPath;
            if (path != null)
            {
                try {
                    isFullPath = Platform.IsAbsolutePath(path);
                } catch {
                    loadPaths.Add(_context.EncodePath(path));
                    return;
                }
            }
            else
            {
                path       = "../Lib";
                isFullPath = false;
            }

            if (!isFullPath)
            {
                try {
                    if (String.IsNullOrEmpty(applicationBaseDir))
                    {
                        applicationBaseDir = _context.Platform.GetEnvironmentVariable(RubyContext.BinDirEnvironmentVariable);
                        if (!Directory.Exists(applicationBaseDir))
                        {
                            applicationBaseDir = AppDomain.CurrentDomain.BaseDirectory;
                        }
                    }
                } catch (SecurityException) {
                    applicationBaseDir = null;
                }

                try {
                    path = Platform.GetFullPath(RubyUtils.CombinePaths(applicationBaseDir, path));
                } catch {
                    loadPaths.Add(_context.EncodePath(path));
                    return;
                }
            }

            path = path.Replace('\\', '/');
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ironruby")));
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ruby/site_ruby/" + _context.StandardLibraryVersion)));
            loadPaths.Add(_context.EncodePath(RubyUtils.CombinePaths(path, "ruby/" + _context.StandardLibraryVersion)));
#endif
        }
Ejemplo n.º 4
0
        private ResolvedFile FindFile(string /*!*/ path, bool appendExtensions, string[] sourceFileExtensions)
        {
            Assert.NotNull(path);
            bool   isAbsolutePath;
            string extension;
            string home = null;

#if !SILVERLIGHT
            if (path.StartsWith("~/", StringComparison.Ordinal) || path.StartsWith("~\\", StringComparison.Ordinal))
            {
                try {
                    home = Environment.GetEnvironmentVariable("HOME");
                } catch (SecurityException) {
                    home = null;
                }

                if (home == null)
                {
                    throw RubyExceptions.CreateArgumentError(String.Format("couldn't find HOME environment -- expanding `{0}'", path));
                }
            }
#endif
            try {
                if (home != null)
                {
                    path = RubyUtils.CombinePaths(home, path.Substring(2));
                }

                isAbsolutePath = Platform.IsAbsolutePath(path);
                extension      = RubyUtils.GetExtension(path);
            } catch (ArgumentException e) {
                throw RubyExceptions.CreateLoadError(e);
            }

            // Absolute path -> load paths not consulted.
            if (isAbsolutePath)
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            string[] loadPaths = GetLoadPathStrings();

            if (loadPaths.Length == 0)
            {
                return(null);
            }

            // If load paths are non-empty and the path starts with .\ or ..\ then MRI also ignores the load paths.
            if (path.StartsWith("./", StringComparison.Ordinal) ||
                path.StartsWith("../", StringComparison.Ordinal) ||
                path.StartsWith(".\\", StringComparison.Ordinal) ||
                path.StartsWith("..\\", StringComparison.Ordinal))
            {
                return(ResolveFile(path, extension, appendExtensions, sourceFileExtensions));
            }

            foreach (var dir in loadPaths)
            {
                try {
                    ResolvedFile result = ResolveFile(RubyUtils.CombinePaths(dir, path), extension, appendExtensions, sourceFileExtensions);
                    if (result != null)
                    {
                        return(result);
                    }
                } catch (ArgumentException) {
                    // invalid characters in path
                }
            }

            return(null);
        }