Exemple #1
0
        public IFile GetInputFile(FilePath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (path.IsRelative)
            {
                IFile notFound = null;
                foreach (DirectoryPath inputPath in InputPaths.Reverse())
                {
                    IFile file = GetFile(RootPath.Combine(inputPath).CombineFile(path));
                    if (notFound == null)
                    {
                        notFound = file;
                    }
                    if (file.Exists)
                    {
                        return file;
                    }
                }
                if (notFound == null)
                {
                    throw new InvalidOperationException("The input paths collection must have at least one path");
                }
                return notFound;
            }
            return GetFile(path);
        }
Exemple #2
0
            public void CanSeeIfAPathHasAnExtension(string fullPath, bool expected)
            {
                // Given, When
                FilePath path = new FilePath(fullPath);

                // Then
                Assert.AreEqual(expected, path.HasExtension);
            }
Exemple #3
0
 public void Copy(FilePath destination, bool overwrite)
 {
     if (destination == null)
     {
         throw new ArgumentNullException(nameof(destination));
     }
     FileSystem.Retry(() => _file.CopyTo(destination.FullPath, overwrite));
 }
Exemple #4
0
 public void Move(FilePath destination)
 {
     if (destination == null)
     {
         throw new ArgumentNullException(nameof(destination));
     }
     FileSystem.Retry(() => _file.MoveTo(destination.FullPath));
 }
Exemple #5
0
 /// <summary>
 /// Combines the current path with the file name of a <see cref="FilePath"/>.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns>A combination of the current path and the file name of the provided <see cref="FilePath"/>.</returns>
 public FilePath GetFilePath(FilePath path)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     return new FilePath(System.IO.Path.Combine(FullPath, path.GetFilename().FullPath));
 }
Exemple #6
0
 protected ReadWorkspace(FilePath path)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     _path = path;
 }
Exemple #7
0
 /// <summary>
 /// Combines the current path with a <see cref="FilePath"/>.
 /// The provided <see cref="FilePath"/> must be relative.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns>A combination of the current path and the provided <see cref="FilePath"/>.</returns>
 public FilePath CombineFile(FilePath path)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     return !path.IsRelative ? path : new FilePath(System.IO.Path.Combine(FullPath, path.FullPath));
 }
Exemple #8
0
            public void CanGetDirectoryForFilePath()
            {
                // Given, When
                FilePath path = new FilePath("temp/hello.txt");
                DirectoryPath directory = path.GetDirectory();

                // Then
                Assert.AreEqual("temp", directory.FullPath);
            }
            public void SameAssetInstancesIsConsideredEqual(bool isCaseSensitive)
            {
                // Given, When
                PathComparer comparer = new PathComparer(isCaseSensitive);
                FilePath path = new FilePath("shaders/basic.vert");

                // Then
                Assert.True(comparer.Equals(path, path));
            }
Exemple #10
0
 public IDocument GetDocument(IExecutionContext context, IDocument sourceDocument, FilePath source, Stream stream, 
     IEnumerable<KeyValuePair<string, object>> items = null, bool disposeStream = true)
 {
     if (sourceDocument == null || ModuleExtensions.AsNewDocumentModules.Contains(context.Module))
     {
         return new Document(_initialMetadata, source, stream, null, items, disposeStream);
     }
     return new Document((Document)sourceDocument, source, stream, items, disposeStream);
 }
Exemple #11
0
            public void ShouldThrowIfExtensionIsNull()
            {
                // Given
                FilePath path = new FilePath("temp/hello.txt");

                // When
                TestDelegate test = () => path.AppendExtension(null);

                // Then
                Assert.Throws<ArgumentNullException>(test);
            }
Exemple #12
0
            public void CanChangeExtensionOfPath()
            {
                // Given
                FilePath path = new FilePath("temp/hello.txt");

                // When
                path = path.ChangeExtension(".dat");

                // Then
                Assert.AreEqual("temp/hello.dat", path.ToString());
            }
Exemple #13
0
            public void CanAppendExtensionToPath(string extension, string expected)
            {
                // Given
                FilePath path = new FilePath("temp/hello.txt");

                // When
                path = path.AppendExtension(extension);

                // Then
                Assert.AreEqual(expected, path.ToString());
            }
            public void SamePathsAreConsideredEqual(bool isCaseSensitive)
            {
                // Given, When
                PathComparer comparer = new PathComparer(isCaseSensitive);
                FilePath first = new FilePath("shaders/basic.vert");
                FilePath second = new FilePath("shaders/basic.vert");

                // Then
                Assert.True(comparer.Equals(first, second));
                Assert.True(comparer.Equals(second, first));
            }
Exemple #15
0
            public void CanGetDirectoryForFilePathInRoot()
            {
                // Given
                FilePath path = new FilePath("hello.txt");

                // When
                DirectoryPath directory = path.Directory;

                // Then
                Assert.AreEqual(".", directory.FullPath);
            }
Exemple #16
0
            public void CanGetExtension(string fullPath, string expected)
            {
                // Given
                FilePath result = new FilePath(fullPath);

                // When
                string extension = result.Extension;

                // Then
                Assert.AreEqual(expected, extension);
            }
Exemple #17
0
            public void ShouldHideIndexPagesForFilePath(string path, string expected)
            {
                // Given
                FilePath filePath = new FilePath(path);

                // When
                string link = LinkGenerator.GetLink(filePath, null, null, true, false);

                // Then
                Assert.AreEqual(expected, link);
            }
Exemple #18
0
        public IFile GetFile(FilePath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!path.IsRelative)
            {
                throw new ArgumentException("Path must be relative", nameof(path));
            }

            return new LocalFile(_path.CombineFile(path));
        }
Exemple #19
0
        public static FilePath Resolve(DirectoryPath source, FilePath target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            return Resolve(source, target.Directory).GetFilePath(target.FileName);
        }
Exemple #20
0
        public LocalFile(FilePath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (path.IsRelative)
            {
                throw new ArgumentException("Path must be absolute", nameof(path));
            }

            _path = path.Collapse();
            _file = new FileInfo(_path.FullPath);
        }
Exemple #21
0
        protected override void ParseOptions(ArgumentSyntax syntax)
        {
            syntax.DefineOption("w|watch", ref _watch, "Watches the input folder for any changes.");
            _preview = syntax.DefineOption("p|preview", ref _previewPort, false, "Start the preview web server on the specified port (default is " + _previewPort + ").").IsSpecified;
            if (syntax.DefineOption("force-ext", ref _previewForceExtension, "Force the use of extensions in the preview web server (by default, extensionless URLs may be used).").IsSpecified && !_preview)
            {
                syntax.ReportError("force-ext can only be specified if the preview server is running.");
            }
            if (syntax.DefineOption("preview-root", ref _previewRoot, DirectoryPath.FromString, "The path to the root of the preview server, if not the output folder.").IsSpecified && !_preview)
            {
                syntax.ReportError("preview-root can only be specified if the preview server is running.");
            }
            syntax.DefineOptionList("i|input", ref _configOptions.InputPaths, DirectoryPath.FromString, "The path(s) of input files, can be absolute or relative to the current folder.");
            syntax.DefineOption("o|output", ref _configOptions.OutputPath, DirectoryPath.FromString, "The path to output files, can be absolute or relative to the current folder.");
            syntax.DefineOption("c|config", ref _configOptions.ConfigFilePath, FilePath.FromString, "Configuration file (by default, config.wyam is used).");
            syntax.DefineOption("u|update-packages", ref _configOptions.UpdatePackages, "Check the NuGet server for more recent versions of each package and update them if applicable.");
            syntax.DefineOption("use-local-packages", ref _configOptions.UseLocalPackages, "Toggles the use of a local NuGet packages folder.");
            syntax.DefineOption("use-global-sources", ref _configOptions.UseGlobalSources, "Toggles the use of the global NuGet sources (default is false).");
            syntax.DefineOption("packages-path", ref _configOptions.PackagesPath, DirectoryPath.FromString, "The packages path to use (only if use-local is true).");
            syntax.DefineOption("output-script", ref _configOptions.OutputScript, "Outputs the config script after it's been processed for further debugging.");
            syntax.DefineOption("verify-config", ref _verifyConfig, false, "Compile the configuration but do not execute.");
            syntax.DefineOption("noclean", ref _configOptions.NoClean, "Prevents cleaning of the output path on each execution.");
            syntax.DefineOption("nocache", ref _configOptions.NoCache, "Prevents caching information during execution (less memory usage but slower execution).");

            _logFilePath = $"wyam-{DateTime.Now:yyyyMMddHHmmssfff}.txt";
            if (!syntax.DefineOption("l|log", ref _logFilePath, FilePath.FromString, false, "Log all trace messages to the specified log file (by default, wyam-[datetime].txt).").IsSpecified)
            {
                _logFilePath = null;
            }

            // Metadata
            IReadOnlyList<string> globalMetadata = null;
            if (syntax.DefineOptionList("g|global", ref globalMetadata, "Specifies global metadata as a sequence of key=value pairs.").IsSpecified)
            {
                _configOptions.GlobalMetadata = MetadataParser.Parse(globalMetadata);
            }
            IReadOnlyList<string> initialMetadata = null;
            if (syntax.DefineOptionList("initial", ref initialMetadata, "Specifies initial document metadata as a sequence of key=value pairs.").IsSpecified)
            {
                _configOptions.InitialMetadata = MetadataParser.Parse(initialMetadata);
            }
        }
Exemple #22
0
 /// <summary>
 /// Specifies an alternate ViewStart file to use for all Razor pages processed by this module.
 /// </summary>
 /// <param name="path">The path to the alternate ViewStart file.</param>
 public Razor WithViewStart(FilePath path)
 {
     _viewStartPath = (doc, ctx) => path;
     return this;
 }
Exemple #23
0
 public File(FilePath path)
 {
     _path = path;
     _file = new FileInfo(path.FullPath);
 }
Exemple #24
0
 /// <summary>
 /// Specifies a file name to use as common metadata.
 /// </summary>
 /// <param name="metadataFileName">Name of the metadata file.</param>
 /// <param name="inherited">If set to <c>true</c>, metadata from documents with this file name will be inherited by documents in nested directories.</param>
 /// <param name="replace">If set to <c>true</c>, metadata from this document will replace any existing metadata on the target document.</param>
 public DirectoryMeta WithMetadataFile(FilePath metadataFileName, bool inherited = false, bool replace = false)
 {
     return WithMetadataFile((x, y) => x.Source != null && x.Source.FileName.Equals(metadataFileName), inherited, replace);
 }
Exemple #25
0
        private void LoadAssemblyFromPath(string path)
        {
            FilePath filePath = new FilePath(path);

            // Attempt to load directly, and we're done if it's absolute regardless
            if (LoadAssemblyFromFile(filePath.FullPath) != null || filePath.IsAbsolute)
            {
                return;
            }

            // Attempt to load from the entry assembly path
            if (LoadAssemblyFromFile(_entryAssemblyDirectory.Path.CombineFile(filePath).FullPath) != null)
            {
                return;
            }

            // Attempt to load from the build root
            LoadAssemblyFromFile(_fileSystem.RootPath.CombineFile(filePath).FullPath);
        }
Exemple #26
0
 /// <summary>
 /// Transforms input documents using a specified XSLT file from the file system.
 /// </summary>
 /// <param name="xsltPath">The path of the XSLT file to use.</param>
 public Xslt(FilePath xsltPath)
 {
     _xsltPath = (a, b) => xsltPath;
 }
Exemple #27
0
            public void ThrowsForRelativeFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                FilePath relativePath = new FilePath("A/B/C.txt");

                // When, Then
                Assert.Throws<ArgumentException>(() => fileSystem.GetFileProvider(relativePath));
            }
Exemple #28
0
 /// <summary>
 /// Reads the project file at the specified path.
 /// </summary>
 /// <param name="path">The project file path.</param>
 public ReadProject(FilePath path) : base(path)
 {
 }
Exemple #29
0
            public void ReturnsOtherProviderForFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                IFileProvider defaultProvider = Substitute.For<IFileProvider>();
                IFileProvider fooProvider = Substitute.For<IFileProvider>();
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, defaultProvider);
                fileSystem.FileProviders.Add("foo", fooProvider);
                FilePath path = new FilePath("foo", "/a/b/c.txt");

                // When
                IFileProvider result = fileSystem.GetFileProvider(path);

                // Then
                Assert.AreEqual(fooProvider, result);
            }
Exemple #30
0
            public void ThrowsIfProviderNotFoundForFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                FilePath path = new FilePath("foo", "/a/b/c.txt");

                // When, Then
                Assert.Throws<KeyNotFoundException>(() => fileSystem.GetFileProvider(path));
            }