Skip to content

Commit

Permalink
Merge branch 'develop' into feature/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed May 5, 2020
2 parents 628ff39 + 1037059 commit 83ea0bd
Show file tree
Hide file tree
Showing 211 changed files with 1,904 additions and 843 deletions.
24 changes: 19 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
image: pikalab/ci:jdk13oracle-git-graphviz
image: pikalab/ci:ubuntu-jdk14-git-gradle-graphviz

variables:
GOPTS: "--no-daemon --console=plain"
CI: "true"
BEFORE_TASK: ""
AFTER_TASK: ""
GCMD: "./gradlew"
GCMD: "gradle"
BUILD_TASK: "assemble"
TEST_TASK: "check -x dokka"
TEST_JVM_TASK: "jvmTest -x dokka"
TEST_JS_TASK: "clean jsTest -x dokka"
BINTRAY_TASK: "publishAllToBintray"
JS_COMPILE_TASK: "clean jsMain"
NPM_PUBLISH_TASK: "npmPublish"
GITHUB_PUBLISH_TASK: "githubRelease"
PAGES_TASK: "orchidBuild"
ORG_GRADLE_PROJECT_orchidBaseUrl: "https://pika-lab.gitlab.io/tuprolog/2p-in-kotlin/"

before_script:
- chmod +x gradlew
- source $HOME/.sdkman/bin/sdkman-init.sh

cache:
paths:
- $HOME/.gradle/caches
- $HOME/.gradle/wrapper
- $HOME/.gradle/nodejs
- $HOME/.gradle/
- gradle/
- .gradle/
- build/

Compile:
stage: build
Expand All @@ -34,6 +35,9 @@ Compile:
Test JVM:
stage: test
script: $GCMD $BEFORE_TASK $TEST_JVM_TASK $AFTER_TASK $GOPTS
artifacts:
reports:
junit: "**/build/test-results/jvmTest/*.xml"

Test JS:
stage: test
Expand All @@ -59,6 +63,16 @@ Deploy to NPM:
only:
- /^(master)|(release)|(develop)$/

Deploy to GitHub:
stage: deploy
script:
- $GCMD $BEFORE_TASK $GITHUB_PUBLISH_TASK $AFTER_TASK $GOPTS
environment:
name: GitHub
url: "https://github.com/tuProlog/2p-kt/releases"
only:
- /^(master)|(release)|(develop)$/

pages:
script:
- mkdir public
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 2P in Kotlin

Some quick links:
* [GitLab Repository](https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin) (the one used by developers)
* [GitHub Repository](https://github.com/tuProlog/2p-kt) (where JVM releases are hosted)
* [NPM Repository](https://www.npmjs.com/org/tuprolog) (where JS releases are hosted)
* [Maven Repository](https://bintray.com/pika-lab/tuprolog) (where all releases are hosted)

## Intro

![The 2P logo](https://gitlab.com/pika-lab/tuprolog/2p-in-kotlin/raw/master/logo.png)

[tuProlog](https://www.cs.nmsu.edu/ALP/2013/10/tuprolog-making-prolog-ubiquitous/) (2P henceforth) is multi-paradigm
Expand Down Expand Up @@ -29,6 +37,7 @@ aimed at bridging the logic programming with the Kotlin object-oriented \& funct
namely `parser-theory`.

A complete overview about modules and their dependencies is provided by the following diagram:

![2P-Kt project map](https://www.plantuml.com/plantuml/svg/TP31Rjim38RlV0eYT-q1XY0ePfy6332GPATTD8k9jSgY8SenWdNlFbjQNSLhBpRuVp_vYtoIg4CSUmUH1uoCFpb6xj7OG6sqx46UhHzqq3rAfmrFrb_nefqG5EZ2pb30tu3uHRVFry2ZDnKx3lkz7YooT_V30TdP6xtd2SnnvdToZgVt3BOVt2Sq5BLrit7gR2Ju0_0lUDToe1s-3bhbqTlBVRUMiICEHMt4gTof1UlgGK-j6PmVG1wIoMabmkuspodNVMIgTLh4jgdnM6sWn42wbmoFAnnq40flRsogBVfrwtUulK-oVlt-xJ-pVEJTHfPRDYU0vGMuVr669wymtGO_ew61l94VdZraRRNaVaY_GaxRGlekebekKLP7WBf25UorY-hbW4ikrET2IJb96eUbhYkeJmNFYREs6ivBiLUluT3C0OukR_ERKnBAzcPjRwhSeGxffFFMev0aAMKc_GXFvCtOkxy0)

The modular, unopinionated architecture of 2P-Kt is deliberately aimed at supporting and encouraging extensions towards
Expand Down Expand Up @@ -77,7 +86,7 @@ To import the 2P-Kt module named `2P_MODULE` (version `2P_VERSION`) into your Ma
<repositories>
<repository>
<id>bintray-2p-repo</id>
<url>https://bintray.com/pika-lab/tuprolog</url>
<url>https://dl.bintray.com/pika-lab/tuprolog/</url>
</repository>
</repositories>
```
Expand Down
66 changes: 58 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseExtension
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import node.Bugs
import node.NpmPublishExtension
Expand All @@ -19,12 +21,14 @@ plugins {
id("com.jfrog.bintray") version Versions.com_jfrog_bintray_gradle_plugin
id("org.danilopianini.git-sensitive-semantic-versioning") version Versions.org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin
id("de.fayard.buildSrcVersions") version Versions.de_fayard_buildsrcversions_gradle_plugin
id("com.github.breadmoirai.github-release") version Versions.com_github_breadmoirai_github_release_gradle_plugin
}

repositories {
maven(Repos.Mirrors.mavenCentralEurope)
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/dokka")
maven(Repos.dokka)
}

group = "it.unibo.tuprolog"
Expand All @@ -49,13 +53,17 @@ val bintrayRepo: String by project
val bintrayUserOrg: String by project
val projectLicense: String by project
val projectIssues: String by project
val githubOwner: String by project
val githubRepo: String by project

val signingKey = getPropertyOrWarnForAbsence("signingKey")
val signingPassword = getPropertyOrWarnForAbsence("signingPassword")
val bintrayUser = getPropertyOrWarnForAbsence("bintrayUser")
val bintrayKey = getPropertyOrWarnForAbsence("bintrayKey")
val ossrhUsername = getPropertyOrWarnForAbsence("ossrhUsername")
val ossrhPassword = getPropertyOrWarnForAbsence("ossrhPassword")
val githubToken = getPropertyOrWarnForAbsence("githubToken")
val npmToken = getPropertyOrWarnForAbsence("npmToken")

val allSubprojects = subprojects.map { it.name }.toSet()
val jvmSubprojects = setOf("parser-jvm", "examples")
Expand Down Expand Up @@ -165,6 +173,7 @@ ktSubprojects.forEachProject {
configureUploadToBintray("kotlinMultiplatform", "js", "jvm", "metadata")
configureSigning()
configureJsPackage()
configureUploadToGithub({ "jvm" in it })
}

jvmSubprojects.forEachProject {
Expand All @@ -180,6 +189,7 @@ jvmSubprojects.forEachProject {
configureUploadToMavenCentral()
configureUploadToBintray()
configureSigning()
configureUploadToGithub()
}

jsSubprojects.forEachProject {
Expand All @@ -196,6 +206,49 @@ jsSubprojects.forEachProject {
configureSigning()
}

configure<GithubReleaseExtension> {
if (githubToken != null) {
token(githubToken)
owner(githubOwner)
repo(githubRepo)
tagName { version.toString() }
releaseName { version.toString() }
allowUploadToExisting { true }
prerelease { false }
draft { false }
try {
body(
"""|## CHANGELOG
|${changelog().call()}
""".trimMargin()
)
} catch (e: NullPointerException) {
e.message?.let { warn(it) }
}
}
}

fun Project.configureUploadToGithub(
jarTaskPositiveFilter: (String) -> Boolean = { "jar" in it },
jarTaskNegativeFilter: (String) -> Boolean = { "dokka" in it || "source" in it }
) {
if (githubToken == null) return

val jarTasks = tasks.withType(Jar::class).asSequence()
.filter { jarTaskPositiveFilter(it.name.toLowerCase()) }
.filter { !jarTaskNegativeFilter(it.name.toLowerCase()) }
.map { it.archiveFile }
.toList()

rootProject.configure<GithubReleaseExtension> {
releaseAssets(*(releaseAssets.toList() + jarTasks).toTypedArray())
}

rootProject.tasks.withType(GithubReleaseTask::class) {
dependsOn(*jarTasks.toTypedArray())
}
}

fun Project.configureDokka(vararg platforms: String) {
tasks.withType<DokkaTask> {
outputDirectory = docDir
Expand All @@ -206,10 +259,9 @@ fun Project.configureDokka(vararg platforms: String) {
platforms.forEach { registerPlatform(it) }
}
}

}

task<DefaultTask>("packAllDokka") {
val packAllDokka: DefaultTask by tasks.creating(DefaultTask::class.java) {
group = "documentation"
}

Expand All @@ -229,7 +281,7 @@ fun Project.configureDokka(vararg platforms: String) {
archiveClassifier.set("javadoc")
}

tasks.getByName("packAllDokka").dependsOn(packDokkaForPlatform)
packAllDokka.dependsOn(packDokkaForPlatform)
}
} else {
val packDokka by tasks.creating(Jar::class) {
Expand All @@ -241,7 +293,7 @@ fun Project.configureDokka(vararg platforms: String) {
archiveClassifier.set("javadoc")
}

tasks.getByName("packAllDokka").dependsOn(packDokka)
packAllDokka.dependsOn(packDokka)
}
}

Expand Down Expand Up @@ -393,11 +445,9 @@ fun NamedDomainObjectContainerScope<GradlePassConfigurationImpl>.registerPlatfor
fun Project.configureJsPackage(packageJsonTask: String = "jsPackageJson", compileTask: String = "jsMainClasses") {
apply<NpmPublishPlugin>()

val npmToken: String by this

configure<NpmPublishExtension> {
nodeRoot = rootProject.tasks.withType<NodeJsSetupTask>().asSequence().map { it.destination }.first()
token = npmToken
token = npmToken ?: ""
packageJson = tasks.getByName<KotlinPackageJsonTask>(packageJsonTask).packageJson
nodeSetupTask = rootProject.tasks.getByName("kotlinNodeJsSetup").path
jsCompileTask = compileTask
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import org.gradle.api.tasks.testing.TestResult
import org.gradle.kotlin.dsl.KotlinClosure2
import org.gradle.kotlin.dsl.withType

private val FULL_VERSION_REGEX = "^[0-9]+\\.[0-9]+\\.[0-9]+$".toRegex()

val Project.isFullVersion: Boolean
get() = version.toString().matches(FULL_VERSION_REGEX)

fun Project.configureTestResultPrinting() {
tasks.withType<AbstractTestTask> {
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
Expand Down
8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import kotlin.String

/**
* Generated by https://github.com/jmfayard/buildSrcVersions
*
Expand Down Expand Up @@ -92,6 +94,10 @@ object Libs {
"org.danilopianini.git-sensitive-semantic-versioning:org.danilopianini.git-sensitive-semantic-versioning.gradle.plugin:" +
Versions.org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin

const val com_github_breadmoirai_github_release_gradle_plugin: String =
"com.github.breadmoirai.github-release:com.github.breadmoirai.github-release.gradle.plugin:" +
Versions.com_github_breadmoirai_github_release_gradle_plugin

const val org_jetbrains_kotlin_multiplatform_gradle_plugin: String =
"org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:" +
Versions.org_jetbrains_kotlin_multiplatform_gradle_plugin
Expand All @@ -118,7 +124,7 @@ object Libs {
const val plantuml: String = "net.sourceforge.plantuml:plantuml:" + Versions.plantuml

/**
* 0.1.2
* 0.1.3
*/
const val kt_math: String = "io.github.gciatto:kt-math:" + Versions.kt_math
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Repos.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Repos {
val dokka = "https://dl.bintray.com/kotlin/dokka"
val kotlinx = "https://kotlin.bintray.com/kotlinx"

object Mirrors {
val mavenCentralEurope = "https://maven-central-eu.storage-download.googleapis.com/maven2"
}
}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import kotlin.String
import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

Expand All @@ -19,6 +20,8 @@ object Versions {

const val org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin: String = "0.2.2"

const val com_github_breadmoirai_github_release_gradle_plugin: String = "2.2.12"

const val org_jetbrains_kotlin_multiplatform_gradle_plugin: String = "1.3.72"

const val de_fayard_buildsrcversions_gradle_plugin: String = "0.7.0"
Expand All @@ -31,7 +34,7 @@ object Versions {

const val plantuml: String = "1.2020.2" // available: "8059"

const val kt_math: String = "0.1.2"
const val kt_math: String = "0.1.3"

/**
* Current version: "6.3"
Expand Down
5 changes: 3 additions & 2 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/Numeric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gciatto.kt.math.BigInteger
import kotlin.js.JsName
import kotlin.jvm.JvmStatic

interface Numeric : Constant, Comparable<Numeric> {
interface Numeric : Constant {

override val isNumber: Boolean
get() = true
Expand All @@ -23,7 +23,8 @@ interface Numeric : Constant, Comparable<Numeric> {

override fun freshCopy(scope: Scope): Numeric = this

override fun compareTo(other: Numeric): Int = decimalValue.compareTo(other.decimalValue)
@JsName("compareValueTo")
fun compareValueTo(other: Numeric): Int = decimalValue.compareTo(other.decimalValue)

companion object {

Expand Down
13 changes: 11 additions & 2 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/Term.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import kotlin.js.JsName
* Base type for all logic terms.
* [Term]s are immutable tree-like data structures.
*/
interface Term {
interface Term : Comparable<Term> {

/**
* Empty companion aimed at letting extentions be injected through extention methods
* Empty companion aimed at letting extensions be injected through extension methods
*/
companion object

Expand All @@ -32,6 +32,15 @@ interface Term {
@Suppress("UNCHECKED_CAST")
fun <T : Term> castTo(): T = this as T

/**
* Compares this term to the provided one, returning a positive integer if this term _precedes_ [other],
* a negative integer if [other] precedes this term, or `0` otherwise
* @param other is the term to be compared against this term
* @return an [Int] indicating whether this term precedes [other] or not
*/
override fun compareTo(other: Term): Int =
TermComparator.DefaultComparator.compare(this, other)

/**
* Checks whether an[other] term is _structurally equals_ to the current one or not.
* Structural equivalence is a looser type of equivalence (w.r.t. term equivalence)
Expand Down
Loading

0 comments on commit 83ea0bd

Please sign in to comment.