diff --git a/src/main/scala/IdeaModuleDescriptor.scala b/src/main/scala/IdeaModuleDescriptor.scala
new file mode 100644
index 0000000..a303c2c
--- /dev/null
+++ b/src/main/scala/IdeaModuleDescriptor.scala
@@ -0,0 +1,54 @@
+import sbt.{Logger, BasicDependencyProject}
+import xml.{XML, Node}
+
+case class IdeaModuleDescriptor(val project: BasicDependencyProject, log: Logger) extends ProjectPaths {
+ def save: Unit = {
+ val moduleDescriptorPath = String.format("%s/%s.iml", projectPath, project.name)
+ XML.save(moduleDescriptorPath, moduleXml)
+ log.info("Created " + moduleDescriptorPath)
+ }
+
+ def moduleXml: Node = {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ project.info.dependencies.map { dep =>
+ log.info("Project dependency: " + dep.name)
+
+ }
+ }
+ {
+ ideClasspath.getFiles.filter(_.getPath.endsWith(".jar")).map { jarFile =>
+
+
+
+
+
+
+
+
+
+ }
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/scala/IdeaPlugin.scala b/src/main/scala/IdeaPlugin.scala
index e0168e7..c37ea19 100644
--- a/src/main/scala/IdeaPlugin.scala
+++ b/src/main/scala/IdeaPlugin.scala
@@ -1,120 +1,10 @@
import sbt._
-import sbt.Configurations._
-import java.io.File
-import xml.{XML, Node}
trait IdeaPlugin extends BasicDependencyProject {
lazy val idea = task { createIdeaProject; None } dependsOn(update) describedAs("Creates IntelliJ IDEA project files.")
def createIdeaProject: Unit = {
- if (info.parent.isEmpty) {
- val projectDescriptorPath = String.format("%s/%s.ipr", projectPath, name)
- XML.save(projectDescriptorPath, projectXml)
- log.info("Created " + projectDescriptorPath)
- }
- val moduleDescriptorPath = String.format("%s/%s.iml", projectPath, name)
- XML.save(moduleDescriptorPath, moduleXml)
- log.info("Created " + moduleDescriptorPath)
- }
-
- def projectPath: File = info.projectPath.asFile
- def childProjects: List[(String, String)] = subProjects.values.toList.map { s =>
- (projectRelativePath(s.info.projectPath.asFile), s.name)
- }
-
- def projectRelativePath(target: File): String = {
- def pathComponentsOf(f: File): List[String] = {
- val p = f.getParentFile
- if (p == null) Nil else List(f.getName) ::: pathComponentsOf(p)
- }
- val projectPathComponents = pathComponentsOf(projectPath).reverseMap(Some(_))
- val targetPathComponents = pathComponentsOf(target).reverseMap(Some(_))
- val pathComponents = projectPathComponents.zipAll(targetPathComponents, None, None).dropWhile(x => x._1 == x._2)
- val (projectBranch, targetBranch) = List.unzip(pathComponents)
- val prefix = projectBranch.takeWhile(_ != None).foldLeft("")((acc, x) => acc + "../")
- val suffix = targetBranch.takeWhile(_ != None).foldLeft("")((acc, x) => acc + (if (acc != "") "/" else "") + x.get)
- prefix + suffix
- }
-
- def ideClasspath: PathFinder = fullClasspath(Runtime) +++ managedClasspath(Optional) +++ fullClasspath(Test)
- def buildScalaJarDir: Path = rootProject.info.bootPath / String.format("scala-%s", buildScalaVersion) / "lib"
- def scalaCompilerJar: File = (buildScalaJarDir / "scala-compiler.jar").asFile
- def scalaLibraryJar: File = (buildScalaJarDir / "scala-library.jar").asFile
-
- def projectXml: Node = {
-
-
-
-
-
-
-
- {
- childProjects.map { case (modulePath, moduleName) =>
-
- }
- }
-
-
- {
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
- }
-
- def moduleXml: Node = {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- info.dependencies.map { dep =>
- log.info("Project dependency: " + dep.name)
-
- }
- }
- {
- ideClasspath.getFiles.filter(_.getPath.endsWith(".jar")).map { jarFile =>
-
-
-
-
-
-
-
-
-
- }
- }
-
-
+ if (info.parent.isEmpty) IdeaProjectDescriptor(this, log).save
+ IdeaModuleDescriptor(this, log).save
}
}
diff --git a/src/main/scala/IdeaProjectDescriptor.scala b/src/main/scala/IdeaProjectDescriptor.scala
new file mode 100644
index 0000000..b3903f8
--- /dev/null
+++ b/src/main/scala/IdeaProjectDescriptor.scala
@@ -0,0 +1,43 @@
+import sbt.{Logger, BasicDependencyProject}
+import xml.{XML, Node}
+
+case class IdeaProjectDescriptor(val project: BasicDependencyProject, log: Logger) extends ProjectPaths {
+ def save: Unit = {
+ val projectDescriptorPath = String.format("%s/%s.ipr", projectPath, project.name)
+ XML.save(projectDescriptorPath, projectXml)
+ log.info("Created " + projectDescriptorPath)
+ }
+
+ def projectXml: Node = {
+
+
+
+
+
+
+
+ {
+ childProjects.map { case (modulePath, moduleName) =>
+
+ }
+ }
+
+
+ {
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/scala/ProjectPaths.scala b/src/main/scala/ProjectPaths.scala
new file mode 100644
index 0000000..4e101f6
--- /dev/null
+++ b/src/main/scala/ProjectPaths.scala
@@ -0,0 +1,30 @@
+import java.io.File
+import sbt.Configurations._
+import sbt.{Path, PathFinder, BasicDependencyProject}
+
+trait ProjectPaths {
+ val project: BasicDependencyProject
+
+ def projectPath: File = project.info.projectPath.asFile
+ def childProjects: List[(String, String)] = project.subProjects.values.toList.map { s =>
+ (relativePath(s.info.projectPath.asFile), s.name)
+ }
+ def relativePath(targetPath: File): String = {
+ def pathComponentsOf(f: File): List[String] = {
+ val p = f.getParentFile
+ if (p == null) Nil else List(f.getName) ::: pathComponentsOf(p)
+ }
+ val basePathComponents = pathComponentsOf(projectPath).reverseMap(Some(_))
+ val targetPathComponents = pathComponentsOf(targetPath).reverseMap(Some(_))
+ val pathComponents = basePathComponents.zipAll(targetPathComponents, None, None).dropWhile(x => x._1 == x._2)
+ val (baseBranch, targetBranch) = List.unzip(pathComponents)
+ val prefix = baseBranch.takeWhile(_ != None).foldLeft("")((acc, x) => acc + ".." + File.separator)
+ val suffix = targetBranch.takeWhile(_ != None).foldLeft("")((acc, x) => acc + (if (acc != "") File.separator else "") + x.get)
+ prefix + suffix
+ }
+
+ def ideClasspath: PathFinder = project.fullClasspath(Runtime) +++ project.managedClasspath(Optional) +++ project.fullClasspath(Test)
+ def buildScalaJarDir: Path = project.rootProject.info.bootPath / String.format("scala-%s", project.buildScalaVersion) / "lib"
+ def scalaCompilerJar: File = (buildScalaJarDir / "scala-compiler.jar").asFile
+ def scalaLibraryJar: File = (buildScalaJarDir / "scala-library.jar").asFile
+}
\ No newline at end of file