public void Read(string filename)
        {
            // Example:
            // <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
            //      <ItemGroup>
            //			<ProjectReference Include="..\Cx.Attributes\Cx.Attributes.csproj">
            //				<Project>{EFDBD81C-64BE-47F3-905E-7618B61BD224}</Project>
            //				<Name>Cx.Attributes</Name>
            //			</ProjectReference>
            XDocument  xdoc = XDocument.Load(filename);
            XNamespace ns   = "http://schemas.microsoft.com/developer/msbuild/2003";

            IEnumerable <XElement> tfw = xdoc.Root.Elements(ns + "PropertyGroup").Elements(ns + "TargetFrameworkVersion");

            if (tfw.Count() > 0)
            {
                TargetVersion = tfw.First().Value;
            }

            Guid = new Guid(xdoc.Root.Elements(ns + "PropertyGroup").Elements(ns + "ProjectGuid").First().Value);

            OutputType = xdoc.Root.Elements(ns + "PropertyGroup").Elements(ns + "OutputType").First().Value;

            foreach (var projRef in from el in xdoc.Root.Elements(ns + "ItemGroup").Elements(ns + "ProjectReference")
                     select new
            {
                Path = el.Attribute("Include").Value,
                Name = el.Element(ns + "Name").Value,
            })
            {
                string projPath = Path.Combine(Path.GetDirectoryName(filename), projRef.Path);
                ReferencedProjects.Add(projRef.Name, projPath);
            }
        }
        public void ShouldAddProjectToPathThenFillCopyForEachReferencedProjects()
        {
            //GIVEN
            var projects   = new ReferencedProjects(Any.Array <ProjectId>(), Any.Instance <INScanSupport>());
            var reference1 = Substitute.For <IReferencedProject>();
            var reference2 = Substitute.For <IReferencedProject>();
            var reference3 = Substitute.For <IReferencedProject>();
            var dependencyPathInProgress = Substitute.For <IDependencyPathInProgress>();
            var clonedPathInProgress1    = Any.Instance <IDependencyPathInProgress>();
            var clonedPathInProgress2    = Any.Instance <IDependencyPathInProgress>();
            var clonedPathInProgress3    = Any.Instance <IDependencyPathInProgress>();
            var project = Any.Instance <IDependencyPathBasedRuleTarget>();


            projects.Add(Any.ProjectId(), reference1);
            projects.Add(Any.ProjectId(), reference2);
            projects.Add(Any.ProjectId(), reference3);

            dependencyPathInProgress.CloneWith(project).Returns(
                clonedPathInProgress1,
                clonedPathInProgress2,
                clonedPathInProgress3);

            //WHEN
            projects.FillAllBranchesOf(dependencyPathInProgress, project);

            //THEN
            reference1.Received(1).FillAllBranchesOf(clonedPathInProgress1);
            reference2.Received(1).FillAllBranchesOf(clonedPathInProgress2);
            reference3.Received(1).FillAllBranchesOf(clonedPathInProgress3);
        }
Beispiel #3
0
 public ProjectModel AddReferencedProjects(params string[] referencedProjects)
 {
     ReferencedProjects.AddRange(referencedProjects.Select(r => new ReferencedProjectModel()
     {
         ProjectId = r
     }));
     return(this);
 }
Beispiel #4
0
 public void RemoveImportedModule(string path)
 {
     VSGeneroPackage.Instance.DefaultAnalyzer.RemoveImportedProject(path);
     if (ReferencedProjects.ContainsKey(path))
     {
         IGeneroProject remEntry;
         ReferencedProjects.TryRemove(path, out remEntry);
     }
 }
Beispiel #5
0
 public void ReferencesProjects(params CsProj[] projectReferences)
 {
     foreach (var reference in projectReferences)
     {
         if (!ReferencedProjects.Select(tuple => tuple.Value).Contains(reference.Guid))
         {
             ReferencedProjects.Add(reference.AssemblyName, reference.Guid);
         }
     }
 }
        public void ShouldFinalizeDependencyPathWithProjectWhenTheReferencesAreEmpty()
        {
            //GIVEN
            var projects = new ReferencedProjects(Any.Array <ProjectId>(), Any.Instance <INScanSupport>());
            var dependencyPathInProgress = Substitute.For <IDependencyPathInProgress>();
            var project = Any.Instance <IDependencyPathBasedRuleTarget>();

            //WHEN
            projects.FillAllBranchesOf(dependencyPathInProgress, project);

            //THEN
            dependencyPathInProgress.Received(1).FinalizeWith(project);
        }
Beispiel #7
0
        public IGeneroProject AddImportedModule(string path, IGeneroProjectEntry importer)
        {
            IGeneroProject refProj = null;

            if (!ReferencedProjects.TryGetValue(path, out refProj))
            {
                // need to tell the genero project analyzer to add a directory to the project
                refProj = VSGeneroPackage.Instance.DefaultAnalyzer.AddImportedProject(path, importer);
                if (refProj == null)
                {
                    // TODO: need to report that the project is invalid?
                }
                else
                {
                    ReferencedProjects.AddOrUpdate(path, refProj, (x, y) => y);
                }
            }
            return(refProj);
        }
        public void ShouldResolveProjectsAndLogAllErrorsThatOccur()
        {
            //GIVEN
            var id1 = Any.ProjectId();
            var id2 = Any.ProjectId();
            var id3 = Any.ProjectId();
            var referencedProjectsIds = new[] { id1, id2, id3 };
            var support = Substitute.For <INScanSupport>();
            var exceptionFromResolution = Any.Instance <ReferencedProjectNotFoundInSolutionException>();
            var projects = new ReferencedProjects(referencedProjectsIds, support);
            var solution = Substitute.For <ISolutionContext>();
            var project  = Any.Instance <IReferencingProject>();

            solution.When(ResolvingReferencesFrom(project, id2)).Throw(exceptionFromResolution);

            //WHEN
            projects.ResolveFrom(project, solution);

            //THEN
            solution.Received(1).ResolveReferenceFrom(project, id1);
            solution.Received(1).ResolveReferenceFrom(project, id2);
            solution.Received(1).ResolveReferenceFrom(project, id3);
            support.Received(1).Report(exceptionFromResolution);
        }
        void ParseVSLinuxProject(string filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            //add a namespace manager if xmlns is defined
            if (doc.DocumentElement.Attributes["xmlns"] != null)
            {
                string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
                nsmgr.AddNamespace("MsBuild", xmlns);
            }

            //Source files
            foreach (XmlNode node in doc.SelectNodes(SourceFileXPath, nsmgr))
            {
                string  sourceFilename;
                XmlNode sourceFile = node.Attributes.GetNamedItem(SourceFileAttr);
                if (sourceFile != null)
                {
                    sourceFilename = sourceFile.Value;
                    if (sourceFilename.EndsWith(".c") || sourceFilename.EndsWith(".cpp"))
                    {
                        SourceFiles.Add(sourceFilename.Replace('\\', '/'));
                    }
                }
            }

            //Project references
            foreach (XmlNode node in doc.SelectNodes(ProjectReferenceFileXPath, nsmgr))
            {
                XmlNode sourceFile = node.Attributes.GetNamedItem(SourceFileAttr);
                if (sourceFile != null)
                {
                    ReferencedProjects.Add(Path.GetFileNameWithoutExtension(sourceFile.Value));
                }
            }

            //Library dependencies
            foreach (XmlNode node in doc.SelectNodes(LibraryDependenciesXPath, nsmgr))
            {
                string   dependenciesString = node.InnerText;
                string[] dependencies       = dependenciesString.Split(';');
                foreach (string dependency in dependencies)
                {
                    if (!LibraryDependencies.Contains(dependency) && dependency.Trim(' ').Length > 0)
                    {
                        LibraryDependencies.Add(dependency);
                    }
                }
            }

            //Additional library directories
            foreach (XmlNode node in doc.SelectNodes(AdditionalLibraryDirectoriesXPath, nsmgr))
            {
                string   dirsString = node.InnerText;
                string[] dirs       = dirsString.Split(';');
                foreach (string dir in dirs)
                {
                    //Discard directories with wildcards: either starting with '%' or containing'$('
                    if (!dir.StartsWith('%') && !dir.Contains("$(") && !AdditionalLibraryDirectories.Contains(dir) && dir.Trim(' ').Length > 0)
                    {
                        AdditionalLibraryDirectories.Add(dir.Trim(' '));
                    }
                }
            }

            //Additional link options
            foreach (XmlNode node in doc.SelectNodes(AdditionalLinkOptionsXPath, nsmgr))
            {
                AdditionalLinkOptions = node.InnerText; //if there are different configurations, just take the last one
            }
            //Additional compile options
            foreach (XmlNode node in doc.SelectNodes(AdditionalCompileOptionsXPath, nsmgr))
            {
                AdditionalCompileOptions = node.InnerText; //if there are different configurations, just take the last one
            }
            //Additional sources to copy mapping
            foreach (XmlNode node in doc.SelectNodes(AdditionalSourcesToCopyMappingXPath, nsmgr))
            {
                string   mappingString = node.InnerText;
                string[] mappings      = mappingString.Split(';');
                foreach (string mapping in mappings)
                {
                    int separatorIndex = mapping.IndexOf(":=");
                    if (separatorIndex > 0)
                    {
                        string source = mapping.Substring(0, separatorIndex);
                        string dst    = mapping.Substring(separatorIndex + 2);
                        AdditionalSourcesToCopyMapping[source] = dst;
                    }
                }
            }


            SuccessfullyParsed = true;
        }
Beispiel #10
0
 public ProjectModel AddReferencedProjects(params ReferencedProjectModel[] referencedProjects)
 {
     ReferencedProjects.AddRange(referencedProjects);
     return(this);
 }