/* sbt -- Simple Build Tool
 * Copyright 2009  Mikko Peltonen, Mark Harrah
 */
package sbt

object object sbt.SourceModificationWatchSourceModificationWatch
{
	def (sbt.Project,Int)(=> Boolean)(=> Unit)UnitwatchUntil(sbt.Projectproject: sbt.ProjectProject, IntpollDelaySec: IntInt)(=> BooleanterminationCondition: => Boolean)(=> UnitonSourcesModified: => Unit)
	{
		def => Iterable[java.io.File]sourceFiles: Iterable[java.io.File]Iterable[java.io.File] =
			=> sbt.PathFindersourcesFinder.=> scala.collection.Set[sbt.Path]get.((sbt.Path) => Option[sbt.Path])Iterable[Option[sbt.Path]]map(object sbt.PathPath.(sbt.Path,sbt.Path)Option[sbt.Path]relativize(sbt.Projectproject.=> sbt.ProjectInfoinfo.=> sbt.ProjectDirectoryprojectPath, sbt.Path_)).((Option[sbt.Path]) => Boolean)Iterable[Option[sbt.Path]]filter(Option[sbt.Path]_.=> BooleanisDefined).((Option[sbt.Path]) => java.io.File)Iterable[java.io.File]map(Option[sbt.Path]_.=> sbt.Pathget.=> java.io.FileasFile)
	
		def => sbt.PathFindersourcesFinder: sbt.PathFinderPathFinder = sbt.Projectproject.=> List[sbt.Project]topologicalSort.(sbt.PathFinder)((sbt.PathFinder, sbt.Project) => sbt.PathFinder)sbt.PathFinderfoldLeft(object sbt.PathPath.=> sbt.PathFinderemptyPathFinder) {
			(sbt.PathFinderacc, sbt.Projectprj) => sbt.PathFinderacc (sbt.PathFinder)sbt.PathFinder+++ (sbt.Projectprj sbt.PathFindermatch {
				sbt.PathFindercase sbt.BasicScalaProjectprj: sbt.BasicScalaProjectBasicScalaProject => sbt.BasicScalaProjectprj.=> sbt.PathFindermainSources (sbt.PathFinder)sbt.PathFinder+++ sbt.BasicScalaProjectprj.=> sbt.PathFindertestSources
				sbt.PathFindercase _ => object sbt.PathPath.=> sbt.PathFinderemptyPathFinder
			})
		}
		def (Long,Int)Unitloop(LonglastCallbackCallTime: LongLong, IntpreviousFileCount: IntInt)
		{
			val (Long, Int)(LonglastModifiedTime, IntfileCount) = => Iterable[java.io.File]sourceFiles.((Long, Int))(((Long, Int), java.io.File) => (Long, Int))(Long, Int)foldLeft((Long,Int)(Long, Int)(Long(0L)0L, Int(0)0)){((Long, Int)acc, java.io.Filefile) => (Long,Int)(Long, Int)(object MathMath.(Long,Long)Longmax((Long, Int)acc.=> Long_1, java.io.Filefile.()LonglastModified), (Long, Int)acc.=> Int_2 (Int)Int+ Int(1)1)}
			val LongnewCallbackCallTime =
				// check if sources are modified
				Longif (LonglastModifiedTime (Long)Boolean> LonglastCallbackCallTime (Boolean)Boolean|| IntpreviousFileCount (Int)Boolean!= IntfileCount)
				{
					val Longnow = object java.lang.SystemSystem.()LongcurrentTimeMillis
					=> UnitonSourcesModified
					Longnow
				}
				else
					LonglastCallbackCallTime
			object java.lang.ThreadThread.(Long)Unitsleep(IntpollDelaySec implicit scala.Predef.int2long : (Int)Long* Int(1000)1000)
			Unitif(=> Boolean!=> BooleanterminationCondition)
				(Long,Int)Unitloop(LongnewCallbackCallTime, IntfileCount)
		}
		(Long,Int)Unitloop(Long(0L)0L, Int(0)0)
	}
}