Exemple #1
0
        public string Serialize(IProject project)
        {
            var pom = new PomDocument();

            SaveProject(project, pom);
            return(pom.ToString());
        }
Exemple #2
0
        public string Serialize(IProject project, string contentToUpdate)
        {
            var document = XDocument.Parse(contentToUpdate);
            var pom      = new PomDocument(document);

            SaveProject(project, pom);
            return(pom.ToString());
        }
Exemple #3
0
        public IProject Deserialize(string content)
        {
            var document = XDocument.Parse(content);
            var pom      = new PomDocument(document);
            var project  = _dataFactory.CreateProject();

            LoadProject(pom, project);
            return(project);
        }
Exemple #4
0
        internal void LoadProject(PomDocument pom, IProject project)
        {
            var rootElement = pom.RootElement;

            LoadProjectReference(rootElement, project);
            LoadParentReference(rootElement, project);

            project.Packaging    = rootElement.ReadElementValueOrNull("packaging");
            project.Name         = rootElement.ReadElementValueOrNull("name");
            project.ModelVersion = rootElement.ReadElementValueOrNull("modelVersion");

            LoadBuildContainer(rootElement, project);

            project.Profiles = rootElement.ReadElements("profiles", "profile")
                               .Select(LoadProfile).ToList();
        }
Exemple #5
0
        internal void SaveProject(IProject project, PomDocument pom)
        {
            var rootElement = pom.RootElement;

            SaveProjectReference(project, rootElement);
            SaveParentReference(project, rootElement);

            rootElement.SetElementValue("packaging", project.Packaging);
            rootElement.SetElementValue("name", project.Name);
            rootElement.SetElementValue("modelVersion", project.ModelVersion);

            SaveBuildContainer(project, rootElement);

            if (!project.Profiles.Any())
            {
                rootElement.RemoveElement("profiles");
            }
            else
            {
                var profileNode = rootElement.SingleOrCreate("profiles");

                HashSet <PomElement> usedElements = new HashSet <PomElement>(new PomElement.Comparer());
                foreach (var profile in project.Profiles)
                {
                    var profElement = profileNode
                                      .Elements()
                                      .FirstOrDefault(e => e.ReadElementValueOrNull("id") == profile.Id) ?? profileNode.AddElement("profile");

                    usedElements.Add(profElement);
                    SaveProfile(profile, profElement);
                }

                //delete all profiles elements which are not in the Profiles array
                foreach (var profElem in profileNode.Elements().Where(e => !usedElements.Contains(e)))
                {
                    profElem.Remove();
                }
            }
        }