-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from delphi-hub/develop
Pre-Release Merge
- Loading branch information
Showing
13 changed files
with
251 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 0.13.17 | ||
sbt.version = 1.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/main/scala/de/upb/cs/swt/delphi/cli/commands/Command.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") | ||
} | ||
|
||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/scala/de/upb/cs/swt/delphi/cli/commands/RetrieveCommand.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/main/scala/de/upb/cs/swt/delphi/cli/commands/TestCommand.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |