Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
acunniffe committed Mar 15, 2018
2 parents 6b40294 + 584d274 commit 93c78d8
Show file tree
Hide file tree
Showing 43 changed files with 531 additions and 108 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ server/target/
sdk/target/
core/target/

test-examples/resources/tmp/
test-examples/resources/tmp/

19 changes: 14 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name := "optic-core"

organization := "com.opticdev"

version := "0.1.0"
val appVersion = "0.1.1"

version := appVersion

val appVersion = "0.1.0"

val commonSettings: Seq[Def.Setting[_]] = Seq(
version := appVersion,
Expand All @@ -27,8 +28,16 @@ lazy val common = (project in file("common")).
.settings(libraryDependencies ++= Dependencies.commonDependencies)

lazy val sdk = (project in file("sdk")).
enablePlugins(BuildInfoPlugin).
settings(commonSettings: _*)
.settings(libraryDependencies ++= Dependencies.sdkDependencies)
.settings(
libraryDependencies ++= Dependencies.sdkDependencies,
buildInfoKeys := Seq[BuildInfoKey](
"opticMDTar" -> Constants.opticMDTar,
"opticMDTarSum" -> Constants.opticMDTarSum,
),
buildInfoPackage := "com.opticdev.sdk"
)
.dependsOn(common)

lazy val opm = (project in file("opm")).
Expand Down Expand Up @@ -64,10 +73,10 @@ lazy val server = (project in file("server")).
.dependsOn(arrow % "compile->compile;test->test")
.settings(
test in assembly := {},
assemblyJarName in assembly := "server-assembly.jar",
mainClass in assembly := Some("com.opticdev.server.http.Lifecycle"),
mainClass in packageBin := Some("com.opticdev.server.http.Lifecycle")
)
)
.enablePlugins(AssemblyPlugin)


concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.opticdev.common.storage
package com.opticdev.common

import better.files.File
import com.opticdev.common.storage.{Linux, Mac, OS, Windows}
import org.apache.commons.lang3.SystemUtils

object PlatformConstants {
Expand All @@ -22,4 +23,18 @@ object PlatformConstants {
.createIfNotExists(asDirectory = true, createParents = false)
}






//Exec paths
val bashPath: String = platform match {
case Mac => "/bin/bash"
}

val nodePath: String = platform match {
case Mac => "/usr/local/bin/node"
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.opticdev.common.storage

import better.files.File
import com.opticdev.common.PlatformConstants

object DataDirectory {
val root = PlatformConstants.dataDirectory

val packages = PlatformConstants.dataDirectory / "packages"
val parsers = PlatformConstants.dataDirectory / "parsers"
val compiled = PlatformConstants.dataDirectory / "compiled"
val sourcegear = PlatformConstants.dataDirectory / "sourcegear"

val bin = PlatformConstants.dataDirectory / "bin"

def hasValidStructure = {
root.isDirectory &&
parsers.isDirectory &&
packages.isDirectory &&
compiled.isDirectory &&
sourcegear.isDirectory
bin.isDirectory
}

def buildDirectoryStructure = {
Expand All @@ -23,6 +27,7 @@ object DataDirectory {
packages.createIfNotExists(asDirectory = true)
compiled.createIfNotExists(asDirectory = true)
sourcegear.createIfNotExists(asDirectory = true)
bin.createIfNotExists(asDirectory = true)
}

def delete = root.delete(true)
Expand All @@ -32,4 +37,12 @@ object DataDirectory {
buildDirectoryStructure
}

def init : File = {
if (!hasValidStructure) {
reset
}

DataDirectory.root
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.opticdev.common.storage
package com.opticdev.common

import better.files.File
import org.scalatest.FunSpec
import com.opticdev.common.storage.{Mac, OS}
import org.apache.commons.lang3.SystemUtils
import org.scalatest.FunSpec

class PlatformConstantsSpec extends FunSpec {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.opticdev.common.storage

import better.files.File
import com.opticdev.common.PlatformConstants
import org.scalatest.FunSpec

class DataDirectorySpec extends FunSpec {
Expand All @@ -10,24 +11,26 @@ class DataDirectorySpec extends FunSpec {
assert(PlatformConstants.dataDirectory.notExists)
}

it("can init when missing or corrupt") {
DataDirectory.delete
DataDirectory.init
assert(DataDirectory.hasValidStructure)
}

describe("can detect invalid structure") {
it("when empty") {
DataDirectory.root.list.foreach(_.delete(true))
assert(!DataDirectory.hasValidStructure)
}

it("when a folder is missing") {
DataDirectory.delete
DataDirectory.root.createIfNotExists(asDirectory = true)
DataDirectory.packages.createIfNotExists(asDirectory = true)
DataDirectory.compiled.createIfNotExists(asDirectory = true)
assert(!DataDirectory.hasValidStructure)
}

}

it("can create the directory with valid structure") {
DataDirectory.delete
DataDirectory.buildDirectoryStructure
assert(DataDirectory.hasValidStructure)
}

}
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
testParser: "server/src/main/resources/es7_2.12-0.1.0.jar"
testParser: "server/src/main/resources/es7_2.12-0.1.1.jar"
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class SourceGear {
def findParser(parserRef: ParserRef) = parsers.find(_.languageName == parserRef.languageName)

lazy val validExtensions: Set[String] = parsers.flatMap(_.fileExtensions)
lazy val excludedPaths: Seq[String] = parsers.flatMap(_.excludedPaths).toSeq

def parseFile(file: File) (implicit project: OpticProject) : Try[FileParseResults] =
Try(file.contentAsString).flatMap(i=> parseString(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.opticdev.core.sourcegear.SourceGear
import com.opticdev.core.sourcegear.actors.ActorCluster
import com.opticdev.core.sourcegear.graph.{ProjectGraph, ProjectGraphWrapper}
import com.opticdev.core.sourcegear.project.config.ProjectFile
import com.opticdev.core.sourcegear.project.monitoring.{FileStateMonitor}
import com.opticdev.core.sourcegear.project.monitoring.{FileStateMonitor, ShouldWatch}
import com.opticdev.core.sourcegear.project.status.ProjectStatus
import com.opticdev.opm.providers.ProjectKnowledgeSearchPaths
import net.jcazevedo.moultingyaml.YamlString
Expand All @@ -37,7 +37,6 @@ abstract class OpticProject(val name: String, val baseDirectory: File)(implicit
val projectStatus = projectStatusInstance.immutable
def projectInfo : ProjectInfo = ProjectInfo(name, baseDirectory.pathAsString, projectStatus)


/* Normal Disk Monitoring */

val watcher: ActorRef = baseDirectory.newWatcher(recursive = true)
Expand Down Expand Up @@ -95,7 +94,7 @@ abstract class OpticProject(val name: String, val baseDirectory: File)(implicit
implicit val sourceGear = projectSourcegear
projectStatusInstance.touch
filesStateMonitor.markUpdated(file)
if (file === projectFile.file) {
if (file.isSameFileAs(projectFile.file)) {
projectFile.reload
} else {
if (shouldWatchFile(file)) projectActor ! FileUpdated(file, this)
Expand Down Expand Up @@ -131,12 +130,11 @@ abstract class OpticProject(val name: String, val baseDirectory: File)(implicit
}

/* Control logic for watching files */

def shouldWatchFile(file: File) : Boolean = {
file.isRegularFile &&
file.extension.isDefined &&
projectSourcegear.validExtensions.contains(file.extension.get)
}
//@todo profile this. Seems liable to cause big slowdowns with many files running through it
def shouldWatchFile(file: File) : Boolean =
ShouldWatch.file(file,
projectSourcegear.validExtensions,
projectFile.interface.get.exclude.value.map(i=> File(i.value)) ++ projectSourcegear.excludedPaths.map(i=> File(i)))

def filesToWatch : Set[File] = baseDirectory.listRecursively.toVector.filter(shouldWatchFile).toSet
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import scala.util.Try
class Project(name: String, baseDirectory: File)(implicit logToCli: Boolean = false, actorCluster: ActorCluster) extends OpticProject(name, baseDirectory) {

private var sourceGear: SourceGear = {
projectStatusInstance.sourceGearStatus = Building
projectFileChanged(projectFile)
SourceGear.unloaded
}
Expand All @@ -23,6 +24,7 @@ class Project(name: String, baseDirectory: File)(implicit logToCli: Boolean = fa
override def projectFileChanged(newPf: ProjectFile): Unit = {
super.projectFileChanged(newPf)
if (newPf.interface.isSuccess) {
projectStatusInstance.sourceGearStatus = Building
SGConstructor.fromProjectFile(newPf).onComplete(i => {
if (i.isSuccess) {
sourceGear = i.get.inflate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class ProjectFile(val file: File, createIfDoesNotExist : Boolean = true, onChang

val knowledgePaths =PFListInterface.forKey[YamlString]("knowledge_paths", YamlArray(Vector()), yaml)

val ignored_files =PFListInterface.forKey[YamlString]("ignored_files", YamlArray(Vector()), yaml)
val exclude =PFListInterface.forKey[YamlString]("exclude", YamlArray(Vector()), yaml)

lastHash = Crypto.createSha1(contents)
// val relationships =PFListInterface.forKey[YamlString]("relationships", YamlArray(Vector()), yaml)
PFRootInterface(name, parsers, knowledge, knowledgePaths, ignored_files)
PFRootInterface(name, parsers, knowledge, knowledgePaths, exclude)
}

def interface = interfaceStore
Expand All @@ -74,7 +74,7 @@ class ProjectFile(val file: File, createIfDoesNotExist : Boolean = true, onChang
YamlString("parsers") -> interface.get.parsers.yamlValue,
YamlString("knowledge") -> interface.get.knowledge.yamlValue,
YamlString("knowledge_paths") -> interface.get.knowledgePaths.yamlValue,
YamlString("ignored_files") -> interface.get.ignored_files.yamlValue
YamlString("exclude") -> interface.get.exclude.yamlValue
// YamlString("relationships") -> relationships.yamlValue
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ trait PFInterface {
}

case class PFRootInterface(
name: PFFieldInterface[YamlString],
parsers: PFListInterface[YamlString],
knowledge: PFListInterface[YamlString],
knowledgePaths: PFListInterface[YamlString],
ignored_files: PFListInterface[YamlString]
name: PFFieldInterface[YamlString],
parsers: PFListInterface[YamlString],
knowledge: PFListInterface[YamlString],
knowledgePaths: PFListInterface[YamlString],
exclude: PFListInterface[YamlString]
)

case class PFListInterface[T <: YamlValue](initialValue: List[T]) extends PFInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.opticdev.core.sourcegear.project.monitoring

import better.files.File
import com.opticdev.core.sourcegear.SourceGear

object ShouldWatch {
def file(file: File, validExtensions: Set[String], excludedPaths: Seq[File]) : Boolean = {
val isValidFile =
file.isRegularFile &&
file.extension.isDefined &&
validExtensions.contains(file.extension.get)

if (isValidFile) {

excludedPaths.filter(_.exists).foldLeft(true) {
case (bool, path) => {
if (!bool) bool else {
!( path.isSameFileAs(file) || path.isParentOf(file))
}
}
}

} else false

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.opticdev.core.sourcegear.project.status

import play.api.libs.json.{JsObject, JsString}
import play.api.libs.json.{JsArray, JsBoolean, JsObject, JsString}

class ImmutableProjectStatus(projectStatus: ProjectStatus) {

Expand All @@ -16,19 +16,46 @@ class ImmutableProjectStatus(projectStatus: ProjectStatus) {
def monitoringChanged(callback: (MonitoringStatus)=> Unit) = projectStatus.monitoringChanged(callback)
def configChanged(callback: (ConfigStatus)=> Unit) = projectStatus.configChanged(callback)
def firstPassChanged(callback: (FirstPassStatus)=> Unit) = projectStatus.firstPassChanged(callback)
def statusChanged(callback: (ProjectStatusCase, ImmutableProjectStatus)=> Unit) = projectStatus.statusChanged(callback)

def isValid: Boolean = projectStatus.isValid
def isLoading: Boolean = projectStatus.isLoading
def isReady: Boolean = projectStatus.isReady

def asJson = {
val errors = errorsAsJson
JsObject(Seq(
"loaded" -> JsString(loadedStatus.toString),
"sourcegear" -> JsString(sourceGearStatus.toString),
"monitoring" -> JsString(monitoringStatus.toString),
"config" -> JsString(configStatus.toString),
"firstPass" -> JsString(firstPassStatus.toString),
"lastUpdate" -> JsString(lastUpdate.time.toString),

"isValid"-> JsBoolean(isValid),
"isLoading"-> JsBoolean(isLoading),
"hasErrors"-> JsBoolean(errors.value.nonEmpty),
"errors" -> errors
))
}

def errorsAsJson : JsArray = {
var seq = Seq[JsString]()

configStatus match {
case config: InvalidConfig =>
seq = seq :+ JsString(config.error)
case _ =>
}

sourceGearStatus match {
case status: Invalid =>
seq = seq :+ JsString(status.error)
case _ =>
}

JsArray(seq)
}

override def toString: String = asJson.toString()
}
Loading

0 comments on commit 93c78d8

Please sign in to comment.