Skip to content

Commit

Permalink
Merge pull request #37 from delphi-hub/release/0.9.5
Browse files Browse the repository at this point in the history
Release/0.9.5
  • Loading branch information
bhermann authored Jan 8, 2020
2 parents 9f7b01c + 518f76a commit 94b1fc0
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 247 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: scala
scala:
- 2.12.4
- 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'
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Delphi Command-Line Interface (CLI)
# Delphi Command-Line Interface (CLI) <img src="https://github.com/delphi-hub/delphi/raw/master/img/delphi.png" align="right" height=140/>

The command-line interface for the Delphi platform.

We are currently in pre-alpha state! There is no release and the code in
this repository is purely experimental!

|branch | status | codacy | snyk |
| :---: | :---: | :---: | :---: |
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/app/delphi-hub/delphi-cli?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-cli&amp;utm_campaign=Badge_Grade)| [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli?targetFile=build.sbt) |
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075?branch=develop)](https://www.codacy.com/app/delphi-hub/delphi-cli?branch=develop&amp;utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-cli&amp;utm_campaign=Badge_Grade)| [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/develop/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli/develop?targetFile=build.sbt)
|branch | status | codacy | coverage | snyk |
| :---: | :---: | :---: | :---: | :---: |
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/app/delphi-hub/delphi-cli?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-cli&amp;utm_campaign=Badge_Grade) | [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/manual/delphi-hub/delphi-cli?utm_source=github.com&utm_medium=referral&utm_content=delphi-hub/delphi-cli&utm_campaign=Badge_Coverage) | [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli?targetFile=build.sbt) |
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075?branch=develop)](https://www.codacy.com/app/delphi-hub/delphi-cli?branch=develop&amp;utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-cli&amp;utm_campaign=Badge_Grade)| [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/manual/delphi-hub/delphi-cli?utm_source=github.com&utm_medium=referral&utm_content=delphi-hub/delphi-cli&utm_campaign=Badge_Coverage) | [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/develop/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli/develop?targetFile=build.sbt)

## What is the Delphi Command-Line Interface?

Expand Down Expand Up @@ -42,8 +42,8 @@ Our software is available as a binary release on [GitHub](https://github.com/del

```
$ delphi --help
Delphi Command Line Tool (1.0.0-SNAPSHOT)
Usage: delphi [test|retrieve|search] [options] <args>...
Delphi Command Line Tool (0.9.5-SNAPSHOT)
Usage: delphi-cli [test|features|retrieve|search] [options] <args>...
--version Prints the version of the command line tool.
--help Prints this help text.
Expand Down
97 changes: 82 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,47 +1,114 @@
scalaVersion := "2.12.4"
import com.typesafe.sbt.packager.docker._

ThisBuild / organization := "de.upb.cs.swt.delphi"
ThisBuild / organizationName := "Delphi Project"
ThisBuild / organizationHomepage := Some(url("https://delphi.cs.uni-paderborn.de/"))

ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/delphi-hub/delphi-cli"),
"scm:[email protected]:delphi-hub/delphi-cli.git"
)
)

ThisBuild / developers := List(
Developer(
id = "bhermann",
name = "Ben Hermann",
email = "[email protected]",
url = url("https://www.thewhitespace.de")
)
)

ThisBuild / description := "The command line client for Delphi"
ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / homepage := Some(url("https://delphi.cs.uni-paderborn.de/"))

lazy val scala212 = "2.12.10"
lazy val scala213 = "2.13.1"
lazy val supportedScalaVersions = List(scala213)

ThisBuild / scalaVersion := scala213

name := "delphi"
version := "1.0.0-SNAPSHOT"
version := "0.9.5"
maintainer := "Ben Hermann <[email protected]>"

licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"))

packageSummary := "Windows Package for the Delphi CLI"
packageDescription := """Windows Package for the Delphi CLI"""
wixProductId := "ce07be71-510d-414a-92d4-dff47631848a"
wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424"

scalastyleConfig := baseDirectory.value / "project" / "scalastyle_config.xml"

val akkaVersion = "2.5.14"
val akkaHttpVersion = "10.1.5"
val http4sVersion = "0.21.0-M6"

// Only necessary for SNAPSHOT releases
resolvers += Resolver.sonatypeRepo("snapshots")

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.http4s" %% "http4s-blaze-client" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion
)

libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.1"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.5"
libraryDependencies += "de.vandermeer" % "asciitable" % "0.3.2"
libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.5"
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.7"
libraryDependencies += "au.com.bytecode" % "opencsv" % "2.4"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0" % "test"
libraryDependencies += "joda-time" % "joda-time" % "2.10.5"

libraryDependencies += "de.upb.cs.swt.delphi" %% "delphi-core" % "0.9.2"
libraryDependencies += "de.upb.cs.swt.delphi" %% "delphi-client" % "0.9.2"

libraryDependencies ++= Seq(
"com.softwaremill.sttp" %% "core" % "1.7.2",
"com.softwaremill.sttp" %% "spray-json" % "1.7.2"
)


debianPackageDependencies := Seq("java8-runtime-headless")
mainClass in Compile := Some("de.upb.cs.swt.delphi.cli.DelphiCLI")
discoveredMainClasses in Compile := Seq()

lazy val cli = (project in file(".")).
enablePlugins(JavaAppPackaging).
enablePlugins(DockerPlugin).
settings(
dockerBaseImage := "openjdk:jre-alpine",
dockerAlias := com.typesafe.sbt.packager.docker.DockerAlias(None, Some("delphihub"),"delphi-cli", Some(version.value)),
dockerEntrypoint := Seq("/bin/bash"),
dockerCommands ++= Seq(
Cmd("USER", "root"),
Cmd("RUN", "apk", "--no-cache", "add", "bash"),
Cmd("RUN", "ln", "-s", "/opt/docker/bin/delphi", "/usr/bin/delphi" ),
Cmd("USER", "daemon")
)
).
enablePlugins(ScalastylePlugin).
enablePlugins(BuildInfoPlugin).
enablePlugins(DebianPlugin).
enablePlugins(WindowsPlugin).

enablePlugins(GraalVMNativeImagePlugin).
settings(
graalVMNativeImageOptions ++= Seq(
"--enable-https",
"--enable-http",
"--enable-all-security-services",
"--allow-incomplete-classpath",
"--enable-url-protocols=http,https"
)
).
enablePlugins(JDKPackagerPlugin).
settings(
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.upb.cs.swt.delphi.cli"
buildInfoPackage := "de.upb.cs.swt.delphi.cli",
crossScalaVersions := supportedScalaVersions
)
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"

trapExit := false
fork := true
connectInput := true
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.1.1
sbt.version = 1.2.8
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// build management and packaging
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.15")

// coverage
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.12")
// addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
// addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.14")

// preparation for dependency checking
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.1")
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/de/upb/cs/swt/delphi/cli/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ package de.upb.cs.swt.delphi.cli
* @param verbose Marker if logging should be verbose
* @param mode The command to be run
*/
case class Config(server: String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"),
case class Config(server: String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api"),
verbose: Boolean = false,
raw: Boolean = false,
csv: String = "",
silent: Boolean = false,
list : Boolean = false,
mode: String = "",
query : String = "",
limit : Option[Int] = None,
id : String = "",
timeout : Option[Int] = None,
args: List[String] = List(),
opts: List[String] = List()) {

lazy val consoleOutput = new ConsoleOutput(this)
lazy val csvOutput = new CsvOutput(this)

}
2 changes: 2 additions & 0 deletions src/main/scala/de/upb/cs/swt/delphi/cli/ConsoleOutput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package de.upb.cs.swt.delphi.cli

import de.upb.cs.swt.delphi.cli.artifacts.{RetrieveResult, SearchResult}
import de.upb.cs.swt.delphi.client.FieldDefinition

class ConsoleOutput(config: Config) {

Expand Down Expand Up @@ -45,6 +46,7 @@ class ConsoleOutput(config: Config) {
}
}
case retrieveResults : Seq[RetrieveResult] if retrieveResults.head.isInstanceOf[RetrieveResult] => ResultBeautifier.beautifyRetrieveResults(retrieveResults)
case featureResults : Seq[FieldDefinition] if featureResults.head.isInstanceOf[FieldDefinition] => ResultBeautifier.beautifyFeatures(featureResults)
case _ => value.toString
}
}
Expand Down
69 changes: 69 additions & 0 deletions src/main/scala/de/upb/cs/swt/delphi/cli/CsvOutput.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.cli

import java.io.{BufferedWriter, FileWriter}

import de.upb.cs.swt.delphi.cli.artifacts.Result
import au.com.bytecode.opencsv.CSVWriter

import scala.collection.JavaConverters._

/**
* Export search and retrieve results to .csv file.
*
* @author Lisa Nguyen Quang Do
* @author Ben Hermann
*
*/

class CsvOutput(config: Config) {

def exportResult(value: Any): Unit = {
printToCsv(
value match {
case results :
Seq[Result] if results.headOption.getOrElse(Seq.empty[Array[String]]).isInstanceOf[Result] => resultsToCsv(results)
case _ => Seq.empty[Array[String]]
}
)
}

def printToCsv(table : Seq[Array[String]]): Unit = {
val outputFile = new BufferedWriter(new FileWriter(config.csv, /* append = */false))
val csvWriter = new CSVWriter(outputFile)
csvWriter.writeAll(seqAsJavaList(table))
outputFile.close()
}

def resultsToCsv(results : Seq[Result]) : Seq[Array[String]] = {
val headOption = results.headOption.getOrElse()
if (!headOption.isInstanceOf[Result]) {
Seq.empty[Array[String]]
} else {
val fieldNames = headOption.asInstanceOf[Result].fieldNames()
val tableHeader : Array[String] =
fieldNames.+:("discovered at").+:("version").+:("groupId").+:("artifactId").+:("source").+:("Id").toArray
results.map {
e => {
Array(e.id, e.metadata.source, e.metadata.artifactId, e.metadata.groupId, e.metadata.version,
e.metadata.discovered).++(fieldNames.map(f => e.metricResults(f).toString))
}
}.+:(tableHeader)
}
}
}
Loading

0 comments on commit 94b1fc0

Please sign in to comment.