I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
build.gradle 6.76 KiB
Newer Older
plugins {
    id 'idea'
}
String getReleaseVersion() {
    def releaseVersion
    file("core/java/src/net/i2p/CoreVersion.java").readLines().findAll({ line ->
        line.contains("public final static String VERSION")
    }).first().eachMatch('.*"([^"]+)";', {
        releaseVersion = it[1]
    })
    releaseVersion
}

String getBuildVersion() {
    def buildVersion
    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
        line.contains("public final static long BUILD")
    }).first().eachMatch('.*=\\s+([0-9]+);', {
        buildVersion = it[1]
    })
    buildVersion
}

String getBuildExtra() {
    def buildExtra
    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
        line.contains("public final static String EXTRA")
    }).first().eachMatch('.*"(.*)";', {
        buildExtra = it[1]
    })
    buildExtra
}

String getBuiltBy() {
    def builtBy = ""
    def overrideProps = file("override.properties")
    if (overrideProps.exists()) {
        overrideProps.readLines().findAll({ line ->
            line.contains("build.built-by")
        }).first().eachMatch('.*=(.*)', {
            builtBy = it[1]
        })
    }
    builtBy
}

boolean haveMonotone() {
    file("_MTN").exists()
}

String getWorkspaceVersion() {
    if (haveMonotone()) {
        def stdout = new ByteArrayOutputStream()
        exec {
            executable 'mtn'
            args 'automate', 'get_base_revision_id'
            standardOutput = stdout
        }
        stdout.toString().trim()
    } else {
        'unknown'
    }
}

String compat(String src) {
    if (src.contains('.')) {
        src.substring(src.lastIndexOf('.') + 1)
    } else {
        src
    }
}

String javaExecutable(String targetJavaHome, String execName) {
    def javaExecutablesPath = new File(targetJavaHome, "bin")
    def executable = new File(javaExecutablesPath, execName)
    if (!executable.exists()) {
        throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
    }
    executable.toString()
}

def releaseVersion = getReleaseVersion()
def buildVersion = getBuildVersion()
def buildExtra = getBuildExtra()
def fullVersion = "$releaseVersion-$buildVersion$buildExtra"

def builtBy = getBuiltBy()
def workspaceVersion = getWorkspaceVersion()

// Exclude apps/ dir itself, but include its subdirs
def javaProjects = subprojects - project(':apps')

configure(javaProjects) {
    apply plugin: 'java'
zab2's avatar
zab2 committed
    apply plugin: 'eclipse'
    apply plugin: 'idea'
str4d's avatar
str4d committed
    repositories {
str4d's avatar
str4d committed
    }

    dependencies {
        testCompile 'junit:junit:4.+'
str4d's avatar
str4d committed
        testCompile 'org.hamcrest:hamcrest-library:1.3'
        testCompile 'org.mockito:mockito-core:2.5.0'
    sourceCompatibility = 1.7
    targetCompatibility = 1.7

        // Empty attributes are set by each project. They are initialized
        // here in order to create a defined ordering of the attributes.
            attributes 'Specification-Title': ''
            attributes 'Specification-Version': "$releaseVersion"
            attributes 'Specification-Vendor': 'The I2P Project https://geti2p.net/'
            attributes 'Implementation-Title': ''
            attributes 'Implementation-Version': "$fullVersion"
            attributes 'Implementation-Vendor': 'The I2P Project https://geti2p.net/'
            attributes 'Built-By': "$builtBy"
            attributes 'Build-Date': 'reproducible'
            attributes 'Base-Revision': "$workspaceVersion"
            attributes 'Workspace-Changes': ''
            attributes 'X-Compile-Source-JDK': "$sourceCompatibility"
            attributes 'X-Compile-Target-JDK': "$targetCompatibility"
    tasks.withType(AbstractArchiveTask) {
        preserveFileTimestamps = false
        reproducibleFileOrder = true
    }

    def i2pBootClasspath
    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
    if (java7BootClasspath) {
        i2pBootClasspath = java7BootClasspath
    } else {
        def java7Home = System.getenv("JAVA7_HOME")
        if (java7Home) {
            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
        }
    }

    if (i2pBootClasspath) {
        tasks.withType(AbstractCompile, { AbstractCompile ac ->
            ac.options.bootstrapClasspath = files(i2pBootClasspath)
        })
    } else {
        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
        }
        project.afterEvaluate {
            tasks.withType(JavaCompile) {
                def version = compat(sourceCompatibility)
                logger.info("Configuring $name to use --release $version")
                options.compilerArgs.addAll(['--release', version])
            }

    // Set up Java override if configured (used to test with Java 7).
    def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
    if (targetJavaHome) {
        if (JavaVersion.current().java9Compatible) {
            throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
        }

        project.afterEvaluate {
            logger.info("Target Java home set to ${targetJavaHome}")
            logger.info("Configuring Gradle to use forked compilation and testing")

            tasks.withType(JavaCompile) {
                options.fork = true
                options.forkOptions.javaHome = file(targetJavaHome)
            }

            tasks.withType(Javadoc) {
                executable = javaExecutable(targetJavaHome, "javadoc")
            }

            tasks.withType(Test) {
                executable = javaExecutable(targetJavaHome, "java")
            }

            tasks.withType(JavaExec) {
                executable = javaExecutable(targetJavaHome, "java")
            }
        }
    }
task codeCoverageReport(type: JacocoReport) {
    dependsOn(javaProjects.test)

    jacocoClasspath = project(':core').configurations.jacocoAnt
str4d's avatar
str4d committed
    additionalSourceDirs.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
    sourceDirectories.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
    classDirectories.from(files(javaProjects.sourceSets.main.output))
    executionData.from(files(javaProjects.jacocoTestReport.executionData))

    doFirst {
        executionData = files(executionData.findAll { it.exists() })
    }

    reports {
        xml.enabled true
str4d's avatar
str4d committed
        xml.destination file("${buildDir}/reports/jacoco/report.xml")
str4d's avatar
str4d committed
        html.destination file("${buildDir}/reports/jacoco/html")
//apply from: file('gradle/update.gradle')