forked from mpeltonen/sbt-idea
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OlegYch
authored and
OlegYch
committed
Mar 1, 2011
1 parent
61ee292
commit 4adaacc
Showing
11 changed files
with
225 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
export SBT_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" | ||
./sbt.sh | ||
#!/bin/bash | ||
export SBT_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" | ||
./sbt.sh |
192 changes: 96 additions & 96 deletions
192
sbt-sources-core/src/main/scala/UpdateSourcesTask.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,96 @@ | ||
import java.io.File | ||
import org.apache.ivy.core.retrieve.RetrieveOptions | ||
import org.apache.ivy.Ivy | ||
import sbt._ | ||
|
||
/** | ||
* @author OlegYch | ||
*/ | ||
|
||
trait UpdateSourcesTask { | ||
val self: BasicManagedProject | ||
|
||
import self._ | ||
|
||
val UpdateDescription = | ||
"Resolves and retrieves automatically managed dependencies (including sources)." | ||
|
||
lazy val updateSources = updateSourcesTask(updateIvyModule, ivyUpdateConfiguration) describedAs UpdateDescription | ||
|
||
def updateSourcesTask(module: => IvySbt#Module, configuration: => UpdateConfiguration) = ivyTask { | ||
update(module, configuration) | ||
} | ||
|
||
import scala.collection.jcl.Buffer | ||
import java.{util => ju} | ||
import org.apache.ivy.core.module.descriptor._ | ||
import org.apache.ivy.core.resolve._ | ||
import org.apache.ivy.core.report._ | ||
|
||
def srcDependency(node: IvyNode): DependencyDescriptor = { | ||
val descriptor = node.getAllCallers()(0).getDependencyDescriptor().asInstanceOf[DefaultDependencyDescriptor] | ||
for (conf <- descriptor.getModuleConfigurations) { | ||
def ddad(t: String, attrs: Map[String, String]) = new | ||
DefaultDependencyArtifactDescriptor(descriptor, node.getId.getName, t, "jar", null, | ||
new ju.HashMap[String, String] { | ||
attrs.foreach(e => put(e._1, e._2)) | ||
}) | ||
descriptor.addDependencyArtifact(conf, ddad("jar", Map.empty)) | ||
descriptor.addDependencyArtifact(conf, ddad("src", Map("classifier" -> "sources"))) | ||
} | ||
descriptor | ||
} | ||
|
||
def addSources(getReport: => ResolveReport, md: DefaultModuleDescriptor): Unit = { | ||
val initialReport = getReport | ||
def deps(report: ResolveReport): Seq[IvyNode] = Buffer(report.getDependencies.asInstanceOf[ju.List[IvyNode]]) | ||
def artifacts(report: ResolveReport): Seq[Artifact] = Buffer(report.getArtifacts.asInstanceOf[ju.List[Artifact]]) | ||
log.info("Adding sources for " + artifacts(initialReport).toString) | ||
deps(initialReport).foreach((node: IvyNode) => md.addDependency(srcDependency(node))) | ||
val newReport = getReport | ||
log.info("Added sources " + artifacts(newReport).toString) | ||
return newReport | ||
} | ||
|
||
def update(module: IvySbt#Module, configuration: UpdateConfiguration) { | ||
module.withModule { | ||
case (ivy, md: DefaultModuleDescriptor, default) => | ||
import configuration._ | ||
def report = resolve(logging)(ivy, md, default) | ||
addSources(report, md) | ||
val retrieveOptions = new RetrieveOptions | ||
retrieveOptions.setSync(synchronize) | ||
val patternBase = retrieveDirectory.getAbsolutePath | ||
val pattern = | ||
if (patternBase.endsWith(File.separator)) { | ||
patternBase + configuration.outputPattern | ||
} | ||
else { | ||
patternBase + File.separatorChar + configuration.outputPattern | ||
} | ||
ivy.retrieve(md.getModuleRevisionId, pattern, retrieveOptions) | ||
} | ||
} | ||
|
||
private def resolve(logging: UpdateLogging.Value)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String) = { | ||
val resolveOptions = new ResolveOptions | ||
resolveOptions.setLog(ivyLogLevel(logging)) | ||
val resolveReport = ivy.resolve(module, resolveOptions) | ||
if (resolveReport.hasError) { | ||
throw new ResolveException(resolveReport.getAllProblemMessages.toArray.map(_.toString).toList.removeDuplicates) | ||
} | ||
resolveReport | ||
} | ||
|
||
import UpdateLogging.{Quiet, Full, DownloadOnly} | ||
import org.apache.ivy.core.LogOptions.{LOG_QUIET, LOG_DEFAULT, LOG_DOWNLOAD_ONLY} | ||
|
||
private def ivyLogLevel(level: UpdateLogging.Value) = | ||
level match { | ||
case Quiet => LOG_QUIET | ||
case DownloadOnly => LOG_DOWNLOAD_ONLY | ||
case Full => LOG_DEFAULT | ||
} | ||
} | ||
|
||
final class ResolveException(messages: List[String]) extends RuntimeException(messages.mkString("\n")) | ||
import java.io.File | ||
import org.apache.ivy.core.retrieve.RetrieveOptions | ||
import org.apache.ivy.Ivy | ||
import sbt._ | ||
|
||
/** | ||
* @author OlegYch | ||
*/ | ||
|
||
trait UpdateSourcesTask { | ||
val self: BasicManagedProject | ||
|
||
import self._ | ||
|
||
val UpdateDescription = | ||
"Resolves and retrieves automatically managed dependencies (including sources)." | ||
|
||
lazy val updateSources = updateSourcesTask(updateIvyModule, ivyUpdateConfiguration) describedAs UpdateDescription | ||
|
||
def updateSourcesTask(module: => IvySbt#Module, configuration: => UpdateConfiguration) = ivyTask { | ||
update(module, configuration) | ||
} | ||
|
||
import scala.collection.jcl.Buffer | ||
import java.{util => ju} | ||
import org.apache.ivy.core.module.descriptor._ | ||
import org.apache.ivy.core.resolve._ | ||
import org.apache.ivy.core.report._ | ||
|
||
def srcDependency(node: IvyNode): DependencyDescriptor = { | ||
val descriptor = node.getAllCallers()(0).getDependencyDescriptor().asInstanceOf[DefaultDependencyDescriptor] | ||
for (conf <- descriptor.getModuleConfigurations) { | ||
def ddad(t: String, attrs: Map[String, String]) = new | ||
DefaultDependencyArtifactDescriptor(descriptor, node.getId.getName, t, "jar", null, | ||
new ju.HashMap[String, String] { | ||
attrs.foreach(e => put(e._1, e._2)) | ||
}) | ||
descriptor.addDependencyArtifact(conf, ddad("jar", Map.empty)) | ||
descriptor.addDependencyArtifact(conf, ddad("src", Map("classifier" -> "sources"))) | ||
} | ||
descriptor | ||
} | ||
|
||
def addSources(getReport: => ResolveReport, md: DefaultModuleDescriptor): Unit = { | ||
val initialReport = getReport | ||
if (initialReport.hasError) { | ||
throw new ResolveException(initialReport.getAllProblemMessages.toArray.map(_.toString).toList.removeDuplicates) | ||
} | ||
def deps(report: ResolveReport): Seq[IvyNode] = Buffer(report.getDependencies.asInstanceOf[ju.List[IvyNode]]) | ||
def artifacts(report: ResolveReport): Seq[Artifact] = Buffer(report.getArtifacts.asInstanceOf[ju.List[Artifact]]) | ||
log.info("Adding sources for " + artifacts(initialReport).toString) | ||
deps(initialReport).foreach((node: IvyNode) => md.addDependency(srcDependency(node))) | ||
val newReport = getReport | ||
log.info("Added sources " + artifacts(newReport).toString) | ||
return newReport | ||
} | ||
|
||
def update(module: IvySbt#Module, configuration: UpdateConfiguration) { | ||
module.withModule { | ||
case (ivy, md: DefaultModuleDescriptor, default) => | ||
import configuration._ | ||
def report = resolve(logging)(ivy, md, default) | ||
addSources(report, md) | ||
val retrieveOptions = new RetrieveOptions | ||
retrieveOptions.setSync(synchronize) | ||
val patternBase = retrieveDirectory.getAbsolutePath | ||
val pattern = | ||
if (patternBase.endsWith(File.separator)) { | ||
patternBase + configuration.outputPattern | ||
} | ||
else { | ||
patternBase + File.separatorChar + configuration.outputPattern | ||
} | ||
ivy.retrieve(md.getModuleRevisionId, pattern, retrieveOptions) | ||
} | ||
} | ||
|
||
private def resolve(logging: UpdateLogging.Value)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String) = { | ||
val resolveOptions = new ResolveOptions | ||
resolveOptions.setLog(ivyLogLevel(logging)) | ||
val resolveReport = ivy.resolve(module, resolveOptions) | ||
resolveReport | ||
} | ||
|
||
import UpdateLogging.{Quiet, Full, DownloadOnly} | ||
import org.apache.ivy.core.LogOptions.{LOG_QUIET, LOG_DEFAULT, LOG_DOWNLOAD_ONLY} | ||
|
||
private def ivyLogLevel(level: UpdateLogging.Value) = | ||
level match { | ||
case Quiet => LOG_QUIET | ||
case DownloadOnly => LOG_DOWNLOAD_ONLY | ||
case Full => LOG_DEFAULT | ||
} | ||
} | ||
|
||
final class ResolveException(messages: List[String]) extends RuntimeException(messages.mkString("\n")) |
36 changes: 33 additions & 3 deletions
36
sbt-sources-tests/src/main/scala/ScriptedTestAssertTasks.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import sbt.Project | ||
import org.scalatest.FlatSpec | ||
import sbt.BasicDependencyProject | ||
import org.scalatest.matchers.ShouldMatchers | ||
|
||
trait ScriptedTestAssertTasks { | ||
self: BasicDependencyProject => | ||
|
||
implicit def pathToStrings(p: sbt.PathFinder): Set[String] = p.getFiles.map(_.getName) | ||
|
||
def assertedProjects = (self :: subProjects.values.toList).flatMap { | ||
_ match { | ||
case p: ExpectedManagedLib => Some(p) | ||
case _ => None | ||
} | ||
} | ||
|
||
trait ScriptedTestAssertTasks extends Project { | ||
lazy val assertExpectedSources = task { | ||
//todo | ||
assertedProjects.foreach(p => { | ||
new FlatSpec with ShouldMatchers { | ||
"project dependencies " should "contain sources" in { | ||
pathToStrings(p.compileCp) should equal(p.compileEntries) | ||
pathToStrings(p.testCp) should equal(p.testEntries) | ||
} | ||
execute | ||
} | ||
}) | ||
None | ||
} | ||
} | ||
|
||
trait ExpectedManagedLib extends BasicDependencyProject { | ||
val compileEntries: Set[String] | ||
val testEntries: Set[String] | ||
|
||
def compileCp = projectClasspath(config("compile")) | ||
|
||
def testCp = projectClasspath(config("test")) | ||
} |
8 changes: 8 additions & 0 deletions
8
sbt-sources-tests/src/sbt-test/sources-plugin/basic/project/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#Project properties | ||
#Tue Mar 01 01:14:32 EET 2011 | ||
project.organization=foo | ||
project.name=scripted-test | ||
sbt.version=0.7.5.RC0 | ||
project.version=1.0 | ||
build.scala.versions=2.7.7 | ||
project.initialize=false |
24 changes: 24 additions & 0 deletions
24
sbt-sources-tests/src/sbt-test/sources-plugin/basic/project/build/ScriptedTestProject.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sbt._ | ||
|
||
class ScriptedTestProject(info: ProjectInfo) | ||
extends ParentProject(info) with ScriptedTestAssertTasks with ProjectWithSources with ExpectedManagedLib { | ||
|
||
override def libraryDependencies = super.libraryDependencies ++ Set( | ||
"commons-io" % "commons-io" % "1.4" withSources, | ||
"commons-lang" % "commons-lang" % "2.5", | ||
"xalan" % "serializer" % "2.7.1" | ||
) | ||
|
||
val compileEntries = Set( | ||
"scalatest-1.1.jar1", | ||
"scalatest-1.1-sources.jar", | ||
"serializer-2.7.1.jar", | ||
"commons-io-1.4-sources.jar", | ||
"commons-io-1.4.jar", | ||
"commons-lang-2.5-sources.jar", | ||
"commons-lang-2.5.jar", | ||
"xml-apis-1.3.04.jar" | ||
) | ||
|
||
val testEntries = Set[String]() | ||
} |
8 changes: 8 additions & 0 deletions
8
sbt-sources-tests/src/sbt-test/sources-plugin/basic/project/plugins/Plugins.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sbt._ | ||
|
||
class Plugins(info: ProjectInfo) extends PluginDefinition(info) { | ||
val testedVersion = "0.1.0" | ||
val groupId = "com.olegych" | ||
val sourcesPlugin = groupId % "sbt-sources-plugin" % testedVersion | ||
val scriptedTestUtils = groupId % "sbt-sources-tests_2.7.7" % testedVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
> update-sources | ||
> assert-expected-sources |
2 changes: 1 addition & 1 deletion
2
sbt-sources-tests/src/sbt-test/sources-plugin/multi-module/project/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 46 additions & 4 deletions
50
...es-tests/src/sbt-test/sources-plugin/multi-module/project/build/ScriptedTestProject.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,50 @@ | ||
import sbt._ | ||
|
||
class ScriptedTestProject(info: ProjectInfo) | ||
extends ParentProject(info) with ScriptedTestAssertTasks with ProjectWithSources { | ||
lazy val subproject1 = project("subproject1", "subproject1", new DefaultProject(_) with ProjectWithSources) | ||
lazy val subproject2 = project("subproject2", "subproject2", new DefaultProject(_) with ProjectWithSources, | ||
subproject1) | ||
extends ParentProject(info) with ScriptedTestAssertTasks with ProjectWithSources with ExpectedManagedLib { | ||
|
||
val compileEntries = Set( | ||
"scalaj-http_2.8.0-0.2.5.jar", | ||
"time_2.8.0-0.2.jar", | ||
"commons-codec-1.4.jar", | ||
"joda-time-1.6.jar" | ||
) | ||
|
||
val testEntries = Set( | ||
"junit-4.8.1.jar" | ||
) | ||
|
||
override def libraryDependencies = super.libraryDependencies ++ Set( | ||
"org.scala-tools.time" % "time_2.8.0" % "0.2", | ||
"org.scalaj" % "scalaj-http_2.8.0" % "0.2.5", | ||
"junit" % "junit" % "4.8.1" % "test" | ||
) | ||
|
||
lazy val subproject1 = project("subproject1", "subproject1", new DefaultProject(_) { | ||
override def libraryDependencies = super.libraryDependencies ++ Set( | ||
"commons-io" % "commons-io" % "1.4" withSources, | ||
"commons-lang" % "commons-lang" % "2.5", | ||
"xalan" % "serializer" % "2.7.1" | ||
) | ||
}) | ||
|
||
lazy val subproject2 = project("subproject2", "subproject2", new DefaultProject(_) with ExpectedManagedLib { | ||
val _ = "mysema" at "http://source.mysema.com/maven2/releases" | ||
val __ = "jboss" at "https://repository.jboss.org/nexus/content/groups/public-jboss/" | ||
|
||
override def libraryDependencies = super.libraryDependencies ++ Set( | ||
"com.mysema.querydsl" % "querydsl-jpa" % "2.1.2" | ||
) | ||
|
||
val compileEntries = Set( | ||
"scalaj-http_2.8.0-0.2.5.jar", | ||
"time_2.8.0-0.2.jar", | ||
"commons-codec-1.4.jar", | ||
"joda-time-1.6.jar" | ||
) | ||
|
||
val testEntries = Set( | ||
"junit-4.8.1.jar" | ||
) | ||
}, subproject1) | ||
} |
1 change: 0 additions & 1 deletion
1
sbt-sources-tests/src/sbt-test/sources-plugin/multi-module/test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
> update-sources | ||
> assert-expected-sources |