Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
//file:noinspection SpellCheckingInspection

buildscript {
  repositories {
    mavenCentral()
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath 'org.owasp:dependency-check-gradle:9.0.1'
    classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.2.4"
  }
}

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.1.0'
  id 'com.palantir.git-version' version '3.0.0'
  id 'com.github.spotbugs' version '5.2.4'
}

spotbugs {
  excludeFilter.set(
    file( "${projectDir}/bug-filter.xml" )
  )
}

apply plugin: 'org.owasp.dependencycheck'

repositories {
  mavenCentral()

  maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
  maven { url 'https://nexus.bedatadriven.com/content/groups/public' }

  maven {
    url 'https://css4j.github.io/maven'
    mavenContent {
      releasesOnly()
    }
    content {
      includeGroup 'com.github.css4j'
      includeGroup 'io.sf.carte'
      includeGroup 'io.sf.jclf'
    }
  }
}

// Assume a cross-platform überjar unless targetOs is set.
String[] os = ['win', 'mac', 'linux']

if (project.hasProperty( 'targetOs' )) {
  if ('windows' == targetOs) {
    os = ['win']
  } else if ('macos' == targetOs) {
    os = ['mac']
  } else {
    os = [targetOs]
  }
}

def moduleSecurity = [
  '--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED',
  '--add-opens=javafx.controls/javafx.scene.control=ALL-UNNAMED',
  '--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED',
  '--add-opens=javafx.graphics/javafx.scene.text=ALL-UNNAMED',
  '--add-opens=javafx.graphics/com.sun.javafx.css=ALL-UNNAMED',
  '--add-opens=javafx.graphics/com.sun.javafx.text=ALL-UNNAMED',
  '--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.text=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED',
  '--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED',
]

java {
  sourceCompatibility = 21
  targetCompatibility = 21
}

javafx {
  version = '21'
  modules = ['javafx.base', 'javafx.controls', 'javafx.graphics', 'javafx.swing']
  configuration = 'compileOnly'
}

dependencies {
  def v_junit = '5.10.1'
  def v_flexmark = '0.64.8'
  def v_jackson = '2.16.0'
  def v_echosvg = '1.0.1'
  def v_picocli = '4.7.5'

  // JavaFX
  implementation 'org.controlsfx:controlsfx:11.2.0'
  implementation 'org.fxmisc.richtext:richtextfx:0.11.2'
  implementation 'org.fxmisc.flowless:flowless:0.7.2'
  implementation 'org.fxmisc.wellbehaved:wellbehavedfx:0.3.3'
  implementation 'com.dlsc.preferencesfx:preferencesfx-core:11.16.0'
  implementation 'com.panemu:tiwulfx-dock:0.2'

  // Markdown
  implementation "com.vladsch.flexmark:flexmark:${v_flexmark}"
  implementation "com.vladsch.flexmark:flexmark-ext-definition:${v_flexmark}"
  implementation "com.vladsch.flexmark:flexmark-ext-gfm-strikethrough:${v_flexmark}"
  implementation "com.vladsch.flexmark:flexmark-ext-superscript:${v_flexmark}"
  implementation "com.vladsch.flexmark:flexmark-ext-tables:${v_flexmark}"
  implementation "com.vladsch.flexmark:flexmark-ext-typographic:${v_flexmark}"

  // YAML
  implementation 'org.yaml:snakeyaml:2.2'
  implementation "com.fasterxml.jackson.core:jackson-core:${v_jackson}"
  implementation "com.fasterxml.jackson.core:jackson-databind:${v_jackson}"
  implementation "com.fasterxml.jackson.core:jackson-annotations:${v_jackson}"
  implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${v_jackson}"

  // HTML parsing and rendering
  implementation 'org.jsoup:jsoup:1.17.1'
  implementation 'org.xhtmlrenderer:flying-saucer-core:9.3.1'

  // R
  implementation 'org.apache.commons:commons-compress:1.25.0'
  implementation 'org.codehaus.plexus:plexus-utils:4.0.0'
  implementation 'org.renjin:renjin-script-engine:3.5-beta76'
  implementation 'org.renjin.cran:rjson:0.2.15-renjin-21'

  // SVG
  implementation "io.sf.carte:echosvg-awt-util:${v_echosvg}"
  implementation "io.sf.carte:echosvg-bridge:${v_echosvg}"
  implementation "io.sf.carte:echosvg-css:${v_echosvg}"
  implementation "io.sf.carte:echosvg-dom:${v_echosvg}"
  implementation "io.sf.carte:echosvg-ext:${v_echosvg}"
  implementation "io.sf.carte:echosvg-gvt:${v_echosvg}"
  implementation "io.sf.carte:echosvg-parser:${v_echosvg}"
  implementation "io.sf.carte:echosvg-svg-dom:${v_echosvg}"
  implementation "io.sf.carte:echosvg-svggen:${v_echosvg}"
  implementation "io.sf.carte:echosvg-transcoder:${v_echosvg}"
  implementation "io.sf.carte:echosvg-util:${v_echosvg}"
  implementation "io.sf.carte:echosvg-xml:${v_echosvg}"

  // Misc.
  implementation 'org.ahocorasick:ahocorasick:0.6.3'
  implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
  implementation 'jakarta.validation:jakarta.validation-api:3.0.2'
  implementation 'org.greenrobot:eventbus-java:3.3.1'

  // Command-line parsing
  implementation "info.picocli:picocli:${v_picocli}"
  annotationProcessor "info.picocli:picocli-codegen:${v_picocli}"

  // KeenQuotes, KeenType, KeenSpell, KeenCount.
  implementation fileTree( include: ['**/*.jar'], dir: 'libs' )

  def fx = ['controls', 'graphics', 'fxml', 'swing']

  fx.each { fxitem ->
    os.each { ositem ->
      runtimeOnly "org.openjfx:javafx-${fxitem}:${javafx.version}:${ositem}"
    }
  }

  testImplementation "org.junit.jupiter:junit-jupiter-api:${v_junit}"
  testImplementation "org.junit.jupiter:junit-jupiter-params:${v_junit}"
  testImplementation 'org.testfx:testfx-junit5:4.0.17'
  testImplementation 'org.assertj:assertj-core:3.24.2'
  testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

/**
 * Mozilla's JavaScript engine, Rhino, is used by the SVG rasterizer.
 * The application does not support animated SVG files (the HTML
 * renderer won't honour them), so we can eliminate the dependency from
 * the binaries.
 */
configurations {
  all*.exclude group: 'org.mozilla', module: 'rhino'
}

sourceSets {
  main {
    java {
      srcDirs 'src/main'
    }
  }

  test {
    java {
      srcDirs 'src/test'
    }
  }
}

final resourceDir = sourceSets.main.resources.srcDirs[0]
final Properties config = new Properties()
final File configFile = file( "${resourceDir}/bootstrap.properties" )
final FileInputStream configStream = new FileInputStream( configFile )
config.load( configStream )
configStream.close()

final String applicationName = config.get( 'application.title' ).toString().toLowerCase()
final String applicationPackage = "com.${applicationName}"
final String applicationClass = "${applicationPackage}.Launcher"

compileJava {
  options.compilerArgs += [
    '-Xlint:unchecked',
    '-Xlint:deprecation',
    "-Aproject=${applicationPackage}/${applicationName}"
  ]
}

application {
  mainClass.set( applicationClass )
  applicationDefaultJvmArgs = moduleSecurity
}

version = gitVersion()

final File p = new File( "${resourceDir}/com/${applicationName}/app.properties" )
p.write( "application.version=${version}" )

jar {
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE

  doFirst {
    manifest {
      attributes 'Main-Class': applicationClass
    }
  }

  from {
    (configurations.runtimeClasspath.findAll { !it.path.endsWith( '.pom' ) })
      .collect { it.isDirectory() ? it : zipTree( it ) }
  }

  archiveFileName = "${applicationName}.jar"

  exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}

distributions {
  main {
    distributionBaseName.set( applicationName )

    contents {
      from { ['LICENSE.md', 'README.md'] }
      into( 'images' ) {
        from { 'images' }
      }
    }
  }
}

test {
  useJUnitPlatform()

  doFirst { jvmArgs += moduleSecurity }
  testLogging { exceptionFormat = 'full' }
}

tasks.withType( JavaCompile ).configureEach {
  options.encoding = 'UTF-8'
  options.compilerArgs += '--enable-preview'
}

tasks.withType( JavaExec ).configureEach {
  jvmArgs += '--enable-preview'
}

tasks.withType( Test ).configureEach {
  jvmArgs += '--enable-preview'
}