plugins {
    id 'base'
}

description = 'Builds the engine-side Eclipse module and stages the engine runtime for the PDE plugin'

def framebranch = findProperty('framebranch') ?: 'dev_'

// The engine-side sources (IdeModule + plugin.xml/depends.xml) compile against the
// engine. The PDE plugin (../eclipse) cannot host them: its classpath is OSGi bundles,
// not the engine. So this Gradle project compiles them here and stages the result.
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(25)
    }
}

dependencies {
    compileOnly project(':runtime-api')
    // :dam api-exports :core (org.openedit.*) and commons-logging.
    compileOnly project(':dam')
    compileOnly project(':thoughtframe')
}

jar {
    archiveBaseName.set("${framebranch}tf-eclipse")
}

// The PDE plugin (../eclipse) only compiles against the thin runtime API - one small jar.
tasks.register('assembleLib', Copy) {
    description = 'Stage the thin runtime API into eclipse/lib'
    group = 'eclipse'
    from project(':runtime-api').tasks.named('jar')
    into rootProject.layout.projectDirectory.dir('eclipse/lib')
}

// The engine runtime is loaded by a child classloader, so it lives in a plain folder and
// never has to be an OSGi bundle.
tasks.register('assembleEngine', Copy) {
    description = 'Stage the full engine runtime into eclipse/engine'
    group = 'eclipse'
    from(project(':thoughtframe').tasks.named('jar'))
    // The engine-side eclipse module (IdeModule + plugin.xml/depends.xml).
    from(tasks.named('jar'))
    from(project(':thoughtframe').configurations.runtimeClasspath) {
        exclude 'runtime-api-*.jar'
    }
    into rootProject.layout.projectDirectory.dir('eclipse/engine')
}

tasks.register('cleanLib', Delete) {
    delete rootProject.layout.projectDirectory.dir('eclipse/lib')
    delete rootProject.layout.projectDirectory.dir('eclipse/engine')
}

assemble.dependsOn assembleLib, assembleEngine
clean.dependsOn cleanLib
