From ab483ce0f9942f69841f71f21cf2396664c58cd3 Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Thu, 21 Nov 2019 18:43:26 +0100 Subject: [PATCH 1/4] Added new objects to furnish the client --- client/build.sbt | 7 ++++- .../cs/swt/delphi/client/DelphiClient.scala | 29 +++++++++++++++++++ .../swt/delphi/client/FieldDefinition.scala | 25 ++++++++++++++++ .../de/upb/cs/swt/delphi/client/Query.scala | 9 ++++++ .../upb/cs/swt/delphi/client/Statistics.scala | 3 ++ .../cs/swt/delphi/client/StatisticsJson.scala | 7 +++++ 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 client/src/main/scala/de/upb/cs/swt/delphi/client/DelphiClient.scala create mode 100644 client/src/main/scala/de/upb/cs/swt/delphi/client/FieldDefinition.scala create mode 100644 client/src/main/scala/de/upb/cs/swt/delphi/client/Query.scala create mode 100644 client/src/main/scala/de/upb/cs/swt/delphi/client/Statistics.scala create mode 100644 client/src/main/scala/de/upb/cs/swt/delphi/client/StatisticsJson.scala diff --git a/client/build.sbt b/client/build.sbt index a4a638d..a3b164d 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.5.4", + "com.softwaremill.sttp" %% "spray-json" % "1.5.4" +)*/ + 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..59739fc --- /dev/null +++ b/client/src/main/scala/de/upb/cs/swt/delphi/client/DelphiClient.scala @@ -0,0 +1,29 @@ +package de.upb.cs.swt.delphi.client + +import scala.util.Try +import de.upb.cs.swt.delphi.client.QueryJson._ +import de.upb.cs.swt.delphi.core.model.Artifact + +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) +} From 2fd566ff9675b7e0cd5be0056e381ba4ea5e9637 Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Tue, 26 Nov 2019 16:28:56 +0100 Subject: [PATCH 2/4] Updating build information --- .travis.yml | 3 +- build.sbt | 2 -- client/build.sbt | 8 ++--- .../cs/swt/delphi/client/DelphiClient.scala | 12 +++++--- project/plugins.sbt | 29 +++++++++++++++++++ 5 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 project/plugins.sbt diff --git a/.travis.yml b/.travis.yml index 0a2dc6c..650984f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ 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' diff --git a/build.sbt b/build.sbt index 1ce73e9..fdb9777 100644 --- a/build.sbt +++ b/build.sbt @@ -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 a3b164d..4188316 100644 --- a/client/build.sbt +++ b/client/build.sbt @@ -2,10 +2,10 @@ name := "delphi-client" libraryDependencies += "joda-time" % "joda-time" % "2.10.5" -/* + libraryDependencies ++= Seq( - "com.softwaremill.sttp" %% "core" % "1.5.4", - "com.softwaremill.sttp" %% "spray-json" % "1.5.4" -)*/ + "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 index 59739fc..c7955e0 100644 --- 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 @@ -1,12 +1,16 @@ 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.client.QueryJson._ 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() @@ -17,8 +21,8 @@ abstract class DelphiClient(baseUri : String) { //val (res, time) = processRequest(request) //res.foreach(processResults(_, time)) - } - */ + }*/ + def features() : Try[Seq[FieldDefinition]] def retrieve(identifier : String) : Try[Artifact] diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..43eb9f1 --- /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 From 1e20c8b1e7c0c019061e6983730eff132560fe95 Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Mon, 30 Dec 2019 13:53:33 +0100 Subject: [PATCH 3/4] Fixed syntax --- build.sbt | 2 +- .../de/upb/cs/swt/delphi/core/ql/Syntax.scala | 4 ++-- .../upb/cs/swt/delphi/core/SyntaxTest.scala | 24 +++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/build.sbt b/build.sbt index fdb9777..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" 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 From 7e3435c044a4024210f6087e023489542b6b4f1c Mon Sep 17 00:00:00 2001 From: Ben Hermann Date: Mon, 30 Dec 2019 13:59:28 +0100 Subject: [PATCH 4/4] Deactivated coverage --- .travis.yml | 5 +++-- project/plugins.sbt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 650984f..ecda7fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ scala: - 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/project/plugins.sbt b/project/plugins.sbt index 43eb9f1..4dc55a1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -19,8 +19,8 @@ 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") +//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")