├── .circleci └── config.yml ├── .gitignore ├── DEVELOPER_GUIDE.txt ├── LICENSE.txt ├── NOTICE ├── README.md ├── TODO.txt ├── build ├── build.scala └── build │ └── build.scala ├── cbt ├── cbt.bat ├── compatibility └── src │ └── cbt │ ├── ArtifactInfo.java │ ├── BuildInterface.java │ ├── Context.java │ ├── Dependency.java │ ├── IncompatibleCbtVersionException.java │ └── Result.java ├── coursier └── Coursier.scala ├── doc ├── cbt-developer │ └── version-compatibility.md ├── design.md ├── docs.md ├── faq.md ├── intellij-gsoc.md └── plugin-author-guide.md ├── examples ├── akka-example │ ├── Main.scala │ └── build │ │ └── build.scala ├── build-info-example │ ├── Main.scala │ ├── Readme.md │ ├── build │ │ └── build.scala │ └── src_generated │ │ └── BuildInfo.scala ├── cross-build-example │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.scala ├── cross-rewrite-example │ ├── Readme.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ └── Main.scala ├── dotty-example │ ├── README.md │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.scala ├── dynamic-overrides-example │ └── build │ │ └── build.scala ├── export-build-information │ ├── Main.scala │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── expected.xml ├── fork-example │ ├── Main.scala │ └── build │ │ └── build.scala ├── frege-example │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.fr ├── intellij │ ├── README.md │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.scala ├── kindprojector-example │ ├── Main.scala │ └── build │ │ └── build.scala ├── multi-combined-example │ ├── Readme.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── shared │ │ └── SomeSharedClass.scala │ ├── sub1 │ │ └── SomeConcreteClass.scala │ ├── sub2 │ │ └── SomeOtherConcreteClass.scala │ ├── sub3 │ │ └── Main.scala │ ├── sub4 │ │ ├── Class4.scala │ │ ├── build │ │ │ └── build.scala │ │ └── sub41 │ │ │ └── sub42 │ │ │ └── Sub4Example.scala │ ├── sub5 │ │ └── Main.scala │ └── sub6 │ │ └── Sub6Example.scala ├── multi-standalone-example │ ├── Readme.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── common │ │ ├── SomeSharedClass.scala │ │ └── build │ │ │ ├── build.scala │ │ │ └── build │ │ │ └── build.scala │ ├── shared-build │ │ ├── SharedCbtBuild.scala │ │ └── build │ │ │ └── build.scala │ ├── sub1 │ │ ├── SomeConcreteClass.scala │ │ └── build │ │ │ ├── build.scala │ │ │ └── build │ │ │ └── build.scala │ └── sub2 │ │ ├── SomeOtherConcreteClass.scala │ │ └── build │ │ ├── build.scala │ │ └── build │ │ └── build.scala ├── new-style-macros-example │ ├── Hello.scala │ ├── build │ │ └── build.scala │ └── macros │ │ └── Main.scala ├── proguard-example │ ├── Main.scala │ └── build │ │ ├── build.scala │ │ └── build │ │ └── build.scala ├── resources-example │ ├── Main.scala │ ├── build │ │ └── build.scala │ └── parent │ │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ │ ├── my-resources │ │ └── foo.text │ │ ├── package.scala │ │ ├── parent │ │ └── package.scala │ │ └── resources │ │ └── foo.text ├── restart │ ├── Readme.md │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.scala ├── scala-xray │ ├── build │ │ └── build.scala │ └── src │ │ └── Main.scala ├── scalafix-compiler-plugin-example │ ├── .scalafix.conf │ ├── Main.scala │ └── build │ │ ├── build.scala │ │ └── build │ │ └── build.scala ├── scalafix-example │ ├── Main.scala │ └── build │ │ ├── build.scala │ │ └── build │ │ └── build.scala ├── scalafmt-example │ ├── .scalafmt.conf │ ├── README.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── resources │ │ └── reference.conf │ └── src │ │ └── Main.scala ├── scalajs-plain-example │ ├── README.md │ ├── js │ │ ├── App.scala │ │ ├── Plotly.scala │ │ └── build │ │ │ ├── build.scala │ │ │ └── build │ │ │ └── build.scala │ ├── jvm │ │ └── build │ │ │ └── build.scala │ ├── server │ │ └── public │ │ │ └── index.html │ └── shared │ │ └── SomeSharedClass.scala ├── scalajs-react-example │ ├── README.md │ ├── js │ │ ├── App.scala │ │ ├── Pictures.scala │ │ └── build │ │ │ ├── build.scala │ │ │ └── build │ │ │ └── build.scala │ ├── jvm │ │ └── build │ │ │ └── build.scala │ ├── server │ │ ├── app.js │ │ ├── package.json │ │ └── public │ │ │ └── index.html │ └── shared │ │ └── Picture.scala ├── scalapb-example │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── protobuf-schemas │ │ ├── address.proto │ │ └── person.proto │ └── src │ │ └── Main.scala ├── scalariform-example │ ├── README.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── resources │ │ └── reference.conf │ └── src │ │ └── Main.scala ├── scalastyle │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── scalastyle-config.xml │ └── src │ │ └── Main.scala ├── scalatest-example │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ ├── main │ │ └── scala │ │ │ └── Hello.scala │ │ └── test │ │ └── scala │ │ └── Test.scala ├── scalatex-example │ ├── Foo.scala │ └── docs │ │ ├── build │ │ └── build.scala │ │ ├── readme.scalatex │ │ └── static │ │ └── style.css ├── simple-example │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ └── Main.scala ├── sonatype-release-example │ ├── README.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ └── Main.scala ├── tut │ ├── Readme.md │ ├── build │ │ └── build.scala │ └── tut │ │ └── example.md ├── uber-jar-example │ ├── README.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ ├── Main.scala │ │ └── com │ │ └── github │ │ └── someguy │ │ └── ImportantLib.scala └── wartremover-example │ ├── build │ ├── build.scala │ └── build │ │ └── build.scala │ └── src │ └── Main.scala ├── internal └── plugins │ ├── library │ ├── Library.scala │ └── build │ │ └── build.scala │ └── shared │ ├── Shared.scala │ └── build │ └── build.scala ├── libraries ├── capture_args │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── package.scala ├── common-0 │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ └── cbt │ │ └── reflect │ │ ├── ProxySecurityManager.java │ │ ├── TrapSecurityManager.java │ │ └── TrapSystemExit.java ├── common-1 │ ├── ExitCode.scala │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── common_1.scala │ └── src │ │ └── cbt │ │ └── ExitCode.java ├── eval │ ├── Eval.scala │ ├── Readme.md │ ├── build │ │ └── build.scala │ └── test │ │ ├── EvalTest.scala │ │ └── resources │ │ ├── Base.scala │ │ ├── Deprecated.scala │ │ ├── Derived.scala │ │ ├── DerivedWithInclude.scala │ │ ├── HelloJoe.scala │ │ ├── IncludeInclude.scala │ │ ├── OnePlusOne.scala │ │ ├── RubyInclude.scala │ │ └── file-with-dash.scala ├── file │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── file.scala ├── interfaces │ ├── build │ │ └── build.scala │ └── src │ │ └── cbt │ │ └── interfaces │ │ └── ExitCode.java ├── process │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ ├── process.scala │ └── test │ │ └── test.scala ├── proguard │ ├── Proguard.scala │ ├── Readme.md │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── spec │ │ └── refcard.html ├── readme.txt ├── reflect │ ├── StaticMethod.scala │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── reflect.scala ├── scalatest-runner │ ├── Runner.scala │ └── build │ │ ├── build.scala │ │ └── build │ │ └── build.scala └── scalatex │ ├── AbstractMain.scala │ ├── build │ └── build.scala │ └── lib.scala ├── nailgun_launcher └── src │ └── cbt │ ├── BuildStage1Result.java │ ├── CbtURLClassLoader.java │ ├── ClassLoaderCache.java │ ├── EarlyDependencies.java │ ├── MultiClassLoader2.java │ ├── NailgunLauncher.java │ ├── Stage0Lib.java │ └── ThreadLocalOutputStream.java ├── plugins ├── google-java-format │ ├── GoogleJavaFormat.scala │ ├── build │ │ └── build.scala │ └── src │ │ └── com │ │ └── google │ │ └── errorprone │ │ └── annotations │ │ └── Immutable.java ├── proguard │ ├── Proguard.scala │ └── build │ │ └── build.scala ├── readme.txt ├── sbt_layout │ ├── SbtLayout.scala │ └── build │ │ └── build.scala ├── scalafix-compiler-plugin │ ├── Scalafix.scala │ └── build │ │ └── build.scala ├── scalafix │ ├── Scalafix.scala │ └── build │ │ └── build.scala ├── scalafmt │ ├── Scalafmt.scala │ └── build │ │ └── build.scala ├── scalajs │ ├── ScalaJsBuild.scala │ ├── ScalaJsLib.scala │ └── build │ │ └── build.scala ├── scalapb │ ├── ScalaPB.scala │ ├── build │ │ └── build.scala │ └── src_generated │ │ └── BuildInfo.scala ├── scalariform │ ├── Scalariform.scala │ └── build │ │ └── build.scala ├── scalastyle │ ├── Scalastyle.scala │ ├── build │ │ └── build.scala │ └── resources │ │ └── scalastyle-config.xml ├── sonatype-release │ ├── build │ │ └── build.scala │ └── src │ │ ├── SonatypeRelease.scala │ │ └── sonatype │ │ ├── HttpUtils.scala │ │ ├── SonatypeHttpApi.scala │ │ ├── SonatypeLib.scala │ │ └── models.scala ├── uber-jar │ ├── build │ │ └── build.scala │ └── src │ │ └── UberJar.scala └── wartremover │ ├── WartRemover.scala │ └── build │ └── build.scala ├── ports ├── migration-manager │ └── build │ │ └── build.scala ├── scala-xray │ └── build │ │ └── build.scala └── scalariform │ └── build │ └── build.scala ├── realpath ├── realpath.c └── realpath.sh ├── shell-integration ├── cbt-completions.bash ├── cbt-completions.fish └── cbt-completions.zsh ├── stage1 ├── CachingClassLoader.scala ├── CbtPaths.scala ├── ClassPath.scala ├── ContextImplementation.scala ├── KeyLockedLazyCache.scala ├── MavenRepository.scala ├── MultiClassLoader.scala ├── PoorMansProfiler.scala ├── Stage1.scala ├── Stage1Lib.scala ├── URLClassLoader.scala ├── cbt.scala ├── constants.scala ├── logger.scala └── resolver.scala ├── stage2 ├── BasicBuild.scala ├── BuildBuild.scala ├── DirectoryDependency.scala ├── GitDependency.scala ├── LazyDependency.scala ├── Lib.scala ├── License.scala ├── PackageJars.scala ├── Plugin.scala ├── Publish.scala ├── SbtDependencyDsl.scala ├── Scaffold.scala ├── Stage2.scala ├── ToolsStage2.scala ├── ToolsTasks.scala ├── libraries.scala ├── plugins.scala ├── plugins │ ├── AdvancedFlags.scala │ ├── CommandLineOverrides.scala │ ├── Dotty.scala │ ├── DynamicOverrides.scala │ ├── Ensime.scala │ ├── ExportBuildInformation.scala │ ├── Frege.scala │ ├── GenerateBuildInfo.scala │ ├── GeneratedSections.scala │ ├── GithubPom.scala │ ├── IntelliJ.scala │ ├── KindProjector.scala │ ├── MultipleScalaVersions.scala │ ├── NewStyleMacros.scala │ ├── OldStyleMacros.scala │ ├── PublishToArtifactory.scala │ ├── Readme.md │ ├── ScalaTest.scala │ ├── ScalaXRay.scala │ ├── Scalameta.scala │ ├── Scalatex.scala │ ├── SnapshotVersion.scala │ ├── Tut.scala │ └── readme.txt ├── pom.scala └── ports.scala ├── test ├── broken-build │ ├── build-class-with-wrong-arguments │ │ └── build │ │ │ └── build.scala │ ├── build-class-with-wrong-parent │ │ └── build │ │ │ └── build.scala │ ├── empty-build-file │ │ ├── Main.scala │ │ └── build │ │ │ └── build.scala │ └── no-build-file │ │ ├── Main.scala │ │ └── build │ │ └── foo.scala ├── build │ └── build.scala ├── empty-build │ ├── Main.scala │ └── build │ │ └── build │ │ └── dummy ├── library-test │ ├── Foo.scala │ └── build │ │ └── build.scala ├── multi-build │ ├── build │ │ └── build.scala │ ├── code.scala │ ├── sub1 │ │ └── code.scala │ └── sub2 │ │ └── code.scala ├── nothing │ └── placeholder ├── simple-fixed-cbt │ ├── Main.scala │ └── build │ │ └── build.scala ├── simple-fixed │ ├── Main.scala │ └── build │ │ └── build.scala ├── simple │ ├── Main.scala │ └── build │ │ └── build.scala └── test.scala └── tools └── gui ├── build └── build.scala ├── resources ├── template-project │ ├── build │ │ ├── build.scala │ │ └── build │ │ │ └── build.scala │ └── src │ │ └── main │ │ └── scala │ │ └── Main.scala └── web │ ├── definitions.js │ ├── favicon.ico │ ├── highlight │ ├── LICENSE │ ├── highlight.pack.js │ └── hljs-cbt-theme.css │ ├── index.html │ ├── jquery-3.1.1.min.js │ ├── main.js │ └── styles.css └── src ├── JettyServer.scala ├── Main.scala └── ProjectBuilder.scala /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: ~/cbt 5 | docker: 6 | - image: circleci/java:8-jdk 7 | steps: 8 | - checkout 9 | - restore_cache: 10 | key: dependency-cache 11 | - run: 12 | command: 'mkdir -p ~/cache' 13 | - run: 14 | command: 'rm ~/.gitconfig || true' # avoid url replacement breaking jgit 15 | - run: 16 | command: 'wget http://mirrors.kernel.org/ubuntu/pool/universe/n/nailgun/nailgun_0.9.0+trunk95-3_amd64.deb --continue -O ~/cache/nailgun_0.9.0+trunk95-3_amd64.deb' 17 | - run: 18 | command: 'sudo dpkg -i ~/cache/nailgun_0.9.0+trunk95-3_amd64.deb' 19 | - run: 20 | command: 'wget http://mirrors.kernel.org/ubuntu/pool/universe/s/shellcheck/shellcheck_0.3.3-1~ubuntu14.04.1_amd64.deb --continue -O ~/cache/shellcheck_0.3.3-1~ubuntu14.04.1_amd64.deb' 21 | - run: 22 | command: 'sudo dpkg -i ~/cache/shellcheck_0.3.3-1~ubuntu14.04.1_amd64.deb' 23 | - save_cache: 24 | key: dependency-cache 25 | paths: 26 | - "~/cache" 27 | - run: 28 | command: './cbt direct compile' 29 | - run: 30 | command: './cbt direct test.compile' 31 | - run: 32 | command: './cbt compile' 33 | - run: 34 | command: './cbt -Dlog=all' 35 | - run: 36 | command: 'git diff --exit-code' 37 | - run: 38 | command: './cbt direct test.run slow fork direct' 39 | - run: 40 | command: './cbt direct test.run slow fork' 41 | - run: 42 | command: './cbt direct test.run slow' 43 | - run: 44 | command: './cbt test.run slow fork direct' 45 | - run: 46 | command: './cbt test.run slow fork' 47 | - run: 48 | command: './cbt test.run slow' 49 | - run: 50 | command: 'git diff --exit-code' 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config 2 | cache 3 | classes 4 | lib 5 | out 6 | scala_classes 7 | target/ 8 | *.login 9 | cache_ 10 | .idea 11 | realpath/realpath 12 | node_modules 13 | *fastopt* 14 | *fullopt* 15 | examples/dotty-example/_site 16 | examples/scalajs-plain-example/server/public/generated 17 | examples/scalajs-react-example/server/public/generated 18 | .cbt-loop.tmp 19 | test/simple/src_generated 20 | examples/scalapb-example/src_generated 21 | ScalatexGenerated.scala 22 | .idea/ 23 | *.iml 24 | -------------------------------------------------------------------------------- /DEVELOPER_GUIDE.txt: -------------------------------------------------------------------------------- 1 | Welcome developer. 2 | 3 | CBT has a very easy code base that's easy to master. 4 | Don't shy away from submiting PRs :). And because CBT bootstraps from source 5 | you already have the code there. 6 | 7 | The only tricky parts are class loading and cache invalidation. Most changes 8 | will not need to interfere with this though. 9 | 10 | The ./cbt bash script starts the process. 11 | 12 | You currently need javac, nailgun, gpg and realpath or gcc installed. 13 | 14 | If you have any troubles with class not found, method not found, 15 | abstract method error, NullPointerException, etc. 16 | To restart nailgun try `killall -KILL java` or `kill -kill (jps|grep nailgun|cut -f1 -d " " -)`. 17 | Or try `cbt kill` or `cbt direct ` to circumvent nailgun. 18 | It can also help to delete all target folders `find .|grep target\$|xargs rm -rf` 19 | inside of CBT. Or (almost never) the `cache/` directory. 20 | 21 | To edit/debug CBT in IntelliJ, add the whole directory as a new scala project. 22 | Add the source folders manually and exclude the nested target folders. 23 | 24 | CBT's directory structure 25 | 26 | cbt Shell script launching cbt. Can be symlinked. 27 | compatibility/ Java interfaces that all CBT versions are source compatible to. For communication 28 | between composed builds of different versions. 29 | nailgun_launcher/ Self-contained helper that allows using Nailgun with minimal permanent classpath. (Is this actually needed?) 30 | realpath/ Self-contained realpath source code to correctly figure our CBTs home directory. (Open for replacement ideas.) 31 | stage1/ CBT's code that only relies only on Scala/Java built-ins. Contains a Maven resolver to download libs for stage2. 32 | stage2/ CBT's code that requires additional libs, e.g. jgit 33 | test/ Unit tests that can serve as example builds 34 | sonatype.login Sonatype credentials for deployment. Not in git obviously. 35 | 36 | CBT follows an optimistic merging approach. (See http://hintjens.com/blog:106). 37 | We strongly suggest well polished PRs, but don't want to stall improvements 38 | by discussions about minor flaws. As long as the PR does not break anything and 39 | improves the product, we should merge it, polishing remaining things afterwards. 40 | 41 | On OSX `brew install coreutils` to have gdate and get nanosecond timings during bash script. 42 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016 Jan Christopher Vogt 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | NOTICE files 3 | ======================================================================== 4 | 5 | The following NOTICEs pertain to software distributed with this project. 6 | 7 | ENSIME sbt plugin 8 | Copyright 2014 - 2017 Sam Halliday 9 | Copyright 2010 - 2017 https://github.com/ensime/ensime-sbt/graphs 10 | 11 | Some files are copied from external sources and carry additional 12 | license information which must also be distributed along with this 13 | file and the LICENSE file. 14 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | TODO: 2 | - in progress 3 | - improve logging 4 | 5 | - immediate features 6 | - fix main project main method being run during tests 7 | - investigate and solve multiple compilations of the same SourceDependency Build. Maybe introduce global Build map. 8 | 9 | - cleanup 10 | - move from java File to nio Path 11 | 12 | - near future features 13 | - make cbt's own re-build concurrency safe 14 | - unify with sbts key names where sensible 15 | - allow updating snapshots 16 | - cbt cli options inject add dependencies into default build 17 | - dependency exclusion, etc. 18 | - use cli friendly responses by default everywhere 19 | - class path debugging 20 | - broken jars detection 21 | - invalid files in lib folder 22 | - integrate / build out maven search 23 | - use zinc nailgun multi platform nailgun wrapper https://github.com/typesafehub/zinc/tree/7af98ba11d27d7667301c2222c1e702c7092bc44/src/universal/bin 24 | 25 | 26 | - future features 27 | - loop compiling with cancelling running runs/compiles 28 | - shell tab completion 29 | - maybe scripts for bash/zsh/fish 30 | - maybe interactive shell 31 | - maybe one that exists immediately after execution 32 | 33 | - potential features 34 | - running in-project tasks in parallel using Monad 35 | -------------------------------------------------------------------------------- /build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt 2 | import cbt._ 3 | import cbt_internal._ 4 | 5 | class Build(val context: Context) extends Shared with Scalariform with PublishLocal with CommandLineOverrides{ 6 | override def name: String = "cbt" 7 | override def version: String = "0.9-SNAPSHOT" 8 | override def description: String = "Fast, intuitive Build Tool for Scala" 9 | override def inceptionYear: Int = 2015 10 | 11 | // FIXME: somehow consolidate this with cbt's own boot-strapping from source. 12 | override def dependencies = { 13 | super.dependencies ++ Resolver(mavenCentral).bind( 14 | MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"), 15 | ScalaDependency("org.scala-lang.modules","scala-xml",constants.scalaXmlVersion) 16 | ) :+ libraries.cbt.reflect :+ libraries.cbt.eval :+ libraries.cbt.process 17 | } 18 | 19 | override def sources = Seq( 20 | "nailgun_launcher", "stage1", "stage2", "compatibility" 21 | ).map( projectDirectory / _ ).flatMap( _.listOrFail ) 22 | 23 | override def scalariform = super.scalariform.copy( 24 | Seq( 25 | context.cbtHome / "stage2" / "DirectoryDependency.scala", 26 | context.cbtHome / "stage2" / "LazyDependency.scala", 27 | context.cbtHome / "stage2" / "plugins" / "IntelliJ.scala", 28 | context.cbtHome / "stage2" / "plugins" / "ScalaTest.scala", 29 | context.cbtHome / "stage2" / "plugins" / "Scalatex.scala", 30 | context.cbtHome / "stage2" / "plugins" / "Tut.scala", 31 | context.cbtHome / "stage2" / "libraries.scala", 32 | context.cbtHome / "stage2" / "plugins.scala", 33 | context.cbtHome / "stage2" / "ports.scala" 34 | ) 35 | ) 36 | 37 | override def compile = { 38 | scalariform() 39 | super.compile 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = ( 5 | super.dependencies :+ cbtInternal.shared :+ plugins.scalariform 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /compatibility/src/cbt/ArtifactInfo.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | 3 | public interface ArtifactInfo extends Dependency{ 4 | public abstract String artifactId(); 5 | public abstract String groupId(); 6 | public abstract String version(); 7 | } 8 | -------------------------------------------------------------------------------- /compatibility/src/cbt/BuildInterface.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.io.*; 3 | 4 | public interface BuildInterface extends Dependency{ 5 | // needed to propagate through build builds. Maybe we can get rid of this. 6 | public default BuildInterface finalBuild(File current){ 7 | return finalBuild(); // legacy forwarder 8 | } 9 | @Deprecated 10 | public default File[] triggerLoopFilesArray(){ 11 | return new File[0]; 12 | }; 13 | 14 | // deprecated methods, which clients are still allowed to implement, but not required 15 | public default BuildInterface finalBuild(){ 16 | throw new IncompatibleCbtVersionException("You need to override this method."); 17 | }; // needed to propagage through build builds. Maybe we can get rid of this. 18 | public abstract BuildInterface copy(Context context); 19 | public abstract String scalaVersion(); 20 | public abstract String[] crossScalaVersionsArray(); 21 | } 22 | -------------------------------------------------------------------------------- /compatibility/src/cbt/Context.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.io.*; 3 | import java.util.*; 4 | import java.util.concurrent.*; 5 | 6 | // TODO: try to reduce the number of members 7 | public interface Context{ 8 | // recently added methods that needs default values for old versions to work 9 | public default long cbtLastModified(){ 10 | throw new IncompatibleCbtVersionException("You need to override this method."); 11 | }; 12 | public default Map persistentCache(){ 13 | throw new IncompatibleCbtVersionException("You need to override this method."); 14 | }; 15 | public default Map transientCache(){ 16 | throw new IncompatibleCbtVersionException("You need to override this method."); 17 | }; 18 | public default long start(){ 19 | throw new IncompatibleCbtVersionException("You need to override this method."); 20 | }; 21 | public default File workingDirectory(){ 22 | return projectDirectory(); 23 | }; 24 | public default boolean loop(){ 25 | return false; 26 | }; 27 | 28 | // methods that exist for longer which every CBT version in use should have by now, no default values needed 29 | public abstract File cwd(); // REPLACE by something that allows to run cbt on some other directly 30 | public abstract String[] argsArray(); // replace this by https://github.com/cvogt/cbt/issues/172 ? 31 | public abstract String[] enabledLoggersArray(); 32 | public abstract String scalaVersionOrNull(); // needed to propagate scalaVersion to dependendee builds 33 | public abstract File cache(); 34 | public abstract File cbtHome(); 35 | public abstract File cbtRootHome(); // REMOVE 36 | public abstract File compatibilityTarget(); // maybe replace this with search in the classloader for it? 37 | public abstract BuildInterface parentBuildOrNull(); 38 | 39 | // deprecated methods 40 | @java.lang.Deprecated 41 | public abstract Long startCompat(); 42 | @java.lang.Deprecated 43 | public abstract Boolean cbtHasChangedCompat(); 44 | @java.lang.Deprecated 45 | public abstract ConcurrentHashMap permanentKeys(); 46 | @java.lang.Deprecated 47 | public abstract ConcurrentHashMap permanentClassLoaders(); 48 | @java.lang.Deprecated 49 | public abstract File projectDirectory(); 50 | } 51 | -------------------------------------------------------------------------------- /compatibility/src/cbt/Dependency.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.io.*; 3 | 4 | public interface Dependency{ 5 | // recently added methods that needs default values for old versions to work 6 | public default String moduleKey(){ 7 | throw new IncompatibleCbtVersionException("You need to override this method."); 8 | }; 9 | public default long lastModified(){ 10 | throw new IncompatibleCbtVersionException("You need to override this method."); 11 | }; 12 | public default ClassLoader classLoader(){ 13 | throw new IncompatibleCbtVersionException("You need to override this method."); 14 | }; 15 | 16 | // methods that exist for longer which every CBT version in use should have by now, no default values needed 17 | public abstract String show(); 18 | public abstract Dependency[] dependenciesArray(); 19 | public abstract File[] exportedClasspathArray(); 20 | 21 | // deprecated methods 22 | @java.lang.Deprecated 23 | public abstract boolean needsUpdateCompat(); 24 | @java.lang.Deprecated 25 | public abstract File[] dependencyClasspathArray(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /compatibility/src/cbt/IncompatibleCbtVersionException.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | 3 | public class IncompatibleCbtVersionException extends RuntimeException{ 4 | public IncompatibleCbtVersionException( String msg, Throwable parent ){ 5 | super( msg, parent ); 6 | } 7 | public IncompatibleCbtVersionException( String msg ){ 8 | super( msg ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /compatibility/src/cbt/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | package cbt; 3 | import java.io.*; 4 | public interface Result{ 5 | public abstract int exitCode(); 6 | public abstract OutputStream out(); 7 | public abstract OutputStream err(); 8 | public abstract InputStream in(); 9 | public abstract T value(); 10 | } 11 | */ 12 | -------------------------------------------------------------------------------- /coursier/Coursier.scala: -------------------------------------------------------------------------------- 1 | /* 2 | package cbt 3 | object Coursier{ 4 | implicit class CoursierDependencyResolution(d: JavaDependency){ 5 | import d._ 6 | def resolveCoursier = { 7 | import coursier._ 8 | val repositories = Seq( 9 | Cache.ivy2Local, 10 | MavenResolver("https://repo1.maven.org/maven2") 11 | ) 12 | 13 | val start = Resolution( 14 | Set( 15 | JavaDependency( 16 | Module(groupId, artifactId), version 17 | ) 18 | ) 19 | ) 20 | 21 | val fetch = Fetch.from(repositories, Cache.fetch()) 22 | 23 | 24 | val resolution = start.process.run(fetch).run 25 | 26 | val errors: Seq[(JavaDependency, Seq[String])] = resolution.errors 27 | 28 | if(errors.nonEmpty) throw new Exception(errors.toString) 29 | 30 | import java.io.File 31 | import scalaz.\/ 32 | import scalaz.concurrent.Task 33 | 34 | val localArtifacts: Seq[FileError \/ File] = Task.gatherUnordered( 35 | resolution.artifacts.map(Cache.file(_).run) 36 | ).run 37 | 38 | val files = localArtifacts.map(_.toEither match { 39 | case Left(error) => throw new Exception(error.toString) 40 | case Right(file) => file 41 | }) 42 | 43 | resolution.dependencies.map( d => cbt.JavaDependency(d.module.organization,d.module.name, d.version)).toVector 44 | } 45 | } 46 | } 47 | */ -------------------------------------------------------------------------------- /doc/docs.md: -------------------------------------------------------------------------------- 1 | 2 | ### Clearing the screen during task looking 3 | ``` 4 | override def loop{ 5 | lib.clearScreen 6 | super.compile 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /doc/faq.md: -------------------------------------------------------------------------------- 1 | ## How to fix my abstract method errors or other linking errors? 2 | 3 | If the types in the error involve Scala standard library types, 4 | chances are you are mixing dependencies using different Scala versions. 5 | Be aware that `ScalaVersion` is bound to the scalaVersion of the Build 6 | class it is called in. Transferring those objects can easily lead 7 | to version conflicts. We'll try to detect or prevent these in the 8 | future: https://github.com/cvogt/cbt/issues/478 9 | 10 | It's also possible that you've hit a bug in CBT, but linking related 11 | bugs have been rare since early 2017. 12 | -------------------------------------------------------------------------------- /examples/akka-example/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.akka_example 2 | 3 | import akka.http.scaladsl.server._ 4 | import akka.http.scaladsl.model._ 5 | import akka.http.scaladsl.server.Directives._ 6 | import akka.http.scaladsl.settings._ 7 | 8 | object Service extends HttpApp with App { 9 | override protected def route = 10 | path("test") { 11 | get { 12 | complete(HttpResponse()) 13 | } 14 | } 15 | 16 | // CBT isolates it's classloaders. Even when using `direct` mode and a flatClassLoader, 17 | // it will not use the jvm's system classloader stack for the application. 18 | // This means if applications are hard-coded against the system classloader, 19 | // e.g. for loading configuration files from their users or their own jars, 20 | // they will not find them. One way around this is telling CBT to fork the process. 21 | // (via `override def fork = true` in your build) 22 | // This "just" works, but you'll loose all caching speedup benefits. 23 | // Alternatively, applications like akka often allow providing a custom 24 | // classloader instead and then benefit from CBT's classloader caching. Here is how: 25 | val system = akka.actor.ActorSystem( "my-actor-system", classLoader = Some(this.getClass.getClassLoader) ) 26 | startServer("localhost", 8080, ServerSettings(system), system) 27 | } 28 | -------------------------------------------------------------------------------- /examples/akka-example/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples_build.akka_example 2 | 3 | import cbt._ 4 | import java.net.URL 5 | 6 | class Build(val context: Context) extends BaseBuild { 7 | 8 | override def defaultScalaVersion = "2.12.1" 9 | 10 | override def dependencies = 11 | super.dependencies ++ 12 | Resolver(mavenCentral).bind( 13 | ScalaDependency("com.typesafe.akka", "akka-http", "10.0.5") 14 | ) 15 | 16 | } 17 | -------------------------------------------------------------------------------- /examples/build-info-example/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | def main(args: Array[String]): Unit = { 3 | import BuildInfo._ 4 | println("scalaVersion: "+scalaVersion) 5 | println("groupId: "+groupId) 6 | println("artifactId: "+artifactId) 7 | println("version: "+version) 8 | } 9 | } -------------------------------------------------------------------------------- /examples/build-info-example/Readme.md: -------------------------------------------------------------------------------- 1 | This is an example how to propagate build-time information 2 | such as version or scalaVersion to runtime. 3 | The advantage of the approach taken here is simplicity. 4 | -------------------------------------------------------------------------------- /examples/build-info-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | import java.nio.file.Files._ 3 | 4 | class Build(val context: Context) extends PackageJars with GenerateBuildInfo{ 5 | override def name = "build-info-example" 6 | def groupId = "cbt.examples" 7 | override def defaultScalaVersion = "2.11.8" 8 | def version = "0.1" 9 | override def buildInfo = super.buildInfo.copy( 10 | s""" 11 | def artifactId = "$artifactId" 12 | def groupId = "$groupId" 13 | def version = "$version" 14 | def scalaVersion = "$scalaVersion" 15 | """ 16 | ) 17 | } 18 | -------------------------------------------------------------------------------- /examples/build-info-example/src_generated/BuildInfo.scala: -------------------------------------------------------------------------------- 1 | // generated file 2 | object BuildInfo{ 3 | 4 | def artifactId = "build-info-example" 5 | def groupId = "cbt.examples" 6 | def version = "0.1" 7 | def scalaVersion = "2.11.8" 8 | 9 | } 10 | -------------------------------------------------------------------------------- /examples/cross-build-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends MultipleScalaVersions{ 3 | override def scalaVersions = Seq("2.10.5","2.11.7") 4 | } 5 | -------------------------------------------------------------------------------- /examples/cross-build-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main extends App { 2 | println("Hello World") 3 | } 4 | -------------------------------------------------------------------------------- /examples/cross-rewrite-example/Readme.md: -------------------------------------------------------------------------------- 1 | This is an example of how to use scalafix rewrite rules to produce multiple 2 | variants of the same code base for different scala versions, e.g. 2.11.8 and 3 | 2.12.1 and against different comparable libraries, e.g. cats and scalaz. 4 | 5 | To package the jars for all combinations run `cbt cross.package`. 6 | -------------------------------------------------------------------------------- /examples/cross-rewrite-example/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples_build.cross_rewrite 2 | import cbt._ 3 | import java.io.File 4 | import scala.meta._ 5 | import scalafix.util._ 6 | import scalafix.util.TreePatch._ 7 | import scalafix.util.TokenPatch._ 8 | 9 | class Build(val context: Context) extends BaseBuild{ outer => 10 | override def defaultScalaVersion = "2.11.8" 11 | 12 | def versions = Seq[(String, Seq[Patch])]( 13 | scalaVersion -> Seq(), 14 | "2.12.1" -> Seq( 15 | RemoveGlobalImport( 16 | importer"scala.concurrent.Future" 17 | ), 18 | AddGlobalImport( 19 | importer"scala.util.Try" 20 | ) 21 | ) 22 | ) 23 | def libs = Seq[(String, MavenDependency, Seq[Patch])]( 24 | ( 25 | "scalaz", 26 | ScalaDependency( "org.scalaz", "scalaz-core", "7.2.2" ), 27 | Seq( 28 | ) 29 | ), 30 | ( 31 | "cats", 32 | ScalaDependency( "org.typelevel", "cats", "0.9.0" ), 33 | Seq( 34 | ) 35 | ) 36 | ) 37 | 38 | def cross = versions.flatMap{ case ( v, version_rewrites ) => 39 | libs.map{ 40 | case ( label, dep, lib_rewrites ) => 41 | val d = outer.target / "rewrites" / label ++ "-" ++ v 42 | d.mkdirs 43 | new Build(context) with Scalafix with PackageJars{ 44 | override def groupId = "org.cvogt" 45 | override def artifactId = "cbt-examples-cross-rewrite-" + label 46 | override def version = "0.1" 47 | override def defaultScalaVersion = v 48 | override def dependencies = super.dependencies ++ Resolver( mavenCentral ).bind( dep ) 49 | override def projectDirectory = d 50 | override def scaladoc = None 51 | override def sources = { 52 | val fromTo = lib.autoRelative( outer.sources ).collect{ 53 | case (location, relative) if location.isFile 54 | => location -> projectDirectory / "src" / relative 55 | } 56 | 57 | val to = fromTo.map(_._2) 58 | assert( ( to diff to.distinct ).isEmpty ) 59 | 60 | Scalafix.apply(lib).config( 61 | outer.classpath, 62 | files = fromTo, 63 | patches = lib_rewrites ++ version_rewrites, 64 | allowEmpty = true 65 | ).apply 66 | 67 | to 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /examples/cross-rewrite-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalafix 5 | } 6 | -------------------------------------------------------------------------------- /examples/cross-rewrite-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | import scala.concurrent.Future 2 | -------------------------------------------------------------------------------- /examples/dotty-example/README.md: -------------------------------------------------------------------------------- 1 | Dotty example project compiling hello world with the next version of Scala. 2 | 3 | All you need to do to enable Dotty is `extends Dotty` in your build.scala . 4 | -------------------------------------------------------------------------------- /examples/dotty-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends Dotty 3 | -------------------------------------------------------------------------------- /examples/dotty-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | package dotty_example 2 | object Main extends Foo("Hello Dotty - trait parameters, yay"){ 3 | def main(args: Array[String]): Unit = { 4 | println(hello) 5 | 6 | // Sanity check the classpath: this won't run if the dotty jar is not present. 7 | val x: Int => Int = z => z 8 | x(1) 9 | } 10 | } 11 | 12 | trait Foo(val hello: String) 13 | -------------------------------------------------------------------------------- /examples/dynamic-overrides-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends CommandLineOverrides{ 3 | def foo2 = "Build" 4 | def bar2: String = 5 | newBuild[Build]{""" 6 | override def foo2 = "Bar2: "+Option(getClass.getName) 7 | """}.foo2 8 | 9 | def baz2: String = 10 | newBuild[Build]{""" 11 | override def foo2 = "Baz2: "+Option(getClass.getName) 12 | override def baz2 = bar2 13 | """}.baz2 14 | def foo = "Build" 15 | 16 | def bar: String = newBuild[Bar].bar 17 | def baz: String = newBuild[Baz].baz 18 | def bam: String = newBuild[Bam].baz 19 | } 20 | trait Bar extends Build{ 21 | override def bar: String = foo 22 | override def foo = "Bar: "+getClass.getName 23 | } 24 | trait Baz extends Build{ 25 | override def foo = "Baz: "+getClass.getName 26 | override def baz = bar 27 | } 28 | trait Bam extends Bar{ 29 | override def foo = "Baz: "+getClass.getName 30 | override def baz = bar 31 | } 32 | -------------------------------------------------------------------------------- /examples/export-build-information/Main.scala: -------------------------------------------------------------------------------- 1 | package export_build_information 2 | object Main{ 3 | def main( args: Array[String] ): Unit = { 4 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/export-build-information/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild 4 | -------------------------------------------------------------------------------- /examples/export-build-information/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = 5 | super.dependencies ++ 6 | Resolver(mavenCentral, sonatypeReleases).bind( 7 | ScalaDependency( "org.scala-lang.modules", "scala-xml", "1.0.6" ) 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /examples/fork-example/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.fork_example 2 | 3 | import akka.http.scaladsl.server._ 4 | import akka.http.scaladsl.model._ 5 | import akka.http.scaladsl.server.Directives._ 6 | import akka.http.scaladsl.settings._ 7 | 8 | object Service extends HttpApp with App { 9 | // should all appear in separate lines 10 | System.out.println("HelloHello") 11 | System.err.println("HelloHello") 12 | System.out.println("HelloHello") 13 | System.err.println("HelloHello") 14 | System.out.println("HelloHello") 15 | System.err.println("HelloHello") 16 | System.out.println("HelloHello") 17 | System.err.println("HelloHello") 18 | System.out.println("HelloHello") 19 | System.err.println("HelloHello") 20 | 21 | override protected def route = 22 | path("test") { 23 | get { 24 | complete(HttpResponse()) 25 | } 26 | } 27 | 28 | startServer("localhost", 8080) 29 | } 30 | -------------------------------------------------------------------------------- /examples/fork-example/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples_build.akka_example 2 | 3 | import cbt._ 4 | import java.net.URL 5 | 6 | class Build(val context: Context) extends BaseBuild { 7 | override def defaultScalaVersion = "2.12.1" 8 | 9 | override def fork = true 10 | 11 | override def dependencies = 12 | super.dependencies ++ 13 | Resolver(mavenCentral).bind( 14 | ScalaDependency("com.typesafe.akka", "akka-http", "10.0.5") 15 | ) 16 | 17 | } 18 | -------------------------------------------------------------------------------- /examples/frege-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Frege { 4 | override def classifier = Some("jdk7") 5 | override def inline = false 6 | override def fregeSource = "1.7" 7 | override def fregeTarget = "1.7" 8 | } 9 | -------------------------------------------------------------------------------- /examples/frege-example/src/Main.fr: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | main = putStrLn "Hello World." 4 | -------------------------------------------------------------------------------- /examples/intellij/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/intellij/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild with IntelliJ { 4 | override def name = "idea-plugin-example" 5 | } 6 | -------------------------------------------------------------------------------- /examples/intellij/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main extends App { 2 | println("This is an example Application for illustrating CBT IntelliJ project generator") 3 | } 4 | -------------------------------------------------------------------------------- /examples/kindprojector-example/Main.scala: -------------------------------------------------------------------------------- 1 | package kindprojector_example 2 | 3 | object Main { 4 | 5 | def parametric[F[_]]: Unit = () 6 | 7 | def main(args: Array[String]): Unit = { 8 | parametric[Either[String, ?]] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/kindprojector-example/build/build.scala: -------------------------------------------------------------------------------- 1 | package kindprojector_example_build 2 | 3 | import cbt._ 4 | 5 | class Build(val context: Context) extends BaseBuild with KindProjectorPlugin { 6 | 7 | override def scalacOptions: Seq[String] = 8 | super.scalacOptions ++ 9 | Seq("-language:higherKinds") 10 | 11 | } 12 | -------------------------------------------------------------------------------- /examples/multi-combined-example/Readme.md: -------------------------------------------------------------------------------- 1 | This is an example how to do a multi-project build with a single build file. 2 | -------------------------------------------------------------------------------- /examples/multi-combined-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt_examples.multi_combined_example.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild{ 4 | //println(DirectoryDependency( projectDirectory / ".." / "sub4" / "build" ).exportedClasspath) 5 | override def dependencies: Seq[cbt.Dependency] = 6 | super.dependencies :+ DirectoryDependency( projectDirectory / ".." / "sub4" / "build" ) 7 | def foo = DirectoryDependency( projectDirectory / ".." / "sub4" / "build" ) 8 | } 9 | -------------------------------------------------------------------------------- /examples/multi-combined-example/shared/SomeSharedClass.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined 2 | class SomeSharedClass{ 3 | def main(args: Array[String]): Unit = { 4 | println(this.getClass.getSimpleName) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub1/SomeConcreteClass.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined 2 | object SomeConcreteClass extends SomeSharedClass 3 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub2/SomeOtherConcreteClass.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined 2 | object SomeOtherConcreteClass extends SomeSharedClass{ 3 | new cbt_examples.multi_combined_example.sub6.Sub6Example 4 | } 5 | 6 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub3/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined_example.sub3 2 | object Main{ 3 | def main( args: Array[String] ): Unit = { 4 | println( Console.GREEN ++ "Hello " ++ Console.RESET + new cbt_examples.multi_combined_example.sub4.sub41.sub42.Sub4Example ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub4/Class4.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined_example.sub4 2 | class Sub4Example 3 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub4/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt_examples.multi_combined_example.sub4 2 | import cbt._ 3 | class Build(val context: Context) extends BaseBuild{ 4 | def sub41 = new Sub41(context) 5 | } 6 | class Sub41(val context: Context) extends BaseBuild{ 7 | override def projectDirectory = context.workingDirectory / "sub41" 8 | def sub42 = new Sub42(context.copy(workingDirectory=projectDirectory)) 9 | } 10 | class Sub42(val context: Context) extends BaseBuild{ 11 | override def projectDirectory = context.workingDirectory / "sub42" 12 | def hello = "Hello from Sub42" 13 | } 14 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub4/sub41/sub42/Sub4Example.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined_example.sub4.sub41.sub42 2 | class Sub4Example 3 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub5/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined_example.sub5 2 | object Main{ 3 | def main( args: Array[String] ): Unit = { 4 | println( Console.GREEN ++ "Hello " ++ Console.RESET ++ new cbt.examples.multi_combined_example.sub4.sub41.sub42.Sub4Example ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/multi-combined-example/sub6/Sub6Example.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.multi_combined_example.sub6 2 | class Sub6Example 3 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/Readme.md: -------------------------------------------------------------------------------- 1 | This is an example how to build a multi-project build using CBT while keeping each project self-contained with it's own build files. 2 | 3 | Check the multi-combined-example for how to do it with a single build file for all builds together instead. 4 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends SharedCbtBuild{ 3 | override def dependencies = 4 | super.dependencies ++ // don't forget super.dependencies here 5 | Seq( 6 | // source dependency 7 | DirectoryDependency( projectDirectory ++ "/sub1" ), 8 | DirectoryDependency( projectDirectory ++ "/sub2" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile ++ "/shared-build" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/common/SomeSharedClass.scala: -------------------------------------------------------------------------------- 1 | class SomeSharedClass -------------------------------------------------------------------------------- /examples/multi-standalone-example/common/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends SharedCbtBuild 4 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/common/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile.getParentFile ++ "/shared-build" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/shared-build/SharedCbtBuild.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | trait SharedCbtBuild extends BaseBuild{ 3 | override def defaultScalaVersion = "2.10.6" 4 | } -------------------------------------------------------------------------------- /examples/multi-standalone-example/shared-build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def dependencies = 4 | super.dependencies :+ // don't forget super.dependencies here 5 | context.cbtDependency 6 | } 7 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub1/SomeConcreteClass.scala: -------------------------------------------------------------------------------- 1 | class SomeConcreteClass extends SomeSharedClass 2 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub1/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends SharedCbtBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile ++ "/common" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub1/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile.getParentFile ++ "/shared-build" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub2/SomeOtherConcreteClass.scala: -------------------------------------------------------------------------------- 1 | class SomeOtherConcreteClass extends SomeSharedClass 2 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub2/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends SharedCbtBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile ++ "/common" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/multi-standalone-example/sub2/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild{ 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory.getParentFile.getParentFile ++ "/shared-build" ) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /examples/new-style-macros-example/Hello.scala: -------------------------------------------------------------------------------- 1 | package macroparadise_example 2 | import macros._ 3 | 4 | @Main object Hello{ 5 | println("hello, world!") 6 | } 7 | -------------------------------------------------------------------------------- /examples/new-style-macros-example/build/build.scala: -------------------------------------------------------------------------------- 1 | package macroparadise_example_build 2 | import cbt._ 3 | 4 | trait SharedSettings extends NewStyleMacros{ 5 | override def defaultScalaVersion = "2.12.2" 6 | } 7 | 8 | class Build(val context: Context) extends SharedSettings{ 9 | override def dependencies = 10 | super.dependencies :+ 11 | new MacroBuild( context.copy( workingDirectory = projectDirectory / "macros" ) ) 12 | } 13 | 14 | class MacroBuild(val context: Context) extends SharedSettings{ 15 | override def dependencies = 16 | super.dependencies :+ 17 | Resolver( mavenCentral ).bindOne( ScalaDependency( "org.scalameta", "scalameta", "1.8.0" ) ) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /examples/new-style-macros-example/macros/Main.scala: -------------------------------------------------------------------------------- 1 | package macroparadise_example.macros 2 | 3 | import scala.meta._ 4 | import scala.collection.immutable.Seq 5 | 6 | class Main extends scala.annotation.StaticAnnotation { 7 | inline def apply(defn: Any): Any = meta { 8 | defn match { 9 | case q"object $name { ..$stats }" => 10 | MainMacroImpl.expand(name, stats) 11 | case _ => 12 | abort("@main must annotate an object.") 13 | } 14 | } 15 | } 16 | 17 | // This is an example how we can refactor the macro implementation into a utility 18 | // function which can be used for unit testing, see MainUnitTest. 19 | object MainMacroImpl { 20 | def expand(name: Term.Name, stats: Seq[Stat]): Defn.Object = { 21 | val main = q"def main(args: Array[String]): Unit = { ..$stats }" 22 | q"object $name { $main }" 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/proguard-example/Main.scala: -------------------------------------------------------------------------------- 1 | package proguard_example 2 | object Main{ 3 | def main( args: Array[String] ): Unit = { 4 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/proguard-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends ProGuard{ 4 | def proguard = ProGuard( (Nil, """ 5 | public class proguard_example.Main{ 6 | public void main(java.lang.String[]); 7 | } 8 | """ ) ) 9 | } 10 | -------------------------------------------------------------------------------- /examples/proguard-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.proguard 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources-example/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt.example.resources 2 | import scala.collection.JavaConverters._ 3 | import java.nio.file.{Files, Paths} 4 | object Main{ 5 | def getResource = Option(getClass.getClassLoader.getResource("foo.text")) 6 | def getResources = getClass.getClassLoader.getResources("foo.text").asScala.toList 7 | 8 | def main( args: Array[String] ): Unit = { 9 | println("Reading parent's resources") 10 | println("") 11 | // resources are in the parent 12 | println("via child: " + getResource.nonEmpty + " " + getResources.size ) 13 | println("") 14 | // this one is where the resources are 15 | println("via parent: " + parent.getResource.nonEmpty + " " + parent.getResources.size ) 16 | println("") 17 | // parent is parent.parent's child. reading children's resources only works 18 | // with a flat classloader in cbt. Try `override def flatClassLoader = true`. 19 | // or `cbt runFlat` when extending `DynamicOverrides` 20 | println("via parent.parent: " + parent.parent.getResource.nonEmpty + " " + parent.parent.getResources.size ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/resources-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends DynamicOverrides{ 3 | override def dependencies = 4 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 5 | Seq( 6 | DirectoryDependency( projectDirectory ++ "/parent" ) 7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /examples/resources-example/parent/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def dependencies = 4 | super.dependencies ++ // don't forget super.dependencies here 5 | Seq( 6 | DirectoryDependency( projectDirectory ++ "/parent" ) 7 | ) 8 | 9 | override def resourceClasspath = super.resourceClasspath ++ ClassPath( 10 | Seq(projectDirectory ++ "/my-resources") 11 | ) 12 | } 13 | -------------------------------------------------------------------------------- /examples/resources-example/parent/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BuildBuild{ 3 | /* 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory ++ "/subProject" ) 9 | ) ++ 10 | Resolver( mavenCentral ).bind( 11 | // CBT-style Scala dependencies 12 | ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) 13 | MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) 14 | 15 | // SBT-style dependencies 16 | "com.lihaoyi" %% "ammonite-ops" % "0.5.5" 17 | "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" 18 | ) 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /examples/resources-example/parent/my-resources/foo.text: -------------------------------------------------------------------------------- 1 | Hello from a resource in my-resources/ (the additional location manually added here in build.scala) 2 | -------------------------------------------------------------------------------- /examples/resources-example/parent/package.scala: -------------------------------------------------------------------------------- 1 | package cbt.example.resources.parent 2 | import scala.collection.JavaConverters._ 3 | object `package`{ 4 | def getResource = Option(getClass.getClassLoader.getResource("foo.text")) 5 | def getResources = getClass.getClassLoader.getResources("foo.text").asScala.toList 6 | } 7 | -------------------------------------------------------------------------------- /examples/resources-example/parent/parent/package.scala: -------------------------------------------------------------------------------- 1 | package cbt.example.resources.parent.parent 2 | import scala.collection.JavaConverters._ 3 | object `package`{ 4 | def getResource = Option(getClass.getClassLoader.getResource("foo.text")) 5 | def getResources = getClass.getClassLoader.getResources("foo.text").asScala.toList 6 | } 7 | -------------------------------------------------------------------------------- /examples/resources-example/parent/resources/foo.text: -------------------------------------------------------------------------------- 1 | Hello from a resource in resources/ (the default location) 2 | -------------------------------------------------------------------------------- /examples/restart/Readme.md: -------------------------------------------------------------------------------- 1 | This example's main method simply prints the current process id. 2 | This can be used to experiment with cbt's restart feature 3 | (the equivalent to sbt-revolver). 4 | 5 | ``` 6 | cbt direct loop restart 7 | ``` 8 | 9 | starts the main method in a separate process and kills it, when 10 | a change in project, build file or cbt is detected. 11 | -------------------------------------------------------------------------------- /examples/restart/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def dependencies = super.dependencies :+ libraries.cbt.process 4 | } -------------------------------------------------------------------------------- /examples/restart/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main extends App { 2 | while(true){ 3 | Thread.sleep(1000) 4 | println( "process " + cbt.process.currentProcessId + " is still running" ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/scala-xray/build/build.scala: -------------------------------------------------------------------------------- 1 | package tut_build 2 | import cbt._ 3 | class Build(val context: Context) extends ScalaXRay 4 | -------------------------------------------------------------------------------- /examples/scala-xray/src/Main.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.sxr 2 | object Main{ 3 | def main( args: Array[String] ): Unit = { 4 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/scalafix-compiler-plugin-example/.scalafix.conf: -------------------------------------------------------------------------------- 1 | rewrites = [ 2 | ProcedureSyntax 3 | ExplicitImplicit 4 | VolatileLazyVal 5 | ] 6 | 7 | patches.addGlobalImports = [ 8 | "scala.collection.immutable" 9 | ] 10 | -------------------------------------------------------------------------------- /examples/scalafix-compiler-plugin-example/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | lazy val x = 1 + 1 3 | 4 | implicit def toString(i :Int) = i.toString 5 | 6 | def main( args: Array[String] ){ 7 | println("Hello world!") 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/scalafix-compiler-plugin-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild with ScalafixCompilerPlugin 4 | -------------------------------------------------------------------------------- /examples/scalafix-compiler-plugin-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalafixCompilerPlugin 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalafix-example/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | lazy val x = 1 + 1 3 | 4 | implicit def toString(i :Int) = i.toString 5 | 6 | def main( args: Array[String] ){ 7 | println("Hello world!") 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/scalafix-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | import scala.meta._ 4 | import scalafix.rewrite._ 5 | import scalafix.util._ 6 | import scalafix.util.TreePatch._ 7 | import scalafix.util.TokenPatch._ 8 | 9 | class Build(val context: Context) extends BaseBuild{ 10 | override def compile = { 11 | new BasicBuild(context) with Scalafix{ 12 | override def scalafix = super.scalafix.copy( 13 | patches = 14 | Seq( 15 | AddGlobalImport( 16 | importer"scala.collection.immutable" 17 | ) 18 | ), 19 | rewrites = Seq( 20 | ProcedureSyntax, 21 | ExplicitImplicit, 22 | VolatileLazyVal 23 | ) 24 | ) 25 | }.scalafix.apply 26 | super.compile // <- as scalafix trigger compile already before re-writing, this will just return the cached compile result before rewriting 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/scalafix-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalafix 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalafmt-example/.scalafmt.conf: -------------------------------------------------------------------------------- 1 | style: defaultWithAlign 2 | danglingParentheses: true 3 | 4 | spaces { 5 | inImportCurlyBraces: true 6 | } 7 | 8 | rewriteTokens { 9 | "->": "→" 10 | "=>": "⇒" 11 | } 12 | -------------------------------------------------------------------------------- /examples/scalafmt-example/README.md: -------------------------------------------------------------------------------- 1 | This example shows integration with scalafmt plugin. 2 | 3 | Reformat executed on every `cbt compile` call, and affects only *.scala source files. 4 | 5 | You can provide your custom scalfmt preferences in build via `scalafmtConfig`. 6 | 7 | To see formatting in action: execute `cbt breakFormatting` to break formatting and then execute`cbt scalafmt` to get formatting back. 8 | 9 | To check if your code is properly formatted(for example as part of CI validation), you can execute: 10 | 11 | ``` 12 | cbt scalafmt 13 | git diff --exit-code 14 | ``` 15 | 16 | Last command will return non-zero code, if your code isn't properly formatted. 17 | -------------------------------------------------------------------------------- /examples/scalafmt-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild with Scalafmt { 4 | override def compile = { 5 | scalafmt 6 | super.compile 7 | } 8 | 9 | def breakFormatting = { 10 | import java.nio.file._ 11 | import java.nio.charset.Charset 12 | import scala.collection.JavaConverters._ 13 | val utf8 = Charset.forName("UTF-8") 14 | sourceFiles foreach { file => 15 | val path = file.toPath 16 | val fileLines = Files.readAllLines(path, utf8).asScala 17 | val brokenLines = fileLines map (l => 18 | l.dropWhile(_ == ' ') 19 | .replaceAll("⇒", "=>") 20 | .replaceAll("→", "->") 21 | ) 22 | Files.write(path, brokenLines.asJava, utf8) 23 | } 24 | System.err.println("Done breaking formatting") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/scalafmt-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalafmt 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalafmt-example/resources/reference.conf: -------------------------------------------------------------------------------- 1 | // should not reformat this, cause it is not in source files 2 | some { 3 | inside { 4 | foo: 22 5 | bar: false 6 | baz: "hello" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/scalafmt-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | import scala.concurrent.{ Await, Future } 2 | import scala.concurrent.duration._ 3 | 4 | object Main extends App { 5 | println("fooo") 6 | val futureRes = Await.result(Future.successful(1), 5.seconds) 7 | List(1, 2, 4, 5, 6) match { 8 | case h :: _ ⇒ println("not empty list") 9 | case Nil ⇒ println("empty list") 10 | } 11 | 12 | List(1 → 2, 2 → 3, 3 → 4) match { 13 | case (1, 2) :: _ ⇒ 90 → 1 14 | case (22, 44) :: _ ⇒ 1 → 150 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/README.md: -------------------------------------------------------------------------------- 1 | 2 | Compilation instructions 3 | ------------------------------------------- 4 | 1. `cd js` 5 | 2. `cbt compile` or `cbt fullOpt.compile` 6 | 7 | Execution instructions 8 | ------------------------------------------- 9 | 1. open `server/public/index.html` in a browser 10 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/js/App.scala: -------------------------------------------------------------------------------- 1 | package prototype 2 | 3 | import org.scalajs.dom 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.JSON 7 | import scala.scalajs.js.JSApp 8 | import scala.scalajs.js.annotation.JSExport 9 | 10 | @JSExport("App") 11 | object App extends JSApp { 12 | def main(): Unit = { 13 | val trace1 = """{ 14 | | "x": [1, 2, 3, 4], 15 | | "y": [10, 15, 13, 17], 16 | | "type": "scatter" 17 | |} """.stripMargin 18 | val trace2 = """{ 19 | | "x": [1, 2, 3, 4], 20 | | "y": [16, 5, 11, 9], 21 | | "type": "scatter" 22 | |} """.stripMargin 23 | val data = js.Array(trace1, trace2).map(trace => JSON.parse(trace)) 24 | val doc = dom.document 25 | Plotly.newPlot("plotly", data) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/js/Plotly.scala: -------------------------------------------------------------------------------- 1 | package prototype 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | object Plotly extends js.Object { 7 | def newPlot(id: String, data: js.Array[js.Dynamic]): js.Any = js.native 8 | } 9 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/js/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends ScalaJsBuild{ 3 | override def name = "my-project" 4 | 5 | override def sources = super.sources ++ Seq( 6 | projectDirectory.getParentFile ++ "/shared" 7 | ) 8 | 9 | override def dependencies = ( 10 | super.dependencies ++ 11 | Resolver( mavenCentral ).bind( 12 | "org.scala-js" %%% "scalajs-dom" % "0.9.0" 13 | ) 14 | ) 15 | 16 | override def scalaJsTargetFile = 17 | projectDirectory.getParentFile ++ ("/server/public/generated/" ++ name ++ ".js") 18 | } 19 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/js/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BuildBuild{ 3 | override def dependencies = super.dependencies :+ plugins.scalaJs 4 | } 5 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/jvm/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def sources = super.sources ++ Seq( 4 | projectDirectory.getParentFile ++ "/shared" 5 | ) 6 | } 7 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/server/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Prototype 5 | 6 | 7 | 8 | 9 | execute
cbt fastOptJs
in
js/
to generate/update the .js file 10 |
11 | 12 | 13 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/scalajs-plain-example/shared/SomeSharedClass.scala: -------------------------------------------------------------------------------- 1 | package prototype 2 | case class SomeSharedClass(i: Int) 3 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/README.md: -------------------------------------------------------------------------------- 1 | 2 | Compilation instructions 3 | ------------------------------------------- 4 | 1. `cd js` 5 | 2. `cbt compile` or `cbt fullOpt.compile` 6 | 7 | Execution instructions 8 | ------------------------------------------- 9 | 1. `cd ../server` 10 | 2. `npm install` 11 | 3. `node app.js` 12 | 4. Go to http://localhost:3000 in a browser 13 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/js/App.scala: -------------------------------------------------------------------------------- 1 | package prototype 2 | 3 | import japgolly.scalajs.react.ReactDOM 4 | import org.scalajs.dom 5 | 6 | import scala.scalajs.js.JSApp 7 | import scala.scalajs.js.annotation.JSExport 8 | 9 | @JSExport("App") 10 | object App extends JSApp { 11 | def main(): Unit = { 12 | val doc = dom.document 13 | ReactDOM.render(Pictures.PictureComponent(), doc.getElementById("main")) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/js/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends ScalaJsBuild{ 3 | override def name = "my-project" 4 | 5 | override def sources = super.sources ++ Seq( 6 | projectDirectory.getParentFile ++ "/shared" 7 | ) 8 | 9 | override def dependencies = ( 10 | super.dependencies ++ 11 | Resolver( mavenCentral ).bind( 12 | //"org.scalatest" %%% "scalatest" % "3.0.0-RC2", 13 | "com.github.japgolly.scalajs-react" %%% "core" % "0.10.4", // for example 14 | // for example if you want explicitely state scala version 15 | "org.scala-js" % "scalajs-dom_sjs0.6_2.11" % "0.9.0" 16 | ) 17 | ) 18 | 19 | override def scalaJsTargetFile = 20 | projectDirectory.getParentFile ++ ("/server/public/generated/" ++ name ++ ".js") 21 | } 22 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/js/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BuildBuild{ 3 | override def dependencies = super.dependencies :+ plugins.scalaJs 4 | } 5 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/jvm/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def sources = super.sources ++ Seq( 4 | projectDirectory.getParentFile ++ "/shared" 5 | ) 6 | } 7 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/server/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var https = require('https'); 3 | 4 | var app = express(); 5 | 6 | app.get('/data', function(req, res){ 7 | 8 | var request = https.get( 9 | //'https://api.instagram.com/v1/media/popular?client_id=642176ece1e7445e99244cec26f4de1f&callback=?', 10 | 'https://pixabay.com/api/?key=2741116-9706ac6d4a58f2b5416225505&q=yellow+flowers&image_type=photo', 11 | function(response) { 12 | var body = ""; 13 | response.on('data', function(data) { 14 | body += data; 15 | }); 16 | response.on('end', function() { 17 | console.log(body); 18 | try { 19 | res.send(JSON.parse(body)); 20 | } catch (e) { 21 | return console.error(e); 22 | } 23 | }); 24 | } 25 | ); 26 | request.on('error', function(e) { 27 | console.log('Problem with request: ' + e.message); 28 | }); 29 | request.end(); 30 | }); 31 | 32 | app.use(express.static(__dirname + '/public')); 33 | 34 | var server = app.listen(3000, function () { 35 | var host = server.address().address; 36 | var port = server.address().port; 37 | 38 | console.log('Example app listening at http://%s:%s', host, port); 39 | }); 40 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "prototype", 5 | "main": "app.js", 6 | "author": "Katrin", 7 | "license": "UNLICENSED", 8 | "private": true, 9 | "dependencies": { 10 | "express": "^4.13.3", 11 | "express-ws": "^0.2.6", 12 | "body-parser": "^1.14.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/server/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Prototype 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/scalajs-react-example/shared/Picture.scala: -------------------------------------------------------------------------------- 1 | package prototype 2 | 3 | case class Picture(id: String, url: String, src: String, title: String, favorite: Boolean = false) 4 | -------------------------------------------------------------------------------- /examples/scalapb-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild with Scalapb { 4 | override def compile = taskCache[Build]("compile").memoize{ 5 | scalapb.apply 6 | super.compile 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/scalapb-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalapb 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalapb-example/protobuf-schemas/address.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package foo; 4 | message Address { 5 | optional string street = 1; 6 | } 7 | -------------------------------------------------------------------------------- /examples/scalapb-example/protobuf-schemas/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "address.proto"; 4 | 5 | package foo; 6 | message Person { 7 | optional string name = 1; 8 | optional int32 age = 2; 9 | 10 | // Address is a message defined somewhere else. 11 | repeated Address addresses = 3; 12 | } 13 | -------------------------------------------------------------------------------- /examples/scalapb-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | import foo._ 2 | object Main extends App { 3 | println( 4 | person.Person( 5 | Some("name"), 6 | Some(123), 7 | Seq( 8 | address.Address( 9 | Some("High Street") 10 | ) 11 | ) 12 | ) 13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /examples/scalariform-example/README.md: -------------------------------------------------------------------------------- 1 | This example shows integration with scalariform plugin. 2 | 3 | Reformat executed on every `cbt compile` call, and affects only *.scala source files. 4 | 5 | You can provide your custom scalariform preferences in build via `scalariformPreferences`. 6 | 7 | To see formatting in action: execute `cbt breakFormatting` to break formatting and then execute `cbt scalariformFormat` to get formatting back. 8 | 9 | To check if your code is properly formatted(for example as part of CI validation), you can execute: 10 | 11 | ``` 12 | cbt scalariformFormat 13 | git diff --exit-code 14 | ``` 15 | 16 | Last command will return non-zero code, if your code isn't properly formatted. 17 | -------------------------------------------------------------------------------- /examples/scalariform-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | import scalariform.formatter.preferences._ 3 | 4 | class Build(val context: Context) extends BaseBuild with Scalariform { 5 | override def compile = { 6 | scalariform() 7 | super.compile 8 | } 9 | 10 | override def scalariform = super.scalariform.copy( 11 | preferences = FormattingPreferences() 12 | .setPreference(SpacesAroundMultiImports, true) 13 | .setPreference(DoubleIndentClassDeclaration, true) 14 | .setPreference(RewriteArrowSymbols, true) 15 | ) 16 | 17 | final def breakFormatting = { 18 | import java.nio.file._ 19 | import java.nio.charset.Charset 20 | import scala.collection.JavaConverters._ 21 | val utf8 = Charset.forName("UTF-8") 22 | sourceFiles foreach { file => 23 | val path = file.toPath 24 | val fileLines = Files.readAllLines(path, utf8).asScala 25 | val brokenLines = fileLines map (_.dropWhile(_ == ' ')) 26 | Files.write(path, brokenLines.asJava, utf8) 27 | } 28 | System.err.println("Done breaking formatting") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/scalariform-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalariform 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalariform-example/resources/reference.conf: -------------------------------------------------------------------------------- 1 | // should not reformat this, cause it is not in source files 2 | some { 3 | inside { 4 | foo: 22 5 | bar: false 6 | baz: "hello" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/scalariform-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | import scala.concurrent.{ Await, Future } 2 | import scala.concurrent.duration._ 3 | 4 | object Main extends App { 5 | println("fooo") 6 | val futureRes = Await.result(Future.successful(1), 5.seconds) 7 | List(1, 2, 4, 5, 6) match { 8 | case h :: _ ⇒ println("not empty list") 9 | case Nil ⇒ println("empty list") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/scalastyle/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild with Scalastyle{ 4 | override def scalastyle = super.scalastyle.copy( 5 | Scalastyle.readConfigFromXml( projectDirectory / "scalastyle-config.xml" ) 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /examples/scalastyle/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.scalastyle 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalastyle/scalastyle-config.xml: -------------------------------------------------------------------------------- 1 | 2 | CBT Scalastyle example configuration 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/scalastyle/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main { 2 | def main(args: Array[String]): Unit = { 3 | // <- tab here 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/scalatest-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends SbtLayoutMain { 3 | outer => 4 | /* FIXME: calling `cbt rt` for `examples/scalatest-example` leads to 5 | java.lang.Exception: This should never happend. Could not find (org.scala-lang,scala-reflect) in 6 | (org.scala-lang,scala-library) -> BoundMavenDependency(1488121318000,cbt/cache/maven,MavenDependency(org.scala-lang,scala-library,2.11.8,Classifier(None)),Vector(https://repo1.maven.org/maven2)) 7 | at cbt.Stage1Lib$$anonfun$actual$1.apply(Stage1Lib.scala:425) 8 | */ 9 | override def test: Dependency = { 10 | new BasicBuild(context) with ScalaTest with SbtLayoutTest{ 11 | override def dependencies = outer +: super.dependencies 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/scalatest-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild{ 4 | override def dependencies = super.dependencies ++ Seq( 5 | plugins.sbtLayout 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /examples/scalatest-example/src/main/scala/Hello.scala: -------------------------------------------------------------------------------- 1 | object Main extends App{ 2 | 3 | println("Hello World") 4 | 5 | def square(x: Int) = x * x 6 | 7 | } 8 | -------------------------------------------------------------------------------- /examples/scalatest-example/src/test/scala/Test.scala: -------------------------------------------------------------------------------- 1 | import collection.mutable.Stack 2 | import org.scalatest._ 3 | 4 | class Test extends FlatSpec with Matchers { 5 | "square" should "return double" in { 6 | Main.square(2) should be (4) 7 | } 8 | 9 | "A Stack" should "pop values in last-in-first-out order" in { 10 | val stack = new Stack[Int] 11 | stack.push(1) 12 | stack.push(2) 13 | stack.pop() should be (2) 14 | stack.pop() should be (1) 15 | } 16 | 17 | it should "throw NoSuchElementException if an empty stack is popped" in { 18 | val emptyStack = new Stack[Int] 19 | a [NoSuchElementException] should be thrownBy { 20 | emptyStack.pop() 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /examples/scalatex-example/Foo.scala: -------------------------------------------------------------------------------- 1 | package cbt_example.scalatex 2 | object Foo{ 3 | def foo(i: Int, j: Int) = i * j + i * j 4 | } 5 | -------------------------------------------------------------------------------- /examples/scalatex-example/docs/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_examples.scalatex_example_build 2 | import cbt._ 3 | import java.io._ 4 | import java.nio.file._ 5 | import java.nio.file.attribute._ 6 | class Build(val context: Context) extends Scalatex{ 7 | override def dependencies = super.dependencies ++ Seq( 8 | DirectoryDependency( projectDirectory / ".." ) 9 | ) 10 | override def run = { 11 | scalatex.apply 12 | super.run 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/scalatex-example/docs/readme.scalatex: -------------------------------------------------------------------------------- 1 | @import scalatags.Text.all._ 2 | @h1("cbt.http.client") 3 | @p 4 | @ul 5 | @li 6 | http client library 7 | @li 8 | super simple and easy to use 9 | @li 10 | type-safe and resource-leak-safe 11 | @li 12 | no dependencies besides JDK 13 | @li 14 | complete (offers everything @pre(`class`:="inline"){java.net.URLConnection} does) 15 | @repl 16 | cbt_example.scalatex.Foo.foo(1,2) 17 | 18 | @comment{ 19 | @h3 20 | Usage example 21 | } -------------------------------------------------------------------------------- /examples/scalatex-example/docs/static/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Muli'); 2 | body{ 3 | font-family: 'Muli', sans-serif; 4 | width: 600px; 5 | left: 50%; 6 | margin-left: -300px; 7 | position: absolute; 8 | } 9 | 10 | h1, h2, h3, h4, h5, h6{ 11 | color: #007bbf; 12 | } 13 | 14 | .path-readme li{ 15 | font-size: 30px; 16 | } 17 | 18 | pre{ 19 | display: block; 20 | border-top: 0px; 21 | border-bottom: 0px; 22 | border-left: 0; 23 | border-right: 0; 24 | border-color: #007bbf; 25 | border-style: solid; 26 | padding: 5px 0; 27 | } 28 | 29 | pre.inline{ 30 | display: inline; 31 | border: 0; 32 | } 33 | -------------------------------------------------------------------------------- /examples/simple-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | /* 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory ++ "/subProject" ) 9 | ) ++ 10 | Resolver( mavenCentral ).bind( 11 | // CBT-style Scala dependencies 12 | ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) 13 | MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) 14 | 15 | // SBT-style dependencies 16 | "com.lihaoyi" %% "ammonite-ops" % "0.5.5" 17 | "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" 18 | ) 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /examples/simple-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BuildBuild{ 3 | /* 4 | override def dependencies = 5 | super.dependencies ++ // don't forget super.dependencies here 6 | Seq( 7 | // source dependency 8 | DirectoryDependency( projectDirectory ++ "/subProject" ) 9 | ) ++ 10 | Resolver( mavenCentral ).bind( 11 | // CBT-style Scala dependencies 12 | ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) 13 | MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) 14 | 15 | // SBT-style dependencies 16 | "com.lihaoyi" %% "ammonite-ops" % "0.5.5" 17 | "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" 18 | ) 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /examples/simple-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main extends App { 2 | println("Hello World") 3 | } 4 | -------------------------------------------------------------------------------- /examples/sonatype-release-example/README.md: -------------------------------------------------------------------------------- 1 | TBD 2 | -------------------------------------------------------------------------------- /examples/sonatype-release-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import java.net.URL 2 | 3 | import cbt._ 4 | 5 | class Build(val context: Context) extends SonatypeRelease { 6 | def groupId: String = "com.github.rockjam" 7 | def version: String = "0.0.15" 8 | override def name: String = "cbt-sonatype-release-example" 9 | 10 | def description: String = "Plugin for CBT to release artifacts to sonatype OSS" 11 | def developers: Seq[Developer] = Seq( 12 | Developer( 13 | "rockjam", 14 | "Nikolay Tatarinov", 15 | "GMT+3", 16 | new URL("https://github.com/rockjam") 17 | ) 18 | ) 19 | def inceptionYear: Int = 2016 20 | def licenses: Seq[cbt.License] = Seq(License.Apache2) 21 | def organization: Option[cbt.Organization] = None 22 | def scmConnection: String = "" 23 | def scmUrl: String = "https://github.com/rockjam/cbt-sonatype.git" 24 | def url: java.net.URL = new URL("https://github.com/rockjam/cbt-sonatype") 25 | 26 | override def dependencies = 27 | super.dependencies ++ 28 | Resolver( mavenCentral ).bind( 29 | ScalaDependency("com.chuusai", "shapeless", "2.3.2") 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /examples/sonatype-release-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.sonatypeRelease 5 | } 6 | -------------------------------------------------------------------------------- /examples/sonatype-release-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main extends App { 2 | println("This is serious app that does nothing, but has shapeless dependency") 3 | } 4 | -------------------------------------------------------------------------------- /examples/tut/Readme.md: -------------------------------------------------------------------------------- 1 | Tut files need to be in tut/. Generated files go to target/tut/. -------------------------------------------------------------------------------- /examples/tut/build/build.scala: -------------------------------------------------------------------------------- 1 | package tut_build 2 | import cbt._ 3 | class Build(val context: Context) extends Tut 4 | -------------------------------------------------------------------------------- /examples/tut/tut/example.md: -------------------------------------------------------------------------------- 1 | 2 | This is a tut doc. 3 | 4 | ```tut 5 | 1 + 1 6 | ``` 7 | 8 | -------------------------------------------------------------------------------- /examples/uber-jar-example/README.md: -------------------------------------------------------------------------------- 1 | ### Uber-jar plugin example 2 | 3 | This example shows how to build uber jar(aka fat jar) with `UberJar` plugin. 4 | 5 | In order to create uber jar: execute `cbt uberJar`. Produced jar will be in target folder. 6 | 7 | By default, jar name is your `cbt name`, you can provide other name via overriding `uberJarName` task. 8 | 9 | By default, main class is `Main`. You can provide custom main class via overriding `uberJarMainClass` task. 10 | 11 | To run your main class you can execute `java -jar your-jar-name.jar`. 12 | 13 | You can also run scala REPL with your jar classpath and classes with this command: `scala -cp your-jar-name.jar`. 14 | 15 | In scala REPL you will have access to all your project classes and dependencies. 16 | 17 | ``` 18 | scala -cp uber-jar-example-0.0.1.jar 19 | Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_72). 20 | Type in expressions for evaluation. Or try :help. 21 | 22 | scala> import com.github.someguy.ImportantLib 23 | import com.github.someguy.ImportantLib 24 | 25 | scala> ImportantLib.add(1,2) 26 | res0: Int = 3 27 | 28 | scala> ImportantLib.currentDirectory 29 | Current directory is: /Users/rockjam/projects/cbt/examples/uber-jar-example/target 30 | 31 | scala> Main.main(Array.empty) 32 | fooo 33 | Current directory is: /Users/rockjam/projects/cbt/examples/uber-jar-example/target 34 | not empty list 35 | 36 | scala> import shapeless._ 37 | import shapeless._ 38 | 39 | scala> 1 :: "String" :: 3 :: HNil 40 | res3: shapeless.::[Int,shapeless.::[String,shapeless.::[Int,shapeless.HNil]]] = 1 :: String :: 3 :: HNil 41 | ``` 42 | -------------------------------------------------------------------------------- /examples/uber-jar-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends UberJar { 4 | override def name: String = "uber-jar-example" 5 | def groupId: String = "com.example" 6 | def version = "0.0.1" 7 | 8 | override def dependencies = super.dependencies ++ 9 | Resolver( mavenCentral ).bind( 10 | ScalaDependency("com.chuusai", "shapeless", "2.3.1"), 11 | ScalaDependency("com.lihaoyi", "fansi", "0.1.3"), 12 | ScalaDependency("org.typelevel", "cats", "0.6.0") 13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /examples/uber-jar-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.uberJar 5 | } 6 | -------------------------------------------------------------------------------- /examples/uber-jar-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | import scala.concurrent.{ Await, Future } 2 | import scala.concurrent.duration._ 3 | 4 | import com.github.someguy.ImportantLib 5 | 6 | object Main extends App { 7 | println("fooo") 8 | val futureRes = Await.result(Future.successful(1), 5.seconds) 9 | 10 | ImportantLib.currentDirectory() 11 | 12 | val hlist = { 13 | import shapeless._ 14 | 1 :: "string" :: 3 :: HNil 15 | } 16 | 17 | List(1, 2, 4, 5, 6) match { 18 | case h :: _ ⇒ println("not empty list") 19 | case Nil ⇒ println("empty list") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/uber-jar-example/src/com/github/someguy/ImportantLib.scala: -------------------------------------------------------------------------------- 1 | package com.github.someguy 2 | 3 | import java.nio.file.Paths 4 | 5 | object ImportantLib { 6 | def add(a: Int, b: Int): Int = a + b 7 | def currentDirectory() = { 8 | println(fansi.Color.Green(s"Current directory is: ${Paths.get("").toAbsolutePath}")) 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /examples/wartremover-example/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | import org.wartremover.warts.{ Null, Var } 4 | import org.wartremover.WartTraverser 5 | 6 | class Build(val context: Context) extends BaseBuild with WartRemover { 7 | 8 | override def wartremoverErrors: Seq[WartTraverser] = Seq(Var, Null) 9 | } 10 | -------------------------------------------------------------------------------- /examples/wartremover-example/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | override def dependencies = super.dependencies :+ plugins.wartremover 5 | } 6 | -------------------------------------------------------------------------------- /examples/wartremover-example/src/Main.scala: -------------------------------------------------------------------------------- 1 | object Main { 2 | def main(args: Array[String]): Unit = { 3 | var nastyVar = null 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /internal/plugins/library/Library.scala: -------------------------------------------------------------------------------- 1 | package cbt_internal 2 | import cbt._ 3 | import java.io._ 4 | import scala.concurrent._ 5 | import scala.concurrent.duration._ 6 | trait Library extends PackageJars with Scalariform with GoogleJavaFormat with DynamicOverrides with AdvancedScala { 7 | def groupId = "org.cvogt" 8 | def inceptionYear: Int 9 | def description: String 10 | def version = "0.9-SNAPSHOT" 11 | override def compile = { 12 | googleJavaFormat() 13 | scalariform() 14 | super.compile 15 | } 16 | 17 | def publishIfChanged = newBuild[PublishIfChanged]({s""" 18 | def inceptionYear = $inceptionYear 19 | def description = ${description.quote} 20 | def apply = if(changedInMaster) publish 21 | """}) 22 | } 23 | 24 | trait PublishIfChanged extends PackageJars with DynamicOverrides with Shared{ 25 | override def url = super.url ++ "/libraries/" ++ name 26 | 27 | def gitHash = { 28 | val p = new ProcessBuilder( 29 | "git rev-parse HEAD".split(" "): _* 30 | ) 31 | .directory( projectDirectory ) 32 | .start 33 | 34 | val sout = new InputStreamReader(p.getInputStream); 35 | import scala.concurrent.ExecutionContext.Implicits.global 36 | val out = Future(blocking(Iterator.continually(sout.read).takeWhile(_ != -1).map(_.toChar).mkString)) 37 | p.waitFor 38 | val revision = Await.result( out, Duration.Inf ).trim 39 | revision 40 | } 41 | override def version = "rev-"++gitHash 42 | 43 | def changedInMaster = ( 44 | 0 === 45 | new ProcessBuilder( 46 | "git diff --exit-code --quiet master..master^ .".split(" "): _* 47 | ) 48 | .directory( projectDirectory ) 49 | .start 50 | .waitFor 51 | ) 52 | } 53 | -------------------------------------------------------------------------------- /internal/plugins/library/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt_internal.library_build_plugin 2 | import cbt._ 3 | class Build(val context: Context) extends Plugin with CbtInternal{ 4 | override def dependencies = ( 5 | super.dependencies :+ cbtInternal.shared :+ plugins.scalariform :+ plugins.googleJavaFormat 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /internal/plugins/shared/Shared.scala: -------------------------------------------------------------------------------- 1 | package cbt_internal 2 | import cbt._ 3 | import java.net.URL 4 | trait Shared extends AdvancedScala with SonatypeRelease with SnapshotVersion with GithubPom with ScalaXRay{ 5 | override def user = "cvogt" 6 | override def groupId = "org.cvogt" 7 | override def organization = Some( Organization( "Jan Christopher Vogt", Some( new URL("http://cvogt.org") ) ) ) 8 | override def licenses = Seq( License.Apache2 ) 9 | override def developers = Seq(cvogt) 10 | override def githubProject = "cbt" 11 | 12 | def cvogt = Developer("cvogt", "Jan Christopher Vogt", "-5", new URL("https://github.com/cvogt/")) 13 | } 14 | -------------------------------------------------------------------------------- /internal/plugins/shared/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt_internal.library_build_plugin 2 | import cbt._ 3 | class Build(val context: Context) extends Plugin{ 4 | override def dependencies = super.dependencies :+ plugins.sonatypeRelease 5 | } 6 | -------------------------------------------------------------------------------- /libraries/capture_args/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt.capture_args 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | def description = ( 6 | "macro that allows you to extract a functions arguments" 7 | ++" as strings in order to programmatically pass them to a stringly typed" 8 | ++" api such as a process call, http or a .main method" 9 | ) 10 | 11 | def inceptionYear = 2017 12 | 13 | override def dependencies = ( 14 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 15 | Resolver( mavenCentral ).bind( 16 | MavenDependency( "org.scala-lang", "scala-reflect", scalaVersion ) 17 | ) 18 | ) 19 | 20 | override def scalacOptions = super.scalacOptions :+ "-language:experimental.macros" 21 | } 22 | -------------------------------------------------------------------------------- /libraries/capture_args/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt.capture_args.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/capture_args/package.scala: -------------------------------------------------------------------------------- 1 | package cbt.capture_args 2 | import scala.reflect._ 3 | import scala.reflect.macros.blackbox.Context 4 | 5 | case class Argument( annotations: Seq[annotation.Annotation], name: String, values: Option[Seq[String]] ) { 6 | def toSeqOption = values.map( name +: _ ) 7 | } 8 | case class Signature( name: String, args: Seq[Argument] ) 9 | 10 | object `package` { 11 | def captureArgsImplementation( c: Context ): c.Tree = { 12 | import c.universe._ 13 | 14 | def literal( a: Any ) = Literal( Constant( a ) ) 15 | def ident( name: String ) = Ident( TermName( name ) ) 16 | 17 | def findOwnerRecursive( symbol: Symbol, predicate: Symbol => Boolean ): Option[Symbol] = { 18 | Option( symbol ).flatMap { 19 | s => 20 | if ( s == NoSymbol ) None else if ( predicate( s ) ) Some( s ) else findOwnerRecursive( s.owner, predicate ) 21 | } 22 | } 23 | 24 | val method: MethodSymbol = ( 25 | findOwnerRecursive( c.internal.enclosingOwner, _.isMethod ).map( _.asMethod ) 26 | orElse 27 | findOwnerRecursive( c.internal.enclosingOwner, _.isClass ).map( _.asClass.primaryConstructor.asMethod ) 28 | getOrElse { 29 | c.error( 30 | c.enclosingPosition, 31 | "embed needs to be called in the body of a qualified method" 32 | ) 33 | ??? 34 | } 35 | ) 36 | val name = literal( method.name.decodedName.toString ) 37 | // Note: method.paramLists requires explicitly annotated result type 38 | val params = method.paramLists.flatten.map( _.asTerm ) 39 | 40 | val args = params.map { s => 41 | val name = literal( s.name.decodedName.toString ) 42 | val i = ident( s.name.toString ) 43 | q"_root_.cbt.capture_args.Argument( _root_.scala.Seq( ..${s.annotations.map( _.tree )} ), $name, valueToStrings($i) )" 44 | } 45 | val tree = q""" 46 | _root_.cbt.capture_args.Signature( name = $name, args = Seq( ..$args ) ) 47 | """ 48 | tree 49 | } 50 | def captureArgs: Signature = macro captureArgsImplementation 51 | } 52 | -------------------------------------------------------------------------------- /libraries/common-0/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.common_0 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | override def inceptionYear = 2017 6 | override def description = "classes shared by multiple cbt libraries and needed in stage 0" 7 | } 8 | -------------------------------------------------------------------------------- /libraries/common-0/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/common-0/src/cbt/reflect/TrapSystemExit.java: -------------------------------------------------------------------------------- 1 | package cbt.reflect; 2 | 3 | import java.security.*; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | public abstract class TrapSystemExit { 7 | public static SecurityManager createSecurityManager(SecurityManager delegateTo) { 8 | return new TrapSecurityManager(delegateTo); 9 | } 10 | 11 | public static T run(TrapSystemExit runnable) throws Throwable { 12 | boolean trapExitCodeBefore = TrapSecurityManager.trapExitCode().get(); 13 | try { 14 | TrapSecurityManager.trapExitCode().set(true); 15 | return runnable.run(); 16 | } catch (InvocationTargetException exception) { 17 | Throwable cause = exception.getCause(); 18 | if (TrapSecurityManager.isTrappedExit(cause)) { 19 | return runnable.wrap(TrapSecurityManager.exitCode(cause)); 20 | } 21 | throw exception; 22 | } catch (Exception exception) { 23 | if (TrapSecurityManager.isTrappedExit(exception)) { 24 | return runnable.wrap(TrapSecurityManager.exitCode(exception)); 25 | } 26 | throw exception; 27 | } finally { 28 | TrapSecurityManager.trapExitCode().set(trapExitCodeBefore); 29 | } 30 | } 31 | 32 | public abstract T run() throws Throwable; 33 | 34 | public abstract T wrap(int exitCode); 35 | } 36 | -------------------------------------------------------------------------------- /libraries/common-1/ExitCode.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | // CLI interop 3 | case class ExitCode( integer: Int ) extends interfaces.ExitCode { 4 | def ||( other: => ExitCode ) = if ( this == ExitCode.Success ) this else other 5 | def &&( other: => ExitCode ) = if ( this != ExitCode.Success ) this else other 6 | } 7 | object ExitCode { 8 | val Success = ExitCode( 0 ) 9 | val Failure = ExitCode( 1 ) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /libraries/common-1/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.common_1 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | override def inceptionYear = 2017 6 | override def description = "classes shared by multiple cbt libraries and needed in stage 1" 7 | override def dependencies = super.dependencies :+ libraries.cbt.common_0 :+ libraries.cbt.interfaces 8 | } 9 | -------------------------------------------------------------------------------- /libraries/common-1/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/common-1/common_1.scala: -------------------------------------------------------------------------------- 1 | package cbt.common_1 2 | import cbt.ExitCode 3 | object `package` extends Module { 4 | implicit class CbtExitCodeOps( val exitCode: ExitCode ) extends AnyVal with ops.CbtExitCodeOps 5 | implicit class TypeInferenceSafeEquals[T]( val value: T ) extends AnyVal with ops.TypeInferenceSafeEquals[T] 6 | implicit class CbtBooleanOps( val condition: Boolean ) extends AnyVal with ops.CbtBooleanOps 7 | implicit class CbtStringOps( val string: String ) extends AnyVal with ops.CbtStringOps 8 | } 9 | 10 | package ops { 11 | trait CbtExitCodeOps extends Any { 12 | def exitCode: ExitCode 13 | def ||( other: => ExitCode ) = if ( exitCode == ExitCode.Success ) exitCode else other 14 | def &&( other: => ExitCode ) = if ( exitCode != ExitCode.Success ) exitCode else other 15 | } 16 | trait TypeInferenceSafeEquals[T] extends Any { 17 | def value: T 18 | /** if you don't manually upcast, this will catch comparing different types */ 19 | def ===( other: T ) = value == other 20 | def =!=( other: T ) = value != other // =!= instead of !==, because it has better precedence 21 | } 22 | trait CbtBooleanOps extends Any { 23 | def condition: Boolean 24 | def option[T]( value: => T ): Option[T] = if ( condition ) Some( value ) else None 25 | } 26 | trait CbtStringOps extends Any { 27 | def string: String 28 | def escape = string.replace( "\\", "\\\\" ).replace( "\"", "\\\"" ) 29 | def quote = s""""$escape"""" 30 | def ~( right: String ): String = string + right 31 | } 32 | } 33 | 34 | trait Module 35 | -------------------------------------------------------------------------------- /libraries/common-1/src/cbt/ExitCode.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | /* 3 | public class ExitCode{ 4 | public int integer; 5 | public ExitCode(int integer){ 6 | this.integer = integer; 7 | } 8 | public static ExitCode apply(int integer){ 9 | return new ExitCode( integer ); 10 | } 11 | public static ExitCode Success = new ExitCode(0); 12 | public static ExitCode Failure = new ExitCode(1); 13 | 14 | @Override 15 | public boolean equals(Object other){ 16 | return (other instanceof ExitCode) && ((ExitCode) other).integer == integer; 17 | } 18 | @Override 19 | public int hashCode(){ 20 | return integer; 21 | } 22 | } 23 | 24 | */ 25 | -------------------------------------------------------------------------------- /libraries/eval/Readme.md: -------------------------------------------------------------------------------- 1 | Eval - Scala runtime code compilation and evaluation 2 | 3 | The code for Eval originally comes out of https://github.com/twitter/util . History was transferred to see origin and author of the changes in this file, but history was re-written to eliminate file renames. 4 | 5 | The code was moved rather than a dependency on twitter/util added for these reasons: 6 | - With minor changes the dependency on twitter `util-core` can be removed, which allows CBT to avoid adding it as a dependency 7 | - According to @ryanoneill, Eval is deprecated within twitter (https://github.com/twitter/util/pull/179) 8 | -------------------------------------------------------------------------------- /libraries/eval/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends PackageJars{ 3 | outer => 4 | def groupId = "org.cvogt" 5 | def version = "0.9-SNAPSHOT" 6 | override def dependencies = super.dependencies :+ 7 | new ScalaCompilerDependency( context.cbtLastModified, context.paths.mavenCache, scalaVersion ) 8 | 9 | override def test: Dependency = { 10 | new BasicBuild(context.copy(workingDirectory = projectDirectory ++ "/test")) with ScalaTest{ 11 | override def dependencies = super.dependencies ++ Seq( 12 | DirectoryDependency(projectDirectory++"/..") 13 | ) 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/Base.scala: -------------------------------------------------------------------------------- 1 | trait Base extends (() => String) { 2 | def apply() = "hello" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/Deprecated.scala: -------------------------------------------------------------------------------- 1 | new (() => String) { 2 | @deprecated("don't use hello") 3 | def hello() = "hello" 4 | 5 | def apply() = hello() 6 | } 7 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/Derived.scala: -------------------------------------------------------------------------------- 1 | new Base { } 2 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/DerivedWithInclude.scala: -------------------------------------------------------------------------------- 1 | new Base { 2 | #include HelloJoe.scala 3 | } 4 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/HelloJoe.scala: -------------------------------------------------------------------------------- 1 | /* real-time declarative programming now */ 2 | override def toString = "hello, joe" 3 | 4 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/IncludeInclude.scala: -------------------------------------------------------------------------------- 1 | val b1 = 2 | #include DerivedWithInclude.scala 3 | val b2 = 4 | #include DerivedWithInclude.scala 5 | new Base { 6 | override def toString = b1 + "; " + b2 7 | } 8 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/OnePlusOne.scala: -------------------------------------------------------------------------------- 1 | 1 + 1 2 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/RubyInclude.scala: -------------------------------------------------------------------------------- 1 | object CodeThatIncludesSomeRuby { 2 | #include hello.rb 3 | } 4 | -------------------------------------------------------------------------------- /libraries/eval/test/resources/file-with-dash.scala: -------------------------------------------------------------------------------- 1 | "hello" 2 | -------------------------------------------------------------------------------- /libraries/file/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | override def inceptionYear = 2017 6 | override def description = "helpers to work with java io and nio" 7 | override def dependencies = super.dependencies :+ libraries.cbt.common_1 8 | } 9 | -------------------------------------------------------------------------------- /libraries/file/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/interfaces/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends PackageJars{ 3 | def groupId = "org.cvogt" 4 | def version = "0.9-SNAPSHOT" 5 | } 6 | -------------------------------------------------------------------------------- /libraries/interfaces/src/cbt/interfaces/ExitCode.java: -------------------------------------------------------------------------------- 1 | package cbt.interfaces; 2 | public interface ExitCode{ 3 | public int integer(); 4 | } 5 | -------------------------------------------------------------------------------- /libraries/process/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.process 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | override def inceptionYear = 2017 6 | override def description = "helpers for process calls" 7 | override def dependencies = super.dependencies ++ Resolver(mavenCentral).bind( 8 | MavenDependency( "net.java.dev.jna", "jna-platform", "4.4.0" ) 9 | ) :+ libraries.cbt.common_1 10 | } 11 | -------------------------------------------------------------------------------- /libraries/process/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/process/test/test.scala: -------------------------------------------------------------------------------- 1 | object Tests{ 2 | def main(args: Array[String]): Unit = { 3 | val pb = new ProcessBuilder("cat") 4 | val p = pb.start 5 | cbt.process.getProcessId( p ) // checks that it actually gets a process id 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /libraries/proguard/Readme.md: -------------------------------------------------------------------------------- 1 | Type-safe Scala api on top of proguards .main method. 2 | 3 | TODO: 4 | - capture stdout and make it available to the caller via stream 5 | -------------------------------------------------------------------------------- /libraries/proguard/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package proguard_build.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = ( 5 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 6 | Resolver( mavenCentral, sonatypeReleases ).bind( 7 | ScalaDependency("org.scala-lang.modules","scala-xml","1.0.5"), 8 | "org.ccil.cowan.tagsoup" % "tagsoup" % "1.2.1" 9 | ) ++ Seq( cbtInternal.library ) 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /libraries/readme.txt: -------------------------------------------------------------------------------- 1 | This folder contains libraries used by cbt and it's plugins. 2 | They are separated so they can be published and used separately 3 | from cbt itself. 4 | -------------------------------------------------------------------------------- /libraries/reflect/StaticMethod.scala: -------------------------------------------------------------------------------- 1 | package cbt.reflect 2 | import java.lang.reflect.Method 3 | case class StaticMethod[Arg, Result]( function: Arg => Result, method: Method ) extends ( Arg => Result ) { 4 | def apply( arg: Arg ): Result = function( arg ) 5 | } 6 | -------------------------------------------------------------------------------- /libraries/reflect/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect 2 | import cbt._ 3 | import cbt_internal._ 4 | class Build(val context: Context) extends Library{ 5 | override def inceptionYear = 2017 6 | override def description = "discover classes on your classpath and invoke methods reflectively, preventing System.exit" 7 | override def dependencies = super.dependencies :+ libraries.cbt.file :+ libraries.cbt.common_1 8 | } 9 | -------------------------------------------------------------------------------- /libraries/reflect/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.reflect.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/scalatest-runner/Runner.scala: -------------------------------------------------------------------------------- 1 | package cbt.scalatest 2 | 3 | import org.scalatest._ 4 | 5 | import java.io.File 6 | 7 | object Runner { 8 | def run( classpath: Array[File], classLoader: ClassLoader ): Unit = { 9 | val suiteNames = classpath.map( d => discoverSuites( d, classLoader ) ).flatten 10 | runSuites( suiteNames.map( loadSuite( _, classLoader ) ) ) 11 | } 12 | 13 | def runSuites( suites: Seq[Suite] ) = { 14 | def color: Boolean = true 15 | def durations: Boolean = true 16 | def shortstacks: Boolean = true 17 | def fullstacks: Boolean = true 18 | def stats: Boolean = true 19 | def testName: String = null 20 | def configMap: ConfigMap = ConfigMap.empty 21 | suites.foreach { 22 | _.execute( testName, configMap, color, durations, shortstacks, fullstacks, stats ) 23 | } 24 | } 25 | 26 | def discoverSuites( discoveryPath: File, classLoader: ClassLoader ): Seq[String] = { 27 | classLoader 28 | .loadClass( "org.scalatest.tools.SuiteDiscoveryHelper" ) 29 | .getMethod( "discoverSuiteNames", classOf[List[_]], classOf[ClassLoader], classOf[Option[_]] ) 30 | .invoke( null, List( discoveryPath.toString ++ "/" ), classLoader, None ) 31 | .asInstanceOf[Set[String]] 32 | .toVector 33 | } 34 | def loadSuite( name: String, classLoader: ClassLoader ) = { 35 | classLoader.loadClass( name ).getConstructor().newInstance().asInstanceOf[Suite] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libraries/scalatest-runner/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_libraries_build.scalatest_runner 2 | import cbt._ 3 | import cbt_internal._ 4 | 5 | class Build(val context: Context) extends Library{ 6 | override def inceptionYear = 2017 7 | override def description = "run scalatest tests from given directory and classpath (compatible with 2.12 and 2.11)" 8 | 9 | override def dependencies = super.dependencies ++ 10 | Resolver( mavenCentral ).bind( 11 | ScalaDependency("org.scalatest","scalatest", if(scalaMajorVersion == "2.12") "3.0.1" else "2.2.6") 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /libraries/scalatest-runner/build/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.scalatest_runner.build 2 | import cbt._ 3 | class Build(val context: Context) extends BuildBuild with CbtInternal{ 4 | override def dependencies = super.dependencies :+ cbtInternal.library 5 | } 6 | -------------------------------------------------------------------------------- /libraries/scalatex/AbstractMain.scala: -------------------------------------------------------------------------------- 1 | package cbt.plugins.scalatex.runtime 2 | 3 | import java.io.File 4 | import java.nio.file.{ Files, Paths } 5 | import scalatags.Text.all._ 6 | trait AbstractMain{ 7 | def dependencyClasspath: Seq[File] 8 | def files: Seq[(String,SeqFrag[Frag])] 9 | def htmlTarget: File 10 | def render: SeqFrag[Frag] => String => String 11 | def main(args: Array[String]): Unit = { 12 | val changed = files.flatMap{ 13 | case (name, contents) => 14 | val path = htmlTarget.toPath.resolve(name + ".html") 15 | import Files._ 16 | createDirectories(path.getParent) 17 | val newContents = render(contents)(name) 18 | if( !exists(path) || new String( Files.readAllBytes( path ) ) != newContents ){ 19 | write( path, newContents.getBytes ) 20 | Some( path ) 21 | } else None 22 | } 23 | if( args.lift(0).map(_=="open").getOrElse(false) ) 24 | changed.headOption.foreach{ file => 25 | System.out.println(file) 26 | val old = Option(System.getProperty("apple.awt.UIElement")) 27 | System.setProperty("apple.awt.UIElement", "true") 28 | java.awt.Desktop.getDesktop().open(file.toFile) 29 | old.foreach(System.setProperty("apple.awt.UIElement", _)) 30 | } 31 | else System.out.println(changed.mkString("\\n")) 32 | } 33 | val repl = new cbt.plugins.scalatex.runtime.repl( this.getClass.getClassLoader, dependencyClasspath: _* ) 34 | } 35 | -------------------------------------------------------------------------------- /libraries/scalatex/build/build.scala: -------------------------------------------------------------------------------- 1 | package scalatex_build 2 | import cbt._ 3 | class Build(val context: Context) extends BaseBuild{ 4 | override def dependencies = ( 5 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 6 | Seq( 7 | libraries.cbt.eval 8 | ) ++ 9 | Resolver( mavenCentral, sonatypeReleases ).bind( 10 | ScalaDependency( "com.lihaoyi", "scalatex-api", "0.3.7" ), 11 | ScalaDependency( "com.lihaoyi", "scalatex-site", "0.3.7" ), 12 | ScalaDependency("org.cvogt","scala-extensions","0.5.0"), 13 | ScalaDependency("org.scalameta", "scalameta", "1.6.0") 14 | ) 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /nailgun_launcher/src/cbt/BuildStage1Result.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | public class BuildStage1Result{ 3 | public long start; 4 | public long stage1LastModified; 5 | public ClassLoader classLoader; 6 | public String stage1Classpath; 7 | public String nailgunClasspath; 8 | public String compatibilityClasspath; 9 | public BuildStage1Result( long start, long stage1LastModified, ClassLoader classLoader, String stage1Classpath, String nailgunClasspath, String compatibilityClasspath ){ 10 | this.start = start; 11 | this.stage1LastModified = stage1LastModified; 12 | this.classLoader = classLoader; 13 | this.stage1Classpath = stage1Classpath; 14 | this.nailgunClasspath = nailgunClasspath; 15 | this.compatibilityClasspath = compatibilityClasspath; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nailgun_launcher/src/cbt/CbtURLClassLoader.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.io.*; 3 | import java.net.*; 4 | import java.util.*; 5 | import static cbt.Stage0Lib.*; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | public class CbtURLClassLoader extends java.net.URLClassLoader{ 8 | public String toString(){ 9 | return ( 10 | super.toString() 11 | + "(\n " 12 | + Arrays.toString(getURLs()) 13 | + ",\n " 14 | + mkString("\n ",(getParent() == null?"":getParent().toString()).split("\n")) 15 | + "\n)" 16 | ); 17 | } 18 | ConcurrentHashMap cache = new ConcurrentHashMap(); 19 | public Class loadClass(String name) throws ClassNotFoundException{ 20 | Class _class = super.loadClass(name); 21 | if(_class == null) throw new ClassNotFoundException(name); 22 | else return _class; 23 | } 24 | public Class loadClass(String name, boolean resolve) throws ClassNotFoundException{ 25 | //System.out.println("loadClass("+name+") on \n"+this); 26 | synchronized( cache ){ 27 | if(!cache.containsKey(name)) 28 | cache.put(name, new Object()); 29 | } 30 | Object key = cache.get(name); 31 | synchronized( key ){ 32 | if(!cache.containsKey(key)){ 33 | try{ 34 | cache.put(key, super.loadClass(name, resolve)); 35 | } catch (ClassNotFoundException e){ 36 | cache.put(key, Object.class); 37 | } 38 | } 39 | Class _class = (Class) cache.get(key); 40 | if(_class == Object.class){ 41 | if( name.equals("java.lang.Object") ) 42 | return Object.class; 43 | else return null; 44 | } else { 45 | return _class; 46 | } 47 | } 48 | } 49 | void assertExist(URL[] urls){ 50 | for(URL url: urls){ 51 | if(!new File(url.getPath()).exists()){ 52 | throw new AssertionError("File does not exist when trying to create CbtURLClassLoader: "+url); 53 | } 54 | } 55 | } 56 | public CbtURLClassLoader(URL[] urls, ClassLoader parent){ 57 | super(urls, parent); 58 | assertExist(urls); 59 | } 60 | public CbtURLClassLoader(URL[] urls){ 61 | super(urls, null); 62 | assertExist(urls); 63 | } 64 | } -------------------------------------------------------------------------------- /nailgun_launcher/src/cbt/ClassLoaderCache.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | 3 | import java.util.*; 4 | import static java.io.File.pathSeparator; 5 | import static cbt.Stage0Lib.*; 6 | 7 | final public class ClassLoaderCache{ 8 | public Map hashMap; 9 | final ThreadLocal> seen = new ThreadLocal>(){ 10 | @Override protected HashSet initialValue(){ 11 | return new HashSet(); 12 | } 13 | }; 14 | 15 | public ClassLoaderCache( 16 | Map hashMap 17 | ){ 18 | this.hashMap = hashMap; 19 | } 20 | 21 | public ClassLoader get( String key, long timestamp ){ 22 | seen.get().add( key ); 23 | @SuppressWarnings("unchecked") 24 | ClassLoader t = (ClassLoader) hashMap.get( 25 | hashMap.get( key ) 26 | ); 27 | assert hashMap.get(t).equals(timestamp); 28 | return t; 29 | } 30 | 31 | public boolean containsKey( String key, long timestamp ){ 32 | boolean contains = hashMap.containsKey( key ); 33 | if( contains ){ 34 | Object keyObject = hashMap.get( key ); 35 | Object classLoader = hashMap.get( keyObject ); 36 | long oldTimestamp = (long) hashMap.get( classLoader ); 37 | boolean res = oldTimestamp == timestamp; 38 | return res; 39 | } else { 40 | return false; 41 | } 42 | } 43 | 44 | public void put( String key, ClassLoader value, long timestamp ){ 45 | assert !seen.get().contains( key ): "Thread tries to update cache key after observing it: " + key; 46 | LockableJavaKey keyObject = new LockableJavaKey(); 47 | hashMap.put( key, keyObject ); 48 | hashMap.put( keyObject, value ); 49 | hashMap.put( value, timestamp ); 50 | } 51 | 52 | @Override public String toString(){ 53 | StringBuilder res = new StringBuilder(); 54 | res.append("ClassLoaderCache(\n\n"); 55 | for( Object key: hashMap.keySet() ){ 56 | if( key instanceof String ) 57 | res.append( 58 | mkString( "\n", key.toString().split(":") ) + " -> " + hashMap.get( hashMap.get(key) ) 59 | + "\n\n" 60 | ); 61 | } 62 | res.append("\n\n"); 63 | return res.toString(); 64 | } 65 | } 66 | class LockableJavaKey{} 67 | -------------------------------------------------------------------------------- /nailgun_launcher/src/cbt/MultiClassLoader2.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.net.*; 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | public class MultiClassLoader2 extends ClassLoader{ 7 | public ClassLoader[] parents; 8 | public ClassLoader[] parents(){ 9 | return this.parents; 10 | } 11 | public MultiClassLoader2(ClassLoader... parents){ 12 | super(null); 13 | this.parents = parents; 14 | } 15 | public Class findClass(String name) throws ClassNotFoundException{ 16 | for(ClassLoader parent: parents){ 17 | try{ 18 | return parent.loadClass(name); 19 | } catch (ClassNotFoundException e) { 20 | if(e.getMessage() != name) throw e; 21 | } 22 | } 23 | // FIXME: have a logger in Java land 24 | // System.err.println("NOT FOUND: "+name); 25 | return null; 26 | } 27 | public URL findResource(String name){ 28 | for(ClassLoader parent: parents){ 29 | URL res = parent.getResource(name); 30 | if(res != null) return res; 31 | } 32 | return null; 33 | } 34 | public Enumeration findResources(String name) throws IOException{ 35 | ArrayList resources = new ArrayList(); 36 | for(ClassLoader parent: parents){ 37 | for(URL resource: Collections.list(parent.getResources(name))){ 38 | resources.add( resource ); 39 | } 40 | } 41 | return Collections.enumeration(resources); 42 | } 43 | public String toString(){ 44 | return super.toString() + "(" + Arrays.toString(parents) +")"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /nailgun_launcher/src/cbt/ThreadLocalOutputStream.java: -------------------------------------------------------------------------------- 1 | package cbt; 2 | import java.io.*; 3 | 4 | public class ThreadLocalOutputStream extends OutputStream{ 5 | final public ThreadLocal threadLocal; 6 | final private OutputStream initialValue; 7 | 8 | public ThreadLocalOutputStream( OutputStream initialValue ){ 9 | this.initialValue = initialValue; 10 | threadLocal = new ThreadLocal() { 11 | @Override protected OutputStream initialValue() { 12 | return ThreadLocalOutputStream.this.initialValue; 13 | } 14 | }; 15 | } 16 | 17 | public OutputStream get(){ 18 | return threadLocal.get(); 19 | } 20 | 21 | public void set( OutputStream outputStream ){ 22 | threadLocal.set( outputStream ); 23 | } 24 | 25 | public void write( int b ) throws IOException{ 26 | // after implementing this I realized NailgunLauncher uses the same hack, 27 | // so probably this is not a problem performance 28 | get().write(b); 29 | } 30 | 31 | public void flush() throws IOException{ 32 | get().flush(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /plugins/google-java-format/GoogleJavaFormat.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import java.io.File 4 | import java.nio.file.Files._ 5 | import java.nio.file._ 6 | 7 | import com.google.googlejavaformat.java._ 8 | 9 | trait GoogleJavaFormat extends BaseBuild { 10 | def googleJavaFormat() = GoogleJavaFormat.apply( lib, sourceFiles.filter(_.string endsWith ".java") ).format 11 | } 12 | 13 | object GoogleJavaFormat{ 14 | case class apply( lib: Lib, files: Seq[File] ){ 15 | /** @param whiteSpaceInParenthesis more of a hack to make up for missing support in Scalafmt. Does not respect alignment and maxColumn. */ 16 | def format = { 17 | val (successes, errors) = lib.transformFilesOrError( files, in => 18 | try{ 19 | Right( new Formatter().formatSource(in) ) 20 | } catch { 21 | case e: FormatterException => Left( e ) 22 | } 23 | ) 24 | if(errors.nonEmpty) 25 | throw new RuntimeException( 26 | "Google Java Format failed to parse some files:\n" ++ errors.map{ 27 | case (file, error) => file.string ++ ":" ++ error.toString 28 | }.mkString("\n"), 29 | errors.head._2 30 | ) 31 | successes 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /plugins/google-java-format/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | override def dependencies = 5 | super.dependencies ++ 6 | Resolver( mavenCentral ).bind( 7 | MavenDependency( "com.google.googlejavaformat", "google-java-format", "1.3" ) 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /plugins/google-java-format/src/com/google/errorprone/annotations/Immutable.java: -------------------------------------------------------------------------------- 1 | package com.google.errorprone.annotations; 2 | // to suppress warning 3 | // "Class com.google.errorprone.annotations.Immutable not found - continuing with a stub." 4 | // there probably is a better solution 5 | public class Immutable{} 6 | -------------------------------------------------------------------------------- /plugins/proguard/Proguard.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | trait ProGuard extends BaseBuild { 4 | def proguard: () => ClassPath 5 | def ProGuard(keep: (Seq[cbt.proguard.KeepOptionModifier], String)) = { 6 | cbt.ProGuard(context).proguard( 7 | outjars = Some( Seq(scalaTarget / "proguarded.jar") ), 8 | injars = Some( classpath.files ), 9 | libraryjars = Some( ClassPath( cbt.proguard.ProGuard.`rt.jar` ).files ), 10 | keep = Some( keep ) 11 | ) 12 | } 13 | } 14 | 15 | object ProGuard { 16 | def apply( implicit context: Context ) = { 17 | import context._ 18 | val lib = new Lib(context.logger) 19 | import cbt.proguard.ProGuard._ 20 | cbt.proguard.ProGuard( 21 | (args: Seq[String]) => MavenResolver( 22 | cbtLastModified, context.paths.mavenCache, mavenCentral 23 | )( 24 | context.logger, transientCache, context.classLoaderCache 25 | ).bindOne( 26 | MavenDependency(groupId, artifactId, version) 27 | ).runMain(cbt.proguard.ProGuard.mainClass, args).integer, 28 | ClassPath(_), 29 | context.logger.log("proguard",_) 30 | ) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugins/proguard/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.proguard 2 | import cbt._ 3 | class Build(val context: Context) extends Plugin{ 4 | override def dependencies = ( 5 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 6 | Seq( libraries.proguard ) 7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /plugins/readme.txt: -------------------------------------------------------------------------------- 1 | This directory is for plugins plugins which are shipped with CBT, 2 | but need to be explicitly dependended upon in the BuildBuild. 3 | This is nice for plugins, which themselves have dependencies 4 | that we do not want CBT to depend on. 5 | See stage2/plugins/ for built-in plugins, that have no dependencies. 6 | -------------------------------------------------------------------------------- /plugins/sbt_layout/SbtLayout.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | // TODO: move this into stage2 to avoid having to call zinc separately for this as a plugin 3 | trait SbtLayoutTest extends BaseBuild{ 4 | override def sources = Seq(projectDirectory ++ "/src/test/scala") 5 | override def compileTarget = super.compileTarget.getParentFile ++ "/test-classes" 6 | } 7 | 8 | trait SbtLayoutMain extends BaseBuild{ 9 | override def sources = Seq( projectDirectory ++ "/src/main/scala" ) 10 | } 11 | -------------------------------------------------------------------------------- /plugins/sbt_layout/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends Plugin 3 | -------------------------------------------------------------------------------- /plugins/scalafix-compiler-plugin/Scalafix.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import cbt._ 4 | import java.nio.file.Files._ 5 | import java.nio.file._ 6 | import java.io.File 7 | 8 | trait ScalafixCompilerPlugin extends BaseBuild { 9 | def scalafixVersion = "0.3.1" 10 | 11 | override def scalacOptions = super.scalacOptions ++ 12 | Scalafix.scalacOptions(projectDirectory.toPath, 13 | Resolver( mavenCentral, sonatypeReleases ).bindOne( 14 | ScalaDependency( "ch.epfl.scala", "scalafix-nsc", scalafixVersion ) 15 | ).jar) 16 | } 17 | 18 | object Scalafix { 19 | def scalacOptions( rootPath: Path, nscJar: File ) = 20 | Seq( 21 | "-Xplugin:" ++ nscJar.string, 22 | "-Yrangepos" 23 | ) ++ configOption(rootPath) 24 | 25 | def configOption( rootPath: Path ) = 26 | Some( rootPath.resolve(".scalafix.conf").toAbsolutePath ) 27 | .filter(isRegularFile(_)).map("-P:scalafix:" ++ _.toString).toSeq 28 | } 29 | -------------------------------------------------------------------------------- /plugins/scalafix-compiler-plugin/build/build.scala: -------------------------------------------------------------------------------- 1 | package scalafix_build 2 | 3 | import cbt._ 4 | 5 | class Build(val context: Context) extends Plugin { 6 | override def dependencies = ( 7 | super.dependencies ++ 8 | Resolver( mavenCentral, sonatypeReleases ).bind( 9 | ScalaDependency( "ch.epfl.scala", "scalafix-nsc", "0.3.1" ) 10 | ) 11 | ) 12 | } 13 | -------------------------------------------------------------------------------- /plugins/scalafix/Scalafix.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import java.io.File 4 | 5 | import scala.meta._ 6 | import scala.meta.semantic.v1._ 7 | import scala.meta.{ Symbol => _, _ } 8 | import scalafix._, rewrite._, config._, util._ 9 | import org.scalameta.{logger => scalametaLogger} 10 | 11 | import cbt._ 12 | 13 | trait Scalafix extends Scalameta{ 14 | def scalafix = Scalafix.apply( lib ).config( 15 | classpath, 16 | sourceFiles zip sourceFiles 17 | ) 18 | } 19 | 20 | object Scalafix{ 21 | case class apply( lib: Lib ){ 22 | case class config( 23 | classpath: ClassPath, 24 | files: Seq[(File,File)], 25 | patches: Seq[Patch] = Seq(), 26 | rewrites: Seq[ Rewrite[ScalafixMirror] ] = Seq(), 27 | allowEmpty: Boolean = false 28 | ){ 29 | def mirror = 30 | Mirror( 31 | classpath.string, 32 | files.map(_._1).mkString(File.pathSeparator) 33 | ) 34 | 35 | def context(file: File): ( RewriteCtx[Mirror], RewriteCtx[ScalafixMirror] ) = ( 36 | scalafix.rewrite.RewriteCtx( 37 | mirror.dialect(file).parse[Source].get, ScalafixConfig(), mirror 38 | ), 39 | scalafix.rewrite.RewriteCtx( 40 | mirror.dialect(file).parse[Source].get, ScalafixConfig(), ScalafixMirror.fromMirror( mirror ) 41 | ) 42 | ) 43 | 44 | def apply: Unit = { 45 | require( 46 | allowEmpty || rewrites.nonEmpty || patches.nonEmpty, 47 | "You need to provide some rewrites via: `override def scalafix = super.scalafix.copy( rewrites = Seq(...) )`" 48 | ) 49 | files.foreach{ case (from, to) => 50 | implicit val ( ctx, ctx2 ) = context(from) 51 | lib.writeIfChanged( 52 | to, 53 | Patch( 54 | ( 55 | patches 56 | ++ rewrites.flatMap( 57 | _.rewrite( ctx2 ).to 58 | ) 59 | ).to 60 | ) 61 | ) 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /plugins/scalafix/build/build.scala: -------------------------------------------------------------------------------- 1 | package scalafix_build 2 | 3 | import cbt._ 4 | 5 | class Build(val context: Context) extends Plugin { 6 | override def dependencies = super.dependencies ++ Seq( 7 | //plugins.scalameta 8 | ) :+ Resolver( mavenCentral ).bindOne( 9 | ScalaDependency( 10 | "ch.epfl.scala", "scalafix-core", "0.3.2" 11 | ) 12 | ).copy( 13 | // required until https://github.com/scalacenter/scalafix/issues/100 is fixed 14 | replace = _ => _.flatMap{ 15 | case m@MavenDependency("org.scalameta", artifactId,_,_,_) 16 | if (artifactId startsWith "scalahost_") 17 | || (artifactId startsWith "contrib_") 18 | => Seq( m ) 19 | case MavenDependency("org.scalameta", _,_,_,_) => Seq( 20 | MavenDependency( 21 | "org.scalameta", "scalahost_" ++ scalaVersion, "1.6.0" 22 | ) 23 | ) 24 | case other => Seq( other ) 25 | } 26 | ) 27 | } 28 | -------------------------------------------------------------------------------- /plugins/scalafmt/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | private val ScalafmtVersion = "0.6.2" 5 | 6 | override def dependencies = 7 | super.dependencies ++ 8 | Resolver( mavenCentral ).bind( 9 | ScalaDependency("com.geirsson", "scalafmt-cli", ScalafmtVersion) 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /plugins/scalajs/ScalaJsBuild.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | import java.net.URL 4 | 5 | // TODO: maybe move this into stage2 to avoid having to call zinc separately for this as a plugin 6 | trait ScalaJsBuild extends DynamicOverrides{ 7 | final protected val scalaJsLib = ScalaJsLib( 8 | scalaJsVersion, scalaVersion, context.cbtLastModified, context.paths.mavenCache 9 | ) 10 | import scalaJsLib.{link => _,_} 11 | 12 | def scalaJsVersion = "0.6.8" 13 | final protected val scalaJsMajorVersion: String = lib.libMajorVersion(scalaJsVersion) 14 | final protected val artifactIdSuffix = s"_sjs$scalaJsMajorVersion" 15 | 16 | override def dependencies = super.dependencies :+ scalaJsLibraryDependency 17 | override def scalacOptions = super.scalacOptions ++ scalaJsLib.scalacOptions 18 | 19 | /** Note: We make same assumption about scala version. 20 | In order to be able to choose different scala version, one has to use %. */ 21 | implicit class ScalaJsDependencyBuilder(groupId: String){ 22 | def %%%(artifactId: String) = new DependencyBuilder2( 23 | groupId, artifactId + artifactIdSuffix, Some(scalaMajorVersion)) 24 | } 25 | 26 | override def compile = { 27 | val res = super.compile 28 | scalaJsLib.link( scalaJsTargetFile, scalaJsOptions, target +: dependencyClasspath.files ) 29 | res 30 | // FIXME: we need to rethink the concept of a "compile" task I think. 31 | // An exit code would probably be more appropriate here. 32 | } 33 | 34 | def scalaJsOptions: Seq[String] = Seq() 35 | 36 | /** Where to put the generated js file */ 37 | def scalaJsTargetFile: File = target / "app.js" 38 | 39 | override def cleanFiles = super.cleanFiles :+ scalaJsTargetFile :+ (scalaJsTargetFile ++ ".map") 40 | 41 | def fullOpt = newBuild[ScalaJsBuild](""" 42 | override def scalaJsOptions = "--fullOpt" +: super.scalaJsOptions 43 | """) 44 | } 45 | -------------------------------------------------------------------------------- /plugins/scalajs/ScalaJsLib.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | 4 | case class ScalaJsLib( 5 | scalaJsVersion: String, scalaVersion: String, cbtLastModified: Long, mavenCache: File 6 | )(implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache){ 7 | val lib = new Lib(logger) 8 | def dep(artifactId: String) = MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( 9 | MavenDependency("org.scala-js", artifactId, scalaJsVersion) 10 | ) 11 | 12 | def link( 13 | outputPath: File, scalaJsOptions: Seq[String], entriesToLink: Seq[File] 14 | ): ExitCode = { 15 | outputPath.getParentFile.mkdirs 16 | val scalaJsCliDep = dep( "scalajs-cli_"++lib.libMajorVersion(scalaVersion) ) 17 | outputPath.getParentFile.mkdirs 18 | scalaJsCliDep.runMain( 19 | "org.scalajs.cli.Scalajsld", 20 | Seq( 21 | "--sourceMap", 22 | "--stdlib", s"${scalaJsLibraryDependency.jar.getAbsolutePath}", 23 | "--output", outputPath.string 24 | ) ++ scalaJsOptions ++ entriesToLink.map(_.getAbsolutePath) 25 | ) 26 | } 27 | 28 | val scalaJsLibraryDependency = dep( "scalajs-library_"++lib.libMajorVersion(scalaVersion) ) 29 | 30 | // Has to be full Scala version because the compiler is incompatible between versions 31 | val scalaJsCompilerDependency = dep( "scalajs-compiler_"++scalaVersion ) 32 | val scalacOptions = Seq( 33 | "-Xplugin:" ++ scalaJsCompilerDependency.jar.string, 34 | "-Xplugin-require:scalajs" 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /plugins/scalajs/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin 4 | -------------------------------------------------------------------------------- /plugins/scalapb/ScalaPB.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import com.trueaccord.scalapb._ 4 | import _root_.protocbridge.ProtocBridge 5 | import _root_.scalapb.ScalaPbCodeGenerator 6 | import java.io.File 7 | 8 | trait Scalapb extends BaseBuild{ 9 | override def dependencies = super.dependencies ++ Resolver( mavenCentral ).bind( 10 | ScalaDependency( 11 | "com.trueaccord.scalapb", "scalapb-runtime", cbt.scalapb.BuildInfo.scalaPBVersion 12 | ) 13 | ) 14 | 15 | def scalapb = Scalapb.apply(lib).config( 16 | input = projectDirectory / "protobuf-schemas", 17 | output = projectDirectory / "src_generated" 18 | ) 19 | } 20 | 21 | sealed trait ProtocVersion 22 | object ProtocVersion{ 23 | case object v310 extends ProtocVersion 24 | case object v300 extends ProtocVersion 25 | case object v261 extends ProtocVersion 26 | case object v250 extends ProtocVersion 27 | case object v241 extends ProtocVersion 28 | } 29 | 30 | object Scalapb{ 31 | case class apply(lib: Lib){ 32 | case class config( 33 | input: File, 34 | output: File, 35 | version: ProtocVersion = ProtocVersion.v310, 36 | flatPackage: Boolean = false, 37 | javaConversions: Boolean = false, 38 | grpc: Boolean = true, 39 | singleLineToString: Boolean = false 40 | ){ 41 | def apply = { 42 | output.mkdirs 43 | val protoFiles = input.listRecursive.filter(_.isFile).map(_.string).toArray 44 | val options = Seq( 45 | javaConversions.option("java_conversions"), 46 | grpc.option("grpc"), 47 | singleLineToString.option("single_line_to_string"), 48 | flatPackage.option("flat_package") 49 | ).flatten.mkString(",") 50 | import _root_.protocbridge.frontend.PluginFrontend 51 | val pluginFrontend: PluginFrontend = PluginFrontend.newInstance() 52 | val (scriptPath, state) = pluginFrontend.prepare( ScalaPbCodeGenerator ) 53 | try { 54 | lib.redirectOutToErr( 55 | ExitCode( 56 | com.github.os72.protocjar.Protoc.runProtoc( 57 | Array( 58 | "-" ++ version.getClass.getSimpleName.stripSuffix("$"), 59 | "-I=" ++ input.string, 60 | s"--scala_out=$options:" ++ output.string, 61 | s"--plugin=protoc-gen-scala=${scriptPath}" 62 | ) ++ protoFiles 63 | ) 64 | ) 65 | ) 66 | } finally { 67 | pluginFrontend.cleanup(state) 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /plugins/scalapb/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | private val scalaPBVersion = "0.5.47" 5 | 6 | override def dependencies = 7 | super.dependencies ++ 8 | Resolver( mavenCentral ).bind( 9 | ScalaDependency( "com.trueaccord.scalapb", "scalapbc", scalaPBVersion ) 10 | ) 11 | 12 | override def compile = { buildInfo; super.compile } 13 | 14 | def buildInfo = lib.writeIfChanged( 15 | projectDirectory / "src_generated/BuildInfo.scala", 16 | s"""// generated file 17 | package cbt.scalapb 18 | object BuildInfo{ 19 | def scalaPBVersion = "$scalaPBVersion" 20 | } 21 | """ 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/scalapb/src_generated/BuildInfo.scala: -------------------------------------------------------------------------------- 1 | // generated file 2 | package cbt.scalapb 3 | object BuildInfo{ 4 | def scalaPBVersion = "0.5.47" 5 | } 6 | -------------------------------------------------------------------------------- /plugins/scalariform/Scalariform.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import java.io.File 4 | import java.nio.file.FileSystems 5 | import java.nio.file.Files._ 6 | 7 | import scalariform.formatter.ScalaFormatter 8 | import scalariform.formatter.preferences.{ FormattingPreferences, Preserve } 9 | import scalariform.parser.ScalaParserException 10 | 11 | trait Scalariform extends BaseBuild { 12 | def scalariform = Scalariform.apply(lib, scalaVersion).config(sourceFiles.filter(_.string endsWith ".scala")) 13 | } 14 | 15 | object Scalariform{ 16 | val defaultPreferences: FormattingPreferences = { 17 | import scalariform.formatter.preferences._ 18 | FormattingPreferences() 19 | .setPreference(AlignParameters, true) 20 | .setPreference(AlignArguments, true) 21 | .setPreference(AlignSingleLineCaseStatements, true) 22 | .setPreference(MultilineScaladocCommentsStartOnFirstLine, true) 23 | .setPreference(SpaceInsideParentheses, true) 24 | .setPreference(SpacesWithinPatternBinders, true) 25 | .setPreference(SpacesAroundMultiImports, true) 26 | .setPreference(DoubleIndentClassDeclaration, false) 27 | //.setPreference(NewlineAtEndOfFile, true) 28 | .setPreference(DanglingCloseParenthesis, Preserve) 29 | .setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true) 30 | } 31 | 32 | case class apply( lib: Lib, scalaVersion: String ){ 33 | case class config( 34 | files: Seq[File], preferences: FormattingPreferences = Scalariform.defaultPreferences 35 | ) extends (() => Seq[File]){ 36 | def apply = { 37 | val (successes, errors) = lib.transformFilesOrError( files, in => 38 | try{ 39 | Right( ScalaFormatter.format( in, preferences, Some(scalaVersion) ) ) 40 | } catch { 41 | case e: ScalaParserException => Left( e ) 42 | } 43 | ) 44 | if(errors.nonEmpty) 45 | throw new RuntimeException( 46 | "Scalariform failed to parse some files:\n" ++ errors.map{ 47 | case (file, error) => file.string ++ ": " ++ error.getMessage 48 | }.mkString("\n"), 49 | errors.head._2 50 | ) 51 | successes 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /plugins/scalariform/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | override def dependencies = super.dependencies :+ /* ports.scalariform */Resolver( mavenCentral ).bindOne( 5 | ScalaDependency("org.scalariform", "scalariform", "0.1.8") 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /plugins/scalastyle/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | private val scalaStyleVersion = "0.8.0" 5 | 6 | override def dependencies = ( 7 | super.dependencies ++ 8 | Resolver( mavenCentral ).bind( 9 | ScalaDependency( "org.scalastyle", "scalastyle", scalaStyleVersion ) 10 | ) 11 | ) 12 | } 13 | -------------------------------------------------------------------------------- /plugins/sonatype-release/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin 4 | -------------------------------------------------------------------------------- /plugins/sonatype-release/src/SonatypeRelease.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | // TODO: maybe move this into stage2 to avoid having to call zinc separately for this as a plugin 3 | 4 | import cbt.sonatype.SonatypeLib 5 | 6 | /** 7 | * Sonatype release plugin. 8 | * It provides ability to release your artifacts to Sonatype OSSRH 9 | * and publish to Central repository (aka Maven Central). 10 | * 11 | * Release proccess is executed in two steps: 12 | * • `sonatypePublishSigned` 13 | * - creates staging repository to publish artifacts; 14 | * - publishes signed artifacts(jars) to staging repository. 15 | * • `sonatypeRelease` 16 | * - closes staging repository; 17 | * - promotes staging repository to Central repository; 18 | * - drops staging repository after release. 19 | */ 20 | trait SonatypeRelease extends Publish{ 21 | protected def sonatypeLib = SonatypeLib(groupId) 22 | 23 | def publishSonatype = sonatypeLib.publishSigned( publishedArtifacts, releaseFolder ) 24 | 25 | override def publish = super.publish ++ publishSonatype 26 | } 27 | -------------------------------------------------------------------------------- /plugins/sonatype-release/src/sonatype/HttpUtils.scala: -------------------------------------------------------------------------------- 1 | package cbt.sonatype 2 | 3 | import java.net.URL 4 | 5 | import cbt.Stage0Lib 6 | 7 | import scala.annotation.tailrec 8 | import scala.util.{ Failure, Success, Try } 9 | 10 | private[sonatype] object HttpUtils { 11 | // Make http GET. On failure request will be retried with exponential backoff. 12 | def GET(uri: String, headers: Map[String, String]): (Int, String) = 13 | withRetry(httpRequest("GET", uri, headers)) 14 | 15 | // Make http POST. On failure request will be retried with exponential backoff. 16 | def POST(uri: String, body: Array[Byte], headers: Map[String, String]): (Int, String) = 17 | withRetry(httpRequest("POST", uri, headers, body)) 18 | 19 | private def httpRequest(method: String, uri: String, headers: Map[String, String], body: Array[Byte] = Array.emptyByteArray): (Int, String) = { 20 | val conn = Stage0Lib.openConnectionConsideringProxy(new URL(uri)) 21 | conn.setReadTimeout(60000) // 1 minute 22 | conn.setConnectTimeout(30000) // 30 seconds 23 | 24 | (Map("User-Agent" -> "CBT build tool") ++ headers) foreach { case (k,v) => 25 | conn.setRequestProperty(k, v) 26 | } 27 | conn.setRequestMethod(method) 28 | if(method == "POST" || method == "PUT") { // PATCH too? 29 | conn.setDoOutput(true) 30 | conn.getOutputStream.write(body) 31 | } 32 | 33 | val arr = new Array[Byte](conn.getContentLength) 34 | conn.getInputStream.read(arr) 35 | 36 | conn.getResponseCode -> new String(arr) 37 | } 38 | 39 | // ============== General utilities 40 | 41 | def withRetry[T](f: => T): T = withRetry(4000, 5)(f) 42 | 43 | /** 44 | * Retry execution of `f` `retriesLeft` times 45 | * with `delay` doubled between attempts. 46 | */ 47 | @tailrec 48 | def withRetry[T](delay: Int, retriesLeft: Int)(f: ⇒ T): T = { 49 | Try(f) match { 50 | case Success(result) ⇒ 51 | result 52 | case Failure(e) ⇒ 53 | if (retriesLeft == 0) { 54 | throw new Exception(e) 55 | } else { 56 | val newDelay = delay * 2 57 | val newRetries = retriesLeft - 1 58 | // log(s"Failed with exception: $e, will retry $newRetries times; waiting: $delay") 59 | Thread.sleep(delay) 60 | 61 | withRetry(newDelay, newRetries)(f) 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /plugins/sonatype-release/src/sonatype/models.scala: -------------------------------------------------------------------------------- 1 | package cbt.sonatype 2 | 3 | case class StagingProfile( 4 | id: String, 5 | name: String, 6 | repositoryTargetId: String, 7 | resourceURI: String 8 | ) 9 | 10 | case class StagingRepositoryId( string: String ){ 11 | def repositoryId = string // deprecated 12 | } 13 | 14 | object RepositoryState { 15 | val fromString: String => RepositoryState = { 16 | case "open" => Open 17 | case "closed" => Closed 18 | case "released" => Released 19 | case other => Unknown(other) 20 | } 21 | } 22 | sealed trait RepositoryState 23 | case object Open extends RepositoryState 24 | case object Closed extends RepositoryState 25 | case object Released extends RepositoryState 26 | case class Unknown(state: String) extends RepositoryState 27 | 28 | case class StagingRepository( 29 | profileId: String, 30 | profileName: String, 31 | repositoryId: String, 32 | state: RepositoryState // stands as `type` in XML response 33 | ) 34 | -------------------------------------------------------------------------------- /plugins/uber-jar/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin 4 | -------------------------------------------------------------------------------- /plugins/wartremover/WartRemover.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import org.wartremover.WartTraverser 4 | import java.io.File 5 | 6 | trait WartRemover extends BaseBuild { 7 | 8 | override def scalacOptions = 9 | super.scalacOptions ++ wartremoverScalacOptions 10 | 11 | private[this] def wartremoverCompilerDependency: String = 12 | MavenResolver( 13 | context.cbtLastModified, 14 | context.paths.mavenCache, 15 | mavenCentral).bindOne( 16 | ScalaDependency("org.wartremover", "wartremover", "1.1.1") 17 | ).jar.string 18 | 19 | private[this] def wartremoverScalacOptions: Seq[String] = 20 | Seq("-Xplugin:" ++ wartremoverCompilerDependency) ++ 21 | wartremoverErrorsScalacOptions ++ 22 | wartremoverWarningsScalacOptions ++ 23 | wartremoverExcludedScalacOptions ++ 24 | wartremoverClasspathsScalacOptions 25 | 26 | private[this] def wartremoverErrorsScalacOptions: Seq[String] = 27 | wartremoverErrors.distinct.map(w => s"-P:wartremover:traverser:${w.className}") 28 | 29 | private[this] def wartremoverWarningsScalacOptions: Seq[String] = 30 | wartremoverWarnings.distinct 31 | .filterNot(wartremoverErrors contains _) 32 | .map(w => s"-P:wartremover:only-warn-traverser:${w.className}") 33 | 34 | private[this] def wartremoverExcludedScalacOptions: Seq[String] = 35 | wartremoverExcluded.distinct.map(c => s"-P:wartremover:excluded:${c.getAbsolutePath}") 36 | 37 | private[this] def wartremoverClasspathsScalacOptions: Seq[String] = 38 | wartremoverClasspaths.distinct.map(cp => s"-P:wartremover:cp:$cp") 39 | 40 | /** List of Warts that will be reported as compilation errors. */ 41 | def wartremoverErrors: Seq[WartTraverser] = Seq.empty 42 | 43 | /** List of Warts that will be reported as compilation warnings. */ 44 | def wartremoverWarnings: Seq[WartTraverser] = Seq.empty 45 | 46 | /** List of files to be excluded from all checks. */ 47 | def wartremoverExcluded: Seq[File] = Seq.empty 48 | 49 | /** List of classpaths for custom Warts. */ 50 | def wartremoverClasspaths: Seq[String] = Seq.empty 51 | } 52 | -------------------------------------------------------------------------------- /plugins/wartremover/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends Plugin { 4 | override def dependencies = 5 | super.dependencies ++ 6 | Resolver( mavenCentral ).bind( 7 | ScalaDependency("org.wartremover", "wartremover", "1.1.1") 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /ports/migration-manager/build/build.scala: -------------------------------------------------------------------------------- 1 | package migration_manager_build 2 | import cbt._ 3 | class Build(val context: Context) extends BaseBuild{ 4 | override def dependencies = 5 | Resolver( mavenCentral ).bind( 6 | MavenDependency( "org.scala-lang", "scala-compiler", scalaVersion ) 7 | ) 8 | def mima = GitDependency.checkout( 9 | "git@github.com:typesafehub/migration-manager.git", "92cbce52b4bf04ca1c338f34818ebfb9f0ebc285" 10 | ) 11 | override def generatedSources = Seq( mima / "core" ) 12 | } 13 | -------------------------------------------------------------------------------- /ports/scala-xray/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_ports.sxr 2 | import cbt._ 3 | import java.net._ 4 | import java.io._ 5 | class Build(val context: Context) extends PackageJars with AdvancedScala with CommandLineOverrides{ outer => 6 | override def defaultScalaVersion = "2.11.8" 7 | def groupId = "org.scala-sbt" 8 | 9 | private def gitHash = scalaVersion match { 10 | case "2.12.0" => "6484c9e90fae956044653e4dd764d8fdd15ccf99" 11 | case v if v.startsWith( "2.12" ) => "67261cdbcc27a1e044d7b280b2db0a02ba27add5" 12 | case v if v.startsWith( "2.11" ) => "cb66c7aaad618dc072d75f5899d9fdf3e8fde8d8" 13 | case v if v.startsWith( "2.10" ) => "1239fa39b5ee8c171af3f9df201497561d749826" 14 | case v => throw new Exception( "Unsupported scalaVersion: " + v ) 15 | } 16 | 17 | private def gitUrl = "https://github.com/cvogt/browse.git" 18 | 19 | def version = "rev-"+gitHash 20 | 21 | override def dependencies = Seq( libraries.scala.compiler ) 22 | lazy val github = GitDependency.checkout( gitUrl, gitHash ) 23 | override def sources = Seq( 24 | github / "src" / "main" / "scala" 25 | ) 26 | 27 | override def resourceClasspath = { 28 | val jquery_version = "1.3.2" 29 | val jquery_scrollto_version = "1.4.2" 30 | val jquery_qtip_version = "2.1.1" 31 | 32 | val resourcesManaged = github / "target" / "resources_managed" 33 | lib.write( 34 | resourcesManaged / "jquery-all.js", 35 | Seq( 36 | "https://code.jquery.com/jquery-" ~ jquery_version ~ ".min.js", 37 | "http://cdn.jsdelivr.net/jquery.scrollto/" ~ jquery_scrollto_version ~ "/jquery.scrollTo.min.js", 38 | "http://qtip2.com/v/" ~ jquery_qtip_version ~ "/jquery.qtip.min.js" 39 | ).map{ s => 40 | val url = new URL( s ) 41 | val file = resourcesManaged / new File( url.getPath ).getName 42 | lib.download( url, file, None ) 43 | file.readAsString 44 | }.mkString("\n") 45 | ) 46 | 47 | ClassPath( 48 | Seq( 49 | github / "src" / "main" / "resources", 50 | resourcesManaged 51 | ) 52 | ) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ports/scalariform/build/build.scala: -------------------------------------------------------------------------------- 1 | package migration_manager_build 2 | import cbt._ 3 | class Build(val context: Context) extends AdvancedScala{ outer => 4 | override def dependencies = Seq( libraries.scala.xml, libraries.scala.parserCombinators ) 5 | 6 | val scalariform = GitDependency.checkout( 7 | "https://github.com/scala-ide/scalariform.git", "f53978c60579fa834ac9e56986a6133c0a621bfd" 8 | ) 9 | 10 | override def sources = Seq( 11 | scalariform / "scalariform" / "src" / "main" / "scala" / "scalariform" 12 | ) 13 | 14 | override def scalacOptions = super.scalacOptions ++ Seq( 15 | "-language:implicitConversions", "-language:reflectiveCalls" 16 | ) 17 | 18 | override def test = new BasicBuild( context ) with ScalaTest{ 19 | override def target = outer.target / "test" 20 | override def dependencies = super.dependencies :+ outer 21 | override def scalacOptions = outer.scalacOptions 22 | override def sources = Seq( 23 | scalariform / "scalariform" / "src" / "test" / "scala" / "scalariform" 24 | ) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /realpath/realpath.c: -------------------------------------------------------------------------------- 1 | // http://stackoverflow.com/questions/284662/how-do-you-normalize-a-file-path-in-bash 2 | // realpath.c: display the absolute path to a file or directory. 3 | // Adam Liss, August, 2007 4 | // This program is provided "as-is" to the public domain, without express or 5 | // implied warranty, for any non-profit use, provided this notice is maintained. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static char *s_pMyName; 14 | void usage(void); 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | char 19 | sPath[PATH_MAX]; 20 | 21 | 22 | s_pMyName = strdup(basename(argv[0])); 23 | 24 | if (argc < 2) 25 | usage(); 26 | 27 | printf("%s\n", realpath(argv[1], sPath)); 28 | return 0; 29 | } 30 | 31 | void usage(void) 32 | { 33 | fprintf(stderr, "usage: %s PATH\n", s_pMyName); 34 | exit(1); 35 | } -------------------------------------------------------------------------------- /realpath/realpath.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # is there a realiable cross-platform was to do this without relying on compiling C code? 4 | 5 | DIR=$(dirname $(readlink "$0") 2>/dev/null || dirname "$0" 2>/dev/null ) 6 | which realpath 2>&1 > /dev/null 7 | REALPATH_INSTALLED=$? 8 | 9 | if [ ! $REALPATH_INSTALLED -eq 0 ]; then 10 | if [ ! -f $DIR/realpath ]; then 11 | >&2 echo "Compiling realpath" 12 | gcc $DIR/realpath.c -o $DIR/realpath 13 | chmod u+x $DIR/realpath 14 | fi 15 | $DIR/realpath $1 16 | else 17 | realpath $1 18 | fi 19 | -------------------------------------------------------------------------------- /shell-integration/cbt-completions.bash: -------------------------------------------------------------------------------- 1 | # this does currently not support for completion of nested methods, e.g. snapshot.comp 2 | # bash 4 should be able to do that via $READLINE_LINE and $READLINE_POINT, see 3 | # http://unix.stackexchange.com/questions/106761/simulating-readline-line-in-bash-4-0/106832 4 | __cbt() 5 | { 6 | local cur prev opts 7 | COMPREPLY=() 8 | cur="${COMP_WORDS[COMP_CWORD]}" 9 | prev="${COMP_WORDS[COMP_CWORD-1]}" 10 | opts="$(cbt complete)" 11 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 12 | return 0 13 | } 14 | 15 | complete -F __cbt cbt 16 | -------------------------------------------------------------------------------- /shell-integration/cbt-completions.fish: -------------------------------------------------------------------------------- 1 | complete --command cbt --no-files -a '(cbt complete (commandline --current-buffer) (commandline --cursor))' #|fzf --height 90% --reverse)' 2 | -------------------------------------------------------------------------------- /shell-integration/cbt-completions.zsh: -------------------------------------------------------------------------------- 1 | # this does currently not support for completion of nested methods, e.g. snapshot.comp 2 | # zsh should be able to do that via $BUFFER, see 3 | # http://unix.stackexchange.com/questions/14230/zsh-tab-completion-on-empty-line 4 | 5 | _cbt() { 6 | reply=( "${(ps:\n:)$(cbt complete)}" ) 7 | } 8 | 9 | compctl -K _cbt cbt 10 | -------------------------------------------------------------------------------- /stage1/CachingClassLoader.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.net._ 3 | import java.util.concurrent.ConcurrentHashMap 4 | import scala.util.Try 5 | 6 | trait CachingClassLoader extends ClassLoader{ 7 | def logger: Logger 8 | val cache = new KeyLockedLazyCache[Option[Class[_]]]( new ConcurrentHashMap[AnyRef,AnyRef], Some(logger) ) 9 | override def loadClass(name: String, resolve: Boolean) = { 10 | cache.get( name, Try(super.loadClass(name, resolve)).toOption ).getOrElse(null) 11 | } 12 | override def loadClass(name: String) = { 13 | val _class = super.loadClass(name) 14 | if(_class == null) throw new ClassNotFoundException(name) 15 | else _class 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /stage1/CbtPaths.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | case class CbtPaths(private val cbtHome: File, private val cache: File){ 4 | val fSep = File.separator 5 | val userHome: File = new File(Option(System.getProperty("user.home")).get) 6 | val nailgun: File = cbtHome ++ (fSep+"nailgun_launcher") 7 | val stage1: File = cbtHome ++ (fSep+"stage1") 8 | val stage2: File = cbtHome ++ (fSep+"stage2") 9 | val mavenCache: File = cache ++ (fSep+"maven") 10 | private val target = NailgunLauncher.TARGET.stripSuffix(fSep) 11 | val stage1Target: File = stage1 ++ (fSep ++ target) 12 | val stage2Target: File = stage2 ++ (fSep ++ target) 13 | val stage1StatusFile: File = stage1Target ++ ".last-success" 14 | val stage2StatusFile: File = stage2Target ++ ".last-success" 15 | val compatibility: File = cbtHome ++ (fSep+"compatibility") 16 | val nailgunTarget: File = nailgun ++ (fSep ++ target) 17 | val nailgunStatusFile: File = nailgunTarget ++ ".last-success" 18 | } 19 | -------------------------------------------------------------------------------- /stage1/ClassPath.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | import java.net._ 4 | 5 | object ClassPath{ 6 | def flatten( classPaths: Seq[ClassPath] ): ClassPath = ClassPath( classPaths.map(_.files).flatten ) 7 | } 8 | case class ClassPath(files: Seq[File] = Seq()){ 9 | private val duplicates = (files diff files.distinct).distinct 10 | assert( 11 | duplicates.isEmpty, 12 | "Duplicate classpath entries found:\n" ++ duplicates.mkString("\n") ++ "\nin classpath:\n"++string 13 | ) 14 | private val nonExisting = files.distinct.filterNot(_.exists) 15 | assert( 16 | nonExisting.isEmpty, 17 | "Classpath contains entires that don't exist on disk:\n" ++ nonExisting.mkString("\n") ++ "\nin classpath:\n"++string 18 | ) 19 | 20 | def +:(file: File) = ClassPath(file +: files) 21 | def :+(file: File) = ClassPath(files :+ file) 22 | def ++(other: ClassPath) = ClassPath(files ++ other.files) 23 | def string = strings.mkString( File.pathSeparator ) 24 | def strings = files.map{ 25 | f => f.string + ( 26 | // using file extension instead of isDirectory for performance reasons 27 | if( f.getName.endsWith(".jar") /* !f.isDirectory */ ) "" else File.separator 28 | ) 29 | }.sorted 30 | 31 | def verify( lib: Stage1Lib ) = { 32 | val ( directories, jarFiles ) = files.partition(_.isDirectory) 33 | val all = lib.autoRelative( 34 | directories 35 | ) ++ jarFiles.flatMap{ f => 36 | import collection.JavaConverters._ 37 | new java.util.jar.JarFile(f).entries.asScala.filterNot(_.isDirectory).toVector.map( 38 | f -> _.toString 39 | ) 40 | } 41 | val duplicates = 42 | all 43 | .groupBy( _._2 ) 44 | .filter( _._2.size > 1 ) 45 | .filter( _._1 endsWith ".class" ) 46 | .mapValues( _.map( _._1 ) ) 47 | .toSeq 48 | .sortBy( _._1 ) 49 | assert( 50 | duplicates.isEmpty, 51 | { 52 | "Conflicting:\n\n" + 53 | duplicates.map{ 54 | case ( path, locations ) => 55 | path + " exits in multiple locations:\n" + locations.mkString("\n") 56 | }.mkString("\n\n") 57 | } 58 | ) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /stage1/ContextImplementation.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | 4 | class ContextImplementation( 5 | override val workingDirectory: File, 6 | override val cwd: File, 7 | override val argsArray: Array[String], 8 | override val enabledLoggersArray: Array[String], 9 | override val start: Long, 10 | override val cbtLastModified: Long, 11 | override val scalaVersionOrNull: String, 12 | override val persistentCache: java.util.Map[AnyRef,AnyRef], 13 | override val transientCache: java.util.Map[AnyRef,AnyRef], 14 | override val cache: File, 15 | override val cbtHome: File, 16 | override val cbtRootHome: File, 17 | override val compatibilityTarget: File, 18 | override val parentBuildOrNull: BuildInterface, 19 | override val loop: Boolean 20 | ) extends Context{ 21 | @deprecated("this method is replaced by workingDirectory","") 22 | def projectDirectory = workingDirectory 23 | @deprecated("this method is replaced by cbtLastModified","") 24 | def cbtHasChangedCompat = true 25 | @deprecated("this method is replaced by start","") 26 | def startCompat = start 27 | @deprecated("this methods is replaced by persistentCache","") 28 | def permanentKeys = throw new IncompatibleCbtVersionException("You need to upgrade your CBT version in this module. The Context field permanentKeys is no longer supported."); 29 | @deprecated("this methods is replaced by persistentCache","") 30 | def permanentClassLoaders = throw new IncompatibleCbtVersionException("You need to upgrade your CBT version in this module. The Context field permanentClassLoaders is no longer supported."); 31 | } 32 | -------------------------------------------------------------------------------- /stage1/KeyLockedLazyCache.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | private[cbt] class LockableKey 4 | /** 5 | A hashMap that lazily computes values if needed during lookup. 6 | Locking occurs on the key, so separate keys can be looked up 7 | simultaneously without a deadlock. 8 | */ 9 | final private[cbt] class KeyLockedLazyCache[T <: AnyRef]( 10 | val hashMap: java.util.Map[AnyRef,AnyRef], 11 | logger: Option[Logger] 12 | ){ 13 | final val seen = new ThreadLocal[collection.mutable.Set[AnyRef]](){ 14 | override protected def initialValue = collection.mutable.Set[AnyRef](); 15 | } 16 | def get( key: AnyRef, value: => T ): T = { 17 | seen.get.add( key ); 18 | val lockableKey = hashMap.synchronized{ 19 | if( ! (hashMap containsKey key) ){ 20 | val lockableKey = new LockableKey 21 | //logger.foreach(_.resolver("CACHE MISS: " ++ key.toString)) 22 | hashMap.put( key, lockableKey ) 23 | lockableKey 24 | } else { 25 | val lockableKey = hashMap get key 26 | //logger.foreach(_.resolver("CACHE HIT: " ++ lockableKey.toString ++ " -> " ++ key.toString)) 27 | lockableKey 28 | } 29 | } 30 | import collection.JavaConversions._ 31 | //logger.resolver("CACHE: \n" ++ hashMap.mkString("\n")) 32 | // synchronizing on key only, so asking for a particular key does 33 | // not block the whole hashMap, but just that hashMap entry 34 | lockableKey.synchronized{ 35 | if( ! (hashMap containsKey lockableKey) ){ 36 | hashMap.put( lockableKey, value ) 37 | } 38 | (hashMap get lockableKey).asInstanceOf[T] 39 | } 40 | } 41 | def update( key: AnyRef, value: T ): T = { 42 | assert( 43 | !seen.get.contains( key ), 44 | "Thread tries to update cache key after observing it: " + key 45 | ) 46 | val lockableKey = hashMap get key 47 | lockableKey.synchronized{ 48 | hashMap.put( lockableKey, value ) 49 | value 50 | } 51 | } 52 | def remove( key: AnyRef ) = hashMap.synchronized{ 53 | assert(hashMap containsKey key) 54 | val lockableKey = hashMap get key 55 | lockableKey.synchronized{ 56 | if(hashMap containsKey lockableKey){ 57 | // this is so hashMap in the process of being replaced (which mean they have a key but no value) 58 | // are not being removed 59 | hashMap.remove( key ) 60 | hashMap.remove( lockableKey ) 61 | } 62 | } 63 | } 64 | def containsKey( key: AnyRef ) = hashMap.synchronized{ 65 | hashMap containsKey key 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /stage1/MavenRepository.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | import java.net._ 4 | case class MavenResolver( 5 | cbtLastModified: Long, mavenCache: File, urls: URL* 6 | )( 7 | implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache 8 | ){ 9 | def bind( dependencies: MavenDependency* ): Seq[BoundMavenDependency] 10 | = dependencies.map( BoundMavenDependency(cbtLastModified,mavenCache,_,urls.toVector) ).toVector 11 | def bindOne( dependency: MavenDependency ): BoundMavenDependency 12 | = BoundMavenDependency( cbtLastModified, mavenCache, dependency, urls.toVector ) 13 | } 14 | -------------------------------------------------------------------------------- /stage1/MultiClassLoader.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.net._ 3 | import scala.collection.JavaConverters._ 4 | 5 | // do not make this a case class, required object identity equality 6 | class MultiClassLoader(final val parents: Seq[ClassLoader])(implicit val logger: Logger) extends ClassLoader(null) with CachingClassLoader{ 7 | override def findClass(name: String) = { 8 | parents.find( parent => 9 | try{ 10 | null != parent.loadClass(name) // FIXME: is it correct to just ignore the resolve argument here? 11 | } catch { 12 | case _:ClassNotFoundException => false 13 | } 14 | ).map( 15 | _.loadClass(name) 16 | ).getOrElse( null ) 17 | } 18 | 19 | // FIXME: is there more than findClass and findResource that needs to be dispatched? 20 | override def findResource(name: String): URL = { 21 | parents.foldLeft(null: URL)( 22 | (acc, parent) => if( acc == null ) parent.getResource(name) else acc 23 | ) 24 | } 25 | override def findResources(name: String): java.util.Enumeration[URL] = { 26 | java.util.Collections.enumeration( 27 | parents.flatMap( _.getResources(name).asScala ).asJava 28 | ) 29 | } 30 | 31 | override def toString = ( 32 | scala.Console.BLUE 33 | ++ super.toString 34 | ++ scala.Console.RESET 35 | ++ "(" 36 | ++ ( 37 | if(parents.nonEmpty)( 38 | "\n" ++ parents.map(_.toString).mkString(",\n").split("\n").map(" "++_).mkString("\n") ++ "\n" 39 | ) else "" 40 | ) ++")" 41 | ) 42 | } 43 | -------------------------------------------------------------------------------- /stage1/PoorMansProfiler.scala: -------------------------------------------------------------------------------- 1 | /* 2 | // temporary debugging tool 3 | package cbt 4 | import java.util._ 5 | import collection.JavaConversions._ 6 | object PoorMansProfiler{ 7 | val entries = new HashMap[String, Long] 8 | def profile[T](name: String)(code: => T): T = { 9 | val before = System.currentTimeMillis 10 | if(!(entries containsKey name)){ 11 | entries.put( name, 0 ) 12 | } 13 | val res = code 14 | entries.put( name, (entries get name) + (System.currentTimeMillis - before) ) 15 | res 16 | } 17 | def summary: String = { 18 | "Profiling Summary:\n" + entries.toSeq.sortBy(_._2).map{ 19 | case (name, value) => name + ": " + (value / 1000.0) 20 | }.mkString("\n") 21 | } 22 | } 23 | */ -------------------------------------------------------------------------------- /stage1/URLClassLoader.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import java.net._ 4 | import scala.util.Try 5 | 6 | case class URLClassLoader( classPath: ClassPath, parent: ClassLoader )( implicit val logger: Logger ) 7 | extends java.net.URLClassLoader( 8 | classPath.strings.map( p => new URL("file:" ++ p) ).toArray, 9 | parent 10 | ) with CachingClassLoader{ 11 | override def loadClass(name: String) = { 12 | logger.log("classloader","loadClass " + name) 13 | super.loadClass(name) 14 | } 15 | val id = Math.abs( new java.util.Random().nextInt ) 16 | override def toString = ( 17 | scala.Console.BLUE 18 | ++ getClass.getSimpleName ++ ":" ++ id.toString 19 | ++ scala.Console.RESET 20 | ++ "(\n" 21 | ++ ( 22 | getURLs.map(_.toString).sorted.mkString(",\n") 23 | ++ ( 24 | if(getParent() != ClassLoader.getSystemClassLoader().getParent()) 25 | ",\n" ++ Option(getParent()).map(_.toString).getOrElse("null") 26 | else "" 27 | ) 28 | ).split("\n").map(" "++_).mkString("\n") 29 | ++ "\n)" 30 | ) 31 | } 32 | 33 | /* 34 | trait ClassLoaderLogging extends ClassLoader{ 35 | def logger: Logger 36 | val prefix = s"[${getClass.getSimpleName}] " 37 | val postfix = " in \name" ++ this.toString 38 | override def loadClass(name: String, resolve: Boolean): Class[_] = { 39 | //logger.resolver(prefix ++ s"loadClass($name, $resolve)" ++ postfix ) 40 | super.loadClass(name, resolve) 41 | } 42 | override def loadClass(name: String): Class[_] = { 43 | //logger.resolver(prefix ++ s"loadClass($name)" ++ postfix ) 44 | super.loadClass(name) 45 | } 46 | override def findClass(name: String): Class[_] = { 47 | //logger.resolver(prefix ++ s"findClass($name)" ++ postfix ) 48 | super.findClass(name) 49 | } 50 | } 51 | */ 52 | -------------------------------------------------------------------------------- /stage1/constants.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | object constants{ 3 | val scalaXmlVersion = EarlyDependencies.scalaXmlVersion 4 | val scalaVersion = EarlyDependencies.scalaVersion 5 | val zincVersion = EarlyDependencies.zincVersion 6 | val scalaMajorVersion = scalaVersion.split("\\.").take(2).mkString(".") 7 | } 8 | -------------------------------------------------------------------------------- /stage1/logger.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | /** 4 | * This represents a logger with namespaces that can be enabled or disabled as needed. The 5 | * namespaces are defined using {{enabledLoggers}}. Possible values are defined in the subobject 6 | * "names". 7 | * 8 | * We can replace this with something more sophisticated eventually. 9 | */ 10 | case class Logger(enabledLoggers: Set[String], start: Long) { 11 | def this(enabledLoggers: Option[String], start: Long) = { 12 | this( 13 | enabledLoggers.toVector.flatMap( _.split(",") ).toSet, 14 | start 15 | ) 16 | } 17 | 18 | val disabledLoggers: Set[String] = enabledLoggers.filter(_.startsWith("-")).map(_.drop(1)) 19 | 20 | def log(name: String, msg: => String) = { 21 | if( 22 | ( 23 | (enabledLoggers contains name) 24 | || (enabledLoggers contains "all") 25 | ) && !(disabledLoggers contains name) 26 | ){ 27 | logUnguarded(name, msg) 28 | } 29 | } 30 | 31 | def showInvocation(method: String, args: Any) = method ++ "( " ++ args.toString ++ " )" 32 | 33 | final def stage1(msg: => String) = log(names.stage1, msg) 34 | final def stage2(msg: => String) = log(names.stage2, msg) 35 | final def loop(msg: => String) = log(names.loop, msg) 36 | final def task(msg: => String) = log(names.task, msg) 37 | final def composition(msg: => String) = log(names.composition, msg) 38 | final def resolver(msg: => String) = log(names.resolver, msg) 39 | final def lib(msg: => String) = log(names.lib, msg) 40 | final def test(msg: => String) = log(names.test, msg) 41 | final def git(msg: => String) = log(names.git, msg) 42 | final def pom(msg: => String) = log(names.pom, msg) 43 | final def dynamic(msg: => String) = log(names.dynamic, msg) 44 | final def run(msg: => String) = log(names.run, msg) 45 | final def transientCache(msg: => String) = log(names.transientCache, msg) 46 | 47 | private object names{ 48 | val stage1 = "stage1" 49 | val stage2 = "stage2" 50 | val loop = "loop" 51 | val task = "task" 52 | val resolver = "resolver" 53 | val composition = "composition" 54 | val lib = "lib" 55 | val test = "test" 56 | val pom = "pom" 57 | val run = "run" 58 | val git = "git" 59 | val dynamic = "dynamic" 60 | val transientCache = "transientCache" 61 | } 62 | 63 | private def logUnguarded(name: String, msg: => String) = { 64 | val timeTaken = ((System.currentTimeMillis.toDouble - start) / 1000).toString 65 | System.err.println( s"[$timeTaken][$name] $msg" ) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /stage2/BuildBuild.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.nio.file._ 3 | import java.io.File 4 | 5 | class ConcreteBuildBuild(val context: Context) extends BuildBuild 6 | 7 | trait BuildBuild extends BaseBuild{ 8 | override def dependencies = super.dependencies :+ context.cbtDependency 9 | 10 | object plugins extends plugins( context, scalaVersion ) 11 | 12 | /** CBT relies on hierarchical classloaders */ 13 | final override def flatClassLoader = false 14 | 15 | assert( 16 | projectDirectory.getName === lib.buildDirectoryName, 17 | s"You can't extend ${lib.buildBuildClassName} in: " + projectDirectory + "/" + lib.buildDirectoryName 18 | ) 19 | } 20 | 21 | trait CbtInternal extends BaseBuild{ 22 | protected object cbtInternal{ 23 | def shared = DirectoryDependency(context.cbtHome / "/internal/plugins/shared") 24 | def library = DirectoryDependency(context.cbtHome / "/internal/plugins/library") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /stage2/LazyDependency.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | class LazyDependency( _dependency: => Dependency )( implicit logger: Logger, transientCache: java.util.Map[AnyRef, AnyRef], classLoaderCache: ClassLoaderCache ) extends Dependency { 3 | lazy val dependency = _dependency 4 | override def classLoader = dependency.classLoader 5 | def dependenciesArray = Array( dependency ) 6 | def exportedClasspathArray = Array() 7 | override def lastModified = dependency.lastModified 8 | override lazy val moduleKey = show 9 | def show = s"LazyDependency(${dependency.show})" 10 | override def toString = show 11 | override def equals( other: Any ) = other match { 12 | case d: LazyDependency => d.dependency === dependency 13 | case _ => false 14 | } 15 | def dependencyClasspathArray = dependency.classpath.files.toArray 16 | def needsUpdateCompat = false 17 | } 18 | -------------------------------------------------------------------------------- /stage2/PackageJars.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | 4 | // would love to call this just `Package` but that conflicts with scala package objects. 5 | trait PackageJars extends BaseBuild with ArtifactInfo{ 6 | def name: String 7 | def artifactId = name 8 | def version: String 9 | def `package`: Seq[File] = lib.concurrently( enableConcurrency )( 10 | Seq(() => jar, () => docJar, () => srcJar) 11 | )( _() ).flatten 12 | 13 | def jarFilePrefix = artifactId++"_"++scalaMajorVersion++"-"++version 14 | 15 | def jar: Option[File] = taskCache[PackageJars]("jar").memoize{ 16 | val file = jarTarget / jarFilePrefix++".jar" 17 | if( file.lastModified < lastModified ) 18 | lib.createJar( file, exportedClasspath.files ) 19 | else Some( file ) 20 | } 21 | 22 | def srcJar: Option[File] = taskCache[PackageJars]("srcJar").memoize{ 23 | val file = jarTarget / jarFilePrefix++"-sources.jar" 24 | if( file.lastModified < lastModified ) 25 | lib.createJar( file, nonEmptySourceFiles ) 26 | else Some( file ) 27 | } 28 | 29 | def docJar: Option[File] = taskCache[PackageJars]("docJar").memoize{ 30 | val file = jarTarget / jarFilePrefix++"-javadoc.jar" 31 | if( file.lastModified < lastModified ) 32 | lib.createJar( file, scaladoc.toSeq ) 33 | else Some( file ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /stage2/Plugin.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait Plugin extends BaseBuild{ 3 | override def dependencies = super.dependencies :+ context.cbtDependency 4 | object plugins extends plugins( context, scalaVersion ) 5 | 6 | /** CBT relies on hierarchical classloaders */ 7 | final override def flatClassLoader = false 8 | } 9 | -------------------------------------------------------------------------------- /stage2/Publish.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | import java.net.URL 4 | import java.nio.file.Files.readAllBytes 5 | 6 | trait Publish extends PublishLocal // FIXME: delete 7 | trait PublishLocal extends PackageJars{ 8 | def description: String 9 | def url: URL 10 | def developers: Seq[Developer] 11 | def licenses: Seq[License] 12 | def scmUrl: String 13 | def scmConnection: String 14 | def inceptionYear: Int 15 | def organization: Option[Organization] 16 | 17 | // ========== publish ========== 18 | protected def releaseFolder = s"/${groupId.replace(".","/")}/${artifactId}_$scalaMajorVersion/$version" 19 | 20 | def publishedArtifacts = `package` :+ pom 21 | 22 | def publishLocal: Unit = lib.publishLocal( 23 | publishedArtifacts, context.paths.mavenCache, releaseFolder 24 | ) 25 | // ========== package ========== 26 | 27 | /** put additional xml that should go into the POM file in here */ 28 | def pom: File = lib.pom( 29 | groupId = groupId, 30 | artifactId = artifactId, 31 | version = version, 32 | scalaMajorVersion = scalaMajorVersion, 33 | name = name, 34 | description = description, 35 | url = url, 36 | developers = developers, 37 | licenses = licenses, 38 | scmUrl = scmUrl, 39 | scmConnection = scmConnection, 40 | inceptionYear, 41 | organization, 42 | dependencies = dependencies, 43 | jarTarget = jarTarget 44 | ) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /stage2/SbtDependencyDsl.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait SbtDependencyDsl{ self: BaseBuild => 3 | /** SBT-like dependency builder DSL for syntax compatibility */ 4 | class DependencyBuilder2( groupId: String, artifactId: String, scalaVersion: Option[String] ){ 5 | def %(version: String) = scalaVersion.map( 6 | v => ScalaDependency(groupId, artifactId, version, scalaVersion = v) 7 | ).getOrElse( 8 | MavenDependency(groupId, artifactId, version) 9 | ) 10 | } 11 | implicit class DependencyBuilder(groupId: String){ 12 | def %%(artifactId: String) = new DependencyBuilder2( groupId, artifactId, Some(scalaMajorVersion) ) 13 | def %(artifactId: String) = new DependencyBuilder2( groupId, artifactId, None ) 14 | } 15 | } -------------------------------------------------------------------------------- /stage2/Stage2.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | import java.util.{Set=>_,_} 4 | 5 | object Stage2 extends Stage2Base{ 6 | def getBuild(context: Context): Dependency = DirectoryDependency( context, None ) 7 | 8 | def run( args: Stage2Args ): ExitCode = { 9 | import args.logger 10 | val paths = CbtPaths(args.cbtHome,args.cache) 11 | import paths._ 12 | val lib = new Lib(args.logger) 13 | logger.stage2(s"Stage2 start") 14 | 15 | val task = args.args.lift( 0 ) 16 | 17 | import scala.collection.JavaConverters._ 18 | val context: Context = new ContextImplementation( 19 | args.cwd, 20 | args.cwd, 21 | args.args.drop( 1 ).toArray, 22 | logger.enabledLoggers.toArray, 23 | logger.start, 24 | args.stage2LastModified, 25 | null, 26 | args.classLoaderCache.hashMap, 27 | args.transientCache, 28 | args.cache, 29 | args.cbtHome, 30 | args.cbtHome, 31 | args.compatibilityTarget, 32 | null, 33 | args.loop 34 | ) 35 | val code = lib.callReflective( 36 | DirectoryDependency( context, None ), 37 | task, context 38 | ) 39 | logger.stage2(s"Stage2 end with exit code "+code.integer) 40 | code 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /stage2/ToolsStage2.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io._ 3 | object ToolsStage2 extends Stage2Base{ 4 | def run( _args: Stage2Args ): ExitCode = { 5 | val args = _args.args.dropWhile(Seq("tools") contains _) 6 | val lib = new Lib(_args.logger) 7 | val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.cache, _args.cbtHome, _args.stage2LastModified)(_args.classLoaderCache) 8 | lib.callReflective(toolsTasks, args.lift(0), null) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /stage2/libraries.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | class libraries( context: Context, scalaVersion: String, scalaMajorVersion: String ) { 3 | private def dep( name: String ) = DirectoryDependency( 4 | context.copy( 5 | scalaVersion = Some( scalaVersion ), 6 | workingDirectory = context.cbtHome / "libraries" / name 7 | ), 8 | None 9 | ) 10 | object cbt { 11 | def captureArgs = dep( "capture_args" ) 12 | def common_0 = dep( "common-0" ) 13 | def common_1 = dep( "common-1" ) 14 | def eval = dep( "eval" ) 15 | def file = dep( "file" ) 16 | def interfaces = dep( "interfaces" ) 17 | def process = dep( "process" ) 18 | def proguard = dep( "proguard" ) 19 | def reflect = dep( "reflect" ) 20 | def scalatestRunner = dep( "scalatest-runner" ) 21 | def scalatex = dep( "scalatex" ) 22 | } 23 | object scala { 24 | private def _maven = ( g: String, a: String, v: String ) => { 25 | MavenResolver( 26 | context.cbtLastModified, context.paths.mavenCache, mavenCentral 27 | )( 28 | context.logger, context.transientCache, context.classLoaderCache 29 | ) bindOne MavenDependency( g, a, v ) 30 | } 31 | 32 | def compiler = _maven( "org.scala-lang", "scala-compiler", scalaVersion ) 33 | def library = _maven( "org.scala-lang", "scala-library", scalaVersion ) 34 | def reflect = _maven( "org.scala-lang", "scala-reflect", scalaVersion ) 35 | 36 | def parserCombinators = _maven( "org.scala-lang.modules", "scala-parser-combinators_" ++ scalaMajorVersion, "1.0.5" ) 37 | def xml = _maven( "org.scala-lang.modules", "scala-xml_" ++ scalaMajorVersion, "1.0.6" ) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /stage2/plugins.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | class plugins( context: Context, scalaVersion: String ) { 3 | private def plugin( name: String ) = DirectoryDependency( 4 | context.copy( 5 | scalaVersion = Some( scalaVersion ), 6 | workingDirectory = context.cbtHome / "plugins" / name 7 | ), 8 | None 9 | ) 10 | final lazy val googleJavaFormat = plugin( "google-java-format" ) 11 | final lazy val proguard = plugin( "proguard" ) 12 | final lazy val sbtLayout = plugin( "sbt_layout" ) 13 | final lazy val scalafix = plugin( "scalafix" ) 14 | final lazy val scalafixCompilerPlugin = plugin( "scalafix-compiler-plugin" ) 15 | final lazy val scalafmt = plugin( "scalafmt" ) 16 | final lazy val scalaJs = plugin( "scalajs" ) 17 | final lazy val scalapb = plugin( "scalapb" ) 18 | final lazy val scalariform = plugin( "scalariform" ) 19 | final lazy val scalastyle = plugin( "scalastyle" ) 20 | final lazy val sonatypeRelease = plugin( "sonatype-release" ) 21 | final lazy val uberJar = plugin( "uber-jar" ) 22 | final lazy val wartremover = plugin( "wartremover" ) 23 | } 24 | -------------------------------------------------------------------------------- /stage2/plugins/AdvancedFlags.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait AdvancedScala extends BaseBuild{ 3 | override def scalacOptions = super.scalacOptions ++ Seq( 4 | "-language:postfixOps", 5 | "-language:implicitConversions", 6 | "-language:higherKinds", 7 | "-language:existentials", 8 | "-language:experimental.macros" 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /stage2/plugins/CommandLineOverrides.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait CommandLineOverrides extends DynamicOverrides{ 3 | def `with`: Any = { 4 | lib.callReflective( 5 | newBuild[DynamicOverrides]( 6 | context.copy( 7 | args = context.args.drop(2) 8 | ) 9 | )( s""" 10 | ${context.args.lift(0).getOrElse("")} 11 | """ ), 12 | context.args.lift(1) orElse Some("void"), 13 | context 14 | ) 15 | } 16 | def eval = { 17 | lib.callReflective( 18 | newBuild[CommandLineOverrides]( 19 | context.copy( 20 | args = ( context.args.lift(0).map("println{ "+_+" }") ).toSeq 21 | ) 22 | ){""}, 23 | Some("with"), 24 | context 25 | ) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /stage2/plugins/GenerateBuildInfo.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | trait GenerateBuildInfo extends BaseBuild{ 4 | override def compile = { buildInfo.apply; super.compile } 5 | def buildInfo = GenerateBuildInfo.apply( lib ).config( 6 | s""" 7 | def scalaVersion = "$scalaVersion" 8 | """, 9 | None, 10 | "BuildInfo", 11 | projectDirectory / "src_generated" 12 | ) 13 | } 14 | object GenerateBuildInfo{ 15 | case class apply( lib: Lib ){ 16 | case class config( body: String, `package`: Option[String], className: String, file: File ){ 17 | def apply = { 18 | lib.writeIfChanged( 19 | file / className ++ ".scala", 20 | s"""// generated file${`package`.map("\npackage "++_++"").getOrElse("")} 21 | object $className{ 22 | $body 23 | } 24 | """ 25 | ) 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /stage2/plugins/GeneratedSections.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.nio.file.Files._ 3 | object replaceSections{ 4 | def apply( 5 | subject: String, 6 | sections: Seq[(String, String)], 7 | generatedSectionBeginMarker: String => String = name => s"AUTO GENERATED SECTION BEGIN: $name ", 8 | generatedSectionEndMarker: String => String = name => s"AUTO GENERATED SECTION END: $name " 9 | ): String = { 10 | assert( 11 | generatedSectionBeginMarker("foo").endsWith(" "), 12 | "generatedSectionStartMarker needs to end with a space character" 13 | ) 14 | assert( 15 | generatedSectionEndMarker("foo").endsWith(" "), 16 | "generatedSectionEndMarker needs to end with a space character" 17 | ) 18 | sections.headOption.map{ 19 | case (name, replacement) => 20 | replaceSections( 21 | s"(?s)(\n[^\n]*AUTO GENERATED SECTION BEGIN: $name [^\n]*\n).*(\n[^\n]*AUTO GENERATED SECTION END: $name [^\n]*\n)" 22 | .r.replaceAllIn( subject, m => m.group(1) ++ replacement ++ m.group(2) ), 23 | sections.tail 24 | ) 25 | }.getOrElse(subject) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /stage2/plugins/GithubPom.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.net.URL 3 | trait GithubPom extends Publish{ 4 | def user: String 5 | def githubProject = name 6 | def githubUser = user 7 | final def githubUserProject = githubUser ++ "/" ++ githubProject 8 | override def url = new URL(s"http://github.com/$githubUserProject") 9 | override def scmUrl = s"git@github.com:$githubUserProject.git" 10 | override def scmConnection = s"scm:git:$scmUrl" 11 | } 12 | -------------------------------------------------------------------------------- /stage2/plugins/KindProjector.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | import java.io.File 4 | 5 | trait KindProjectorPlugin extends BaseBuild { 6 | def kindProjectorVersion = "0.9.4" 7 | 8 | override def scalacOptions = super.scalacOptions ++ 9 | KindProjector.scalacOptions( 10 | KindProjector.dependencies( scalaMajorVersion, kindProjectorVersion, context.cbtLastModified, context.paths.mavenCache ).jar 11 | ) 12 | } 13 | 14 | object KindProjector { 15 | def dependencies( 16 | scalaMajorVersion: String, kindProjectorVersion: String, cbtLastModified: Long, mavenCache: File 17 | )( 18 | implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache 19 | ) = 20 | MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( 21 | MavenDependency( 22 | "org.spire-math", "kind-projector_"+scalaMajorVersion, kindProjectorVersion 23 | ) 24 | ) 25 | 26 | def scalacOptions( jarPath: File ) = 27 | Seq( 28 | "-Xplugin:" ++ jarPath.string 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /stage2/plugins/MultipleScalaVersions.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | trait MultipleScalaVersions extends DynamicOverrides{ 4 | def scalaVersions: Seq[String] = Seq(scalaVersion, "2.10.6") 5 | def cross: Seq[MultipleScalaVersions] = 6 | scalaVersions.map{ v => 7 | newBuild[MultipleScalaVersions](context.copy(scalaVersion = Some(v)))(""" 8 | override def sources = super.sources :+ ( projectDirectory / "src_" ++ scalaMajorVersion ) 9 | """) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /stage2/plugins/NewStyleMacros.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | 4 | trait NewStyleMacros extends BaseBuild{ 5 | def newStyleMacrosVersion = "3.0.0-M9" 6 | 7 | override def scalacOptions = super.scalacOptions ++ NewStyleMacros.scalacOptions( 8 | NewStyleMacros.dependencies( scalaVersion, newStyleMacrosVersion, context.cbtLastModified, context.paths.mavenCache ).jar 9 | ) 10 | } 11 | 12 | object NewStyleMacros{ 13 | def dependencies( 14 | scalaVersion: String, newStyleMacrosVersion: String, cbtLastModified: Long, mavenCache: java.io.File 15 | )( 16 | implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache 17 | ) = 18 | MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( 19 | MavenDependency( "org.scalameta", "paradise_"+scalaVersion, newStyleMacrosVersion ) 20 | ) 21 | 22 | def scalacOptions( jarPath: File ) = 23 | Seq( 24 | "-Xplugin:" ++ jarPath.string, 25 | "-Yrangepos", 26 | "-Xplugin-require:macroparadise" 27 | ) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /stage2/plugins/OldStyleMacros.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait OldStyleMacros extends BaseBuild{ 3 | def oldStyleMacrosVersion = "2.1.0" 4 | 5 | private def scalaParadiseDependency = 6 | Resolver( mavenCentral ).bindOne( 7 | "org.scalamacros" % ("paradise_" ++ scalaVersion) % oldStyleMacrosVersion 8 | ) 9 | 10 | override def dependencies = ( 11 | super.dependencies // don't forget super.dependencies here 12 | ++ ( 13 | if(scalaVersion.startsWith("2.10.")) 14 | Seq(scalaParadiseDependency) 15 | else 16 | Seq() 17 | ) 18 | ) 19 | 20 | override def scalacOptions = ( 21 | super.scalacOptions 22 | ++ ( 23 | if(scalaVersion.startsWith("2.10.")) 24 | Seq("-Xplugin:"++scalaParadiseDependency.jar.string) 25 | else 26 | Seq() 27 | ) 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /stage2/plugins/PublishToArtifactory.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.net._ 3 | import java.io._ 4 | trait PublishToArtifactory extends PublishLocal{ 5 | def Artifactory = cbt.Artifactory( lib, publishedArtifacts, releaseFolder ) 6 | } 7 | case class Artifactory( lib: Lib, publishedArtifacts: Seq[File], releaseFolder: String ){ 8 | case class withURL( url: URL, credentials: Option[String] = None ){ 9 | def publishUnsigned = lib.publishUnsigned( publishedArtifacts, url ++ releaseFolder, credentials ) 10 | def publishSigned = lib.publishSigned( publishedArtifacts, url ++ releaseFolder, credentials ) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /stage2/plugins/Readme.md: -------------------------------------------------------------------------------- 1 | Essential CBT plugins 2 | 3 | Not part of CBT's core to keep it slim and so they can have dependencies if needed. 4 | -------------------------------------------------------------------------------- /stage2/plugins/ScalaTest.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | trait ScalaTest extends BaseBuild { 4 | override def dependencies = super.dependencies :+ libraries.cbt.scalatestRunner 5 | override def run: ExitCode = { 6 | classLoader.loadClass( "cbt.scalatest.Runner" ).method( 7 | "run", classOf[Array[File]], classOf[ClassLoader] 8 | ).invoke( null, exportedClasspath.files.toArray, classLoader ) 9 | ExitCode.Success 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /stage2/plugins/ScalaXRay.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | trait ScalaXRay extends BaseBuild{ 4 | override def scalacOptions = { 5 | super.scalacOptions ++ ScalaXRay.scalacOptions( 6 | ports.scalaXRay.dependency.asInstanceOf[PackageJars] 7 | ) 8 | } 9 | } 10 | object ScalaXRay{ 11 | def scalacOptions( plugin: PackageJars, linkFile: Option[File] = None ) = 12 | Seq( 13 | "-Xplugin:" ~ plugin.jar.get.string, 14 | "-Xplugin-require:sxr" 15 | //"-P:sxr:base-directory:" ~ baseDirectory.string 16 | ) ++ linkFile.map( "-P:sxr:link-file:" ~ _.string ) 17 | } 18 | -------------------------------------------------------------------------------- /stage2/plugins/Scalameta.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.io.File 3 | trait Scalameta extends BaseBuild{ 4 | def scalaMetaVersion: String = "1.6.0" 5 | 6 | override def scalacOptions = super.scalacOptions ++ Scalameta.scalacOptions( 7 | Scalameta.scalaHost( scalaVersion, scalaMetaVersion, context.cbtLastModified, context.paths.mavenCache ).jar 8 | ) 9 | } 10 | object Scalameta{ 11 | def scalaHost( 12 | scalaVersion: String, scalaMetaVersion: String, cbtLastModified: Long, mavenCache: java.io.File 13 | )( 14 | implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache 15 | ) = 16 | MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( 17 | MavenDependency( 18 | "org.scalameta", "scalahost_"+scalaVersion, scalaMetaVersion 19 | ) 20 | ) 21 | 22 | def scalacOptions( scalaHost: File ) = 23 | Seq( 24 | "-Xplugin:" ++ scalaHost.string, 25 | "-Yrangepos", 26 | "-Xplugin-require:scalahost" 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /stage2/plugins/SnapshotVersion.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | 3 | trait SnapshotVersion extends ArtifactInfo with DynamicOverrides{ 4 | def snapshot = newBuild[SnapshotVersion]{""" 5 | override def version = super.version ++ "-SNAPSHOT" 6 | """} 7 | } 8 | -------------------------------------------------------------------------------- /stage2/plugins/Tut.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | trait Tut extends BaseBuild { 3 | def tut = Tut.apply( lib, context.cbtLastModified, context.paths.mavenCache, scalaMajorVersion ).config( 4 | projectDirectory / "tut", target / "tut", classpath, scalacOptions 5 | ) 6 | } 7 | 8 | import java.io.File 9 | object Tut { 10 | case class apply( 11 | lib: Lib, cbtLastModified: Long, mavenCache: File, scalaMajorVersion: String 12 | )( 13 | implicit 14 | logger: Logger, transientCache: java.util.Map[AnyRef, AnyRef], classLoaderCache: ClassLoaderCache 15 | ) { 16 | case class config( 17 | sourceDirectory: File, 18 | targetDirectory: File, 19 | classpath: ClassPath, 20 | scalacOptions: Seq[String], 21 | fileExtensionRegex: String = """.*\.(md|txt|htm|html)""", 22 | version: String = "0.4.8" 23 | ) { 24 | def apply = 25 | lib.redirectOutToErr { 26 | tut( version ).runMain( 27 | "tut.TutMain", 28 | Seq( 29 | sourceDirectory.string, targetDirectory.string, fileExtensionRegex, "-cp", classpath.string 30 | ) ++ scalacOptions 31 | ) 32 | } 33 | } 34 | def tut( version: String ) = MavenResolver( cbtLastModified, mavenCache, bintray( "tpolecat" ), mavenCentral ).bindOne( 35 | MavenDependency( "org.tpolecat", "tut-core_" ~ scalaMajorVersion, version ) 36 | ) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /stage2/plugins/readme.txt: -------------------------------------------------------------------------------- 1 | This directory is for built-in plugins which are always available. 2 | This is nice for plugins, which themselves do not have any 3 | compile-time dependencies except for CBT itself. 4 | See /plugins/ for plugins, that require an explicit dependency in the BuildBuild. 5 | -------------------------------------------------------------------------------- /stage2/pom.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | import java.net.URL 3 | case class Organization( 4 | name: String, 5 | url: Option[URL] 6 | ) 7 | -------------------------------------------------------------------------------- /stage2/ports.scala: -------------------------------------------------------------------------------- 1 | package cbt 2 | class ports( context: Context, scalaVersion: String ) { 3 | private def dep( name: String ) = DirectoryDependency( 4 | context.copy( 5 | scalaVersion = Some( scalaVersion ), 6 | workingDirectory = context.cbtHome / "ports" / name 7 | ), 8 | None 9 | ) 10 | def mima = dep( "migration-manager" ) 11 | def scalariform = dep( "scalariform" ) 12 | def scalaXRay = dep( "scala-xray" ) 13 | } 14 | -------------------------------------------------------------------------------- /test/broken-build/build-class-with-wrong-arguments/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.build_class_with_wrong_arguments 2 | import cbt._ 3 | class Build(i: Int, val context: Context) extends BaseBuild 4 | -------------------------------------------------------------------------------- /test/broken-build/build-class-with-wrong-parent/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) 3 | -------------------------------------------------------------------------------- /test/broken-build/empty-build-file/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | def main( args: Array[String] ): Unit = { 3 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/broken-build/empty-build-file/build/build.scala: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvogt/cbt/01912ff5e28b9c42b8b4eeb97efdc627a2970afc/test/broken-build/empty-build-file/build/build.scala -------------------------------------------------------------------------------- /test/broken-build/no-build-file/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | def main( args: Array[String] ): Unit = { 3 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/broken-build/no-build-file/build/foo.scala: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvogt/cbt/01912ff5e28b9c42b8b4eeb97efdc627a2970afc/test/broken-build/no-build-file/build/foo.scala -------------------------------------------------------------------------------- /test/build/build.scala: -------------------------------------------------------------------------------- 1 | package cbt_build.cbt.test 2 | import cbt._ 3 | class Build(val context: cbt.Context) extends BaseBuild{ 4 | override def dependencies = super.dependencies :+ context.cbtDependency 5 | def apply = run 6 | override def run = { 7 | classes.flatMap( lib.findCbtMain ).head( context ) 8 | } 9 | def args = context.args 10 | } 11 | -------------------------------------------------------------------------------- /test/empty-build/Main.scala: -------------------------------------------------------------------------------- 1 | object Main{ 2 | def main( args: Array[String] ): Unit = { 3 | println( Console.GREEN ++ "Hello World" ++ Console.RESET ) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/empty-build/build/build/dummy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvogt/cbt/01912ff5e28b9c42b8b4eeb97efdc627a2970afc/test/empty-build/build/build/dummy -------------------------------------------------------------------------------- /test/library-test/Foo.scala: -------------------------------------------------------------------------------- 1 | package lib_test 2 | object Foo{ 3 | def bar = "Hello, Foo Bar" 4 | } 5 | -------------------------------------------------------------------------------- /test/library-test/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | // cbt:https://github.com/cvogt/cbt.git#f11b8318b85f16843d8cfa0743f64c1576614ad6 4 | class Build(val context: Context) extends BaseBuild with PackageJars{ 5 | def groupId = "cbt.test" 6 | def version = "0.1" 7 | def name = "library-test" 8 | 9 | override def dependencies = 10 | super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. 11 | Seq( 12 | // source dependency 13 | // DirectoryDependency( projectDirectory ++ "/subProject" ) 14 | ) ++ 15 | // pick resolvers explicitly for individual dependencies (and their transitive dependencies) 16 | Resolver( mavenCentral, sonatypeReleases ).bind( 17 | // CBT-style Scala dependencies 18 | // ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) 19 | // MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) 20 | 21 | // SBT-style dependencies 22 | // "com.lihaoyi" %% "ammonite-ops" % "0.5.5" 23 | // "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /test/multi-build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | class Build(val context: Context) extends BaseBuild{ 3 | override def dependencies = Seq( 4 | DirectoryDependency(projectDirectory++"/sub1"), 5 | DirectoryDependency(projectDirectory++"/sub2") 6 | ) ++ super.dependencies 7 | } 8 | -------------------------------------------------------------------------------- /test/multi-build/code.scala: -------------------------------------------------------------------------------- 1 | object Main extends App{ 2 | println("root here") 3 | println(Foo(5)) 4 | println(Bar("test")) 5 | } 6 | -------------------------------------------------------------------------------- /test/multi-build/sub1/code.scala: -------------------------------------------------------------------------------- 1 | case class Foo(i: Int) 2 | object Main extends App{ 3 | println("sub1 here") 4 | } -------------------------------------------------------------------------------- /test/multi-build/sub2/code.scala: -------------------------------------------------------------------------------- 1 | case class Bar(s: String) 2 | object Main extends App{ 3 | println("sub1 here") 4 | } 5 | -------------------------------------------------------------------------------- /test/nothing/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvogt/cbt/01912ff5e28b9c42b8b4eeb97efdc627a2970afc/test/nothing/placeholder -------------------------------------------------------------------------------- /test/simple-fixed-cbt/Main.scala: -------------------------------------------------------------------------------- 1 | import lib_test.Foo 2 | import org.eclipse.jgit.lib.Ref 3 | import com.spotify.missinglink.ArtifactLoader 4 | object Main extends App{ 5 | println(Foo.bar) 6 | } 7 | -------------------------------------------------------------------------------- /test/simple-fixed-cbt/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | // cbt:https://github.com/cvogt/cbt.git#f11b8318b85f16843d8cfa0743f64c1576614ad6 4 | class Build(val context: cbt.Context) extends PackageJars{ 5 | override def dependencies = super.dependencies ++ Seq( 6 | DirectoryDependency( context.cbtHome ++ "/test/library-test" ) 7 | ) ++ Resolver( mavenCentral ).bind( 8 | MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"), 9 | MavenDependency("com.spotify", "missinglink-core", "0.1.1") 10 | ) 11 | def groupId: String = "cbt.test" 12 | def version: String = "0.1" 13 | def name: String = "simple-fixed-cbt" 14 | } -------------------------------------------------------------------------------- /test/simple-fixed/Main.scala: -------------------------------------------------------------------------------- 1 | import lib_test.Foo 2 | object Main extends App{ 3 | println(Foo.bar) 4 | } 5 | -------------------------------------------------------------------------------- /test/simple-fixed/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(context: cbt.Context) extends BasicBuild(context){ 4 | override def dependencies = ( 5 | super.dependencies 6 | ++ 7 | Seq( 8 | GitDependency("https://github.com/cvogt/cbt.git", "f11b8318b85f16843d8cfa0743f64c1576614ad6", Some("test/library-test")) 9 | ) 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /test/simple/Main.scala: -------------------------------------------------------------------------------- 1 | import org.eclipse.jgit.lib.Ref 2 | import com.spotify.missinglink.ArtifactLoader 3 | object Main extends App{ 4 | println("hello, world") 5 | } 6 | -------------------------------------------------------------------------------- /tools/gui/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild { 4 | 5 | override def dependencies = { 6 | super.dependencies ++ Resolver(mavenCentral).bind( 7 | MavenDependency("org.eclipse.jetty", "jetty-server", "9.3.12.v20160915"), 8 | ScalaDependency("org.scalaj", "scalaj-http", "2.3.0"), 9 | MavenDependency("com.atlassian.commonmark", "commonmark", "0.7.1") 10 | ) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tools/gui/resources/template-project/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BaseBuild##with## { 4 | 5 | ##name####dependencies##} 6 | -------------------------------------------------------------------------------- /tools/gui/resources/template-project/build/build/build.scala: -------------------------------------------------------------------------------- 1 | import cbt._ 2 | 3 | class Build(val context: Context) extends BuildBuild { 4 | 5 | override def dependencies = super.dependencies##plus## 6 | 7 | } 8 | -------------------------------------------------------------------------------- /tools/gui/resources/template-project/src/main/scala/Main.scala: -------------------------------------------------------------------------------- 1 | ##package##object Main { 2 | def main(args: Array[String]): Unit = { 3 | println("Hello World") 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tools/gui/resources/web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cvogt/cbt/01912ff5e28b9c42b8b4eeb97efdc627a2970afc/tools/gui/resources/web/favicon.ico -------------------------------------------------------------------------------- /tools/gui/resources/web/highlight/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006, Ivan Sagalaev 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of highlight.js nor the names of its contributors 12 | may be used to endorse or promote products derived from this software 13 | without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /tools/gui/resources/web/highlight/hljs-cbt-theme.css: -------------------------------------------------------------------------------- 1 | .hljs { 2 | display: block; 3 | overflow-x: auto; 4 | padding: 0.5em; 5 | background: #002b36; 6 | color: #fff; 7 | } 8 | 9 | .hljs-bullet, 10 | .hljs-quote, 11 | .hljs-link, 12 | .hljs-number, 13 | .hljs-regexp, 14 | .hljs-literal { 15 | color: #7cb2bf; 16 | } 17 | 18 | .hljs-emphasis { 19 | font-style: italic; 20 | } 21 | 22 | .hljs-keyword, 23 | .hljs-selector-tag, 24 | .hljs-section, 25 | .hljs-attribute, 26 | .hljs-name, 27 | .hljs-variable { 28 | color: #e6514e; 29 | } 30 | 31 | .hljs-string { 32 | color: #27b3d9; 33 | } 34 | 35 | .hljs-strong, 36 | .hljs-subst, 37 | .hljs-type, 38 | .hljs-built_in, 39 | .hljs-builtin-name, 40 | .hljs-symbol, 41 | .hljs-selector-id, 42 | .hljs-selector-attr, 43 | .hljs-selector-pseudo, 44 | .hljs-template-tag, 45 | .hljs-template-variable, 46 | .hljs-addition { 47 | font-weight: bold; 48 | } 49 | 50 | .hljs-emphasis { 51 | font-style: italic; 52 | } 53 | 54 | .hljs-comment, 55 | .hljs-deletion, 56 | .hljs-meta { 57 | color: #7f7f7f; 58 | } 59 | -------------------------------------------------------------------------------- /tools/gui/resources/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | CBT 9 | 10 | 11 | 12 | 13 |
14 | 18 |
19 | 20 |

CBT bootstrap

21 | 22 | 23 | or 24 | 25 |
26 | 27 |
project location:
28 | 29 |
30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 |
49 | 50 | select an example: 51 | 52 | 53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 61 |
62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tools/gui/resources/web/main.js: -------------------------------------------------------------------------------- 1 | Notifications.init($("#notifications")); 2 | 3 | Popup.init($("#popup"), $("#popup-table")); 4 | 5 | Dependencies.init($("#search-btn"), $("#query"), $("#dependencies")); 6 | 7 | ProjectLocation.init($("#cwd"), $("#name")); 8 | 9 | ["#create-project-btn", "#copy-project-btn", "#flow-create-btn", "#flow-copy-btn"].forEach(id => $(id)[0].disabled = false); 10 | 11 | $("#flow-copy-btn")[0].style.width = $("#flow-create-btn")[0].offsetWidth + "px"; 12 | 13 | function setFlowCreate() { 14 | $("#flow-create").show(); 15 | $("#flow-copy").hide(); 16 | 17 | let createBtn = $("#flow-create-btn"); 18 | let copyBtn = $("#flow-copy-btn"); 19 | createBtn.blur(); 20 | createBtn[0].disabled = true; 21 | copyBtn[0].disabled = false; 22 | 23 | ProjectLocation.updateName($("#name").val()); 24 | } 25 | 26 | function createProject() { 27 | let button = $("#create-project-btn")[0]; 28 | let buttonText = button.innerHTML; 29 | button.innerHTML = "..."; 30 | button.blur(); 31 | button.disabled = true; 32 | ajax("/project/new", { 33 | name: $("#name").val(), 34 | pack: $("#package").val(), 35 | dependencies: Dependencies.serialize(), 36 | flags: getFlags() 37 | }, "post").done(() => { 38 | Notifications.show("Project created."); 39 | }).always(() => { 40 | button.innerHTML = buttonText; 41 | button.disabled = false; 42 | }); 43 | } 44 | 45 | function setFlowCopy() { 46 | $("#flow-copy").show(); 47 | $("#flow-create").hide(); 48 | 49 | let createBtn = $("#flow-create-btn"); 50 | let copyBtn = $("#flow-copy-btn"); 51 | copyBtn.blur(); 52 | copyBtn[0].disabled = true; 53 | createBtn[0].disabled = false; 54 | 55 | Examples.unselectExample(); 56 | 57 | Examples.fetchExamples(); 58 | } 59 | 60 | function copyProject() { 61 | let name = $("#selected-example").html(); 62 | let button = $("#copy-project-btn")[0]; 63 | let buttonText = button.innerHTML; 64 | button.innerHTML = "..."; 65 | button.blur(); 66 | button.disabled = true; 67 | ajax("/project/copy", {name: name}, "post").done(() => { 68 | Notifications.show("Project copied."); 69 | }).always(() => { 70 | button.innerHTML = buttonText; 71 | button.disabled = false; 72 | }); 73 | } 74 | -------------------------------------------------------------------------------- /tools/gui/src/JettyServer.scala: -------------------------------------------------------------------------------- 1 | import java.net.MalformedURLException 2 | import javax.servlet.http.{HttpServletRequest, HttpServletResponse} 3 | 4 | import org.eclipse.jetty.server.{Request, Server} 5 | import org.eclipse.jetty.server.handler._ 6 | 7 | import scala.util.{Failure, Success, Try} 8 | 9 | abstract class JettyServer(port: Int, staticFilesUrl: String) { 10 | 11 | private val handlerOfStatic = { 12 | val handler = new ContextHandler("/") 13 | val resourceHandler = new ResourceHandler 14 | resourceHandler.setDirectoriesListed(true) 15 | resourceHandler.setResourceBase(staticFilesUrl) 16 | handler.setHandler(resourceHandler) 17 | handler 18 | } 19 | 20 | private val handlerOfApi = { 21 | val handlerWrapper = new ContextHandler("/api/") 22 | val handler = new AbstractHandler { 23 | override def handle(target: String, 24 | baseRequest: Request, 25 | request: HttpServletRequest, 26 | response: HttpServletResponse) = { 27 | response.setContentType("application/json") 28 | response.setCharacterEncoding("UTF-8") 29 | 30 | route(request.getMethod, target, request.getParameter, response.setContentType) match { 31 | case Success(result) => 32 | response.getWriter.write(result) 33 | case Failure(e: MalformedURLException) => 34 | response.setStatus(HttpServletResponse.SC_NOT_FOUND) 35 | response.getWriter.write(e.getMessage) 36 | case Failure(e) => 37 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) 38 | response.getWriter.write(s"${e.getClass.getName}: ${e.getMessage}") 39 | } 40 | 41 | baseRequest.setHandled(true) 42 | } 43 | } 44 | handlerWrapper.setHandler(handler) 45 | handlerWrapper 46 | } 47 | 48 | private val server = { 49 | val s = new Server(port) 50 | val handlers = new HandlerCollection 51 | handlers.setHandlers(Array(handlerOfStatic, handlerOfApi, new DefaultHandler)) 52 | s.setHandler(handlers) 53 | s 54 | } 55 | 56 | def start() = { 57 | server.start() 58 | println(s"UI server started at localhost:$port") 59 | } 60 | 61 | def stop() = { 62 | server.stop() 63 | println("UI server stopped.") 64 | } 65 | 66 | def route(method: String, path: String, param: String => String, setContentType: String => Unit): Try[String] 67 | } 68 | --------------------------------------------------------------------------------