Skip to content

Commit

Permalink
Merge pull request #12 from mp911de/issue/variable-properties-header
Browse files Browse the repository at this point in the history
Use configured baseUrl in versioneye.properties header #8
  • Loading branch information
reiz committed Feb 17, 2016
2 parents 2ae4364 + 621112f commit 8416f2f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ Compile it:
sbt compile
```

Enable it within your `build.sbt`
Enable it within your `build.sbt` and optionally set properties:

```
enablePlugins(VersionEyePlugin)
// VersionEyePlugin.projectSettings
propertiesPath in versioneye := "/Users/mark/playground/sbt-test/src/qa/resources/versioneye.properties"
apiKey in versioneye := "myApiKey"
baseUrl in versioneye := "https://www.versioneye.com"
apiPath in versioneye := "/api/v2"
publishCrossVersion in versioneye := true
```

## Create a VersionEye project
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/com/versioneye/PropertiesUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object PropertiesUtil {

protected val propertiesFile: String = "versioneye.properties"

def writeProperties(response: ProjectJsonResponse, propertiesFile: File): Unit = {
def writeProperties(response: ProjectJsonResponse, propertiesFile: File, baseUrl: String): Unit = {
var properties: Properties = null

if (!propertiesFile.exists()) {
Expand All @@ -23,13 +23,12 @@ object PropertiesUtil {
properties = loadProperties(propertiesFile)
}


if (response.getId != null) {
properties.setProperty("project_id", response.getId)
}

val fos = new FileOutputStream(propertiesFile)
properties.store(fos, " Properties for https://www.VersionEye.com")
properties.store(fos, s" Properties for $baseUrl")
fos.close()
}

Expand Down
31 changes: 19 additions & 12 deletions src/main/scala/com/versioneye/VersionEyePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object VersionEyePlugin extends sbt.AutoPlugin {
val log = streams.value.log

log.info(".")
log.info("Starting to upload dependencies. This can take a couple seconds ... ")
log.info("Starting to upload dependencies to " + baseUrl.value + ". This can take a couple seconds ... ")
log.info(".")

val scopes: List[String] = getScopes(skipScopes.value)
Expand Down Expand Up @@ -181,7 +181,7 @@ object VersionEyePlugin extends sbt.AutoPlugin {
}

if (updatePropertiesAfterCreate.value) {
writeProperties(projectResponse, getPropertiesFile(propertiesPath.value, baseDirectory.value, false))
writeProperties(projectResponse, getPropertiesFile(propertiesPath.value, baseDirectory.value, false), baseUrl.value)
}
prettyPrint(log, baseUrl.value, projectResponse)
}
Expand All @@ -194,7 +194,7 @@ object VersionEyePlugin extends sbt.AutoPlugin {
val log = streams.value.log

log.info(".")
log.info("Starting to upload dependencies. This can take a couple seconds ... ")
log.info("Starting to upload dependencies to " + baseUrl.value + ". This can take a couple seconds ... ")
log.info(".")

val scopes: List[String] = getScopes(skipScopes.value)
Expand Down Expand Up @@ -231,7 +231,7 @@ object VersionEyePlugin extends sbt.AutoPlugin {
val log = streams.value.log

log.info(".")
log.info("Starting to upload dependencies for license check. This can take a couple seconds ... ")
log.info("Starting to upload dependencies to " + baseUrl.value + " for license check. This can take a couple seconds ... ")
log.info(".")

val scopes: List[String] = getScopes(skipScopes.value)
Expand All @@ -244,7 +244,6 @@ object VersionEyePlugin extends sbt.AutoPlugin {
streams.value.log.info("There are no dependencies in this project !" + organization.value + " / " + name.value)
}


val apiKeyValue = getApiKey(apiKey.value, propertiesPath.value, baseDirectory.value)
val projectIdValue = getVersionEyeProjectId(existingProjectId.value, propertiesPath.value, baseDirectory.value)
val url = getUrl(baseUrl.value, apiPath.value, "/projects/", projectIdValue, "?api_key=" + apiKeyValue)
Expand All @@ -260,11 +259,13 @@ object VersionEyePlugin extends sbt.AutoPlugin {
val projectResponse = getResponse(response)

if (projectResponse.getLicenses_red > 0) {
throw new IllegalStateException("Some components violate the license whitelist! " + "More details here: " + baseUrl.value + "/user/projects/" + projectResponse.getId)
throw new IllegalStateException("Some components violate the license whitelist! " +
"More details here: " + baseUrl.value + "/user/projects/" + projectResponse.getId)
}

if (projectResponse.getLicenses_unknown > 0 && licenseCheckBreakByUnknown.value) {
throw new IllegalStateException("Some components are without any license! " + "More details here: " + baseUrl.value + "/user/projects/" + projectResponse.getId)
throw new IllegalStateException("Some components are without any license! " +
"More details here: " + baseUrl.value + "/user/projects/" + projectResponse.getId)
}

prettyPrint(log, baseUrl.value, projectResponse)
Expand All @@ -288,7 +289,7 @@ object VersionEyePlugin extends sbt.AutoPlugin {
def handleResponseErrorIfAny(response: HttpResponse[String]): Unit = {
if (!response.is2xx) {
val err = getErrorMessage(response);
val errMsg: String = "Status Code: " + response.statusLine + " -> " + err
val errMsg = err.map( msg => "Status Code: " + response.statusLine + " -> " + msg).getOrElse("Status Code: " + response.statusLine);
throw new scala.RuntimeException(errMsg)
}
}
Expand Down Expand Up @@ -316,7 +317,6 @@ object VersionEyePlugin extends sbt.AutoPlugin {

def getResponse(response: HttpResponse[String]): ProjectJsonResponse = {
val body = response.body

val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
return mapper.readValue[ProjectJsonResponse](body)
Expand All @@ -326,17 +326,24 @@ object VersionEyePlugin extends sbt.AutoPlugin {
* Get error message from a HTTP Response (JSON or raw body)
* @param response
*/
def getErrorMessage(response: HttpResponse[String]): String = {
def getErrorMessage(response: HttpResponse[String]): Option[String] = {
val body = response.body

// application/json
if (response.contentType.isEmpty
|| !"application/json".equals(response.contentType.get)
|| response.body.isEmpty) {
return None;
}

val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
val responseMap = mapper.readValue[Map[String, String]](body)
if (responseMap.contains("error")) {
return responseMap.get("error").get
return responseMap.get("error")
}

return body
return None
}

def getUrl(values: String*): String = {
Expand Down

0 comments on commit 8416f2f

Please sign in to comment.