diff --git a/.travis.yml b/.travis.yml index 0a2dc6c..ecda7fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ language: scala scala: - - 2.12.4 + - 2.12.10 + - 2.13.1 script: - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; fi' +# - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; fi' after_success: - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi' +# - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi' diff --git a/build.sbt b/build.sbt index 1ce73e9..b6b6119 100644 --- a/build.sbt +++ b/build.sbt @@ -29,7 +29,7 @@ ThisBuild / publishTo := { } ThisBuild / publishMavenStyle := true -ThisBuild / version := "0.9.0" +ThisBuild / version := "0.9.1" lazy val scala212 = "2.12.10" lazy val scala213 = "2.13.1" @@ -38,8 +38,6 @@ lazy val supportedScalaVersions = List(scala212, scala213) ThisBuild / scalaVersion := scala213 -useGpg := true - lazy val root = (project in file(".")) .settings ( crossScalaVersions := Nil, diff --git a/client/build.sbt b/client/build.sbt index a4a638d..4188316 100644 --- a/client/build.sbt +++ b/client/build.sbt @@ -1,6 +1,11 @@ name := "delphi-client" -libraryDependencies += "io.spray" %% "spray-json" % "1.3.5" libraryDependencies += "joda-time" % "joda-time" % "2.10.5" + +libraryDependencies ++= Seq( + "com.softwaremill.sttp" %% "core" % "1.7.2", + "com.softwaremill.sttp" %% "spray-json" % "1.7.2" +) + libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test" \ No newline at end of file diff --git a/client/src/main/scala/de/upb/cs/swt/delphi/client/DelphiClient.scala b/client/src/main/scala/de/upb/cs/swt/delphi/client/DelphiClient.scala new file mode 100644 index 0000000..c7955e0 --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/DelphiClient.scala @@ -0,0 +1,33 @@ +package de.upb.cs.swt.delphi.client + +import com.softwaremill.sttp._ +import com.softwaremill.sttp.sprayJson._ +import spray.json._ + +import scala.util.Try +import de.upb.cs.swt.delphi.core.model.Artifact +import de.upb.cs.swt.delphi.client.QueryJson._ + +abstract class DelphiClient(baseUri : String) { + def search(query : Query, prettyPrint : Boolean = false) : Try[Seq[SearchResult]] + /* = { + val queryParams = prettyPrint match { + case true => Map("pretty" -> "") + case false => Map() + } + val searchUri = uri"${baseUri}/search?$queryParams" + + val request = sttp.body(query.toJson).post(searchUri) + + //val (res, time) = processRequest(request) + //res.foreach(processResults(_, time)) + }*/ + + def features() : Try[Seq[FieldDefinition]] + + def retrieve(identifier : String) : Try[Artifact] + + def version() : Try[String] + + def statistics() : Try[Statistics] +} diff --git a/client/src/main/scala/de/upb/cs/swt/delphi/client/FieldDefinition.scala b/client/src/main/scala/de/upb/cs/swt/delphi/client/FieldDefinition.scala new file mode 100644 index 0000000..e6333cb --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/FieldDefinition.scala @@ -0,0 +1,25 @@ +// Copyright (C) 2018 The Delphi Team. +// See the LICENCE file distributed with this work for additional +// information regarding copyright ownership. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package de.upb.cs.swt.delphi.client + +import spray.json.DefaultJsonProtocol + +case class FieldDefinition(name : String, description : String) + +object FieldDefinitionJson extends DefaultJsonProtocol { + implicit val transform = jsonFormat2(FieldDefinition) +} \ No newline at end of file diff --git a/client/src/main/scala/de/upb/cs/swt/delphi/client/Query.scala b/client/src/main/scala/de/upb/cs/swt/delphi/client/Query.scala new file mode 100644 index 0000000..8716953 --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/Query.scala @@ -0,0 +1,9 @@ +package de.upb.cs.swt.delphi.client + +import spray.json.DefaultJsonProtocol + +case class Query(query : String, limit : Option[Int] = Some(50)) + +object QueryJson extends DefaultJsonProtocol { + implicit val queryRequestFormat = jsonFormat2(Query) +} diff --git a/client/src/main/scala/de/upb/cs/swt/delphi/client/Statistics.scala b/client/src/main/scala/de/upb/cs/swt/delphi/client/Statistics.scala new file mode 100644 index 0000000..d623ad9 --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/Statistics.scala @@ -0,0 +1,3 @@ +package de.upb.cs.swt.delphi.client + +case class Statistics(total : Long, hermesEnabled : Long) diff --git a/client/src/main/scala/de/upb/cs/swt/delphi/client/StatisticsJson.scala b/client/src/main/scala/de/upb/cs/swt/delphi/client/StatisticsJson.scala new file mode 100644 index 0000000..9dc0bba --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/StatisticsJson.scala @@ -0,0 +1,7 @@ +package de.upb.cs.swt.delphi.client + +import spray.json.DefaultJsonProtocol + +object StatisticsJson extends DefaultJsonProtocol { + implicit val statisticsFormat = jsonFormat2(Statistics) +} diff --git a/core/src/main/scala/de/upb/cs/swt/delphi/core/ql/Syntax.scala b/core/src/main/scala/de/upb/cs/swt/delphi/core/ql/Syntax.scala index 3e5c13f..dc698ce 100644 --- a/core/src/main/scala/de/upb/cs/swt/delphi/core/ql/Syntax.scala +++ b/core/src/main/scala/de/upb/cs/swt/delphi/core/ql/Syntax.scala @@ -67,10 +67,10 @@ class Syntax(val input : ParserInput) extends Parser { def IsTrue = rule { FieldReferenceRule ~> IsTrueExpr } // Literals - def FieldReferenceRule = rule { "[" ~ capture(oneOrMore(CharPredicate.AlphaNum ++ '-' ++ ' ' ++ '_' ++ '(' ++ ':' ++')')) ~ "]" ~> FieldReference } + def FieldReferenceRule = rule { "[" ~ capture(oneOrMore(CharPredicate.AlphaNum ++ '.' ++ '-' ++ ' ' ++ '_' ++ '(' ++ ':' ++')')) ~ "]" ~> FieldReference } def IntegerLiteral = rule { capture(oneOrMore(CharPredicate.Digit)) } - def StringLiteral = rule { '"' ~ capture(oneOrMore(CharPredicate.AlphaNum)) ~ '"'} + def StringLiteral = rule { '"' ~ capture(oneOrMore(CharPredicate.Printable -- '"' )) ~ '"'} def Literal = rule { (IntegerLiteral | StringLiteral ) ~> (_.toString) } diff --git a/core/src/test/scala/de/upb/cs/swt/delphi/core/SyntaxTest.scala b/core/src/test/scala/de/upb/cs/swt/delphi/core/SyntaxTest.scala index 0323d5e..98ab0f7 100644 --- a/core/src/test/scala/de/upb/cs/swt/delphi/core/SyntaxTest.scala +++ b/core/src/test/scala/de/upb/cs/swt/delphi/core/SyntaxTest.scala @@ -16,7 +16,8 @@ package de.upb.cs.swt.delphi.core -import de.upb.cs.swt.delphi.core.ql.Syntax +import de.upb.cs.swt.delphi.core.ql._ +import org.parboiled2.ParseError import org.scalatest.{FlatSpec, Matchers} import scala.util.{Failure, Success} @@ -166,7 +167,7 @@ class SyntaxTest extends FlatSpec with Matchers { "Syntax.notConditionComplex" should "be valid" in { val parseResult = new Syntax("!!([Filter1])&&!([Filter2]<=0||!([Filter3]&&![Filter4]%\"abc\"))").QueryRule.run() - parseResult shouldBe a [Success[_]] + parseResult shouldBe a[Success[_]] parseResult match { case Success(ast) => { ast.toString shouldEqual "AndExpr(NotExpr(NotExpr(IsTrueExpr(FieldReference(Filter1))))," + @@ -175,4 +176,23 @@ class SyntaxTest extends FlatSpec with Matchers { } } } + + "Complex query" should "be valid" in { + val parser = new Syntax("[metrics.classversion.9] > 0 && [metrics.classversion.8] = 0 && [maven.groupId] = \"com.github.xmlet\"") + val parseResult = parser.QueryRule.run() + parseResult match { + case Success(ast) => { + ast shouldEqual + AndExpr( + AndExpr( + GreaterThanExpr(FieldReference("metrics.classversion.9"),"0"), + EqualExpr(FieldReference("metrics.classversion.8"),"0")), + EqualExpr(FieldReference("maven.groupId"),"com.github.xmlet")) + } + case Failure(exception : ParseError) => { + fail(parser.formatError(exception)) + } + case _ => fail() + } + } } \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..4dc55a1 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,29 @@ +// Copyright (C) 2019 The Delphi Team. +// See the LICENCE file distributed with this work for additional +// information regarding copyright ownership. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// build management and packaging +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.1") + +// coverage +//addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1") +//addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "3.0.3") + +// preparation for dependency checking +addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.1") + +// scalastyle +addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") \ No newline at end of file