public bool CanHandleTestFor(string assembly)
        {
            if (!_configuration.UseAutoTestTestRunner)
            {
                return(false);
            }
            if (!File.Exists(assembly))
            {
                return(false);
            }
            var plugins = new PluginLocator().Locate();

            foreach (var plugin in plugins)
            {
                var instance = plugin.New();
                if (instance == null)
                {
                    continue;
                }
                if (instance.ContainsTestsFor(assembly))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        private IGenerator CreateGenerator(IContext context)
        {
            PluginLocator pluginLocator    = context.Kernel.Get <PluginLocator>();
            Type          roslynPluginType = pluginLocator.Locate <IGenerator>();

            return((IGenerator)context.Kernel.Get(roslynPluginType ?? typeof(HelloWorldGenerator)));
        }
Ejemplo n.º 3
0
        private static void initPlugins(PluginLocator locator)
        {
            var plugins = locator.Locate();

            foreach (var plugin in plugins)
            {
                try {
                    plugin.Initialize(_path);
                    plugin.GetCrawlFileTypes();
                    ThreadPool.QueueUserWorkItem(
                        (o) => {
                        try {
                            var currentPlugin = (LanguagePlugin)o;
                            var handler       = new CrawlHandler(_cache, (s) => Logger.Write(s));
                            handler.SetLanguage(currentPlugin.GetLanguage());
                            currentPlugin.Crawl(new string[] { _path }, (line) => handler.Handle(line));
                        } catch (Exception ex) {
                            Logger.Write(ex.ToString());
                        }
                    },
                        plugin);
                } catch (Exception ex) {
                    Logger.Write(ex.ToString());
                }
            }
            Logger.Write("Plugins initialized");
        }
Ejemplo n.º 4
0
 public Installer(string token, string[] sourcePrioritization, Action <string> dispatch, PluginLocator locator)
 {
     _token          = token;
     _dispatch       = dispatch;
     _locator        = locator;
     _packageFetcher = new PackageFetcher(_token, sourcePrioritization, _dispatch);
 }
Ejemplo n.º 5
0
 public EventEndpoint(string keyPath, PluginLocator locator, OpenIDE.CodeEngine.Core.Endpoints.OutputEndpoint outputEndpoint)
 {
     _keyPath                 = keyPath;
     _outputEndpoint          = outputEndpoint;
     _server                  = new TcpServer();
     _server.IncomingMessage += Handle_serverIncomingMessage;
     _server.Start();
     _reactiveEngine = new ReactiveScriptEngine(_keyPath, locator, (publisher, msg) => _outputEndpoint.Send(publisher, msg), dispatch);
 }
Ejemplo n.º 6
0
        public void Should_create_instance()
        {
            var path    = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var locator = new PluginLocator(path);
            var plugins = locator.Locate();
            var plugin  = plugins.Where(x => x.Assembly.Equals(Path.Combine(path, "AutoTest.TestRunners.Tests.dll")) && x.Type.Equals("AutoTest.TestRunners.Tests.Plugins.Plugin1")).First();

            Assert.That(plugin.New(), Is.InstanceOf <IAutoTestNetTestRunner>());
        }
Ejemplo n.º 7
0
        public void Should_locate_plugins()
        {
            var path    = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var locator = new PluginLocator(path);
            var plugins = locator.Locate();

            Assert.IsTrue(plugins.Count() > 0);
            Assert.That(plugins.Where(x => x.Assembly.Equals(Path.Combine(path, "AutoTest.TestRunners.Tests.dll")) && x.Type.Equals("AutoTest.TestRunners.Tests.Plugins.Plugin1")).Count(), Is.EqualTo(1));
            Assert.That(plugins.Where(x => x.Assembly.Equals(Path.Combine(path, "AutoTest.TestRunners.Tests.dll")) && x.Type.Equals("AutoTest.TestRunners.Tests.Plugins.Plugin2")).Count(), Is.EqualTo(1));
        }
Ejemplo n.º 8
0
 private void Init()
 {
     if (PluginLocator == null)
     {
         throw new Exception("PlugEngine needs a ILocator to work");
     }
     Constructor   = new CompactConstructor(PluginLocator.ObjectDefinitions, "default");
     PlugsRegistry = new CompactPlugsRegistry(Constructor);
     PluginLocator.SearchPlugins();
     PlugsRegistry.Add(PluginLocator.Plugins);
 }
Ejemplo n.º 9
0
 public PluginLocator PluginLocator()
 {
     if (_pluginLocator == null)
     {
         _pluginLocator =
             new PluginLocator(
                 _settings.EnabledLanguages,
                 new ProfileLocator(_settings.RootPath),
                 (command) => dispatchMessage(command));
     }
     return(_pluginLocator);
 }
Ejemplo n.º 10
0
        private static IEnumerable <Plugin> allPlugins()
        {
            var currentDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var dir        = Path.Combine(currentDir, "TestRunners");

            if (!Directory.Exists(dir))
            {
                return new Plugin[] { }
            }
            ;
            var locator = new PluginLocator(dir);

            return(locator.Locate());
        }
Ejemplo n.º 11
0
 private static void shutdownPlugins(PluginLocator locator)
 {
     try {
         var plugins = locator.Locate();
         foreach (var plugin in plugins)
         {
             try {
                 Logger.Write("Shutting down plugin " + plugin.GetLanguage());
                 plugin.Shutdown();
             } catch (Exception ex) {
                 Logger.Write(ex.ToString());
             }
         }
     } catch {
     }
 }
 private IEnumerable <IAutoTestNetTestRunner> getIdentifiers()
 {
     if (_identifiers == null)
     {
         var locator = new PluginLocator(Path.GetFullPath("TestRunners"));
         var plugins = locator.Locate();
         _identifiers = plugins
                        .Select(x =>
         {
             var instance = x.New();
             if (instance == null)
             {
                 Logger.WriteDebug(string.Format("Could not create plugin for {0} using {1}", x.Type, x.Assembly));
             }
             return(instance);
         })
                        .Where(x => x != null);
     }
     return(_identifiers);
 }
Ejemplo n.º 13
0
        private RunOptions generateOptions(TestRunInfo[] runInfos)
        {
            var options = new RunOptions();
            var plugins = new PluginLocator().Locate();

            foreach (var plugin in plugins)
            {
                var testRun = getTests(plugin, runInfos);
                if (testRun != null)
                {
                    options.AddTestRun(testRun);
                }
            }

            if (options.TestRuns.Count() == 0)
            {
                return(null);
            }
            return(options);
        }
Ejemplo n.º 14
0
 public ReactiveScriptEngine(string path, PluginLocator locator, Action <string, string> outputDispatcher, Action <string> dispatch)
 {
     _keyPath          = path;
     _outputDispatcher = outputDispatcher;
     _dispatch         = dispatch;
     _pausedScripts    = new List <string>();
     _reader           =
         new ReactiveScriptReader(
             _keyPath,
             () => { return(locator); },
             _outputDispatcher,
             (m) => _dispatch(m));
     _touchHandler = new ScriptTouchHandler(_reader.GetPaths());
     _scripts      = _reader.Read();
     foreach (var script in _scripts)
     {
         if (script.IsService)
         {
             script.StartService();
         }
     }
 }
Ejemplo n.º 15
0
        private string getTestRunner(string testRunner, string assembly, string test)
        {
            if (testRunner.ToLower() != "any")
            {
                return(testRunner);
            }

            var currentDirectory = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                var plugins = new PluginLocator().Locate();
                foreach (var plugin in plugins)
                {
                    var instance = plugin.New();
                    if (instance == null)
                    {
                        continue;
                    }
                    if (instance.IsTest(assembly, test))
                    {
                        return(instance.Identifier);
                    }
                }
            }
            catch (Exception ex)
            {
                AutoTest.Core.DebugLog.Debug.WriteException(ex);
            }
            finally
            {
                Environment.CurrentDirectory = currentDirectory;
            }
            return(testRunner);
        }
Ejemplo n.º 16
0
        public void Start(
            string path,
            ICacheBuilder cache,
            ICrawlResult crawlReader,
            PluginLocator pluginLocator,
            EventEndpoint eventDispatcher,
            string[] ignoreDirectories)
        {
            _cache           = cache;
            _crawlReader     = crawlReader;
            _eventDispatcher = eventDispatcher;
            Logger.Write("Setting up file trackers");
            Logger.Write("Setting up token file trackers");
            _tracker = new FileChangeTracker((x) => {
                if (x.Path.StartsWith(Path.Combine(path, ".OpenIDE")))
                {
                    return;
                }
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Setting up local file trackers");
            _localTracker = new FileChangeTracker((x) => {
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Setting up global file trackers");
            _globalTracker = new FileChangeTracker((x) => {
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Adding plugins to cache");
            var plugins = pluginLocator.Locate().ToList();

            foreach (var x in plugins)
            {
                var plugin = new PluginPattern(x);
                _plugins.Add(plugin);
                _cache.Plugins.Add(
                    new CachedPlugin(x.GetLanguage(), plugin.Patterns));
                Logger.Write("Added plugin " + x.GetLanguage());
            }
            var locator     = new ProfileLocator(path);
            var profilePath = locator.GetLocalProfilePath(locator.GetActiveLocalProfile());

            if (Directory.Exists(profilePath))
            {
                Logger.Write("Starting tracker for {0}", path);
                _tracker.Start(path, getFilter(), handleChanges, ignoreDirectories);
            }
            else
            {
                Logger.Write("No local configuration point so not starting file tracker");
            }
            if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
            {
                if (Directory.Exists(profilePath))
                {
                    Logger.Write("Starting tracker for {0}", profilePath);
                    _localTracker.Start(profilePath, getFilter(), handleChanges, ignoreDirectories);
                }
            }
            var globalPath = locator.GetGlobalProfilePath(locator.GetActiveGlobalProfile());

            if (Directory.Exists(globalPath))
            {
                Logger.Write("Starting tracker for {0}", globalPath);
                _globalTracker.Start(globalPath, getFilter(), handleChanges, ignoreDirectories);
            }
        }
Ejemplo n.º 17
0
        public static CommandEndpoint GetEndpoint(string path, string[] enabledLanguages)
        {
            _path = path;
            var reader = new ConfigReader(_path);

            _interpreters = new Interpreters(_path);
            ProcessExtensions.GetInterpreter =
                (file) => {
                var interpreters = _interpreters
                                   .GetInterpreterFor(Path.GetExtension(file));
                return(interpreters);
            };
            _cache          = new TypeCache();
            _outputEndpoint = new OutputEndpoint(_path);
            Logger.Write("Event endpoint serving on port: {0}", _outputEndpoint.Port);
            var responseDispatcher = new ResponseDispatcher(
                _path,
                false,
                "language-output ",
                (p, m) => _outputEndpoint.Send(p, m),
                (m) => _endpoint.Handle(m),
                (m) => {}
                );

            responseDispatcher.OnlyCommands();
            _pluginLocator = new PluginLocator(
                enabledLanguages,
                new ProfileLocator(_path),
                (msg) => {
                responseDispatcher.Handle(false, msg);
            }
                );
            initPlugins(_pluginLocator);

            _eventEndpoint = new EventEndpoint(_path, _pluginLocator, _outputEndpoint);
            _eventEndpoint.Start();
            Logger.Write("Event endpoint listening on port: {0}", _eventEndpoint.Port);

            Logger.Write("Creating plugin file tracker");
            _tracker = new PluginFileTracker();
            Logger.Write("Starting plugin file tracker");
            var ignoreDirSetting  = reader.Get("oi.ignore.directories");
            var ignoreDirectories = new string[] {};

            if (ignoreDirSetting != null)
            {
                ignoreDirectories = ignoreDirSetting
                                    .Split(new[] { ',' })
                                    .Select(x => {
                    if (Path.IsPathRooted(x))
                    {
                        return(x);
                    }
                    return(Path.Combine(_path, x));
                })
                                    .ToArray();
            }
            _tracker.Start(
                _path,
                _cache,
                _cache,
                _pluginLocator,
                _eventEndpoint,
                ignoreDirectories);
            Logger.Write("Plugin file tracker started");

            _endpoint = new CommandEndpoint(_path, _cache, _eventEndpoint);
            _endpoint.AddHandler(messageHandler);

            _handlers.AddRange(new IHandler[] {
                new GetProjectsHandler(_endpoint, _cache),
                new GetFilesHandler(_endpoint, _cache),
                new GetCodeRefsHandler(_endpoint, _cache),
                new GetSignatureRefsHandler(_endpoint, _cache),
                new GoToDefinitionHandler(_endpoint, _cache, _pluginLocator),
                new FindTypeHandler(_endpoint, _cache),
                new SnippetEditHandler(_endpoint, _cache, _path),
                new SnippetDeleteHandler(_cache, _path),
                new GetRScriptStateHandler(_endpoint, _eventEndpoint),
                new CompleteSnippetHandler(_cache, _path, _endpoint),
                new WriteOutputHandler(_eventEndpoint),

                // Make sure this handler is the last one since the command can be file extension or language name
                new LanguageCommandHandler(_endpoint, _cache, _pluginLocator)
            });
            Logger.Write("Command endpoint started");
            return(_endpoint);
        }
Ejemplo n.º 18
0
 public LanguageCommandHandler(CommandEndpoint endpoint, ICacheBuilder cache, PluginLocator pluginLocator)
 {
     _endpoint      = endpoint;
     _cache         = cache;
     _pluginLocator = pluginLocator;
 }
Ejemplo n.º 19
0
        public void Init()
        {
            var fileCache = new Dictionary <string, Content <Stream> > ();
            Func <string, Content <Stream> > file2Content = (path) => {
                Content <Stream> result = null;
                if (!fileCache.TryGetValue(path, out result))
                {
                    var s = File.OpenRead(path);
                    s.Position = 0;
                    result     = new Content <Stream> (s, CompressionType.None, ContentTypes.Unknown);
                    fileCache.Add(path, result);
                }
                return(result);
            };

            var pdfResponse = new WebResponse {
                AbsoluteUri = WebServer.Uri + "pdf",
                ClearContentAfterServing = false,
                IsStreamOwner            = false
            };

            var viewerDir        = new PluginLocator().PluginDir(PdjJsDirectory) + Path.DirectorySeparatorChar;
            var viewerServerPath = WebServer.Uri + PdjJsDirectory + "/";

            this.ContentGetter = (uri) => {
                if (pdfResponse.AbsoluteUri == uri)
                {
                    return(pdfResponse.GetContentFromContent(
                               new Content <Stream> (
                                   this.Pdf,
                                   CompressionType.None,
                                   PdfContentSpot.PdfContentType)));
                }

                if (uri.StartsWith(viewerServerPath))
                {
                    if (WebServer.HasContent(uri))
                    {
                        return(WebServer.GetContent(uri));
                    }
                    else
                    {
                        var fileName = uri.Replace(viewerServerPath, viewerDir);
                        if (fileName.Contains('?'))
                        {
                            fileName = fileName.Substring(0, fileName.IndexOf('?'));
                        }
                        var c = file2Content(fileName);
                        var r = new WebResponse {
                            AbsoluteUri = uri, ClearContentAfterServing = false, IsStreamOwner = false
                        };
                        var fileGetter = r.Getter(c);
                        WebServer.AddContent(r.AbsoluteUri, fileGetter);
                        return(fileGetter(uri));
                    }
                }
                else
                {
                    Trace.WriteLine("Request not answered: " + uri);
                }

                return(null);
            };

            WebServer.ContentGetter = this.ContentGetter;

            WebServer.Closed += (s, e) => {
                fileCache.Values.ForEach(c => c.Data.Dispose());
                fileCache.Clear();
            };

            ViewerUri = viewerServerPath + ViewerFileName + "?file=" +
                        System.Net.WebUtility.HtmlEncode(pdfResponse.AbsoluteUri);
        }
Ejemplo n.º 20
0
 public GoToDefinitionHandler(CommandEndpoint endpoint, TypeCache cache, PluginLocator locator)
 {
     _endpoint      = endpoint;
     _cache         = cache;
     _pluginLocator = locator;
 }
Ejemplo n.º 21
0
 public ConfigurationHandler(string token, PluginLocator locator, Action <string> eventDispatcher)
 {
     _token           = token;
     _pluginLocator   = locator;
     _eventDispatcher = eventDispatcher;
 }