コード例 #1
0
        AddRedirectedPackageDirectory()
        {
            var allPackageDirRedirection = Graph.Instance.ScriptAssembly.GetCustomAttributes(typeof(PackageDirectoryRedirectAttribute), false);

            if (allPackageDirRedirection.Length > 0)
            {
                foreach (PackageDirectoryRedirectAttribute packageDirRedirect in allPackageDirRedirection)
                {
                    if (packageDirRedirect.Name == PackageDefinition.Name)
                    {
                        if (null != packageDirRedirect.Version)
                        {
                            if (packageDirRedirect.Version != PackageDefinition.Version)
                            {
                                continue;
                            }
                        }

                        if (RelativePathUtilities.IsPathAbsolute(packageDirRedirect.RedirectedPath))
                        {
                            this.Macros.AddVerbatim("packagedir", packageDirRedirect.RedirectedPath);
                        }
                        else
                        {
                            this.Macros.Add("packagedir", this.CreateTokenizedString("@normalize($(bampackagedir)/$(0))", Bam.Core.TokenizedString.CreateVerbatim(packageDirRedirect.RedirectedPath)));
                        }
                        return;
                    }
                }
            }
            this.Macros.Add("packagedir", this.CreateTokenizedString("$(bampackagedir)"));
        }
コード例 #2
0
        AddRedirectedPackageDirectory(
            Module moduleWithAttributes)
        {
            var allModulePackageDirRedirection = moduleWithAttributes.GetType().GetCustomAttributes(typeof(ModulePackageDirectoryRedirectAttribute), false);

            if (allModulePackageDirRedirection.Length > 0)
            {
                if (allModulePackageDirRedirection.Length > 1)
                {
                    throw new Exception("Cannot be more than one module packagedir redirection attribute on module {0}", moduleWithAttributes.GetType().FullName);
                }
                var attr = allModulePackageDirRedirection[0] as ModulePackageDirectoryRedirectAttribute;
                var redirectedNamespace         = attr.SourceModuleType.Namespace;
                var redirectedPackageDefinition = Graph.Instance.Packages.FirstOrDefault(item => item.Name == redirectedNamespace);
                if (null == redirectedNamespace)
                {
                    throw new Exception("Unable to find package definition for module type {0}", attr.SourceModuleType.FullName);
                }
                this.Macros.AddVerbatim("packagedir", redirectedPackageDefinition.GetPackageDirectory());
                return;
            }

            var allPackageDirRedirection = Graph.Instance.ScriptAssembly.GetCustomAttributes(typeof(PackageDirectoryRedirectAttribute), false);

            if (allPackageDirRedirection.Length > 0)
            {
                foreach (PackageDirectoryRedirectAttribute packageDirRedirect in allPackageDirRedirection)
                {
                    if (packageDirRedirect.Name == PackageDefinition.Name)
                    {
                        if (null != packageDirRedirect.Version)
                        {
                            if (packageDirRedirect.Version != PackageDefinition.Version)
                            {
                                continue;
                            }
                        }

                        if (RelativePathUtilities.IsPathAbsolute(packageDirRedirect.RedirectedPath))
                        {
                            this.Macros.AddVerbatim("packagedir", packageDirRedirect.RedirectedPath);
                        }
                        else
                        {
                            this.Macros.Add("packagedir", this.CreateTokenizedString("@normalize($(bampackagedir)/$(0))", Bam.Core.TokenizedString.CreateVerbatim(packageDirRedirect.RedirectedPath)));
                        }
                        return;
                    }
                }
            }
            this.Macros.Add("packagedir", this.CreateTokenizedString("$(bampackagedir)"));
        }
コード例 #3
0
        FunctionExpression(
            string functionName,
            string argument)
        {
            switch (functionName)
            {
            case "basename":
                return(System.IO.Path.GetFileNameWithoutExtension(argument));

            case "filename":
                return(System.IO.Path.GetFileName(argument));

            case "dir":
                return(System.IO.Path.GetDirectoryName(argument));

            case "normalize":
                return(System.IO.Path.GetFullPath(argument));

            case "changeextension":
            {
                var split = argument.Split(',');
                if (split.Length != 2)
                {
                    throw new Exception("Expected 2, not {0}, arguments in the function call {1}({2}) in {3}",
                                        split.Length,
                                        functionName,
                                        argument,
                                        this.OriginalString);
                }
                var original  = split[0];
                var extension = split[1].Trim();
                var changed   = System.IO.Path.ChangeExtension(original, extension);
                return(changed);
            }

            case "removetrailingseperator":
                Log.MessageAll("DEPRECATED for removal in v1.1.0: Use 'removetrailingseparator' with the correct spelling instead.");
                goto case "removetrailingseparator";

            case "removetrailingseparator":
                return(argument.TrimEnd(System.IO.Path.DirectorySeparatorChar));

            case "relativeto":
            {
                var split = argument.Split(',');
                if (split.Length != 2)
                {
                    throw new Exception("Expected 2, not {0}, arguments in the function call {1}({2}) in {3}",
                                        split.Length,
                                        functionName,
                                        argument,
                                        this.OriginalString);
                }
                var path     = split[0];
                var root     = split[1] + System.IO.Path.DirectorySeparatorChar;
                var relative = RelativePathUtilities.GetPath(path, root);
                return(relative);
            }

            case "trimstart":
            {
                var split = argument.Split(',');
                if (split.Length != 2)
                {
                    throw new Exception("Expected 2, not {0}, arguments in the function call {1}({2}) in {3}",
                                        split.Length,
                                        functionName,
                                        argument,
                                        this.OriginalString);
                }
                var original = split[0];
                var totrim   = split[1];
                while (original.StartsWith(totrim))
                {
                    original = original.Replace(totrim, string.Empty);
                }
                return(original);
            }

            case "escapedquotes":
            {
                if (OSUtilities.IsWindowsHosting)
                {
                    // on Windows, escape any backslashes, as these are normal Windows paths
                    // so don't interpret them as control characters
                    argument = argument.Replace("\\", "\\\\");
                }
                return(System.String.Format("\"{0}\"", argument));
            }

            case "ifnotempty":
            {
                var split = argument.Split(',');
                if (split.Length != 3)
                {
                    throw new Exception("Expected 3, not {0}, arguments in the function call {1}({2}) in {3}",
                                        split.Length,
                                        functionName,
                                        argument,
                                        this.OriginalString);
                }
                var predicateString = split[0];
                if (!System.String.IsNullOrEmpty(predicateString))
                {
                    var positiveString = split[1];
                    return(positiveString);
                }
                else
                {
                    var negativeString = split[2];
                    return(negativeString);
                }
            }

            default:
                throw new Exception("Unknown post-function '{0}' in TokenizedString '{1}'", functionName, this.OriginalString);
            }
        }