Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kahliburke/sbt-idea
base: c3ab3f81fe
...
head fork: kahliburke/sbt-idea
compare: 647ce5c1b5
  • 6 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
View
21 README.md
@@ -1,9 +1,18 @@
-Until builds are published to a Maven repository, add the following to ~/.sbt/plugins/project/Build.scala:
+Requirements
+------------
- import sbt._
+* [SBT 0.10+](https://github.com/harrah/xsbt/wiki)
- object MyPlugins extends Build {
- lazy val root = Project("root", file(".")) dependsOn (uri("git://github.com/ijuma/sbt-idea.git#sbt-0.10"))
- }
+Installation
+------------
-Then run `gen-idea` from a SBT shell.
+Add the following lines to ~/.sbt/plugins/build.sbt:
+
+ resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
+
+ libraryDependencies += "com.github.mpeltonen" %% "sbt-idea" % "0.10.0-SNAPSHOT"
+
+Usage
+-----
+
+Run `gen-idea` from a SBT shell.
View
12 build.sbt
@@ -1,7 +1,15 @@
sbtPlugin := true
-name := "xsbt-idea"
+organization := "com.github.mpeltonen"
-organization := "org.sbtidea"
+name := "sbt-idea"
+
+version := "0.10.0-SNAPSHOT"
+
+//sbtVersion := "0.10.1-20110629-052055"
scalacOptions := Seq("-deprecation", "-unchecked")
+
+publishTo := Some(Resolver.file("GitHub Pages", file("../mpeltonen.github.com/maven/")))
+
+resolvers += Resolver.url("Typesafe Snapshots" , url("http://repo.typesafe.com/typesafe/ivy-snapshots/"))
View
1  project/build.properties
@@ -0,0 +1 @@
+sbt.version=0.10.1
View
BIN  sbt-launch-0.10.0.jar → sbt-launch-0.10.1.jar
Binary file not shown
View
11 src/main/scala/org/sbtidea/IdeaProjectDescriptor.scala
@@ -27,7 +27,7 @@ object OutputUtil {
}
}
-class IdeaProjectDescriptor(val projectInfo: IdeaProjectInfo, val env: IdeaProjectEnvironment, val log: Logger) {
+class IdeaProjectDescriptor(val projectInfo: IdeaProjectInfo, val env: IdeaProjectEnvironment, val log: Logger, val useMavenRepo: Boolean) {
def projectRelative(file: File) = {
IO.relativize(projectInfo.baseDir, file.getCanonicalFile).map ("$PROJECT_DIR$/" + _).getOrElse(file.getCanonicalPath)
@@ -119,12 +119,15 @@ class IdeaProjectDescriptor(val projectInfo: IdeaProjectInfo, val env: IdeaProje
val librariesDir = configFile("libraries")
librariesDir.mkdirs
- for (ideaLib <- projectInfo.ideaLibs) {
- // MUST all be _
- val filename = ideaLib.name.replace('.', '_').replace('-', '_') + ".xml"
+ val filenamesAndLibs = for (ideaLib <- projectInfo.ideaLibs)
+ yield (ideaLib, ideaLib.name.replace('.', '_').replace('-', '_').replace(':', '_').replace(' ', '_') + ".xml")
+
+ filenamesAndLibs.foreach { ideaLibAndFileName =>
+ val (ideaLib, filename) = ideaLibAndFileName
saveFile(librariesDir, filename, libraryTableComponent(ideaLib))
}
+
log.info("Created " + configDir)
} else log.error("Skipping .idea creation for " + projectInfo.baseDir + " since directory does not exist")
}
View
66 src/main/scala/org/sbtidea/SbtIdeaModuleMapping.scala
@@ -17,12 +17,46 @@ object SbtIdeaModuleMapping {
m1.organization == m2.organization && name(m1) == name(m2)
}
- private def ideaLibFromModule(moduleReport: ModuleReport) = {
+ private def ideaLibFromModule(moduleReport: ModuleReport, useMavenRepo: Boolean) = {
val module = moduleReport.module
- IdeaLibrary(module.organization + "_" + module.name + "_" + module.revision,
- classes = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == None) => file },
- javaDocs = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == Some("javadoc")) => file },
- sources = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == Some("sources")) => file })
+ val name = useMavenRepo match {
+ case true =>"Maven: %s:%s:%s".format(module.organization, module.name, module.revision)
+ case false => module.organization + "_" + module.name + "_" + module.revision
+ }
+ IdeaLibrary(name,
+ classes = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == None || artifact.classifier == Some(("classes"))) =>
+ depFile(module, artifact, file, useMavenRepo)},
+ javaDocs = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == Some("javadoc")) =>
+ depFile(module, artifact, file, useMavenRepo)},
+ sources = moduleReport.artifacts.collect{ case (artifact, file) if (artifact.classifier == Some("sources")) =>
+ depFile(module, artifact, file, useMavenRepo)}
+ )
+ }
+
+ private def depFile(id: ModuleID, a: Artifact, ivyFile: File, useMavenRepo: Boolean): File = {
+ useMavenRepo match {
+ case true => {
+ val f = mavenFile(id, a)
+ if (f.exists) f else ivyFile
+ }
+ case false => ivyFile
+ }
+ }
+
+ private def mavenFile(id: ModuleID, a: Artifact, overrideClassifier: Option[String] = None): File = {
+ val classifier = (overrideClassifier, a.classifier) match {
+ case (Some(c), _) => "-"+c
+ case (None, Some(c)) => "-"+c
+ case (None, None) => ""
+ }
+// println("Creating maven file: %s, %s, %s".format(id, a, overrideClassifier))
+ val f = localM2Repo / id.organization.replace(".", "/") / id.name / id.revision /
+ "%s-%s%s.%s".format(id.name, id.revision, classifier, a.extension)
+ // If the base file doesn't exist, use the "classes" classifier
+ (f.exists, overrideClassifier) match {
+ case (false, None) => mavenFile(id, a, Some("classes"))
+ case _ => f
+ }
}
private def toScope(conf: String) = {
@@ -36,28 +70,30 @@ object SbtIdeaModuleMapping {
}
}
- private def mapToIdeaModuleLibs(configuration: String, modules: Seq[ModuleReport], deps: Keys.Classpath) = {
+ private def mapToIdeaModuleLibs(configuration: String, modules: Seq[ModuleReport], deps: Keys.Classpath, useMavenLibs: Boolean) = {
val scope = toScope(configuration)
val depFilter = libDepFilter(deps) _
- modules.filter(modReport => depFilter(modReport)).map( moduleReport => {
- (IdeaModuleLibRef(scope, ideaLibFromModule(moduleReport)), moduleReport.module)
- })
+// println("%s, %s".format(configuration, deps))
+
+ modules.map( moduleReport => (IdeaModuleLibRef(scope, ideaLibFromModule(moduleReport, useMavenLibs)), moduleReport.module))
}
private def libDepFilter(deps: Keys.Classpath)(moduleReport: ModuleReport): Boolean = {
- deps.files.exists(dep => moduleReport.artifacts.exists(_._2 == dep))
+ val exists = deps.files.exists(dep => moduleReport.artifacts.exists(_._2 == dep))
+// println("Exists: %s - %s".format(exists, moduleReport))
+ exists
}
- def convertDeps(report: UpdateReport, deps: Keys.Classpath, scalaVersion: String): Seq[(IdeaModuleLibRef, ModuleID)] = {
+ def convertDeps(report: UpdateReport, deps: Keys.Classpath, scalaVersion: String, useMavenLibs: Boolean): Seq[(IdeaModuleLibRef, ModuleID)] = {
Seq("compile", "runtime", "test", "provided").flatMap(report.configuration).foldLeft(Seq[(IdeaModuleLibRef, ModuleID)]()) { (acc, configReport) =>
val filteredModules = configReport.modules.filterNot(m1 =>
acc.exists { case (_, m2) => equivModule(m1.module, m2, scalaVersion) })
- acc ++ mapToIdeaModuleLibs(configReport.configuration, filteredModules, deps)
+ acc ++ mapToIdeaModuleLibs(configReport.configuration, filteredModules, deps, useMavenLibs)
}
}
- def addClassifiers(ideaModuleLibRefs: Seq[(IdeaModuleLibRef, ModuleID)], report: UpdateReport): Seq[(IdeaModuleLibRef, ModuleID)] = {
+ def addClassifiers(ideaModuleLibRefs: Seq[(IdeaModuleLibRef, ModuleID)], report: UpdateReport, useMavenLibs: Boolean): Seq[(IdeaModuleLibRef, ModuleID)] = {
/* Both retrieved from UpdateTask, so we don't need to deal with crossVersion here */
def equivModule(m1: ModuleID, m2: ModuleID): Boolean =
@@ -74,7 +110,7 @@ object SbtIdeaModuleMapping {
} map { case (moduleLibRef, moduleId) =>
val ideaLibrary = {
- val il = ideaLibFromModule(moduleReport)
+ val il = ideaLibFromModule(moduleReport, useMavenLibs)
il.copy(classes = il.classes ++ moduleLibRef.library.classes,
javaDocs = il.javaDocs ++ moduleLibRef.library.javaDocs,
sources = il.sources ++ moduleLibRef.library.sources)
@@ -93,4 +129,6 @@ object SbtIdeaModuleMapping {
modifiedModuleLibRefs ++ unmodifiedModuleLibRefs
}
+
+ lazy val localM2Repo = Path.userHome / ".m2/repository"
}
View
18 src/main/scala/org/sbtidea/SbtIdeaPlugin.scala
@@ -5,6 +5,7 @@ import sbt.Load.BuildStructure
import sbt.CommandSupport._
import sbt.complete._
import sbt.complete.Parsers._
+import sbt.UpdateReport._
import java.io.File
import collection.Seq
import SbtIdeaModuleMapping._
@@ -14,6 +15,7 @@ object SbtIdeaPlugin extends Plugin {
val ideaProjectName = SettingKey[String]("idea-project-name")
val ideaProjectGroup = SettingKey[String]("idea-project-group")
val sbtScalaInstance = SettingKey[ScalaInstance]("sbt-scala-instance")
+ val useLocalMavenRepo = SettingKey[Boolean]("use-local-maven-repo")
override lazy val settings = Seq(Keys.commands += ideaCommand, ideaProjectName := "IdeaProject")
private val WithClassifiers = "with-classifiers"
@@ -55,7 +57,8 @@ object SbtIdeaPlugin extends Plugin {
val parent = new ParentProjectIdeaModuleDescriptor(projectInfo, env, logger(state))
parent.save()
- val rootFiles = new IdeaProjectDescriptor(projectInfo, env, logger(state))
+ val useLocalMaven = useLocalMavenRepo in extracted.currentRef get buildStruct.data getOrElse(false)
+ val rootFiles = new IdeaProjectDescriptor(projectInfo, env, logger(state), useLocalMaven)
rootFiles.save()
val imlDir = new File(projectInfo.baseDir, env.modulePath.get)
@@ -92,6 +95,8 @@ object SbtIdeaPlugin extends Plugin {
val baseDirectory = setting(Keys.baseDirectory, "Missing base directory!")
val target = setting(Keys.target, "Missing target directory")
+ val useLocalMaven = optionalSetting(useLocalMavenRepo)
+
def directoriesFor(config: Configuration) = Directories(
setting(Keys.unmanagedSourceDirectories in config, "Missing unmanaged source directories!"),
setting(Keys.unmanagedResourceDirectories in config, "Missing unmanaged resource directories!"),
@@ -108,12 +113,17 @@ object SbtIdeaPlugin extends Plugin {
val libraries = EvaluateTask.evaluateTask(buildStruct, Keys.update, state, projectRef, false, EvaluateTask.SystemProcessors) match {
case Some(Value(report)) =>
- val libraries = convertDeps(report, deps, scalaInstance.version)
+
+ val useMavenLibs = useLocalMaven match {
+ case Some(b: Boolean) => b
+ case None => false
+ }
+ val libraries = convertDeps(report, deps, scalaInstance.version, useMavenLibs)
val withClassifiers = {
if (args.contains(WithClassifiers)) {
EvaluateTask.evaluateTask(buildStruct, Keys.updateClassifiers, state, projectRef, false, EvaluateTask.SystemProcessors) match {
- case Some(Value(report)) => addClassifiers(libraries, report)
+ case Some(Value(report)) => addClassifiers(libraries, report, useMavenLibs)
case _ => libraries
}
}
@@ -122,7 +132,7 @@ object SbtIdeaPlugin extends Plugin {
if (args.contains(WithSbtClassifiers)) {
EvaluateTask.evaluateTask(buildStruct, Keys.updateSbtClassifiers, state, projectRef, false, EvaluateTask.SystemProcessors) match {
- case Some(Value(report)) => addClassifiers(withClassifiers, report)
+ case Some(Value(report)) => addClassifiers(withClassifiers, report, useMavenLibs)
case _ => withClassifiers
}
}

No commit comments for this range

Something went wrong with that request. Please try again.