Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
-Parsers load at runtime within a few seconds of the first content query on a project
-SDK / Description structure updated to match optic-markdown 0.1.0 spec
-Tests updated
  • Loading branch information
Aidan Cunniffe committed Mar 4, 2018
1 parent 488e452 commit 3b4ee6e
Show file tree
Hide file tree
Showing 31 changed files with 154 additions and 161 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.idea/
target/
project/target/
config.yaml

arrow/target/
common/target/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class ChangesEvaluationSpec extends TestBase with TestPackageProviders {

assert(results.isSuccess)

println(results.stagedFiles.head._2.text)

assert(results.stagedFiles.head._2.text === expectedChange)
}

Expand All @@ -38,8 +36,6 @@ class ChangesEvaluationSpec extends TestBase with TestPackageProviders {
val (changeGroup, sourcegear, expectedChange) = transformModelToRoute
val results = changeGroup.evaluateAndWrite(sourcegear)

println(results.get.stagedFiles.head._2.text)

assert(results.get.stagedFiles.head._2.text == expectedChange)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object ExampleChanges extends TestBase with TestPackageProviders {
| "url": "path/to/resource"
| },
| "atLocation": {
| "file": "/Users/aidancunniffe/Developer/knack/optic-core/test-examples/resources/tmp/test_project/app.js",
| "file": "test-examples/resources/tmp/test_project/app.js",
| "position": 93,
| "_type":"com.opticdev.arrow.changes.location.AsChildOf"
| },
Expand Down Expand Up @@ -133,7 +133,7 @@ object ExampleChanges extends TestBase with TestPackageProviders {
| },
| "gearId": "aacee631",
| "atLocation": {
| "file": "/Users/aidancunniffe/Developer/knack/optic-core/test-examples/resources/tmp/test_project/app.js",
| "file": "test-examples/resources/tmp/test_project/app.js",
| "position": 38,
| "_type":"com.opticdev.arrow.changes.location.AsChildOf"
| },
Expand Down Expand Up @@ -192,16 +192,16 @@ object ExampleChanges extends TestBase with TestPackageProviders {
| }],
| "gearId": "aacee631",
| "locationOptions": [{
| "file": "/Users/aidancunniffe/Developer/knack/optic-core/test-examples/resources/tmp/test_project/nested/model.js",
| "file": "test-examples/resources/tmp/test_project/nested/model.js",
| "position": 173,
| "_type": "com.opticdev.arrow.changes.location.AsChildOf"
| }],
| "location": {
| "file": "/Users/aidancunniffe/Developer/knack/optic-core/test-examples/resources/tmp/test_project/nested/model.js",
| "file": "test-examples/resources/tmp/test_project/nested/model.js",
| "position": 173,
| "_type": "com.opticdev.arrow.changes.location.AsChildOf"
| },
| "inputValue": {"name": "user", "schema": { "firstName": { "type": "string"} }},
| "inputValue": {"name": "user", "schema": { "firstName": { "type": "string"}, "lastName": { "type": "string"}, "email": { "type": "string"} }},
| "_type":"com.opticdev.arrow.changes.RunTransformation"
| }]
""".stripMargin
Expand All @@ -214,7 +214,7 @@ object ExampleChanges extends TestBase with TestPackageProviders {
val changeGroup = Json.fromJson[ChangeGroup](Json.parse(changesJSON)).get


(changeGroup, sourcegear, "import mongoose from 'mongoose'\n\nconst user = mongoose.model('user', new mongoose.Schema({\n 'firstName': 'string',\n 'lastName': 'string',\n 'email': 'string',\n}))\n\napp.post('/user', function (req, res) {\n req.body.firstName\n})")
(changeGroup, sourcegear, "import mongoose from 'mongoose'\n\nconst model = mongoose.model('user', new mongoose.Schema({\n 'firstName': 'string',\n 'lastName': 'string',\n 'email': 'string',\n}))\n\napp.post('/user', function (req, res) {\n req.body.firstName\n req.body.lastName\n req.body.email\n})")

}

Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
testParser: "/Users/aidancunniffe/Developer/knack/parsers/javascript-lang/target/scala-2.12/es7_2.12-0.1.0.jar"
testParser: "server/src/main/resources/es7_2.12-0.1.0.jar"
67 changes: 0 additions & 67 deletions core/src/main/scala-2.12/com/opticdev/core/cli/Installer.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import scala.util.{Failure, Try}

object SGConstructor {

def fromProjectFile(projectFile: ProjectFile) (implicit projectKnowledgeSearchPaths: ProjectKnowledgeSearchPaths = ProjectKnowledgeSearchPaths()) : Future[SGConfig] = Future {
def fromProjectFile(projectFile: ProjectFile) : Future[SGConfig] = Future {

implicit val projectKnowledgeSearchPaths = projectFile.projectKnowledgeSearchPaths

val dependencies = dependenciesForProjectFile(projectFile).get

val compiled = compileDependencyTree(dependencies).get
Expand All @@ -28,8 +31,11 @@ object SGConstructor {
SGConfig(dependencies.hash, parsersRefs.get, gears, schemaSet, transformationSet)
}

def dependenciesForProjectFile(projectFile: ProjectFile) : Try[DependencyTree] = {
val dependencies = projectFile.dependencies.getOrElse(Vector())
def dependenciesForProjectFile(projectFile: ProjectFile): Try[DependencyTree] = {

implicit val projectKnowledgeSearchPaths = projectFile.projectKnowledgeSearchPaths

val dependencies: Seq[PackageRef] = projectFile.dependencies.getOrElse(Vector())
PackageManager.collectPackages(dependencies)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,35 @@ abstract class SourceGear {
val parsed = parsedOption.get
val astGraph = parsed.graph

//@todo clean this up and have the parser return in the parse result.
val parser = parsers.find(_.languageName == parsed.language).get
implicit val sourceGearContext = SGContext(gearSet.fileAccumulator, astGraph, parser, fileContents)
//@todo clean this up and have the parser return in the parse result. right now it only supports the test one
// val parser = parsers.find(_.languageName == parsed.language).get
implicit val sourceGearContext = SGContext(gearSet.fileAccumulator, astGraph, SourceParserManager.installedParsers.head, fileContents)
gearSet.parseFromGraph(fileContents, astGraph, sourceGearContext, project)
} else {
throw parsedOption.failed.get
}
}

def isLoaded : Boolean = true

}

case object UnloadedSourceGear extends SourceGear {
override val parsers = Set()
override val gearSet = new GearSet()
override val schemas = Set()
override val transformations = Set()

override def isLoaded = false
}

object SourceGear {
def default: SourceGear = new SourceGear {
override val parsers: Set[ParserBase] = Set()
override val gearSet = new GearSet()
override val schemas = Set()
override val transformations = Set()
}

def unloaded = UnloadedSourceGear
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,4 @@ abstract class OpticProject(val name: String, val baseDirectory: File)(implicit
}

def filesToWatch : Set[File] = baseDirectory.listRecursively.toVector.filter(shouldWatchFile).toSet

/* Output the search paths for MD in project */

def projectSearchPaths : ProjectKnowledgeSearchPaths = {
val searchPaths = projectFile.interface
.map(_.knowledgePaths.value.toVector)
.getOrElse(Vector())
.collect {
case s: YamlString => File(s.value)
}
.filter(f=> f.exists && f.isDirectory)

ProjectKnowledgeSearchPaths(searchPaths:_*)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ class Project(name: String, baseDirectory: File)(implicit logToCli: Boolean = fa

private var sourceGear: SourceGear = {
projectFileChanged(projectFile)
SourceGear.default
SourceGear.unloaded
}

//do this after sourcegear is initialized

override def projectFileChanged(newPf: ProjectFile): Unit = {
super.projectFileChanged(newPf)
if (newPf.interface.isSuccess) {
SGConstructor.fromProjectFile(newPf)(projectSearchPaths).onComplete(i => {
SGConstructor.fromProjectFile(newPf).onComplete(i => {
if (i.isSuccess) {
sourceGear = i.get.inflate
//run all callbacks
sourcegearchangedCallbacks.foreach(_.apply(sourceGear))
projectStatusInstance.sourceGearStatus = Valid
if (projectStatus.monitoringStatus == Watching) rereadAll
} else {
println(i.failed.get.printStackTrace())
projectStatusInstance.sourceGearStatus = Invalid(i.failed.get.getMessage)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.nio.file.NoSuchFileException
import better.files.File
import com.opticdev.common.PackageRef
import com.opticdev.core.sourcegear.InvalidProjectFileException
import com.opticdev.opm.providers.ProjectKnowledgeSearchPaths
import com.opticdev.parsers.utils.Crypto
import org.yaml.snakeyaml.parser.ParserException

Expand Down Expand Up @@ -109,4 +110,20 @@ class ProjectFile(val file: File, createIfDoesNotExist : Boolean = true, onChang

}

def projectKnowledgeSearchPaths : ProjectKnowledgeSearchPaths = {
val searchPaths = interface
.map(_.knowledgePaths.value.toVector)
.getOrElse(Vector())
.collect {
case s: YamlString => {
val b = new java.io.File(file.parent.pathAsString, s.value)
val absolute = b.getCanonicalPath
File(absolute)
}
}
.filter(f=> f.exists && f.isDirectory)

ProjectKnowledgeSearchPaths(searchPaths:_*)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SGConfigSpec extends TestBase with TestPackageProviders {
}

it("can generate a hexadecimal from hash") {
assert(sgConfig.hashString == "74af44cb")
assert(sgConfig.hashString == "55ea873")
}

it("can inflate to a sourcegear instance") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SGConstructorSpec extends TestBase with TestPackageProviders {
lazy val projectFile = new ProjectFile(File("test-examples/resources/example_packages/express/optic.yaml"))

it("can resolve all dependencies in a project file") {
assert(SGConstructor.dependenciesForProjectFile(projectFile).get.toString == """Tree(Vector(Leaf(OpticMDPackage({"metadata":{"name":"express-js","author":"optic","version":"0.1.0"},"dependencies":{"optic:rest":"0.1.0"},"lenses":[{"name":"Parameter","scope":"internal","schema":"optic:rest/parameter","snippet":{"name":"Parameter","language":"es7","version":"es6","block":"req.query.name"},"rules":[],"variables":[],"subcontainers":[],"components":[{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"query","occurrence":0},"propertyPath":["in"]},{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"name","occurrence":0},"propertyPath":["name"]}]},{"name":"Example Route","scope":"public","schema":"optic:rest/route","snippet":{"name":"Example Route","language":"es7","block":"app.get('url', function (req, res) {\n //:callback \n})"},"rules":[{"type":"children","finder":{"type":"stringFinder","rule":"starting","string":"{","occurrence":0},"ruleType":"any"}],"variables":[],"subcontainers":[{"name":"callback","subcontainer":true,"pulls":[],"childrenRule":"any","schemaComponents":[{"type":"schema","schema":"optic:rest/parameter","propertyPath":["parameters"],"mapUnique":true}]}],"components":[{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"get","occurrence":0},"propertyPath":["method"]},{"type":"code","finder":{"type":"stringFinder","rule":"containing","string":"url","occurrence":0},"propertyPath":["url"]},{"type":"schema","schema":"parameter","mapUnique":true,"propertyPath":["parameters"],"location":{"type":"InParent","finder":null},"options":{"lookupTable":null,"invariant":false,"parser":null,"mutator":null}}]}]},Map(PackageRef(optic:rest,0.1.0) -> PackageRef(optic:rest,0.1.0))),Tree(Vector(Leaf(OpticMDPackage({"metadata":{"name":"rest","author":"optic","version":"0.1.0"},"schemas":[{"id":"route","definition":{"title":"Route","version":"1.0.0","type":"object","required":["method","url"],"properties":{"method":{"type":"string"},"url":{"type":"string"},"parameters":{"type":"array","items":{"$ref":"#/definitions/parameter"}}},"definitions":{"parameter":{"title":"Parameter","version":"1.0.0","slug":"js-example-route-parameter","type":"object","required":["in","name"],"properties":{"in":{"type":"string"},"name":{"type":"string"}}}}}},{"id":"parameter","definition":{"title":"Parameter","version":"1.0.0","type":"object","required":["in","name"],"properties":{"in":{"type":"string"},"name":{"type":"string"}}}}]},Map()),Tree(Vector())))))))""")
assert(SGConstructor.dependenciesForProjectFile(projectFile).get.toString == """Tree(Vector(Leaf(OpticMDPackage({"metadata":{"name":"express-js","author":"optic","version":"0.1.0"},"dependencies":["optic:[email protected]"],"lenses":[{"name":"Parameter","scope":"internal","schema":"optic:rest/parameter","snippet":{"name":"Parameter","language":"es7","version":"es6","block":"req.query.name"},"rules":[],"variables":[],"subcontainers":[],"components":[{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"query","occurrence":0},"propertyPath":["in"]},{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"name","occurrence":0},"propertyPath":["name"]}]},{"name":"Example Route","scope":"public","schema":"optic:rest/route","snippet":{"name":"Example Route","language":"es7","block":"app.get('url', function (req, res) {\n //:callback \n})"},"rules":[{"type":"children","finder":{"type":"stringFinder","rule":"starting","string":"{","occurrence":0},"ruleType":"any"}],"variables":[],"subcontainers":[{"name":"callback","subcontainer":true,"pulls":[],"childrenRule":"any","schemaComponents":[{"type":"schema","schema":"optic:rest/parameter","propertyPath":["parameters"],"mapUnique":true}]}],"components":[{"type":"code","finder":{"type":"stringFinder","rule":"entire","string":"get","occurrence":0},"propertyPath":["method"]},{"type":"code","finder":{"type":"stringFinder","rule":"containing","string":"url","occurrence":0},"propertyPath":["url"]},{"type":"schema","schema":"parameter","mapUnique":true,"propertyPath":["parameters"],"location":{"type":"InParent","finder":null},"options":{"lookupTable":null,"invariant":false,"parser":null,"mutator":null}}]}]},Map(PackageRef(optic:rest,0.1.0) -> PackageRef(optic:rest,0.1.0))),Tree(Vector(Leaf(OpticMDPackage({"metadata":{"name":"rest","author":"optic","version":"0.1.0"},"schemas":[{"id":"route","definition":{"title":"Route","version":"1.0.0","type":"object","required":["method","url"],"properties":{"method":{"type":"string"},"url":{"type":"string"},"parameters":{"type":"array","items":{"$ref":"#/definitions/parameter"}}},"definitions":{"parameter":{"title":"Parameter","version":"1.0.0","slug":"js-example-route-parameter","type":"object","required":["in","name"],"properties":{"in":{"type":"string"},"name":{"type":"string"}}}}}},{"id":"parameter","definition":{"title":"Parameter","version":"1.0.0","type":"object","required":["in","name"],"properties":{"in":{"type":"string"},"name":{"type":"string"}}}}]},Map()),Tree(Vector())))))))""")
}

it("can compile dependencies") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FileAccumulatorSpec extends AkkaTestFixture("FileAccumulatorTest") with Ge

it("map unique schemas finds valid + distinct instances") {

val sourceGear = sourceGearFromDescription("/Users/aidancunniffe/Developer/knack/optic-core/test-examples/resources/example_packages/optic:[email protected]")
val sourceGear = sourceGearFromDescription("test-examples/resources/example_packages/optic:[email protected]")
val result = sourceGear.parseFile(File("test-examples/resources/example_source/ExampleExpress.js"))

implicit val sourceGearContext = SGContext(sourceGear.fileAccumulator, result.get.astGraph, SourceParserManager.installedParsers.head, null)
Expand Down
Loading

0 comments on commit 3b4ee6e

Please sign in to comment.