Skip to content
Snippets Groups Projects
Select Git revision
  • dev default protected
  • main protected
  • chore/using-handlebars
3 results

build.gradle

Blame
  • build.gradle 5.06 KiB
    // --- Buildscripts (must be at the top) ---
    buildscript {
        repositories.mavenCentral()
        dependencies {
            classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.3'
        }
    }
    
    // --- Plugin definitions ---
    plugins {
        id 'com.github.ben-manes.versions'
        id 'java'
        id 'idea'
        id 'org.jastadd'
        id 'java-library'
        id 'maven-publish'
    }
    
    // --- Dependencies ---
    repositories {
        mavenCentral()
        maven {
            name 'gitlab-maven'
            url 'https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven'
        }
    }
    
    configurations {
        relast
    }
    
    dependencies {
        jastadd2 "org.jastadd:jastadd:2.3.5"
        relast group: 'org.jastadd', name: 'relast', version: "${relast_version}"
        implementation group: 'net.sourceforge.plantuml', name: 'plantuml', version: '1.2022.2'
        api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
        implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: "0.9.10"
        implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27'
    }
    
    // --- Preprocessors ---
    File genSrc = file("src/gen/java")
    sourceSets.main.java.srcDir genSrc
    idea.module.generatedSourceDirs += genSrc
    
    File dumpAstGrammar = file('./src/main/jastadd/DumpAst.relast')
    File mustacheGrammar = file('./src/main/jastadd/mustache/Mustache.relast')
    
    task relast(type: JavaExec) {
        group = 'Build'
        classpath = configurations.relast
        mainClass = 'org.jastadd.relast.compiler.Compiler'
    
        doFirst {
            delete "src/gen/jastadd/*"
            mkdir  "src/gen/jastadd/"
        }
    
        args = [
                dumpAstGrammar,
                mustacheGrammar,
                "--listClass=java.util.ArrayList",
                "--jastAddList=JastAddList",
                "--useJastAddNames",
                "--file",
                "--resolverHelper",
                "--grammarName=./src/gen/jastadd/DumpAst"
        ]
    }
    
    // --- JastAdd ---
    jastadd {
        configureModuleBuild()
        modules {
            //noinspection GroovyAssignabilityCheck
            module("DumpAst") {
                jastadd {
                    basedir "."
                    include "src/main/jastadd/**/*.ast"
                    include "src/main/jastadd/**/*.jadd"
                    include "src/main/jastadd/**/*.jrag"
                    include "src/gen/jastadd/**/*.ast"
                    include "src/gen/jastadd/**/*.jadd"
                    include "src/gen/jastadd/**/*.jrag"
                }
            }
        }
    
        cleanGen.doFirst {
            delete "src/gen/java/de"
            delete "src/gen-res/BuildInfo.properties"
        }
    
        preprocessParser.doFirst {
    
            args += ["--no-beaver-symbol"]
    
        }
    
        module = "DumpAst"
        astPackage = 'de.tudresden.inf.st.jastadd.dumpAst.ast'
        genDir = 'src/gen/java'
        buildInfoDir = 'src/gen-res'
        jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
    }
    
    // --- Tests ---
    
    // --- Versioning and Publishing ---
    group = 'de.tudresden.inf.st'
    
    task fatJar(type: Jar) {
        dependsOn jar
        group = "build"
        archiveAppendix = "fatjar"
        from sourceSets.main.output
        from {
            configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it) }
        }
    }
    
    def versionFile = "src/main/resources/${rootProject.getName()}Version.properties"
    
    try {
        def oldProps = new Properties()
        file(versionFile).withInputStream { stream -> oldProps.load(stream) }
        version = oldProps['version']
    } catch (e) {
        // this happens, if either the properties file is not present, or cannot be read from
        throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
    }
    
    task printVersion() {
        doLast {
            println(version)
        }
    }
    
    task newVersion() {
        doFirst {
            def props = new Properties()
            props['version'] = value
            props.store(file(versionFile).newWriter(), null)
        }
    }
    
    task setDevVersionForCI() {
        doFirst {
            def props = new Properties()
            props['version'] = version + "-dev-$System.env.CI_PIPELINE_IID"
            props.store(file(versionFile).newWriter(), null)
        }
    }
    
    java {
        withJavadocJar()
        withSourcesJar()
    }
    
    publishing {
        publications {
            maven(MavenPublication) {
                //noinspection GroovyAssignabilityCheck
                artifactId = 'dumpAst'
                from components.java
            }
        }
        repositories {
            maven {
                url "https://git-st.inf.tu-dresden.de/api/v4/projects/$System.env.CI_PROJECT_ID/packages/maven"
                credentials(HttpHeaderCredentials) {
                    name = 'Job-Token'
                    value = System.getenv("CI_JOB_TOKEN")
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
        }
    }
    
    // --- Misc ---
    task ensureNoTrainlingNewlineForRelationStyleMustache() {
        doFirst {
            def text = project.file("src/main/resources/RelationStyle.mustache").text
            project.file("src/main/resources/RelationStyle.mustache").write(text.strip())
        }
    }
    
    // --- Task order ---
    compileJava.dependsOn ensureNoTrainlingNewlineForRelationStyleMustache
    generateAst.dependsOn relast
    publish.dependsOn jar