aboutsummaryrefslogtreecommitdiff
path: root/libraries/common-1
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-20 22:09:38 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-27 19:56:13 -0400
commitbba2abe7ee38b8903822a07578c46466923d13ed (patch)
treea357fb8def6f58a9ea9a37411f3f5640dcb525fe /libraries/common-1
parentd2f8cade709b7d55a93e18592b6e38247d648ca9 (diff)
downloadcbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.gz
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.bz2
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.zip
start modularizing cbt into libraries
this extracts certain parts of cbt into stand-alone libraries, which can be published to maven and used outside of cbt. This also adds scalariform for these parts of the code. This slows down cbt’s own build a lot because of the number of projects involved! So we’ll follow this by a bunch of performance tweak commits.
Diffstat (limited to 'libraries/common-1')
-rw-r--r--libraries/common-1/ExitCode.java24
-rw-r--r--libraries/common-1/ExitCode.scala11
-rw-r--r--libraries/common-1/build/build.scala8
-rw-r--r--libraries/common-1/build/build/build.scala5
-rw-r--r--libraries/common-1/common_1.scala34
5 files changed, 82 insertions, 0 deletions
diff --git a/libraries/common-1/ExitCode.java b/libraries/common-1/ExitCode.java
new file mode 100644
index 0000000..1c16f67
--- /dev/null
+++ b/libraries/common-1/ExitCode.java
@@ -0,0 +1,24 @@
+package cbt;
+/*
+public class ExitCode{
+ public int integer;
+ public ExitCode(int integer){
+ this.integer = integer;
+ }
+ public static ExitCode apply(int integer){
+ return new ExitCode( integer );
+ }
+ public static ExitCode Success = new ExitCode(0);
+ public static ExitCode Failure = new ExitCode(1);
+
+ @Override
+ public boolean equals(Object other){
+ return (other instanceof ExitCode) && ((ExitCode) other).integer == integer;
+ }
+ @Override
+ public int hashCode(){
+ return integer;
+ }
+}
+
+*/
diff --git a/libraries/common-1/ExitCode.scala b/libraries/common-1/ExitCode.scala
new file mode 100644
index 0000000..41d9f3f
--- /dev/null
+++ b/libraries/common-1/ExitCode.scala
@@ -0,0 +1,11 @@
+package cbt
+// CLI interop
+case class ExitCode( integer: Int ) extends interfaces.ExitCode {
+ def ||( other: => ExitCode ) = if ( this == ExitCode.Success ) this else other
+ def &&( other: => ExitCode ) = if ( this != ExitCode.Success ) this else other
+}
+object ExitCode {
+ val Success = ExitCode( 0 )
+ val Failure = ExitCode( 1 )
+}
+
diff --git a/libraries/common-1/build/build.scala b/libraries/common-1/build/build.scala
new file mode 100644
index 0000000..247fd01
--- /dev/null
+++ b/libraries/common-1/build/build.scala
@@ -0,0 +1,8 @@
+package cbt_build.common_1
+import cbt._
+import cbt_internal._
+class Build(val context: Context) extends Library{
+ override def inceptionYear = 2017
+ override def description = "classes shared by multiple cbt libraries and needed in stage 1"
+ override def dependencies = super.dependencies :+ libraries.common_0 :+ libraries.interfaces
+}
diff --git a/libraries/common-1/build/build/build.scala b/libraries/common-1/build/build/build.scala
new file mode 100644
index 0000000..d3f98ce
--- /dev/null
+++ b/libraries/common-1/build/build/build.scala
@@ -0,0 +1,5 @@
+package cbt_build.reflect.build
+import cbt._
+class Build(val context: Context) extends BuildBuild with CbtInternal{
+ override def dependencies = super.dependencies :+ cbtInternal.library
+}
diff --git a/libraries/common-1/common_1.scala b/libraries/common-1/common_1.scala
new file mode 100644
index 0000000..66da224
--- /dev/null
+++ b/libraries/common-1/common_1.scala
@@ -0,0 +1,34 @@
+package cbt.common_1
+import cbt.ExitCode
+object `package` extends Module {
+ implicit class CbtExitCodeOps( val exitCode: ExitCode ) extends AnyVal with ops.CbtExitCodeOps
+ implicit class TypeInferenceSafeEquals[T]( val value: T ) extends AnyVal with ops.TypeInferenceSafeEquals[T]
+ implicit class CbtBooleanOps( val condition: Boolean ) extends AnyVal with ops.CbtBooleanOps
+ implicit class CbtStringOps( val string: String ) extends AnyVal with ops.CbtStringOps
+}
+
+package ops {
+ trait CbtExitCodeOps extends Any {
+ def exitCode: ExitCode
+ def ||( other: => ExitCode ) = if ( exitCode == ExitCode.Success ) exitCode else other
+ def &&( other: => ExitCode ) = if ( exitCode != ExitCode.Success ) exitCode else other
+ }
+ trait TypeInferenceSafeEquals[T] extends Any {
+ def value: T
+ /** if you don't manually upcast, this will catch comparing different types */
+ def ===( other: T ) = value == other
+ def =!=( other: T ) = value != other // =!= instead of !==, because it has better precedence
+ }
+ trait CbtBooleanOps extends Any {
+ def condition: Boolean
+ def option[T]( value: => T ): Option[T] = if ( condition ) Some( value ) else None
+ }
+ trait CbtStringOps extends Any {
+ def string: String
+ def escape = string.replace( "\\", "\\\\" ).replace( "\"", "\\\"" )
+ def quote = s""""$escape""""
+ def ~( right: String ): String = string + right
+ }
+}
+
+trait Module