Example #1
0
        public async Task GetParentFileTest(string inputFile, string expectedParentFile)
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            Project p   = (Project)sol.Items [0];
            var     dir = p.BaseDirectory;

            string inputFileDestination  = Path.Combine(dir, "FileNesting", inputFile);
            string parentFileDestination = Path.Combine(dir, "FileNesting", expectedParentFile);

            p.AddDirectory("FileNesting");
            p.AddFile(inputFileDestination);
            p.AddFile(parentFileDestination);

            string parentFile = FileNestingService.GetParentFile(p, inputFileDestination);

            Assert.That(parentFile, Is.EqualTo(parentFileDestination), $"Was expecting parent file {parentFileDestination} for {inputFileDestination} but got {parentFile}");

            // Now check we get nothing when parent file doesn't exist
            p.Files.Remove(parentFileDestination);
            parentFile = FileNestingService.GetParentFile(p, inputFileDestination);
            Assert.Null(parentFile, $"Was expecting no parent file for {inputFileDestination} but got {parentFile}");

            sol.Dispose();
        }
Example #2
0
        public override object GetParentObject(object dataObject)
        {
            var file = (ProjectFile)dataObject;
            var dir  = !file.IsLink ? file.FilePath.ParentDirectory : file.Project.BaseDirectory.Combine(file.ProjectVirtualPath).ParentDirectory;

            if (!string.IsNullOrEmpty(file.DependsOn))
            {
                ProjectFile groupUnder = file.Project.Files.GetFile(file.FilePath.ParentDirectory.Combine(file.DependsOn));
                if (groupUnder != null)
                {
                    return(groupUnder);
                }
            }
            else
            {
                // File nesting
                var parentFile = FileNestingService.GetParentFile(file);
                if (parentFile != null)
                {
                    return(parentFile);
                }
            }

            if (dir == file.Project.BaseDirectory)
            {
                return(file.Project);
            }

            return(new ProjectFolder(dir, file.Project, null));
        }
        public async Task AspNetCore_FileNesting()
        {
            string projectFileName = Util.GetSampleProject("aspnetcore-empty-30", "aspnetcore-empty-30.sln");

            using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), projectFileName)) {
                var files = new List <(string, string)> ();
                files.Add(("Index.cshtml.cs", "Index.cshtml"));
                files.Add(("file.html.css", "file.html"));
                files.Add(("bootstrap.css.map", "bootstrap.css"));
                files.Add(("jquery.js", "jquery.ts"));
                files.Add(("site-vsdoc.js", "site.js"));
                files.Add(("jquery.min.js", "jquery.js"));
                files.Add(("template.cs", "template.tt"));
                files.Add(("template.doc", "template.tt"));
                files.Add((".bowerrc", "bower.json"));

                var project = sol.GetAllProjectsWithFlavor <AspNetCoreProjectExtension> ().FirstOrDefault();

                var dir = project.BaseDirectory;
                project.AddDirectory("FileNesting");

                foreach (var f in files)
                {
                    // Create files
                    string inputFileDestination  = Path.Combine(dir, "FileNesting", f.Item1);
                    string parentFileDestination = Path.Combine(dir, "FileNesting", f.Item2);

                    File.WriteAllText(parentFileDestination, "");
                    var parentFile = project.AddFile(parentFileDestination);
                    File.WriteAllText(inputFileDestination, "");
                    var inputFile = project.AddFile(inputFileDestination);

                    var actualParentFile = FileNestingService.GetParentFile(inputFile);
                    Assert.That(parentFile, Is.EqualTo(actualParentFile), $"Was expecting parent file {parentFileDestination} for {inputFileDestination} but got {actualParentFile}");

                    // Disable file nesting on the solution
                    sol.UserProperties.SetValue("MonoDevelop.Ide.FileNesting.Enabled", false);
                    Assert.False(FileNestingService.IsEnabledForProject(project));
                    Assert.Null(FileNestingService.GetParentFile(inputFile));

                    // Re-enable file nesting on the solution
                    sol.UserProperties.SetValue("MonoDevelop.Ide.FileNesting.Enabled", true);
                    Assert.True(FileNestingService.IsEnabledForProject(project));

                    // Test removing files
                    project.Files.Remove(inputFile);
                    Assert.That(FileNestingService.GetChildren(parentFile).Count, Is.EqualTo(0));
                    project.Files.Remove(parentFile);
                }
            }
        }
Example #4
0
 static void CheckAspNetCoreNestingRules(Solution sol)
 {
     foreach (var p in sol.GetAllProjects())
     {
         foreach (var si in p.Files)
         {
             if (si.DependentChildren != null && si.DependentChildren.Count > 0)
             {
                 foreach (var c in si.DependentChildren)
                 {
                     Assert.True(FileNestingService.GetParentFile(p, c.FilePath) == si.FilePath);
                 }
             }
         }
     }
 }
Example #5
0
        internal bool ResolveParent()
        {
            if (dependsOnFile == null && (!string.IsNullOrEmpty(dependsOn) && Project != null))
            {
                //NOTE also that the dependent files are always assumed to be in the same directory
                //This matches VS behaviour
                var parentPath = DependencyPath;

                //don't allow cyclic references
                if (parentPath == FilePath)
                {
                    LoggingService.LogWarning(
                        "Cyclic dependency in project '{0}': file '{1}' depends on '{2}'",
                        Project == null ? "(none)" : Project.Name, FilePath, parentPath
                        );
                    return(true);
                }

                dependsOnFile = Project.Files.GetFile(parentPath);
                if (dependsOnFile != null)
                {
                    if (dependsOnFile.dependentChildren == null)
                    {
                        dependsOnFile.dependentChildren = new List <ProjectFile> ();
                    }
                    dependsOnFile.dependentChildren.Add(this);
                    return(true);
                }
            }
            else
            {
                // File nesting
                var parentPath = FileNestingService.GetParentFile(Project, Name);
                dependsOnFile = Project.Files.GetFile(parentPath);
                if (dependsOnFile != null)
                {
                    if (dependsOnFile.dependentChildren == null)
                    {
                        dependsOnFile.dependentChildren = new List <ProjectFile> ();
                    }
                    dependsOnFile.dependentChildren.Add(this);
                    return(true);
                }
            }

            return(false);
        }