1
0

Initial commit

This commit is contained in:
2020-12-01 02:12:55 +01:00
commit de750de96a
20 changed files with 516 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
plugins {
`kotlin-dsl`
}
kotlinDslPluginOptions {
experimentalWarning.set(false)
}
repositories {
gradlePluginPortal()
maven { setUrl("https://kotlin.bintray.com/kotlinx") }
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20")
implementation("com.konghq:unirest-java:3.11.04")
}
@@ -0,0 +1,56 @@
import kong.unirest.Unirest
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType
import java.io.File
import java.time.LocalDateTime
open class AdventOfCodeExtension {
var session: String? = null
var year: Int = 2020
}
class AdventOfCodePlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.create("aoc") {
group = "Advent of Code"
description = "Download the input of the day"
val extension = project.extensions.create<AdventOfCodeExtension>("adventOfCode")
doLast {
if (extension.session == null) {
throw GradleException("advent of code session not set")
}
val resourceDir: File = project
.project(":days")
.extensions
.getByType<SourceSetContainer>()
.getByName("main")
.resources
.srcDirs
.first()
val currentDay = LocalDateTime.now().dayOfMonth.toString()
val outFile = File(resourceDir, "day" + currentDay.padStart(length = 2, padChar = '0') + ".txt")
val url = "https://adventofcode.com/${extension.year}/day/$currentDay/input"
Unirest.get(url)
.cookie("session", extension.session)
.header("Accept", "text/plain")
.asString()
.ifFailure {
throw GradleException("Failed to get input, got status ${it.status}")
}
.ifSuccess {
outFile.writeText(it.body)
println("Saved input for day $currentDay")
}
}
}
}
}
+27
View File
@@ -0,0 +1,27 @@
@file:Suppress("SpellCheckingInspection")
object Libs {
object Arrow {
const val version = "0.11.0"
const val core = "io.arrow-kt:arrow-core:$version"
const val optics = "io.arrow-kt:arrow-optics:$version"
const val fx = "io.arrow-kt:arrow-fx:$version"
}
object EclipseCollection {
const val api = "org.eclipse.collections:eclipse-collections-api:10.4.0"
const val core = "org.eclipse.collections:eclipse-collections:10.4.0"
}
object Jmh {
const val core = "org.openjdk.jmh:jmh-core:1.26"
const val processor = "org.openjdk.jmh:jmh-generator-annprocess:1.26"
}
object Tests {
const val assertJ = "org.assertj:assertj-core:3.18.1"
const val junit = "org.junit.jupiter:junit-jupiter:5.7.0"
}
}
@@ -0,0 +1,23 @@
plugins {
id("java-library")
id("junit-convention")
}
repositories {
mavenCentral()
jcenter()
maven { url = uri("https://dl.bintray.com/arrow-kt/arrow-kt/") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}
group = "be.vandewalleh"
version = "1.0-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_15
targetCompatibility = JavaVersion.VERSION_15
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
@@ -0,0 +1,12 @@
plugins {
java apply false
}
tasks.withType<Test> {
useJUnitPlatform()
}
dependencies {
testImplementation(Libs.Tests.junit)
testImplementation(Libs.Tests.assertJ)
}
@@ -0,0 +1,25 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("java-convention")
kotlin("jvm")
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.4.20"))
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "15"
javaParameters = true
freeCompilerArgs = listOf(
"-Xinline-classes",
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions",
"-Xopt-in=kotlin.RequiresOptIn"
)
}
}
@@ -0,0 +1 @@
implementation-class=AdventOfCodePlugin