// Copied and adapted from plugin "Graph Database Support"
// by Neueda Technologies, Ltd.
// Modified by Alberto Venturini, 2022
import java.text.SimpleDateFormat
import org.jetbrains.changelog.Changelog

apply plugin: "org.jetbrains.intellij"

dependencies {
    implementation project(':language:cypher')
    implementation project(path: ':ui:jetbrains', configuration: 'instrumentedJar')
}

intellij {
    version = intellijSdkVersion
    pluginName = 'GraphDatabase'
    //updateSinceUntilBuild = false
    sameSinceUntilBuild = false

    publishPlugin {
        token = System.getenv("INTELLIJ_TOKEN")
    }

    if (System.getenv("CI_SERVER") == "yes") {
        downloadSources = false
    } else {
        downloadSources = true
    }

    def homePath = System.properties['user.home']
    sandboxDir = "${homePath}/.intellij/graphdb"
    plugins = ['java']
}

// See https://plugins.jetbrains.com/docs/intellij/configuring-plugin-project.html#patching-the-plugin-configuration-file
patchPluginXml {
    sinceBuild = "223.0"
    //untilBuild = "233.*"
    untilBuild = "999.0"

    def allChanges = {
        changelog.getAll().values()
                .collect { it.withHeader(true) }
                .collect { it.withLinkedHeader(false) }
                .collect { it.withSummary(true) }
                .collect { changelog.renderItem(it as Changelog.Item, Changelog.OutputType.HTML) }
                .join('<br>\n')
    }

    changeNotes.set(
        allChanges()
    )
}

changelog {
    header = "[${-> version.get()}] - ${new SimpleDateFormat("yyyy-MM-dd").format(new Date())}"
    headerParserRegex = ~/(\d+\.\d+\.\d+[\-\w]*)/
    keepUnreleasedSection = true
    repositoryUrl = "https://github.com/albertoventurini/graphdb-intellij-plugin"
}

runIde {
    systemProperty 'graphDatabaseSupportDevelopment', 'true'
}

processResources {
    from 'platform/src/main/resources'
    from 'language/cypher/src/main/resources'
}
