1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Update to github for releases.

This commit is contained in:
Cedric Beust 2015-11-10 11:05:15 -08:00
parent 07f9712e1b
commit 13b87527f6
9 changed files with 137 additions and 54 deletions

View file

@ -1,7 +1,9 @@
import com.beust.kobalt.api.License import com.beust.kobalt.api.License
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.Scm import com.beust.kobalt.api.Scm
import com.beust.kobalt.homeDir import com.beust.kobalt.homeDir
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.internal.test import com.beust.kobalt.internal.test
import com.beust.kobalt.plugin.application.application import com.beust.kobalt.plugin.application.application
import com.beust.kobalt.plugin.java.javaCompiler import com.beust.kobalt.plugin.java.javaCompiler
@ -9,8 +11,10 @@ import com.beust.kobalt.plugin.java.javaProject
import com.beust.kobalt.plugin.kotlin.kotlinCompiler import com.beust.kobalt.plugin.kotlin.kotlinCompiler
import com.beust.kobalt.plugin.kotlin.kotlinProject import com.beust.kobalt.plugin.kotlin.kotlinProject
import com.beust.kobalt.plugin.packaging.assemble import com.beust.kobalt.plugin.packaging.assemble
import com.beust.kobalt.plugin.publish.jcenter
import java.io.File import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
val wrapper = javaProject { val wrapper = javaProject {
name = "kobalt-wrapper" name = "kobalt-wrapper"
@ -87,18 +91,22 @@ val kobalt = kotlinProject(wrapper) {
} }
} }
// install {
// libDir = "lib-test"
// }
test { test {
args("-log", "2", "src/test/resources/testng.xml") args("-log", "1", "src/test/resources/testng.xml")
} }
kotlinCompiler { kotlinCompiler {
args("-nowarn") args("-nowarn")
} }
jcenter { // jcenter {
publish = true // publish = true
file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") // file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip")
} // }
} }
fun readVersion() : String { fun readVersion() : String {
@ -111,6 +119,15 @@ fun readVersion() : String {
return p.getProperty("kobalt.version") return p.getProperty("kobalt.version")
} }
@com.beust.kobalt.api.annotation.Task(name = "copyVersionForWrapper", runBefore = arrayOf("compile"), description = "")
fun taskCopyVersionForWrapper(project: Project) : TaskResult {
if (project.name == "kobalt-wrapper") {
Files.copy(Paths.get("src/main/resources/kobalt.properties"),
Paths.get("modules/wrapper/kobaltBuild/classes/kobalt.properties"),
StandardCopyOption.REPLACE_EXISTING)
}
return TaskResult()
}
//import com.beust.kobalt.plugin.linecount.lineCount //import com.beust.kobalt.plugin.linecount.lineCount
//val plugins = plugins( //val plugins = plugins(
// "com.beust.kobalt:kobalt-line-count:0.15" // "com.beust.kobalt:kobalt-line-count:0.15"

Binary file not shown.

View file

@ -1 +1,2 @@
kobalt.version=0.234 kobalt.version=0.238
kobalt.downloadUrl=https://github.com/cbeust/kobalt/releases/download/0.238/kobalt-0.238.zip

View file

@ -24,7 +24,7 @@ public class Main {
private static final String KOBALTW = "kobaltw"; private static final String KOBALTW = "kobaltw";
private static final String KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"; private static final String KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties";
private static final String PROPERTY_VERSION = "kobalt.version"; private static final String PROPERTY_VERSION = "kobalt.version";
private static final String URL = "https://dl.bintray.com/cbeust/generic/"; private static final String PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl";
private static final String FILE_NAME = "kobalt"; private static final String FILE_NAME = "kobalt";
private static final String DISTRIBUTIONS_DIR = private static final String DISTRIBUTIONS_DIR =
System.getProperty("user.home") + "/.kobalt/wrapper/dist"; System.getProperty("user.home") + "/.kobalt/wrapper/dist";
@ -66,10 +66,16 @@ public class Main {
return new File("kobalt", "wrapper"); return new File("kobalt", "wrapper");
} }
private static final String downloadUrl(String version) {
return "https://github.com/cbeust/kobalt/releases/download/" + version + "/kobalt-" + version + ".zip";
}
private void initWrapperFile(String version) throws IOException { private void initWrapperFile(String version) throws IOException {
File config = new File(getWrapperDir(), KOBALT_WRAPPER_PROPERTIES); File config = new File(getWrapperDir(), KOBALT_WRAPPER_PROPERTIES);
if (! config.exists()) { if (! config.exists()) {
saveFile(config, PROPERTY_VERSION + "=" + version); saveFile(config,
PROPERTY_VERSION + "=" + version + "\n"
+ PROPERTY_DOWNLOAD_URL + "=" + downloadUrl(version) + "\n");
} }
wrapperProperties.load(new FileReader(config)); wrapperProperties.load(new FileReader(config));
} }
@ -78,6 +84,10 @@ public class Main {
return wrapperProperties.getProperty(PROPERTY_VERSION); return wrapperProperties.getProperty(PROPERTY_VERSION);
} }
private String getWrapperDownloadUrl() {
return wrapperProperties.getProperty(PROPERTY_DOWNLOAD_URL);
}
private boolean isWindows() { private boolean isWindows() {
return System.getProperty("os.name").contains("Windows"); return System.getProperty("os.name").contains("Windows");
} }
@ -97,7 +107,7 @@ public class Main {
getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar"); getWrapperDir().getPath() + "/" + FILE_NAME + "-" + getWrapperVersion() + ".jar");
if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) { if (! Files.exists(localZipFile) || ! Files.exists(kobaltJarFile)) {
if (!Files.exists(localZipFile)) { if (!Files.exists(localZipFile)) {
download(fileName, localZipFile.toFile()); download(localZipFile.toFile());
} }
// //
@ -129,7 +139,7 @@ public class Main {
error("Couldn't open zip file " + localZipFile + ": " + e.getMessage()); error("Couldn't open zip file " + localZipFile + ": " + e.getMessage());
error("The file is probably corrupt, downloading it again"); error("The file is probably corrupt, downloading it again");
Files.delete(localZipFile); Files.delete(localZipFile);
download(fileName, localZipFile.toFile()); download(localZipFile.toFile());
} }
} }
} }
@ -161,8 +171,8 @@ public class Main {
private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" }; private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" };
private void download(String fn, File file) throws IOException { private void download(File file) throws IOException {
String fileUrl = URL + fn; String fileUrl = getWrapperDownloadUrl();
URL url = new URL(fileUrl); URL url = new URL(fileUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
@ -238,11 +248,11 @@ public class Main {
Files.write(Paths.get(file.toURI()), text.getBytes()); Files.write(Paths.get(file.toURI()), text.getBytes());
} }
private static void log2(int level, String s) { static void log2(int level, String s) {
p(level, s, false); p(level, s, false);
} }
private static void log(int level, String s) { static void log(int level, String s) {
p(level, "[Wrapper] " + s, true); p(level, "[Wrapper] " + s, true);
} }

View file

@ -59,7 +59,8 @@ private class Main @Inject constructor(
val server: KobaltServer, val server: KobaltServer,
val pluginInfo: PluginInfo, val pluginInfo: PluginInfo,
val projectGenerator: ProjectGenerator, val projectGenerator: ProjectGenerator,
val resolveDependency: ResolveDependency) { val resolveDependency: ResolveDependency,
val wrapper: Wrapper) {
data class RunInfo(val jc: JCommander, val args: Args) data class RunInfo(val jc: JCommander, val args: Args)
@ -137,7 +138,7 @@ private class Main @Inject constructor(
// //
// --init: create a new build project and install the wrapper // --init: create a new build project and install the wrapper
// //
Wrapper().install() wrapper.install()
projectGenerator.run(args) projectGenerator.run(args)
} else if (args.usage) { } else if (args.usage) {
jc.usage() jc.usage()

View file

@ -1,21 +1,64 @@
package com.beust.kobalt.misc package com.beust.kobalt.misc
import com.beust.kobalt.api.Kobalt
import com.google.inject.Inject import com.google.inject.Inject
import java.io.File import java.io.File
import java.io.FileReader
import java.util.*
/**
* Manage kobalt-wrapper.properties.
*/
class KobaltWrapperProperties @Inject constructor() { class KobaltWrapperProperties @Inject constructor() {
private val WRAPPER_DIR = KFiles.KOBALT_DIR + "/wrapper" private val WRAPPER_DIR = KFiles.KOBALT_DIR + "/wrapper"
private val KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties" private val KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"
private val PROPERTY_VERSION = "kobalt.version" private val PROPERTY_VERSION = "kobalt.version"
private val PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl" private val PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl"
fun defaultUrlFor(version: String) =
"bogushttps://github.com/cbeust/kobalt/releases/download/$version/kobalt-$version.zip"
val file: File val file: File
get() = File("$WRAPPER_DIR/$KOBALT_WRAPPER_PROPERTIES") get() = File("$WRAPPER_DIR/$KOBALT_WRAPPER_PROPERTIES")
fun create(version: String) { fun create(version: String) {
log(2, "Creating $file with $version and ${defaultUrlFor(version)}")
KFiles.saveFile(file, listOf( KFiles.saveFile(file, listOf(
"$PROPERTY_VERSION=$version", "$PROPERTY_VERSION=$version",
"$PROPERTY_DOWNLOAD_URL" "$PROPERTY_DOWNLOAD_URL=${defaultUrlFor(version)}"
).joinToString("\n")) ).joinToString("\n"))
} }
val properties : Properties
get() {
val config = file
if (!config.exists()) {
create(Kobalt.version)
}
val result = Properties()
result.load(FileReader(config))
return result
}
val version : String
get() = properties.getProperty(PROPERTY_VERSION)
val downloadUrl : String
get() {
return properties.getProperty(PROPERTY_DOWNLOAD_URL)
?: defaultUrlFor(version)
}
fun maybeCreate(version: String) {
if (! file.exists()) {
create(version)
}
}
// fun urlFor(version: String) : String {
// // val URL = "https://dl.bintray.com/cbeust/generic/"
// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
// return downloadUrl ?: defaultUrlFor(version)
// }
} }

View file

@ -1,15 +1,14 @@
package com.beust.kobalt.misc package com.beust.kobalt.misc
import java.io.File
import javax.inject.Inject import javax.inject.Inject
/** /**
* Update Kobalt to the latest version. * Update Kobalt to the latest version.
*/ */
public class UpdateKobalt @Inject constructor(val github: GithubApi) { public class UpdateKobalt @Inject constructor(val github: GithubApi, val kobaltWrapperProperties: KobaltWrapperProperties) {
fun updateKobalt() { fun updateKobalt() {
val newVersion = github.latestKobaltVersion val newVersion = github.latestKobaltVersion
KFiles.saveFile(File("kobalt/wrapper/kobalt-wrapper.properties"), "kobalt.version=${newVersion.get()}") kobaltWrapperProperties.maybeCreate(newVersion.get())
com.beust.kobalt.wrapper.main(arrayOf()) com.beust.kobalt.wrapper.main(arrayOf())
} }
} }

View file

@ -1,37 +1,34 @@
package com.beust.kobalt.wrapper package com.beust.kobalt.wrapper
import com.beust.kobalt.maven.Http
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.benchmark
import com.beust.kobalt.JavaInfo import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.maven.Http
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltWrapperProperties
import com.beust.kobalt.misc.benchmark
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import com.google.inject.Inject
import java.io.File import java.io.File
import java.io.FileReader
import java.io.InputStream import java.io.InputStream
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import java.util.Properties import java.util.*
import java.util.zip.ZipFile import java.util.zip.ZipFile
public fun main(argv: Array<String>) { public fun main(argv: Array<String>) {
Wrapper().installAndLaunchMain(argv) Kobalt.INJECTOR.getInstance(Wrapper::class.java).installAndLaunchMain(argv)
} }
/** /**
* Download and install a new wrapper if requested. * Download and install a new wrapper if requested.
*/ */
public class Wrapper { public class Wrapper @Inject constructor(val wrapperProperties: KobaltWrapperProperties){
// kobalt.properties // kobalt.properties
private val KOBALT_PROPERTIES = "kobalt.properties" private val KOBALT_PROPERTIES = "kobalt.properties"
private val KOBALTW = "kobaltw" private val KOBALTW = "kobaltw"
private val WRAPPER_DIR = KFiles.KOBALT_DIR + "/wrapper"
private val KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties"
private val PROPERTY_VERSION = "kobalt.version"
val URL = "https://dl.bintray.com/cbeust/generic/"
val FILE_NAME = "kobalt" val FILE_NAME = "kobalt"
private val properties = Properties() private val properties = Properties()
@ -47,7 +44,10 @@ public class Wrapper {
properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) } properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) }
} }
private fun maybeCreateProperties() : Properties { /**
* Attemps to read kobalt.properties (which should always exist).
*/
private fun maybeCreateKobaltProperties() : Properties {
val result = Properties() val result = Properties()
// kobalt.properties is internal to Kobalt // kobalt.properties is internal to Kobalt
@ -61,18 +61,29 @@ public class Wrapper {
return result return result
} }
private fun initWrapperFile(version: String) { // private fun initWrapperFile(version: String) {
val config = File(WRAPPER_DIR, KOBALT_WRAPPER_PROPERTIES) // val config = wrapperProperties.file
if (! config.exists()) { // if (! config.exists()) {
KFiles.saveFile(config, "$PROPERTY_VERSION=$version") // wrapperProperties.create(version)
} // }
properties.load(FileReader(config)) // properties.load(FileReader(config))
} // }
//
private val wrapperVersion : String // private val wrapperVersion : String
get() { // get() {
return properties.getProperty(PROPERTY_VERSION) // return properties.getProperty(PROPERTY_VERSION)
} // }
//
// private val wrapperDownloadUrl : String
// get() {
// return properties.getProperty(PROPERTY_DOWNLOAD_URL)
// }
//
// fun urlFor(version: String) : String {
// // val URL = "https://dl.bintray.com/cbeust/generic/"
// // return "https://dl.bintray.com/cbeust/generic/$fileName-$version.zip"
// return wrapperDownloadUrl ?: defaultUrlFor(version)
// }
/** /**
* Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties * Install a new version if requested in .kobalt/wrapper/kobalt-wrapper.properties
@ -80,12 +91,12 @@ public class Wrapper {
* @return the path to the Kobalt jar file * @return the path to the Kobalt jar file
*/ */
public fun install() : Path { public fun install() : Path {
val properties = maybeCreateProperties() val properties = maybeCreateKobaltProperties()
val version = properties.getProperty(PROPERTY_VERSION) val version = properties.getProperty("kobalt.version")
initWrapperFile(version) wrapperProperties.maybeCreate(version)
log(2, "Wrapper version: ${wrapperProperties.version}")
log(2, "Wrapper version: $wrapperVersion")
val wrapperVersion = wrapperProperties.version
val fileName = "$FILE_NAME-$wrapperVersion.zip" val fileName = "$FILE_NAME-$wrapperVersion.zip"
File(KFiles.distributionsDir).mkdirs() File(KFiles.distributionsDir).mkdirs()
val localZipFile = Paths.get(KFiles.distributionsDir, fileName) val localZipFile = Paths.get(KFiles.distributionsDir, fileName)
@ -93,7 +104,7 @@ public class Wrapper {
val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar") val kobaltJarFile = Paths.get(zipOutputDir, "kobalt/wrapper/$FILE_NAME-$wrapperVersion.jar")
if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) { if (!Files.exists(localZipFile) || !Files.exists(kobaltJarFile)) {
log(1, "Downloading $fileName") log(1, "Downloading $fileName")
val fullUrl = "$URL/$fileName" val fullUrl = wrapperProperties.downloadUrl
val body = Http().get(fullUrl) val body = Http().get(fullUrl)
if (body.code == 200) { if (body.code == 200) {
if (!Files.exists(localZipFile)) { if (!Files.exists(localZipFile)) {
@ -133,7 +144,7 @@ public class Wrapper {
} }
log(2, "$localZipFile extracted") log(2, "$localZipFile extracted")
} else { } else {
error("Couldn't download $URL") error("Couldn't download $fullUrl")
} }
} }

View file

@ -1 +1,2 @@
kobalt.version=0.234 kobalt.version=0.238