Permalink
Browse files

Initial commit of gitignore sbt processor. Creates a .gitignore file …

…in your project root, if one doesn't already exists, and adds common sbt directories to it.
  • Loading branch information...
0 parents commit 9dbeb6fa1943df4833990c71c9408bfe2d0c46cd @pr1001 committed Jan 11, 2011
@@ -0,0 +1,7 @@
+target/
+lib_managed/
+project/boot/
+project/build/target/
+project/plugins/target/
+project/plugins/lib_managed/
+project/plugins/src_managed/
@@ -0,0 +1,8 @@
+#Project properties
+#Tue Jan 11 17:00:17 CET 2011
+project.organization=com.bubblefoundry
+project.name=gitignore
+sbt.version=0.7.4
+project.version=0.1
+build.scala.versions=2.8.1
+project.initialize=false
@@ -0,0 +1,3 @@
+import sbt._
+
+class GitIgnoreProject(info: ProjectInfo) extends ProcessorProject(info)
@@ -0,0 +1 @@
+com.bubblefoundry.gitignore.GitIgnoreProcessor
@@ -0,0 +1,35 @@
+package com.bubblefoundry.gitignore
+
+import sbt._
+import processor.BasicProcessor
+
+import java.io.{BufferedWriter, FileWriter}
+
+class GitIgnoreProcessor extends BasicProcessor {
+ def apply(project: Project, args: String) {
+ // project.log.info("Processor test. args: '" + args + "'")
+ val gitignoreName = ".gitignore"
+ val ignored = List("target/", "lib_managed/", "project/boot/", "project/build/target/", "project/plugins/target/", "project/plugins/lib_managed/", "project/plugins/src_managed/")
+
+ val projectPath = project.rootProject.info.projectPath
+ val gitignorePath = projectPath / gitignoreName
+ val gitignoreFile = gitignorePath.asFile
+
+ // first make sure the file exists
+ if (!gitignorePath.exists) {
+ // don't catch exceptions as we want to fail hard if we can't create the file
+ gitignoreFile.createNewFile()
+ }
+
+ val alreadyIgnored = io.Source.fromFile(gitignoreFile).getLines.toList.map(_.trim) // getLines is supposed to strip newlines but it didn't seem to for me
+ val toIgnore = ignored -- alreadyIgnored
+
+ val out = new BufferedWriter(new java.io.FileWriter(gitignoreFile, true)) // make sure we're appending
+ toIgnore.foreach(ignore => {
+ out.write(ignore)
+ out.newLine
+ })
+ out.flush
+ out.close
+ }
+}

0 comments on commit 9dbeb6f

Please sign in to comment.