commit 27f1f3e9cc390d3c3b69484862cc8187e5947b8d Author: Erik C. Thauvin Date: Wed Jul 27 15:51:42 2016 -0700 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80a944b --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +**/.idea/dictionaries +**/.idea/gradle.xml +**/.idea/libraries +**/.idea/tasks.xml +**/.idea/workspace.xml +*.iws +.DS_Store +.classpath +.gradle +.kobalt +.nb-gradle +.project +.settings +/bin +/build +/deploy +/dist +/example/libs +/gen +/gradle.properties +/out +/proguard-project.txt +/project.properties +/target +/test-output +Thumbs.db +ehthumbs.db +kobaltBuild +local.properties diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a852314 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8ff795e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,53 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml new file mode 100644 index 0000000..999c7b6 --- /dev/null +++ b/.idea/kobalt.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e50b779 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Android Lint + + + Java + + + Portability issuesJava + + + + + + + + + + + + + + + + + + + + + + + 1.8.x + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6b87c48 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt new file mode 100644 index 0000000..7eede88 --- /dev/null +++ b/example/kobalt/src/Build.kt @@ -0,0 +1,48 @@ +import com.beust.kobalt.* +import com.beust.kobalt.plugin.packaging.* +import com.beust.kobalt.plugin.application.* +import com.beust.kobalt.plugin.kotlin.* +import net.thauvin.erik.kobalt.plugin.versioneye.* + +val repos = repos() + +val pl = plugins(file("../kobaltBuild/libs/kobalt-versioneye-0.4.0-beta.jar")) +//val pl = plugins("net.thauvin.erik:kobalt-maven-local:0.5.0") + +val p = project { + + name = "example" + group = "com.example" + artifactId = name + version = "0.1" + + sourceDirectories { + path("src/main/kotlin") + } + + sourceDirectoriesTest { + path("src/test/kotlin") + } + + dependencies { +// compile("com.beust:jcommander:1.48") + } + + dependenciesTest { + compile("org.testng:testng:") + + } + + assemble { + jar { + } + } + + application { + mainClass = "com.example.MainKt" + } + + versionEye { + //baseUrl = "" + } +} diff --git a/example/kobalt/wrapper/kobalt-wrapper.jar b/example/kobalt/wrapper/kobalt-wrapper.jar new file mode 100644 index 0000000..a4889db Binary files /dev/null and b/example/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties new file mode 100644 index 0000000..ed72412 --- /dev/null +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=0.871 \ No newline at end of file diff --git a/example/kobaltw b/example/kobaltw new file mode 100644 index 0000000..c5186d5 --- /dev/null +++ b/example/kobaltw @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/example/kobaltw.bat b/example/kobaltw.bat new file mode 100644 index 0000000..d578071 --- /dev/null +++ b/example/kobaltw.bat @@ -0,0 +1,4 @@ +@echo off +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* diff --git a/example/src/main/kotlin/com/example/Main.kt b/example/src/main/kotlin/com/example/Main.kt new file mode 100644 index 0000000..1df958f --- /dev/null +++ b/example/src/main/kotlin/com/example/Main.kt @@ -0,0 +1,3 @@ +package com.example + +fun main(args: Array) = println("\n\nHello Kotlin world from Kobalt\n\n") \ No newline at end of file diff --git a/example/src/test/kotlin/com/example/MainTest.kt b/example/src/test/kotlin/com/example/MainTest.kt new file mode 100644 index 0000000..96458e9 --- /dev/null +++ b/example/src/test/kotlin/com/example/MainTest.kt @@ -0,0 +1,8 @@ +package com.example + +import org.testng.annotations.Test + +class ExampleTest { + @Test + fun f() = println("Running test") +} \ No newline at end of file diff --git a/kobalt-versioneye.iml b/kobalt-versioneye.iml new file mode 100644 index 0000000..998bba4 --- /dev/null +++ b/kobalt-versioneye.iml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/Build.kt.iml b/kobalt/Build.kt.iml new file mode 100644 index 0000000..a5b227c --- /dev/null +++ b/kobalt/Build.kt.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt new file mode 100644 index 0000000..9fef7c2 --- /dev/null +++ b/kobalt/src/Build.kt @@ -0,0 +1,63 @@ +import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.publish.bintray +import com.beust.kobalt.project +import com.beust.kobalt.repos +import org.apache.maven.model.Developer +import org.apache.maven.model.License +import org.apache.maven.model.Model +import org.apache.maven.model.Scm + +val repos = repos() + + +val p = project { + + name = "kobalt-versioneye" + group = "net.thauvin.erik" + artifactId = name + version = "0.4.0-beta" + + pom = Model().apply { + description = "VersionEye plug-in for the Kobalt build system." + url = "https://github.com/ethauvin/kobalt-versioneye" + licenses = listOf(License().apply { + name = "BSD 3-Clause" + url = "https://opensource.org/licenses/BSD-3-Clause" + }) + scm = Scm().apply { + url = "https://github.com/ethauvin/kobalt-versioneye" + connection = "https://github.com/ethauvin/kobalt-versioneye.git" + developerConnection = "git@github.com:ethauvin/kobalt-versioneye.git" + } + developers = listOf(Developer().apply { + id = "ethauvin" + name = "Erik C. Thauvin" + email = "erik@thauvin.net" + }) + } + + sourceDirectories { + path("src/main/kotlin") + } + + sourceDirectoriesTest { + path("src/test/kotlin") + } + + dependencies { + compile("com.beust:kobalt-plugin-api:0.863") + } + + dependenciesTest { + compile("org.testng:testng:") + + } + + assemble { + mavenJars {} + } + + bintray { + publish = true + } +} diff --git a/kobalt/wrapper/kobalt-wrapper.jar b/kobalt/wrapper/kobalt-wrapper.jar new file mode 100644 index 0000000..a4889db Binary files /dev/null and b/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties new file mode 100644 index 0000000..ed72412 --- /dev/null +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=0.871 \ No newline at end of file diff --git a/kobaltw b/kobaltw new file mode 100644 index 0000000..c5186d5 --- /dev/null +++ b/kobaltw @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/kobaltw.bat b/kobaltw.bat new file mode 100644 index 0000000..d578071 --- /dev/null +++ b/kobaltw.bat @@ -0,0 +1,4 @@ +@echo off +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt new file mode 100644 index 0000000..bd092aa --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt @@ -0,0 +1,197 @@ +/* + * VersionEyePlugin.kt + * + * Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.thauvin.erik.kobalt.plugin.versioneye + +import com.beust.kobalt.Plugins +import com.beust.kobalt.TaskResult +import com.beust.kobalt.api.* +import com.beust.kobalt.api.annotation.Directive +import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.misc.warn +import com.google.gson.GsonBuilder +import com.google.gson.JsonObject +import com.google.inject.Inject +import com.google.inject.Singleton +import okhttp3.* +import java.io.File +import java.io.FileOutputStream +import java.nio.file.Files +import java.nio.file.Paths +import java.util.* + +@Singleton +class VersionEyePlugin @Inject constructor(val configActor: ConfigActor, + val taskContributor: TaskContributor) : + BasePlugin(), ITaskContributor, IConfigActor by configActor { + private val debug = true + private val API_KEY_PROPERTY = "versioneye.apiKey" + private val PROJECT_KEY_PROPERTY = "versioneye.projectKey" + private val PROJECT_ID_PROPERTY = "versioneye.projectId" + private val ORG_PROPERTY = "versioneye.organisation" + private val TEAM_PROPERTY = "versioneye.team" + private val httpClient = OkHttpClient() + + // ITaskContributor + override fun tasksFor(project: Project, context: KobaltContext): List = taskContributor.dynamicTasks + + companion object { + const val NAME: String = "VersionEye" + } + + override val name = NAME + + override fun apply(project: Project, context: KobaltContext) { + super.apply(project, context) + taskContributor.addVariantTasks(this, project, context, "versionEye", group = "publish", + runTask = { versionEye(project) }) + } + + @Task(name = "versionEye", description = "Update and check dependencies on VersionEye") + fun versionEye(project: Project): TaskResult { + + if (debug) { + System.setProperty("http.proxyHost", "127.0.0.1") + System.setProperty("https.proxyHost", "127.0.0.1") + System.setProperty("http.proxyPort", "8888"); + System.setProperty("https.proxyPort", "8888") + } + + val local = project.directory + "/local.properties" + + configurationFor(project)?.let { config -> + if (config.baseUrl.isBlank()) { + warn("Please specify a valid VersionEye base URL.") + return TaskResult() + } else { + var apiKey = System.getProperty(API_KEY_PROPERTY) + val p = Properties() + Paths.get(local).let { path -> + if (path.toFile().exists()) { + Files.newInputStream(path).use { + p.load(it) + } + } + } + + + if (apiKey.isNullOrBlank()) { + apiKey = p.getProperty(API_KEY_PROPERTY) + if (apiKey.isNullOrBlank()) { + warn("Please provide a valid VersionEye API key.") + return TaskResult() + } + } + p.setProperty(API_KEY_PROPERTY, apiKey) + + val result = versionEyeUpdate(if (config.name.isNotBlank()) { + config.name + } else { + project.name + }, config, p) + + FileOutputStream(local).use { output -> + p.store(output, "") + } + + return result + } + } + return TaskResult() + } + + private fun versionEyeUpdate(name: String, config: VersionEyeConfig, p: Properties): TaskResult { + val projectId = p.getProperty(PROJECT_ID_PROPERTY) + val apiKey = p.getProperty(API_KEY_PROPERTY); + val endPoint = if (projectId.isNullOrBlank()) { + "api/v2/projects" + } else { + "api/v2/project/$projectId" + } + + val file = File("../kobaltBuild/libs/kobalt-versioneye-0.4.0-beta.pom") + val requestBody = MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("name", name) + .addFormDataPart("upload", file.name, RequestBody.create(MediaType.parse("application/octet-stream"), file)) + + if (config.organisation.isNotBlank()) { + requestBody.addFormDataPart("orga_name", config.organisation) + } + + if (config.team.isNotBlank()) { + requestBody.addFormDataPart("team_name", config.team) + } + + // @TODO remove + requestBody.addFormDataPart("temp", "true") + + val url = HttpUrl.parse(config.baseUrl).newBuilder() + .addPathSegments(endPoint) + .setQueryParameter("api_key", apiKey) + .build() + val request = Request.Builder() + .url(url) + .post(requestBody.build()) + .build() + + val response = httpClient.newCall(request).execute() + if (!response.isSuccessful) { + warn("Unexpected response from VersionEye: " + response) + return TaskResult() + } else { + val builder = GsonBuilder() + val o = builder.create().fromJson(response.body().charStream(), JsonObject::class.java) + println(o) + } + return TaskResult() + } +} + +@Directive +class VersionEyeConfig() { + var baseUrl = "https://www.versioneye.com/" + var failOnUnknownLicense = false; + var licenseCheck = false; + var name = ""; + var organisation = ""; + var securityCheck = false; + var team = ""; + var visibility = true; +} + +@Directive +fun Project.versionEye(init: VersionEyeConfig.() -> Unit) { + VersionEyeConfig().let { config -> + config.init() + (Plugins.findPlugin(VersionEyePlugin.NAME) as VersionEyePlugin).addConfiguration(this, config) + } +} diff --git a/src/main/resources/META-INF/kobalt-plugin.xml b/src/main/resources/META-INF/kobalt-plugin.xml new file mode 100644 index 0000000..cb9f88d --- /dev/null +++ b/src/main/resources/META-INF/kobalt-plugin.xml @@ -0,0 +1,6 @@ + + VersionEye + + net.thauvin.erik.kobalt.plugin.versioneye.VersionEyePlugin + + \ No newline at end of file