aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Christopher Vogt <oss.nsp@cvogt.org>2017-07-19 11:33:38 -0600
committerGitHub <noreply@github.com>2017-07-19 11:33:38 -0600
commit3c666efaeecbc35e75f273f5078477f6714c84d4 (patch)
treea24079631cab91481b7271edf85e3608eaa04187
parentc339af9ad9b2799a1c3c7aa7815e1f16a8afb41f (diff)
parente098ec58f6191b4934276dc5a3d65279f79cbbcc (diff)
downloadcbt-3c666efaeecbc35e75f273f5078477f6714c84d4.tar.gz
cbt-3c666efaeecbc35e75f273f5078477f6714c84d4.tar.bz2
cbt-3c666efaeecbc35e75f273f5078477f6714c84d4.zip
Merge pull request #549 from darthorimar/build-info
Build info #4
-rw-r--r--examples/export-build-information/expected.xml107
-rw-r--r--stage2/plugins/ExportBuildInformation.scala236
-rw-r--r--test/test.scala11
3 files changed, 274 insertions, 80 deletions
diff --git a/examples/export-build-information/expected.xml b/examples/export-build-information/expected.xml
new file mode 100644
index 0000000..9eb4320
--- /dev/null
+++ b/examples/export-build-information/expected.xml
@@ -0,0 +1,107 @@
+<project name="export-build-information" root="CBT_HOME/examples/export-build-information" rootModule="export-build-information">
+ <modules>
+ <module name="build-build" root="CBT_HOME/examples/export-build-information/build/build" target="CBT_HOME/examples/export-build-information/build/build/target" scalaVersion="2.11.8" type="build">
+ <sourceDirs>
+ <dir>CBT_HOME/examples/export-build-information/build/build</dir>
+ </sourceDirs>
+ <scalacOptions>
+ <option>-feature</option><option>-deprecation</option><option>-unchecked</option>
+ </scalacOptions>
+ <dependencies>
+ <binaryDependency>org.scala-lang:scala-library:2.11.8</binaryDependency>
+
+ </dependencies>
+ <classpath>
+ <classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/net/java/dev/jna/jna-platform/4.4.0/jna-platform-4.4.0.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/eclipse/jgit/org.eclipse.jgit/4.2.0.201601211800-r/org.eclipse.jgit-4.2.0.201601211800-r.jar</classpathItem>
+ </classpath>
+
+ </module><module name="build" root="CBT_HOME/examples/export-build-information/build" target="CBT_HOME/examples/export-build-information/build/target" scalaVersion="2.11.8" type="build">
+ <sourceDirs>
+ <dir>CBT_HOME/examples/export-build-information/build</dir>
+ </sourceDirs>
+ <scalacOptions>
+ <option>-feature</option><option>-deprecation</option><option>-unchecked</option>
+ </scalacOptions>
+ <dependencies>
+ <binaryDependency>org.scala-lang:scala-library:2.11.8</binaryDependency><binaryDependency>org.scala-lang.modules:scala-xml_2.11:1.0.6</binaryDependency>
+
+ </dependencies>
+ <classpath>
+ <classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/net/java/dev/jna/jna-platform/4.4.0/jna-platform-4.4.0.jar</classpathItem><classpathItem>CBT_HOME/cache/maven/org/eclipse/jgit/org.eclipse.jgit/4.2.0.201601211800-r/org.eclipse.jgit-4.2.0.201601211800-r.jar</classpathItem>
+ </classpath>
+ <parentBuild>build-build</parentBuild>
+ </module><module name="export-build-information" root="CBT_HOME/examples/export-build-information" target="CBT_HOME/examples/export-build-information/target" scalaVersion="2.11.8" type="default">
+ <sourceDirs>
+ <dir>CBT_HOME/examples/export-build-information</dir>
+ </sourceDirs>
+ <scalacOptions>
+ <option>-feature</option><option>-deprecation</option><option>-unchecked</option>
+ </scalacOptions>
+ <dependencies>
+ <binaryDependency>org.scala-lang:scala-library:2.11.8</binaryDependency>
+
+ </dependencies>
+ <classpath>
+ <classpathItem>CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</classpathItem>
+ </classpath>
+ <parentBuild>build</parentBuild>
+ </module>
+ </modules>
+ <libraries>
+ <library name="org.scala-lang:scala-library:2.11.8">
+ <jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8-sources.jar</jar>
+ </library><library name="commons-codec:commons-codec:1.6">
+ <jar type="binary">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6-sources.jar</jar>
+ </library><library name="commons-logging:commons-logging:1.1.3">
+ <jar type="binary">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-sources.jar</jar>
+ </library><library name="org.apache.httpcomponents:httpcore:4.3.3">
+ <jar type="binary">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar</jar><jar type="source">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3-sources.jar</jar>
+ </library><library name="org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4">
+ <jar type="binary">CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.6/scala-library-2.11.6.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.6/scala-library-2.11.6-sources.jar</jar>
+ </library><library name="org.scala-lang.modules:scala-xml_2.11:1.0.6">
+ <jar type="binary">CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8-sources.jar</jar>
+ </library><library name="org.scala-lang:scala-reflect:2.11.8">
+ <jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8-sources.jar</jar>
+ </library><library name="net.java.dev.jna:jna:4.4.0">
+ <jar type="binary">CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar</jar><jar type="source">CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0-sources.jar</jar>
+ </library><library name="org.slf4j:slf4j-api:1.7.2">
+ <jar type="binary">CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar</jar><jar type="source">CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2-sources.jar</jar>
+ </library><library name="org.apache.httpcomponents:httpclient:4.3.6">
+ <jar type="binary">CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar</jar><jar type="binary">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6.jar</jar><jar type="binary">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar</jar><jar type="source">CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3-sources.jar</jar>
+ </library><library name="com.googlecode.javaewah:JavaEWAH:0.7.9">
+ <jar type="binary">CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9.jar</jar><jar type="source">CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9-sources.jar</jar>
+ </library><library name="com.jcraft:jsch:0.1.53">
+ <jar type="binary">CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53.jar</jar><jar type="source">CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53-sources.jar</jar>
+ </library><library name="org.scala-lang:scala-compiler:2.11.8">
+ <jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.4/scala-xml_2.11-1.0.4.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.4/scala-xml_2.11-1.0.4-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8-sources.jar</jar>
+ </library><library name="net.java.dev.jna:jna-platform:4.4.0">
+ <jar type="binary">CBT_HOME/cache/maven/net/java/dev/jna/jna-platform/4.4.0/jna-platform-4.4.0.jar</jar><jar type="binary">CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar</jar><jar type="source">CBT_HOME/cache/maven/net/java/dev/jna/jna-platform/4.4.0/jna-platform-4.4.0-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/net/java/dev/jna/jna/4.4.0/jna-4.4.0-sources.jar</jar>
+ </library><library name="org.eclipse.jgit:org.eclipse.jgit:4.2.0.201601211800-r">
+ <jar type="binary">CBT_HOME/cache/maven/org/eclipse/jgit/org.eclipse.jgit/4.2.0.201601211800-r/org.eclipse.jgit-4.2.0.201601211800-r.jar</jar><jar type="binary">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6.jar</jar><jar type="binary">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar</jar><jar type="binary">CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar</jar><jar type="binary">CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9.jar</jar><jar type="binary">CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53.jar</jar><jar type="source">CBT_HOME/cache/maven/org/eclipse/jgit/org.eclipse.jgit/4.2.0.201601211800-r/org.eclipse.jgit-4.2.0.201601211800-r-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-codec/commons-codec/1.6/commons-codec-1.6-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9-sources.jar</jar><jar type="source">CBT_HOME/cache/maven/com/jcraft/jsch/0.1.53/jsch-0.1.53-sources.jar</jar>
+ </library>
+ </libraries>
+ <cbtLibraries>
+ <library name="CBT:process_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/process/target/scala-2.11/process_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:eval_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/eval/target/scala-2.11/eval_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:interfaces_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/interfaces/target/scala-2.11/interfaces_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:common-0_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/common-0/target/scala-2.11/common-0_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:common-1_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/common-1/target/scala-2.11/common-1_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:file_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/file/target/scala-2.11/file_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:reflect_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/libraries/reflect/target/scala-2.11/reflect_2.11-0.9-SNAPSHOT.jar</jar>
+ </library><library name="CBT:cbt_2.11-0.9-SNAPSHOT">
+ <jar type="binary">CBT_HOME/target/scala-2.11/cbt_2.11-0.9-SNAPSHOT.jar</jar>
+ </library>
+ </cbtLibraries>
+ <scalaCompilers>
+ <compiler version="2.11.8">
+ <jar>CBT_HOME/cache/maven/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar</jar><jar>CBT_HOME/cache/maven/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar</jar><jar>CBT_HOME/cache/maven/org/scala-lang/modules/scala-parser-combinators_2.11/1.0.4/scala-parser-combinators_2.11-1.0.4.jar</jar><jar>CBT_HOME/cache/maven/org/scala-lang/modules/scala-xml_2.11/1.0.4/scala-xml_2.11-1.0.4.jar</jar><jar>CBT_HOME/cache/maven/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar</jar>
+ </compiler>
+ </scalaCompilers>
+ </project> \ No newline at end of file
diff --git a/stage2/plugins/ExportBuildInformation.scala b/stage2/plugins/ExportBuildInformation.scala
index c5c69ab..37dcc38 100644
--- a/stage2/plugins/ExportBuildInformation.scala
+++ b/stage2/plugins/ExportBuildInformation.scala
@@ -4,14 +4,24 @@ import cbt._
import java.io._
import java.nio.file._
import scala.xml._
-import scala.util._
+import scala.util._
trait ExportBuildInformation { self: BaseBuild =>
- def buildInfoXml: String =
- BuildInformationSerializer.serialize(BuildInformation.Project(self, context.args)).toString
+ def buildInfoXml: String = {
+ val parameters = BuildInformation.Project.ExportParameters(context.args)
+ val xml = BuildInformationSerializer.serialize(BuildInformation.Project(self, parameters))
+ parameters.outputFile match {
+ case None =>
+ xml.toString
+ case Some(file) =>
+ XML.save(file.getPath, xml)
+ s"Saved to ${file.getPath}"
+ }
+ }
}
object BuildInformation {
+
case class Project(
name: String,
root: File,
@@ -27,6 +37,7 @@ object BuildInformation {
root: File,
scalaVersion: String,
sourceDirs: Seq[File],
+ moduleType: ModuleType,
target: File,
binaryDependencies: Seq[BinaryDependency],
moduleDependencies: Seq[ModuleDependency],
@@ -34,7 +45,7 @@ object BuildInformation {
parentBuild: Option[String],
scalacOptions: Seq[String]
)
-
+
case class Library( name: String, jars: Seq[LibraryJar] )
case class BinaryDependency( name: String )
@@ -43,61 +54,76 @@ object BuildInformation {
case class ScalaCompiler( version: String, jars: Seq[File] )
- case class LibraryJar( jar: File, jarType: JarType.JarType )
+ case class LibraryJar( jar: File, jarType: JarType )
+
+ case class JarType( name: String )
+
+ object JarType {
+ object Binary extends JarType( "binary" )
+ object Source extends JarType( "source" )
+ }
+
+ case class ModuleType( name: String )
- object JarType extends Enumeration {
- type JarType = Value
- val Binary = Value("binary")
- val Source = Value("source")
+ object ModuleType {
+ object Default extends ModuleType( "default" )
+ object Extra extends ModuleType( "extra" )
+ object Test extends ModuleType( "test" )
+ object Build extends ModuleType( "build" )
}
object Project {
- def apply(build: BaseBuild, args: Seq[String]): Project = {
- val extraModuleNames: Seq[String] = args.lift(0).map(_.split(":").toSeq).getOrElse(Seq.empty)
- new BuildInformationExporter(build, extraModuleNames).exportBuildInformation
+ def apply(build: BaseBuild, parameters: ExportParameters): Project = {
+ new BuildInformationExporter(build, parameters).exportBuildInformation
}
- class BuildInformationExporter(rootBuild: BaseBuild, extraModuleNames: Seq[String]) {
+ class BuildInformationExporter(rootBuild: BaseBuild, parameters: ExportParameters) {
+ import parameters._
+
def exportBuildInformation: Project = {
- val moduleBuilds = transitiveBuilds(rootBuild)
- val libraries = moduleBuilds
- .flatMap(_.transitiveDependencies)
- .collect { case d: BoundMavenDependency => exportLibrary(d) }
+ val extraModuleBuilds = extraModulePaths
+ .map(f => DirectoryDependency(f)(rootBuild.context).dependency.asInstanceOf[BaseBuild])
+ val builds = transitiveBuilds((rootBuild, ModuleType.Default) +: extraModuleBuilds.map(b => (b, ModuleType.Extra)))
+ val rootModule = exportModule(rootBuild, ModuleType.Default)
+ val modules = builds
+ .map(m => exportModule(m._1, m._2))
.distinct
- val cbtLibraries = convertCbtLibraries
- val rootModule = exportModule(rootBuild)
- val extraModuleBuilds = extraModuleNames
- .map(f => new File(f))
- .filter(f => f.exists && f.isDirectory)
- .map(f => DirectoryDependency(f)(rootBuild.context).dependency.asInstanceOf[BaseBuild])
- .flatMap(transitiveBuilds)
- val modules = (moduleBuilds ++ extraModuleBuilds)
- .map(exportModule)
+ val libraries = builds
+ .map(_._1)
+ .flatMap(_.transitiveDependencies)
+ .collect { case d: BoundMavenDependency => exportLibrary(d) }
.distinct
+ val cbtLibraries = if (needCbtLibs) convertCbtLibraries else Seq.empty[Library]
val scalaCompilers = modules
.map(_.scalaVersion)
- .map(v => ScalaCompiler(v, resolveScalaCompiler(rootBuild, v)))
+ .map(v => ScalaCompiler(v, resolveScalaCompiler(v)))
+ .distinct
Project(
- rootModule.name,
- rootModule.root,
- rootModule,
- modules,
- libraries,
- cbtLibraries,
- scalaCompilers
+ name = rootModule.name,
+ root = rootModule.root,
+ rootModule = rootModule,
+ modules = modules,
+ libraries = libraries,
+ cbtLibraries = cbtLibraries,
+ scalaCompilers = scalaCompilers
)
}
- private def convertCbtLibraries =
- transitiveBuilds(DirectoryDependency(rootBuild.context.cbtHome)(rootBuild.context).dependenciesArray.head.asInstanceOf[BaseBuild])
+
+ private def convertCbtLibraries = {
+ val cbtBuild =
+ DirectoryDependency(rootBuild.context.cbtHome)(rootBuild.context).dependenciesArray.head.asInstanceOf[BaseBuild]
+ transitiveBuilds(Seq((cbtBuild, ModuleType.Default)), skipTests = true)
+ .map(_._1)
.collect {
case d: BoundMavenDependency => d.jar
case d: PackageJars => d.jar.get
}
.map(exportLibrary)
.distinct
+ }
private def collectDependencies(dependencies: Seq[Dependency]): Seq[ModuleDependency] =
dependencies
@@ -107,7 +133,7 @@ object BuildInformation {
}
.flatten
- private def exportModule(build: BaseBuild): Module = {
+ private def exportModule(build: BaseBuild, moduleType: ModuleType): Module = {
val moduleDependencies = collectDependencies(build.dependencies)
val mavenDependencies = build.dependencies
.collect { case d: BoundMavenDependency => BinaryDependency(formatMavenDependency(d.mavenDependency)) }
@@ -130,6 +156,7 @@ object BuildInformation {
scalaVersion = build.scalaVersion,
sourceDirs = sourceDirs,
target = build.target,
+ moduleType = moduleType,
binaryDependencies = mavenDependencies,
moduleDependencies = moduleDependencies,
classpath = classpath,
@@ -153,30 +180,33 @@ object BuildInformation {
.map(_.toFile)
}
- private def collectLazyBuilds(dependency: Dependency): Option[BaseBuild] =
- dependency match {
- case l: LazyDependency =>
- l.dependency match {
- case d: BaseBuild => Some(d)
- case d: LazyDependency => collectLazyBuilds(d.dependency)
- case _ => None
- }
- case d: BaseBuild => Some(d)
- case _ => None
- }
-
-
- private def transitiveBuilds(build: BaseBuild): Seq[BaseBuild] =
- (build +: build.transitiveDependencies)
- .collect {
- case d: BaseBuild => d +: collectParentBuilds(d).flatMap(transitiveBuilds)
- case d: LazyDependency =>
- collectLazyBuilds(d.dependency)
- .toSeq
- .flatMap(transitiveBuilds)
+ // More effectively to call on a all builds at once rather than on one per time
+ private def transitiveBuilds(builds: Seq[(BaseBuild, ModuleType)], skipTests: Boolean = false): Seq[(BaseBuild, ModuleType)] = {
+ def traverse(visitedProd: (Seq[BaseBuild], Seq[ModuleType]), buildProd: (BaseBuild, ModuleType)): (Seq[BaseBuild], Seq[ModuleType]) = {
+ val (visited, moduleTypes) = visitedProd
+ val (build, moduleType) = buildProd
+ if (visited.contains(build))
+ (visited, moduleTypes)
+ else {
+ val testBuildSeq = if (!skipTests) testBuild(build) else Seq.empty
+ (build.transitiveDependencies.map(d => (d, ModuleType.Default)) ++
+ parentBuild(build).map(d => (d, ModuleType.Build)) ++
+ testBuildSeq.map(d => (d, ModuleType.Test))
+ )
+ .collect {
+ case (d: BaseBuild, t) =>
+ (d, t)
+ case (d: LazyDependency, t) if d.dependency.isInstanceOf[BaseBuild] =>
+ (d.dependency.asInstanceOf[BaseBuild], t)
+ }
+ .filterNot(b => visited.contains(b._1))
+ .foldLeft(build +: visited, moduleType +: moduleTypes)(traverse)
}
- .flatten
- .distinct
+ }
+ val (collectedBuilds, collectedTypes) = builds
+ .foldLeft(Seq.empty[BaseBuild], Seq.empty[ModuleType])(traverse)
+ collectedBuilds.zip(collectedTypes)
+ }
private def exportLibrary(dependency: BoundMavenDependency) = {
val name = formatMavenDependency(dependency.mavenDependency)
@@ -190,14 +220,14 @@ object BuildInformation {
implicit val transientCache: java.util.Map[AnyRef, AnyRef] = rootBuild.context.transientCache
implicit val classLoaderCache: ClassLoaderCache = rootBuild.context.classLoaderCache
val sourceJars = jars
- .map { d =>
+ .map { d =>
Try(d.copy(mavenDependency = d.mavenDependency.copy(classifier = Classifier.sources)).jar)
- }
+ }
.flatMap {
case Success(j) => Some(j)
case Failure(e) =>
logger.log("ExportBuildInformation", s"Can not load a $name library sources. Skipping")
- None
+ None
}
.map(LibraryJar(_, JarType.Source))
Library(name, binaryJars ++ sourceJars)
@@ -206,15 +236,22 @@ object BuildInformation {
private def exportLibrary(file: File) =
Library("CBT:" + file.getName.stripSuffix(".jar"), Seq(LibraryJar(file, JarType.Binary)))
- private def collectParentBuilds(build: BaseBuild): Seq[BaseBuild] =
+ private def parentBuild(build: BaseBuild): Seq[BaseBuild] =
build.context.parentBuild
.map(_.asInstanceOf[BaseBuild])
- .map(b => b +: collectParentBuilds(b))
.toSeq
- .flatten
- private def resolveScalaCompiler(build: BaseBuild, scalaVersion: String) =
- build.Resolver(mavenCentral, sonatypeReleases).bindOne(
+ private def testBuild(build: BaseBuild): Seq[BaseBuild] =
+ Try(build.test)
+ .toOption
+ .toSeq
+ .flatMap {
+ case testBuild: BaseBuild => Seq(testBuild)
+ case _ => Seq.empty
+ }
+
+ private def resolveScalaCompiler(scalaVersion: String) =
+ rootBuild.Resolver(mavenCentral, sonatypeReleases).bindOne(
MavenDependency("org.scala-lang", "scala-compiler", scalaVersion)
).classpath.files
@@ -222,8 +259,7 @@ object BuildInformation {
if (source.isDirectory)
source
else
- source.getParentFile //Let's asume that for now
-
+ source.getParentFile //Let's assume that for now
private def formatMavenDependency(dependency: cbt.MavenDependency) =
s"${dependency.groupId}:${dependency.artifactId}:${dependency.version}"
@@ -237,12 +273,30 @@ object BuildInformation {
.stripPrefix("/")
.replace("/", "-")
}
+
+ case class ExportParameters(extraModulePaths: Seq[File], needCbtLibs: Boolean, outputFile: Option[File])
+
+ object ExportParameters {
+ def apply(args: Seq[String]): ExportParameters = {
+ val argumentParser = new ArgumentParser(args)
+ val extraModulePaths = argumentParser.value("extraModules")
+ .map(_.split(":").toSeq)
+ .getOrElse(Seq.empty)
+ .map(p => new File(p))
+ .filter(f => f.exists && f.isDirectory)
+ val needCbtLibs: Boolean = argumentParser.value("needCbtLibs").forall(_.toBoolean)
+ val outputFile = argumentParser.value("outputFile").map(p => new File(p))
+ ExportParameters(extraModulePaths, needCbtLibs, outputFile)
+ }
+ }
+
}
+
}
object BuildInformationSerializer {
def serialize(project: BuildInformation.Project): Node =
- <project name={project.name} root={project.root.toString} rootModule={project.rootModule.name}>
+ <project name={project.name} root={project.root.getPath} rootModule={project.rootModule.name}>
<modules>
{project.modules.map(serialize)}
</modules>
@@ -258,21 +312,21 @@ object BuildInformationSerializer {
</project>
private def serialize(module: BuildInformation.Module): Node =
- <module name={module.name} root={module.root.toString} target={module.target.toString} scalaVersion={module.scalaVersion}>
+ <module name={module.name} root={module.root.getPath} target={module.target.getPath} scalaVersion={module.scalaVersion} type={module.moduleType.name}>
<sourceDirs>
- {module.sourceDirs.map(d => <dir>{d}</dir>)}
+ {module.sourceDirs.map(d => <dir>{d.getPath: String}</dir>)}
</sourceDirs>
<scalacOptions>
- {module.scalacOptions.map(o => <option>{o}</option>)}
+ {module.scalacOptions.map(o => <option>{o: String}</option>)}
</scalacOptions>
<dependencies>
{module.binaryDependencies.map(serialize)}
{module.moduleDependencies.map(serialize)}
</dependencies>
<classpath>
- {module.classpath.map(c => <classpathItem>{c.toString}</classpathItem>)}
+ {module.classpath.map(c => <classpathItem>{c.getPath: String}</classpathItem>)}
</classpath>
- {module.parentBuild.map(p => <parentBuild>{p}</parentBuild>).getOrElse(NodeSeq.Empty)}
+ {module.parentBuild.map(p => <parentBuild>{p: String}</parentBuild>).getOrElse(NodeSeq.Empty)}
</module>
private def serialize(binaryDependency: BuildInformation.BinaryDependency): Node =
@@ -280,14 +334,36 @@ object BuildInformationSerializer {
private def serialize(library: BuildInformation.Library): Node =
<library name={library.name}>
- {library.jars.map(j => <jar type={j.jarType.toString}>{j.jar}</jar>)}
+ {library.jars.map(j => <jar type={j.jarType.name}>{j.jar.getPath: String}</jar>)}
</library>
+ private def serialize(moduleDependency: BuildInformation.ModuleDependency): Node =
+ <moduleDependency>
+ {moduleDependency.name: String}
+ </moduleDependency>
+
private def serialize(compiler: BuildInformation.ScalaCompiler): Node =
<compiler version={compiler.version}>
- {compiler.jars.map(j => <jar>{j}</jar>)}
+ {compiler.jars.map(j => <jar>{j.getPath: String}</jar>)}
</compiler>
+}
- private def serialize(moduleDependency: BuildInformation.ModuleDependency): Node =
- <moduleDependency>{moduleDependency.name}</moduleDependency>
+
+class ArgumentParser(arguments: Seq[String]) {
+ private val argumentsMap = (arguments :+ "")
+ .sliding(2)
+ .map(_.toList)
+ .foldLeft(Map.empty[String, Option[String]]) {
+ case (m, Seq(k: String, v: String)) if k.startsWith("--") && !v.startsWith("--") =>
+ m + (k.stripPrefix("--") -> Some(v))
+ case (m, (k: String) :: _) if k.startsWith("--") =>
+ m + (k.stripPrefix("--") -> None)
+ case (m, _) => m
+ }
+
+ def value(key: String): Option[String] =
+ argumentsMap.get(key.stripPrefix("--")).flatten
+
+ def persists(key: String): Boolean =
+ argumentsMap.isDefinedAt(key)
} \ No newline at end of file
diff --git a/test/test.scala b/test/test.scala
index 9cb7fd9..adb4d8a 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -506,6 +506,17 @@ object Main{
assert(res.exit0)
}
+ if (slow) {
+ import scala.xml._
+ val expected =
+ (cbtHome / "examples" / "export-build-information" / "expected.xml").readAsString.replaceAll("CBT_HOME", cbtHome.getPath)
+ val expectedXml = Utility.trim(XML.loadString(expected))
+ val res = runCbt("../examples/export-build-information", Seq("buildInfoXml"))
+ assert(res.exit0)
+ val resultXml = Utility.trim(XML.loadString(res.out))
+ assert(resultXml == expectedXml)
+ }
+
/*
// currently fails with
// java.lang.UnsupportedOperationException: scalafix.rewrite.ScalafixMirror.fromMirror $anon#typeSignature requires the semantic api