Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed ruby require for hive files

  • Loading branch information...
commit e0ca98e2361254c800f97d2860baf5cbda82fe8e 1 parent 74777a0
@kmees kmees authored
View
15 src/IronSharePoint.Framework/IronConstant.cs
@@ -54,7 +54,20 @@ public static IronEnvironment IronEnv
}
}
- // static IronConstant()
+ public static string FakeHiveDirectory
+ {
+ get
+ {
+ var dir = Environment.GetEnvironmentVariable("IRONSP_HIVE");
+ if (String.IsNullOrWhiteSpace(dir))
+ {
+ dir = Path.GetTempPath();
+ }
+ return dir;
+ }
+ }
+
+ // static IronConstant()
// {
// var siteFeatureDirectory = SPFarm.Local.FeatureDefinitions[IronConstant.IronHiveSiteFeatureId].RootDirectory;
// var featureDirectory = new DirectoryInfo(siteFeatureDirectory).Parent.FullName;
View
71 src/IronSharePoint.Framework/IronPlatformAdaptationLayer.cs
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
+using IronSharePoint.Util;
using Microsoft.Scripting;
-using System.IO;
namespace IronSharePoint
{
@@ -15,8 +16,9 @@ public IronPlatformAdaptationLayer(IHive hive)
{
_hive = hive;
}
-
- public override string[] GetFileSystemEntries(string path, string searchPattern, bool includeFiles, bool includeDirectories)
+
+ public override string[] GetFileSystemEntries(string path, string searchPattern, bool includeFiles,
+ bool includeDirectories)
{
var entries = new List<string>();
if (includeFiles)
@@ -29,45 +31,84 @@ public override string[] GetFileSystemEntries(string path, string searchPattern,
//entries.AddRange(Directory.GetDirectories(path, searchPattern));
entries.AddRange(_hive.GetDirectories(path, searchPattern));
}
- var result = entries.Distinct().Select(x => Regex.IsMatch(x, @"^\w:") ? x : "@@" + x).ToArray();
+ string[] result = entries.Distinct().Select(x => Regex.IsMatch(x, @"^\w:") ? x : "@@" + x).ToArray();
return result;
}
public override bool DirectoryExists(string path)
{
- return base.DirectoryExists(path) || _hive.DirectoryExists(path);
+ return DelegateToHiveOrBase(path,
+ _hive.DirectoryExists,
+ x => base.DirectoryExists(x) || _hive.DirectoryExists(x));
}
public override bool FileExists(string file)
{
- return base.FileExists(file) || _hive.FileExists(file);
+ return DelegateToHiveOrBase(file,
+ _hive.FileExists,
+ x => base.FileExists(x) || _hive.FileExists(x));
}
public override string GetFullPath(string file)
{
- return base.FileExists(file) ? base.GetFullPath(file) : _hive.GetFullPath(file);
+ return DelegateToHiveOrBase(file,
+ _hive.GetFullPath,
+ x => base.FileExists(file) ? base.GetFullPath(file) : _hive.GetFullPath(file));
}
public override Stream OpenOutputFileStream(string path)
{
- return base.FileExists(path) ? base.OpenInputFileStream(path) : _hive.OpenOutputFileStream(path);
+ return DelegateToHiveOrBase(path,
+ _hive.OpenOutputFileStream,
+ x =>
+ base.FileExists(x) ? base.OpenOutputFileStream(x) : _hive.OpenOutputFileStream(x));
}
public override Stream OpenInputFileStream(string path)
{
- return base.FileExists(path) ? base.OpenInputFileStream(path) : _hive.OpenOutputFileStream(path);
+ return DelegateToHiveOrBase(path,
+ _hive.OpenInputFileStream,
+ x =>
+ base.FileExists(x) ? base.OpenInputFileStream(x) : _hive.OpenOutputFileStream(x));
}
public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share)
{
- return base.FileExists(path) ? base.OpenInputFileStream(path, mode, access, share) : _hive.OpenOutputFileStream(path);
+ return DelegateToHiveOrBase(path,
+ _hive.OpenInputFileStream,
+ x =>
+ base.FileExists(x)
+ ? base.OpenInputFileStream(x, mode, access, share)
+ : _hive.OpenOutputFileStream(x));
+ }
+
+ public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share,
+ int bufferSize)
+ {
+ return DelegateToHiveOrBase(path,
+ _hive.OpenInputFileStream,
+ x =>
+ base.FileExists(x)
+ ? base.OpenInputFileStream(x, mode, access, share, bufferSize)
+ : _hive.OpenOutputFileStream(x));
}
- public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
+ private T DelegateToHiveOrBase<T>(string path, Func<string, T> hive, Func<string, T> @base)
{
- return base.FileExists(path) ?
- base.OpenInputFileStream(path, mode, access, share, bufferSize) :
- _hive.OpenOutputFileStream(path);
+ T result;
+ if (path.StartsWith(IronConstant.FakeHiveDirectory))
+ {
+ result = hive(path.ReplaceFirst(IronConstant.FakeHiveDirectory, string.Empty));
+ }
+ else if (path.StartsWith(IronConstant.FakeHiveDirectory.Replace('\\', '/')))
+ {
+ result = hive(path.ReplaceFirst(IronConstant.FakeHiveDirectory.Replace('\\', '/'), string.Empty));
+ }
+ else
+ {
+ result = @base(path);
+ }
+ return result;
}
public override void CreateDirectory(string path)
@@ -90,4 +131,4 @@ public override void MoveFileSystemEntry(string sourcePath, string destinationPa
throw new NotSupportedException();
}
}
-}
+}
View
20 src/IronSharePoint.Framework/IronRuntime.cs
@@ -7,6 +7,7 @@
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
+using System.Linq;
namespace IronSharePoint
{
@@ -152,8 +153,9 @@ private void Initialize()
rubyEngine.SetSearchPaths(new List<String>
{
Path.Combine(IronConstant.IronRubyRootDirectory, @"ironruby"),
- Path.Combine(IronConstant.IronRubyRootDirectory, @"ruby\site_ruby\1.9.1"),
- Path.Combine(IronConstant.IronRubyRootDirectory, @"ruby\1.9.1")
+ Path.Combine(IronConstant.IronRubyRootDirectory, @"ruby\1.9.1"),
+ IronConstant.FakeHiveDirectory,
+ Path.Combine(IronConstant.IronRubyRootDirectory, @"ruby\site_ruby\1.9.1")
});
var ironRubyEngine = new IronEngine(this, rubyEngine);
@@ -192,11 +194,16 @@ IRON_DEFAULT_LOGGER.error ex
private void PrivilegedInitialize()
{
- string gemDir = Path.Combine(IronConstant.IronRubyRootDirectory, "lib/ironruby/gems/1.9.1").Replace("\\", "/");
+ string gemDir = Path.Combine(IronConstant.IronRubyRootDirectory, "ruby", "gems", "1.9.1");
- Environment.SetEnvironmentVariable("IRONRUBY_10_20", IronConstant.IronRubyRootDirectory);
- Environment.SetEnvironmentVariable("GEM_PATH", gemDir);
- Environment.SetEnvironmentVariable("GEM_HOME", gemDir);
+ var gemPath = (Environment.GetEnvironmentVariable("GEM_PATH") ?? "").Split(new[]{';'}, StringSplitOptions.RemoveEmptyEntries).ToList();
+ if (!gemPath.Contains(gemDir))
+ {
+ gemPath.Add(gemDir);
+ }
+ Environment.SetEnvironmentVariable("GEM_PATH", String.Join(";", gemPath));
+
+ Directory.SetCurrentDirectory(IronConstant.IronRubyRootDirectory);
}
public static IronRuntime GetDefaultIronRuntime(SPSite targetSite)
@@ -268,7 +275,6 @@ public object CreateDynamicInstance(string className, params object[] args)
object obj = null;
object dynamicType = DynamicTypeRegistry[className];
-
if (args != null && args.Length > 0)
{
obj = ScriptRuntime.Operations.CreateInstance(dynamicType, args);
Please sign in to comment.
Something went wrong with that request. Please try again.