Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

fix bugs and compile issues #48

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ project/target/
/proguard-sbt.txt
*.iml
local.*
z-platform.sbt
*/z-platform.sbt
23 changes: 23 additions & 0 deletions android-driver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ The MIT License (MIT)
~
~ Copyright (C) 2012 47 Degrees, LLC http://47deg.com hello@47deg.com
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in
~ all copies or substantial portions of the Software.
-->

<manifest package="com.fortysevendeg.mvessel"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="14" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ class AndroidDriver extends BaseDriver[AndroidCursor] {
logWrapper = new AndroidLogWrapper)
}

private[this] def readTimeOut(params: Map[String, String]): Option[Long] =
protected def readTimeOut(params: Map[String, String]): Option[Long] =
readLongParam(BaseDriver.timeoutParam, params)

private[this] def readRetry(params: Map[String, String]): Option[Int] =
protected def readRetry(params: Map[String, String]): Option[Int] =
readLongParam(BaseDriver.retryParam, params) map (_.toInt)

private[this] def readLongParam(name: String, params: Map[String, String]): Option[Long] =
protected def readLongParam(name: String, params: Map[String, String]): Option[Long] =
params.get(name) flatMap (value => Try(value.toLong).toOption)

val flags =
android.database.sqlite.SQLiteDatabase.CREATE_IF_NECESSARY |
android.database.sqlite.SQLiteDatabase.OPEN_READWRITE |
android.database.sqlite.SQLiteDatabase.NO_LOCALIZED_COLLATORS

private[this] def readFlags(properties: Properties): Int =
protected def readFlags(properties: Properties): Int =
Option(properties) match {
case Some(p) =>
completeFlags(
Expand All @@ -62,14 +62,14 @@ class AndroidDriver extends BaseDriver[AndroidCursor] {
case _ => flags
}

private[this] def completeFlags(databaseFlags: String, androidFlags: String): Int =
protected def completeFlags(databaseFlags: String, androidFlags: String): Int =
(Option(databaseFlags), Option(androidFlags)) match {
case (Some(f), _) => parseInt(f, flags)
case (None, Some(f)) => flags | parseInt(f, 0)
case _ => flags
}

private[this] def parseInt(value: String, defaultValue: Int) =
protected def parseInt(value: String, defaultValue: Int) =
Try(value.toInt).toOption getOrElse defaultValue

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class AndroidCursor(val cursor: Cursor)

override def respond(extras: Bundle): Bundle =
cursor.respond(extras)

override def getNotificationUri: Uri = ???

override def setExtras(extras: Bundle): Unit = ???
}

trait AndroidCursorData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.fortysevendeg.mvessel.api.impl

import android.database.sqlite.SQLiteDatabase
import com.fortysevendeg.mvessel._
import com.fortysevendeg.mvessel.AndroidDriver
import com.fortysevendeg.mvessel.{AndroidDriver, _}
import com.fortysevendeg.mvessel.api.{DatabaseProxy, DatabaseProxyFactory}
import com.fortysevendeg.mvessel.util.ReflectionOps._

Expand All @@ -29,7 +28,6 @@ class AndroidDatabaseFactory extends DatabaseProxyFactory[AndroidCursor] {

override def isLockedException(exception: RuntimeException): Boolean =
lockedExceptionClass exists (_.isAssignableFrom(exception.getClass))

}

class AndroidDatabase(sqliteDatabase: SQLiteDatabase) extends DatabaseProxy[AndroidCursor] {
Expand All @@ -49,6 +47,8 @@ class AndroidDatabase(sqliteDatabase: SQLiteDatabase) extends DatabaseProxy[Andr

override def changedRowCount: Option[Int] = lastChangeCount(sqliteDatabase)

override def inTransaction: Boolean = sqliteDatabase.inTransaction()

override def isOpen: Boolean = sqliteDatabase.isOpen

override def close(): Unit = sqliteDatabase.close()
Expand Down
7 changes: 6 additions & 1 deletion android-it/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ android.Plugin.androidBuild

javacOptions ++= Seq("-target", "1.7", "-source", "1.7")

scalaVersion := "2.11.7"
scalaVersion := "2.12.6"

platformTarget in Android := "android-23"

Expand Down Expand Up @@ -35,3 +35,8 @@ proguardOptions in Android ++= Seq(
"-keep public class * extends junit.framework.TestCase",
"-keepclassmembers class * extends junit.framework.TestCase { *; }"
)

publish := ()
publishM2 := ()
publishLocal := ()
publishArtifact := false
2 changes: 1 addition & 1 deletion android-it/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.8")
addSbtPlugin("org.scala-android" % "sbt-android" % "[1.7.9,)")
25 changes: 25 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
offline := true

crossScalaVersions := Seq(
/*"2.11.7", 多余,不需要两个*/
"2.11.11"
/*"2.12.2", 有一些编译问题:`the interface is not a direct parent`。*/
/*"2.12.6" jitpack 不会cross-build, 还是保留2.11*/)

// 解决生成文档报错导致 jitpack.io 出错的问题。
publishArtifact in packageDoc := false

resolvers += "google" at "https://maven.google.com"

libraryDependencies ++= Seq(
// 解决 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
// 以便 slf4j 日志系统能够兼容 Android Logcat.
// https://stackoverflow.com/questions/34998237/slf4j-android-1-7-not-logging-on-logcat?noredirect=1
"org.slf4j" % "slf4j-android" % "[1.7.14,)",
"org.slf4j" % "slf4j-api" % "[1.7.0,)"
)

publish := ()
publishM2 := ()
publishLocal := ()
publishArtifact := false
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ class DataSource[T <: CursorProxy](
extends SQLDataSource
with WrapperNotSupported {

private[this] val url: String = "jdbc:sqlite:" + dbPath
protected final val url: String = BaseDriver.sqlitePrefix + dbPath

lazy val connection: Connection[T] = driver.connect(url, properties)

override def getConnection: SQLConnection = connection
override def getConnection: SQLConnection = driver.connect(url, properties)

override def getConnection(username: String, password: String): SQLConnection = getConnection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ trait DatabaseProxyFactory[T <: CursorProxy] {
def openDatabase(name: String, flags: Int): DatabaseProxy[T]

def isLockedException(exception: RuntimeException): Boolean

}

trait DatabaseProxy[T <: CursorProxy] {
Expand All @@ -38,6 +37,8 @@ trait DatabaseProxy[T <: CursorProxy] {

def endTransaction(): Unit

def inTransaction: Boolean

def isOpen: Boolean

def getVersion: Int
Expand All @@ -47,5 +48,4 @@ trait DatabaseProxy[T <: CursorProxy] {
def getDriverVersion: String

def close(): Unit

}
18 changes: 10 additions & 8 deletions project/AppBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,38 @@
* all copies or substantial portions of the Software.
*/

import android.AndroidLib
import microsites.MicrositesPlugin
import sbt.Keys._
import sbt._
import sbtbuildinfo.BuildInfoPlugin

object AppBuild extends Build with Settings with SettingsPublish {

lazy val root = (project in file("."))
object AppBuild extends Build with Settings/* with SettingsPublish*/ {
lazy val mvessel = (project in file("."))
// .enablePlugins(AndroidLib)
.settings(basicSettings: _*)
.aggregate(androidDriver, core)

lazy val androidDriver = (project in file("android-driver"))
.enablePlugins(BuildInfoPlugin)
.enablePlugins(AndroidLib)
.configs(IntegrationTest)
.settings(androidDriverSettings: _*)
.settings(Defaults.itSettings : _*)
.settings(libraryDependencies ++= androidDriverLibraries)
.dependsOn(core, mockAndroid % "test->test;it->test")
.settings(androidSettings)
.dependsOn(core/*, mockAndroid % "test->test;it->test"*/)

lazy val core = (project in file("core"))
.settings(coreSettings: _*)
.settings(libraryDependencies ++= coreLibraries)

lazy val mockAndroid = (project in file("mock-android"))
.settings(mockAndroidSettings: _*)
.settings(libraryDependencies ++= mockAndroidLibraries)
// lazy val mockAndroid = (project in file("mock-android"))
// .settings(mockAndroidSettings: _*)
// .settings(libraryDependencies ++= mockAndroidLibraries)

lazy val docs = (project in file("docs"))
.enablePlugins(MicrositesPlugin)
.settings(docsSettings: _*)
.settings(moduleName := "docs")

}
2 changes: 1 addition & 1 deletion project/Libraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ object Libraries {

lazy val sqliteJdbc = "org.xerial" % "sqlite-jdbc" % xerialJdbc

lazy val android = "com.google.android" % "android" % androidJar
// lazy val android = "com.google.android" % "android" % androidJar

}
28 changes: 19 additions & 9 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import java.net.URL

import microsites.MicrositeKeys._
import Libraries._
import sbt._
Expand All @@ -24,7 +23,7 @@ import sbtbuildinfo.BuildInfoPlugin.autoImport._

trait Settings {

this: Build with SettingsPublish =>
this: Build /* with SettingsPublish*/ =>

lazy val commonResolvers = Seq(
Resolver.mavenLocal,
Expand All @@ -51,22 +50,24 @@ trait Settings {
organizationName := "47 Degrees",
organizationHomepage := Some(new URL("http://47deg.com")))

lazy val androidDriverSettings = basicSettings ++ orgSettings ++ publishSettings ++ Seq(
lazy val androidDriverSettings = basicSettings ++ orgSettings /* ++ publishSettings*/ ++ Seq(
name := "mvessel-android",
version := V.project,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "com.fortysevendeg.mvessel",
fork in Test := true)

lazy val coreSettings = basicSettings ++ orgSettings ++ publishSettings ++ Seq(
lazy val coreSettings = basicSettings ++ orgSettings /* ++ publishSettings*/ ++ Seq(
name := "mvessel",
version := V.project,
exportJars := true,
fork in Test := true)

lazy val mockAndroidSettings = basicSettings ++ orgSettings
// lazy val mockAndroidSettings = basicSettings ++ orgSettings

lazy val noPublishSettings = Seq(
publish := (),
publishM2 := (),
publishLocal := (),
publishArtifact := false)

Expand All @@ -91,14 +92,23 @@ trait Settings {
lazy val androidDriverLibraries = Seq(
specs2Core % "it,test",
specs2Mock % "it,test",
sqliteJdbc % "it",
android % "provided")
sqliteJdbc % "it"
// ,
// android % "provided"
)

lazy val coreLibraries = Seq(
specs2Core % "test",
specs2Mock % "test")

lazy val mockAndroidLibraries = Seq(
android % "provided")
// android % "provided"
)

}
lazy val androidSettings = Seq(
// 等同于两句:targetSdkVersion, compileSdkVersion
android.Keys.platformTarget in android.Keys.Android := "android-27",
android.Keys.buildToolsVersion in android.Keys.Android := Some("27.0.3"),
android.Keys.minSdkVersion in android.Keys.Android := "16"
)
}
Loading