<commit_before>/* sbt -- Simple Build Tool
 * Copyright 2008, 2009, 2010  <NAME>
 */

// based on Ivy's PomModuleDescriptorWriter, which is Apache Licensed, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

package sbt;

import java.io.{BufferedWriter, File, OutputStreamWriter, FileOutputStream}
import scala.xml.{Node => XNode, NodeSeq, PrettyPrinter, XML}

import org.apache.ivy.{core, plugins, Ivy}
import core.settings.IvySettings
import core.module.{descriptor, id}
import descriptor.{DependencyDescriptor, License, ModuleDescriptor}
import id.ModuleRevisionId
import plugins.resolver.{ChainResolver, DependencyResolver, IBiblioResolver}

class MakePom
{
	def encoding = "UTF-8"
	def write(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, process: XNode => XNode, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean, output: File): Unit =
		write(process(toPom(ivy, module, configurations, extra, filterRepositories, allRepositories)), output)
	def write(node: XNode, output: File): Unit = write(toString(node), output)
	def write(xmlString: String, output: File)
	{
		output.getParentFile.mkdirs()
		val out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), encoding))
		try
		{
			out.write("<?xml version='1.0' encoding='" + encoding + "'?>")
			out.newLine()
			out.write(xmlString)
		}
		finally { out.close() }
	}

	def toString(node: XNode): String = new PrettyPrinter(1000, 4).format(node)
	def toPom(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean): XNode =
		(<project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
			<modelVersion>4.0.0</modelVersion>
			{ makeModuleID(module) }
			{ extra }
			{ makeDependencies(module, configurations) }
			{ makeRepositories(ivy.getSettings, allRepositories, filterRepositories) }
		</project>)

	def makeModuleID(module: ModuleDescriptor): NodeSeq =
	{
		val mrid = moduleDescriptor(module)
		val a: NodeSeq = 
			(<groupId>{ mrid.getOrganisation }</groupId><commit_msg>use \n for make-pom because PrettyPrinter hard codes it. fixes #95<commit_after>/* sbt -- Simple Build Tool
 * Copyright 2008, 2009, 2010  <NAME>
 */

// based on Ivy's PomModuleDescriptorWriter, which is Apache Licensed, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

package sbt;

import java.io.{BufferedWriter, File, OutputStreamWriter, FileOutputStream}
import scala.xml.{Node => XNode, NodeSeq, PrettyPrinter, XML}

import org.apache.ivy.{core, plugins, Ivy}
import core.settings.IvySettings
import core.module.{descriptor, id}
import descriptor.{DependencyDescriptor, License, ModuleDescriptor}
import id.ModuleRevisionId
import plugins.resolver.{ChainResolver, DependencyResolver, IBiblioResolver}

class MakePom
{
	def encoding = "UTF-8"
	def write(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, process: XNode => XNode, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean, output: File): Unit =
		write(process(toPom(ivy, module, configurations, extra, filterRepositories, allRepositories)), output)
	// use \n as newline because toString uses PrettyPrinter, which hard codes line endings to be \n
	def write(node: XNode, output: File): Unit = write(toString(node), output, "\n")
	def write(xmlString: String, output: File, newline: String)
	{
		output.getParentFile.mkdirs()
		val out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), encoding))
		try
		{
			out.write("<?xml version='1.0' encoding='" + encoding + "'?>" + newline)
			out.write(xmlString)
		}
		finally { out.close() }
	}

	def toString(node: XNode): String = new PrettyPrinter(1000, 4).format(node)
	def toPom(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean): XNode =
		(<project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
			<modelVersion>4.0.0</modelVersion>
			{ makeModuleID(module) }
			{ extra }
			{ makeDependencies(module, configurations) }
			{ makeRepositories(ivy.getSettings, allRepositories, filterRepositories) }
		</project>)

	def makeModuleID(module: ModuleDescriptor): NodeSeq =
	{
		val mrid = moduleDescriptor(module)
		val a: NodeSeq = 
			(<groupId>{ mrid.getOrganisation }</groupId>
{'fraction_non_alphanumeric': 0.13396029258098224, 'fraction_numerical': 0.01755485893416928, 'mean_word_length': 5.458839406207828, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '302928', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1506, 'n_words': 356}