Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
                }
            }
        }