Skip to content

Commit

Permalink
Merge pull request #22 from delphi-hub/develop
Browse files Browse the repository at this point in the history
Pre-Release Merge
  • Loading branch information
bhermann authored Aug 11, 2018
2 parents a47de6e + c0ba94f commit 2afb0dc
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 67 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
language: scala
scala:
- 2.12.4
- 2.12.4
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'
after_success:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi'
13 changes: 1 addition & 12 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,7 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2018 The Delphi Team (represented by Ben Hermann)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
21 changes: 19 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
name := "delphi-cli"
scalaVersion := "2.12.4"

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

scalaVersion := "2.12.4"
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"

libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-core" % "10.0.11"
)

debianPackageDependencies := Seq("java8-runtime-headless")

lazy val cli = (project in file(".")).
enablePlugins(JavaAppPackaging).
enablePlugins(DockerPlugin).
enablePlugins(ScalastylePlugin).
enablePlugins(BuildInfoPlugin).
enablePlugins(DebianPlugin).
enablePlugins(WindowsPlugin).

settings(
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.upb.cs.swt.delphi.cli"
)
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.17
sbt.version = 1.1.1
11 changes: 11 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
// build management and packaging
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")

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

// preparation for dependency checking
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.1")

// scalastyle
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
117 changes: 117 additions & 0 deletions project/scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<parameters>
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
// See the LICENCE.txt 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.]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLineLengthChecker" enabled="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
<parameter name="tabSize"><![CDATA[4]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
</scalastyle>
14 changes: 0 additions & 14 deletions src/main/scala/de/upb/cs/swt/delphi/cli/Command.scala

This file was deleted.

5 changes: 2 additions & 3 deletions src/main/scala/de/upb/cs/swt/delphi/cli/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ 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/"), verbose: Boolean = false, mode : String = "") {

}
case class Config (server : String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"),
verbose: Boolean = false, mode : String = "", args : List[String] = List(), opts : List[String] = List())
13 changes: 12 additions & 1 deletion src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.upb.cs.swt.delphi.cli

import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, TestCommand}


/**
* The application class for the Delphi command line interface
Expand All @@ -20,8 +22,16 @@ object DelphiCLI extends App {
checkConfig(c => if (c.server.isEmpty()) failure("Option server is required.") else success)

cmd("test").action((_,c) => c.copy(mode = "test"))

cmd("retrieve").action((s,c) => c.copy(mode = "retrieve"))
.text("Retrieve a project's description, specified by ID.")
.children(
arg[String]("ID").action((x, c) => c.copy(args = List(x))).text("The ID of the project to retrieve"),
opt[Unit]('f', "file").action((_, c) => c.copy(opts = List("file"))).text("Use to load the ID from file, " +
"with the filepath given in place of the ID")
)

//cmd("search")
//cmd("retrieve")
}
}

Expand All @@ -31,6 +41,7 @@ object DelphiCLI extends App {
cliParser.showHeader()
config.mode match {
case "test" => TestCommand.execute(config)
case "retrieve" => RetrieveCommand.execute(config)
case _ => println("Unknown command")
}

Expand Down
33 changes: 0 additions & 33 deletions src/main/scala/de/upb/cs/swt/delphi/cli/TestCommand.scala

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/scala/de/upb/cs/swt/delphi/cli/commands/Command.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.upb.cs.swt.delphi.cli.commands

import akka.http.scaladsl.model.Uri
import de.upb.cs.swt.delphi.cli.{BlockingHttpClient, Config}

import scala.util.{Failure, Success}

/**
* Represents the implementation of a command of the CLI
*/
trait Command {

/**
* Executes the command implementation
* @param config The current configuration for the command
*/
def execute(config: Config): Unit

/**
* Implements a common request type using currying to avoid code duplication
* @param target The endpoint to perform a Get request on
* @param onSuccess The function to perform on the response (eg. printing it)
* @param config The current configuration for the command
*/
protected def executeGet(target: String, onSuccess: String => Unit)(config: Config) : Unit = {

val uri = Uri(config.server)
println(s"Contacting server ${uri}...")
val resp = BlockingHttpClient.doGet(uri.withPath(uri.path + target))

resp match {
case Success(res) => onSuccess(res)
case Failure(_) => println(s"Could not reach server ${config.server}.")
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.upb.cs.swt.delphi.cli.commands

import de.upb.cs.swt.delphi.cli.Config
import scala.io.Source

/**
* The implementation of the retrieve command.
* Retrieves the contents of the file at the endpoint specified by the config file, and prints them to stdout
*/
object RetrieveCommand extends Command {
override def execute(config: Config): Unit = {
//Checks whether the ID should be loaded from a file or not, and either returns the first line
// of the given file if it is, or the specified ID otherwise
def checkTarget: String = {
if (config.opts.contains("file")) {
val source = Source.fromFile(config.args.head)
val target = source.getLines.next()
source.close()
target
} else config.args.head
}
executeGet(
"/retrieve/" + checkTarget,
s => println(s)
)(config)
}
}
17 changes: 17 additions & 0 deletions src/main/scala/de/upb/cs/swt/delphi/cli/commands/TestCommand.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.upb.cs.swt.delphi.cli.commands

import de.upb.cs.swt.delphi.cli.Config

/**
* The implementation of the test command.
* Tries to connect to the Delphi server and reports on the results of the version call.
*/
object TestCommand extends Command {
override def execute(config: Config): Unit = executeGet(
"/version",
s => {
println("Successfully contacted Delphi server. ")
println("Server version: " + s)
}
)(config)
}

0 comments on commit 2afb0dc

Please sign in to comment.