コード例 #1
0
        /// <summary>
        /// Processes the specified line.
        /// </summary>
        /// <param name="processor">The script processor.</param>
        /// <param name="context">The script processor context.</param>
        /// <param name="currentScriptPath">The current script path.</param>
        /// <param name="line">The line to process.</param>
        /// <returns>
        ///   <c>true</c> if the processor handled the line; otherwise <c>false</c>.
        /// </returns>
        public override bool Process(IScriptProcessor processor, ScriptProcessorContext context, FilePath currentScriptPath, string line)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var tokens = Split(line);

            if (tokens.Length <= 0)
            {
                return(false);
            }

            if (!tokens[0].Equals("#r", StringComparison.Ordinal) &&
                !tokens[0].Equals("#reference", StringComparison.Ordinal))
            {
                return(false);
            }

            var referencePath = new FilePath(tokens[1].UnQuote());

            var directoryPath         = GetAbsoluteDirectory(currentScriptPath);
            var absoluteReferencePath = referencePath.MakeAbsolute(directoryPath);

            context.AddReference(_fileSystem.Exist(absoluteReferencePath)
                ? absoluteReferencePath.FullPath : referencePath.FullPath);

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Processes the specified line.
        /// </summary>
        /// <param name="processor">The script processor.</param>
        /// <param name="context">The script processor context.</param>
        /// <param name="currentScriptPath">The current script path.</param>
        /// <param name="line">The line to process.</param>
        /// <returns>
        ///   <c>true</c> if the processor handled the line; otherwise <c>false</c>.
        /// </returns>
        public override bool Process(IScriptProcessor processor, ScriptProcessorContext context, FilePath currentScriptPath, string line)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var tokens    = Split(line);
            var directive = tokens.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(directive))
            {
                return(false);
            }

            if (!directive.Equals("#addin", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Fetch the addin NuGet ID.
            var addInId = tokens
                          .Select(value => value.UnQuote())
                          .Skip(1).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(addInId))
            {
                return(false);
            }

            // Fetch optional NuGet source.
            var source = tokens
                         .Skip(2)
                         .Select(value => value.UnQuote())
                         .FirstOrDefault();

            // Get the directory path to Cake.
            var applicationRoot = _environment.GetApplicationRoot();

            // Get the addin directory.
            var addInRootDirectoryPath = applicationRoot
                                         .Combine("..\\Addins")
                                         .Collapse()
                                         .MakeAbsolute(_environment);

            var addInDirectoryPath = addInRootDirectoryPath.Combine(addInId);
            var addInRootDirectory = _fileSystem.GetDirectory(addInRootDirectoryPath);

            // Create the addin directory if it doesn't exist.
            if (!addInRootDirectory.Exists)
            {
                _log.Verbose("Creating addin directory {0}", addInRootDirectoryPath.FullPath);
                addInRootDirectory.Create();
            }

            // Fetch available addin assemblies.
            var addInAssemblies = GetAddInAssemblies(addInDirectoryPath);

            // If no assemblies were found, try install addin from NuGet.
            if (addInAssemblies.Length == 0)
            {
                InstallAddin(addInId, addInRootDirectory, source);
                addInAssemblies = GetAddInAssemblies(addInDirectoryPath);
            }

            // Validate found assemblies.
            if (addInAssemblies.Length == 0)
            {
                throw new CakeException("Failed to find AddIn assemblies");
            }

            // Reference found assemblies.
            foreach (var assemblyPath in addInAssemblies.Select(assembly => assembly.Path.FullPath))
            {
                _log.Verbose("Addin: {0}, adding Reference {1}", addInId, assemblyPath);
                context.AddReference(assemblyPath);
            }

            return(true);
        }