Example #1
0
        internal IModule LoadModule(PomElement element)
        {
            var module = _dataFactory.CreateModule();

            module.Path = element.Value;
            return(module);
        }
Example #2
0
        internal void LoadBuildContainer(PomElement element, IBuildContainer container)
        {
            var propertiesElement = element.SingleOrNull("properties");

            if (propertiesElement != null)
            {
                container.Properties = propertiesElement.Elements().Select(LoadProperty).ToList();
            }

            container.Modules = element
                                .ReadElements("modules", "module")
                                .Select(LoadModule)
                                .ToList();

            container.Dependencies = element
                                     .ReadElements("dependencies", "dependency")
                                     .Select(LoadDependency)
                                     .ToList();

            container.DependencyManagement = element
                                             .ReadElements("dependencyManagement", "dependencies", "dependency")
                                             .Select(LoadDependency)
                                             .ToList();

            container.Plugins = element.ReadElements("build", "plugins", "plugin")
                                .Select(LoadPlugin).ToList();

            container.PluginManagement = element.ReadElements("build", "pluginManagement", "plugins", "plugin")
                                         .Select(LoadPlugin).ToList();

            container.TestResources = new BlackBox(element.SingleOrNull("build", "testResources"));
        }
Example #3
0
        protected void SavePlugin(IPlugin plugin, PomElement element)
        {
            SaveProjectReference(plugin, element);

            if (plugin.Extensions)
            {
                element.SetElementValue("extensions", "true");
            }

            if (!plugin.Configuration.IsEmpty)
            {
                element.Add(plugin.Configuration.Value as PomElement);
            }

            if (!plugin.Executions.IsEmpty)
            {
                element.Add(plugin.Executions.Value as PomElement);
            }

            if (!plugin.Dependencies.Any())
            {
                element.RemoveElement("dependencies");
            }
            else
            {
                var dependenciesNode = element.SingleOrCreate("dependencies");
                dependenciesNode.RemoveAllChildElements();
                foreach (IDependency dependency in plugin.Dependencies)
                {
                    var dependencyNode = dependenciesNode.AddElement("dependency");
                    SaveDependency(dependency, dependencyNode);
                }
            }
        }
Example #4
0
        public IProperty LoadProperty(PomElement element)
        {
            var property = _dataFactory.CreateProperty();

            property.Name  = element.LocalName;
            property.Value = element.Value;
            return(property);
        }
Example #5
0
        internal IProfile LoadProfile(PomElement element)
        {
            var profile = _dataFactory.CreateProfile();

            profile.Id = element.ReadElementValueOrNull("id");
            LoadBuildContainer(element, profile);
            return(profile);
        }
Example #6
0
 internal void SaveProfile(IProfile profile, PomElement element)
 {
     if (string.IsNullOrEmpty(profile.Id))
     {
         element.RemoveElement("id");
     }
     else
     {
         element.SetElementValue("id", profile.Id);
     }
     SaveBuildContainer(profile, element);
 }
Example #7
0
        internal void SaveParentReference(IProject project, PomElement rootElement)
        {
            IParentReference parentReference = project.Parent;

            if (parentReference == null)
            {
                rootElement.RemoveElement("parent");
            }
            else
            {
                var parentElement = rootElement.SingleOrCreate("parent");
                SaveProjectReference(parentReference, parentElement);
                parentElement.SetElementValue("relativePath", parentReference.RelativePath);
            }
        }
Example #8
0
        internal void LoadParentReference(PomElement rootElement, IProject project)
        {
            var parentElement = rootElement.SingleOrNull("parent");

            if (parentElement == null)
            {
                project.Parent = null;
            }
            else
            {
                var parentReference = _dataFactory.CreateParentReference();
                LoadProjectReference(parentElement, parentReference);
                parentReference.RelativePath = parentElement.ReadElementValueOrNull("relativePath");
                project.Parent = parentReference;
            }
        }
Example #9
0
        internal void SaveDependency(IDependency dependency, PomElement element)
        {
            SaveProjectReference(dependency, element);

            element.SetElementValue("type", dependency.Type);
            element.SetElementValue("classifier", dependency.Classifier);
            element.SetElementValue("scope", dependency.Scope);

            if (dependency.Optional)
            {
                element.SetElementValue("optional", "true");
            }

            if (!dependency.Exclusions.IsEmpty)
            {
                element.Add(dependency.Exclusions.Value as PomElement);
            }
        }
Example #10
0
        internal IDependency LoadDependency(PomElement element)
        {
            IDependency dependency = _dataFactory.CreateDependency();

            LoadProjectReference(element, dependency);

            dependency.Scope      = element.ReadElementValueOrNull("scope");
            dependency.Type       = element.ReadElementValueOrNull("type");
            dependency.Classifier = element.ReadElementValueOrNull("classifier");

            bool optional;

            dependency.Optional = bool.TryParse(element.ReadElementValueOrNull("optional"), out optional) && optional;

            dependency.Exclusions = new BlackBox(element.SingleOrNull("exclusions"));

            return(dependency);
        }
Example #11
0
        internal IPlugin LoadPlugin(PomElement element)
        {
            var plugin = _dataFactory.CreatePlugin();

            LoadProjectReference(element, plugin);

            bool extensions;

            plugin.Extensions = bool.TryParse(element.ReadElementValueOrNull("extensions"), out extensions) && extensions;

            plugin.Executions    = new BlackBox(element.SingleOrNull("executions"));
            plugin.Configuration = new BlackBox(element.SingleOrNull("configuration"));

            plugin.Dependencies = element
                                  .ReadElements("dependencies", "dependency")
                                  .Select(LoadDependency)
                                  .ToList();

            return(plugin);
        }
Example #12
0
 // REVIEW: element is not PomDocument, it is wrapper XElement (dependency, parent)
 internal void SaveProjectReference(IProjectReference projectReference, PomElement element)
 {
     element.SetElementValue("groupId", projectReference.GroupId);
     element.SetElementValue("artifactId", projectReference.ArtifactId);
     element.SetElementValue("version", projectReference.Version.Value);
 }
Example #13
0
 // REVIEW: element is not PomDocument, it is wrapper XElement (dependency, parent)
 internal void LoadProjectReference(PomElement element, IProjectReference projectReference)
 {
     projectReference.ArtifactId = element.ReadElementValueOrNull("artifactId");
     projectReference.GroupId    = element.ReadElementValueOrNull("groupId");
     projectReference.Version    = element.ReadElementValueOrNull("version").ToVersion();
 }
Example #14
0
 internal void Add(PomElement childElement)
 {
     _element.Add(childElement._element);
 }
Example #15
0
 public void SaveModule(IModule module, PomElement element)
 {
     element.Value = module.Path;
 }
Example #16
0
        internal string ReadElementValueOrNull(params string[] pathElems)
        {
            PomElement element = SingleOrNull(pathElems);

            return(element == null ? null : element.Value);
        }
Example #17
0
        internal void SaveBuildContainer(IBuildContainer container, PomElement element)
        {
            if (!container.Properties.Any())
            {
                element.RemoveElement("properties");
            }
            else
            {
                var propertiesNode = element.SingleOrCreate("properties");
                propertiesNode.RemoveAllChildElements();
                foreach (IProperty property in container.Properties)
                {
                    SaveProperty(property, propertiesNode);
                }
            }

            if (!container.Modules.Any())
            {
                element.RemoveElement("modules");
            }
            else
            {
                var modulesNode = element.SingleOrCreate("modules");
                modulesNode.RemoveAllChildElements();
                foreach (IModule module in container.Modules.Where(m => !string.IsNullOrEmpty(m.Path)))
                {
                    var moduleNode = modulesNode.AddElement("module");
                    SaveModule(module, moduleNode);
                }
            }

            if (!container.Dependencies.Any())
            {
                element.RemoveElement("dependencies");
            }
            else
            {
                var dependenciesNode = element.SingleOrCreate("dependencies");
                dependenciesNode.RemoveAllChildElements();
                foreach (IDependency dependency in container.Dependencies)
                {
                    var dependencyNode = dependenciesNode.AddElement("dependency");
                    SaveDependency(dependency, dependencyNode);
                }
            }

            if (!container.DependencyManagement.Any())
            {
                element.RemoveElement("dependencyManagement");
            }
            else
            {
                var dependencyManagementNode = element.SingleOrCreate("dependencyManagement");
                var dependenciesNode         = dependencyManagementNode.SingleOrCreate("dependencies");
                dependenciesNode.RemoveAllChildElements();
                foreach (IDependency dependency in container.DependencyManagement)
                {
                    var dependencyNode = dependenciesNode.AddElement("dependency");
                    SaveDependency(dependency, dependencyNode);
                }
            }


            // empty build section
            // REVIEW: need refactoring
            if (!container.Plugins.Any() && !container.PluginManagement.Any() && container.TestResources.IsEmpty)
            {
                element.RemoveElement("build");
            }
            else
            {
                var buildNode = element.SingleOrCreate("build");
                if (!container.Plugins.Any())
                {
                    buildNode.RemoveElement("plugins");
                }
                else
                {
                    var pluginsNode = buildNode.SingleOrCreate("plugins");
                    pluginsNode.RemoveAllChildElements();
                    foreach (var plugin in container.Plugins)
                    {
                        var pluginNode = pluginsNode.AddElement("plugin");
                        SavePlugin(plugin, pluginNode);
                    }
                }

                if (!container.PluginManagement.Any())
                {
                    buildNode.RemoveElement("pluginManagement");
                }
                else
                {
                    var pluginManagementNode        = buildNode.SingleOrCreate("pluginManagement");
                    var pluginManagementPluginsNode = pluginManagementNode.SingleOrCreate("plugins");

                    pluginManagementPluginsNode.RemoveAllChildElements();
                    foreach (var plugin in container.PluginManagement)
                    {
                        var pluginNode = pluginManagementPluginsNode.AddElement("plugin");
                        SavePlugin(plugin, pluginNode);
                    }
                }

                if (container.TestResources.IsEmpty)
                {
                    buildNode.RemoveElement("testResources");
                }
                else
                {
                    var testResources = buildNode.SingleOrCreate("testResources");
                    testResources.ReplaceWith(container.TestResources.Value as PomElement);
                }
            }
        }
Example #18
0
 internal void ReplaceWith(PomElement element)
 {
     _element.ReplaceWith(element._element);
 }
Example #19
0
 public void SaveProperty(IProperty property, PomElement element)
 {
     element.SetElementValue(property.Name, property.Value);
 }