Skip to content

Commit

Permalink
Split tests according to the new "modules". Also had to adjust FileTe…
Browse files Browse the repository at this point in the history
…stCase.getTestClassDirectory() to work from Gradle when not passing the "freemarker.test.resourcesDir" system property (which is the case when executing say TemplateTestSuite.main).
  • Loading branch information
kelemen committed Mar 10, 2022
1 parent 7bda738 commit 2bd1907
Show file tree
Hide file tree
Showing 668 changed files with 737 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ before_install:
- java -version

script:
- ./gradlew --continue check javadoc
- ./gradlew --continue clean build -Pjava7CompilerOverride=8 -PfreemarkerDefaultJavaVersion=8 -PsignPublication=false
268 changes: 103 additions & 165 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}

freemarkerRoot {
configureTestUtils("7")

configureSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, "7") { enableTests("8") }
configureSourceSet("jsp20", "7")
configureSourceSet("jsp21", "7") { enableTests() }
configureSourceSet("jython20", "7")
configureSourceSet("jython22", "7")
configureSourceSet("jython25", "7") { enableTests() }
configureSourceSet("core8", "8") { enableTests() }
}

val compileJavacc = tasks.register<freemarker.build.CompileJavaccTask>("compileJavacc") {
sourceDirectory.set(file("freemarker-core/src/main/javacc"))
destinationDirectory.set(buildDir.toPath().resolve("generated").resolve("javacc").toFile())
Expand Down Expand Up @@ -76,74 +88,64 @@ val compileJavacc = tasks.register<freemarker.build.CompileJavaccTask>("compileJ
"final class SimpleCharStream"
)
}
sourceSets.main.get().java.srcDir(compileJavacc)

val allSourceSetNames = ArrayList<String>()

fun configureSourceSet(sourceSetName: String, defaultCompilerVersionStr: String) {
allSourceSetNames.add(sourceSetName)

val compilerVersion = fmExt.freemarkerCompilerVersionOverrideRef
.orElse(providers.gradleProperty("java${defaultCompilerVersionStr}CompilerOverride"))
.getOrElse(defaultCompilerVersionStr)
.let { JavaLanguageVersion.of(it) }

val baseDirName = if (sourceSetName == SourceSet.MAIN_SOURCE_SET_NAME) "core" else sourceSetName
tasks.named<Jar>(sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME).get().sourcesJarTaskName) {
from(compileJavacc.flatMap { it.sourceDirectory })

val sourceSet = sourceSets.maybeCreate(sourceSetName)
sourceSet.java.setSrcDirs(listOf("freemarker-${baseDirName}/src/main/java"))
sourceSet.resources.setSrcDirs(listOf("freemarker-${baseDirName}/src/main/resources"))
from(files("LICENSE", "NOTICE")) {
into("META-INF")
}
}

val rmic = tasks.register<freemarker.build.RmicTask>("rmic") {
val mainSourceSet = sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME).get()
val compileTaskRef = tasks.named<JavaCompile>(mainSourceSet.compileJavaTaskName)

if (sourceSetName == SourceSet.MAIN_SOURCE_SET_NAME) {
sourceSet.java.srcDir(compileJavacc)
} else {
tasks.named<Jar>(mainSourceSet.sourcesJarTaskName) {
from(sourceSet.allSource)
}
classpath.apply {
from(compileTaskRef.map { it.classpath })
from(compileTaskRef.map { it.outputs })
}

val compileOnlyConfigName = "${sourceSetName}${JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME.capitalize()}"
rmiPackage.set("freemarker.debug.impl")
rmiClassPattern.set("Rmi*Impl")

configurations.getByName(compileOnlyConfigName) {
extendsFrom(configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).get())
}
rmiInputClasses.from(mainSourceSet.output.classesDirs)
}

tasks.named<Jar>(JavaPlugin.JAR_TASK_NAME) {
from(sourceSet.output)
}
configurations {
register("combinedClasspath") {
extendsFrom(named("jython25CompileClasspath").get())
extendsFrom(named("jsp21CompileClasspath").get())
}
}

tasks.named<Javadoc>(JavaPlugin.JAVADOC_TASK_NAME) {
source(sourceSet.java)
}
// This source set is only needed, because the OSGI plugin supports only a single sourceSet.
// We are deleting it, because otherwise it would fool IDEs that a source root has multiple owners.
val osgiSourceSet = sourceSets
.create("osgi") {
val otherSourceSets = fmExt.allConfiguredSourceSetNames.get().map { name -> sourceSets.named(name).get() }

dependencies {
add(compileOnlyConfigName, mainSourceSet.output)
testImplementation(sourceSet.output)
}
java.setSrcDirs(otherSourceSets.flatMap { s -> s.java.srcDirs })
resources.setSrcDirs(otherSourceSets.flatMap { s -> s.resources.srcDirs })
}

if (compilerVersion != java.toolchain.languageVersion.get()) {
tasks.named<JavaCompile>(sourceSet.compileJavaTaskName) {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(compilerVersion)
})
}
.apply {
val osgiClasspath = configurations.named("combinedClasspath").get()
compileClasspath = osgiClasspath
runtimeClasspath = osgiClasspath
}
}
.also { sourceSets.remove(it) }

tasks.named<Jar>(JavaPlugin.JAR_TASK_NAME) {
from(rmic.flatMap{ it.destinationDirectory })

configure<aQute.bnd.gradle.BundleTaskExtension> {
bndfile.set(file("osgi.bnd"))

configureSourceSet(SourceSet.MAIN_SOURCE_SET_NAME, "7")
configureSourceSet("jsp20", "7")
configureSourceSet("jsp21", "7")
configureSourceSet("jython20", "7")
configureSourceSet("jython22", "7")
configureSourceSet("jython25", "7")
configureSourceSet("core8", "8")

sourceSets {
test {
val baseDir = "freemarker-test/src/test"
java.setSrcDirs(listOf("${baseDir}/java"))
resources.setSrcDirs(listOf("${baseDir}/resources"))
setSourceSet(osgiSourceSet)
properties.putAll(fmExt.versionDef.versionProperties)
properties.put("moduleOrg", project.group.toString())
properties.put("moduleName", project.name)
}
}

Expand Down Expand Up @@ -182,109 +184,29 @@ tasks.named<Javadoc>(JavaPlugin.JAVADOC_TASK_NAME) {
parentDirName == "log" && logExcludes.contains(fileName)
)
})
}

tasks.named<Test>(JavaPlugin.TEST_TASK_NAME) {
val processResourcesName = sourceSets[SourceSet.TEST_SOURCE_SET_NAME].processResourcesTaskName
val resourcesDestDir = tasks.named<ProcessResources>(processResourcesName).get().destinationDir.toString()
systemProperty("freemarker.test.resourcesDir", resourcesDestDir)

javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(fmExt.testRunnerJavaVersion))
})
}

configurations {
compileOnly {
exclude(group = "xml-apis", module = "xml-apis")
}

register("combinedClasspath") {
extendsFrom(named("jython25CompileOnly").get())
extendsFrom(named("jsp21CompileOnly").get())
}

testImplementation {
extendsFrom(named("jython25CompileOnly").get())
}
}

tasks.named<Jar>(sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME).get().sourcesJarTaskName) {
from(compileJavacc.flatMap { it.sourceDirectory })

from(files("LICENSE", "NOTICE")) {
into("META-INF")
}
}

val rmic = tasks.register<freemarker.build.RmicTask>("rmic") {
val mainSourceSet = sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME).get()
val compileTaskRef = tasks.named<JavaCompile>(mainSourceSet.compileJavaTaskName)

classpath.from(compileTaskRef.map { it.classpath })
classpath.from(compileTaskRef.map { it.outputs })

rmiPackage.set("freemarker.debug.impl")
rmiClassPattern.set("Rmi*Impl")

rmiInputClasses.from(mainSourceSet.output.classesDirs)
}

// This source set is only needed, because the OSGI plugin supports only a single sourceSet.
// We are deleting it, because otherwise it would fool IDEs that a source root has multiple owners.
val osgiSourceSet = sourceSets.create("osgi") {
val otherSourceSets = allSourceSetNames.map { name -> sourceSets.named(name).get() }

java {
setSrcDirs(otherSourceSets.flatMap { s -> s.java.srcDirs })
}
resources {
setSrcDirs(otherSourceSets.flatMap { s -> s.resources.srcDirs })
}
}
val osgiClasspath = configurations.named("combinedClasspath").get()
osgiSourceSet.compileClasspath = osgiClasspath
osgiSourceSet.runtimeClasspath = osgiClasspath
sourceSets.remove(osgiSourceSet)

tasks.named<Jar>(JavaPlugin.JAR_TASK_NAME) {
from(rmic.flatMap{ it.destinationDirectory })

configure<aQute.bnd.gradle.BundleTaskExtension> {
bndfile.set(file("osgi.bnd"))

setSourceSet(osgiSourceSet)
properties.putAll(fmExt.versionDef.versionProperties)
properties.put("moduleOrg", project.group.toString())
properties.put("moduleName", project.name)
}
}

tasks.named<Javadoc>(JavaPlugin.JAVADOC_TASK_NAME) {
javadocTool.set(javaToolchains.javadocToolFor {
languageVersion.set(JavaLanguageVersion.of(fmExt.javadocJavaVersion))
})

val javadocEncoding = StandardCharsets.UTF_8

options {
(options as StandardJavadocDocletOptions).apply {
val displayVersion = fmExt.versionDef.displayVersion
val javadocEncoding = StandardCharsets.UTF_8

locale = "en_US"
encoding = javadocEncoding.name()
windowTitle = "FreeMarker ${displayVersion} API"

val extraOptions = this as StandardJavadocDocletOptions
extraOptions.links("http://docs.oracle.com/javase/8/docs/api/")
links("http://docs.oracle.com/javase/8/docs/api/")

extraOptions.author(true)
extraOptions.version(true)
extraOptions.docEncoding = javadocEncoding.name()
extraOptions.charSet = javadocEncoding.name()
extraOptions.docTitle = "FreeMarker ${displayVersion}"
author(true)
version(true)
docEncoding = javadocEncoding.name()
charSet = javadocEncoding.name()
docTitle = "FreeMarker ${displayVersion}"

// There are too many to check
extraOptions.addStringOption("Xdoclint:-missing", "-quiet")
addStringOption("Xdoclint:-missing", "-quiet")
}

classpath = files(configurations.named("combinedClasspath"))
Expand Down Expand Up @@ -333,9 +255,9 @@ publishing {
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -544,6 +466,17 @@ val slf4jVersion = "1.6.1"
val jettyVersion = "7.6.21.v20160908"
val springVersion = "2.5.6.SEC03"

configurations {
compileOnly {
exclude(group = "xml-apis", module = "xml-apis")
}

"jsp21TestImplementation" {
extendsFrom(compileClasspath.get())
exclude(group = "javax.servlet.jsp")
}
}

dependencies {
compileOnly("jaxen:jaxen:1.0-FCS")
compileOnly("saxpath:saxpath:1.0-FCS")
Expand All @@ -558,7 +491,9 @@ dependencies {
compileOnly("commons-logging:commons-logging:1.1.1") // FIXME: This seems to be unused
compileOnly("org.zeroturnaround:javarebel-sdk:1.2.2")

"core8CompileOnly"("org.dom4j:dom4j:2.1.3")
val dom4j = "org.dom4j:dom4j:2.1.3"

"core8CompileOnly"(dom4j)

"jsp20CompileOnly"("javax.servlet.jsp:jsp-api:2.0")
"jsp20CompileOnly"("javax.servlet:servlet-api:2.4")
Expand All @@ -567,6 +502,17 @@ dependencies {
"jsp21CompileOnly"("javax.servlet.jsp:jsp-api:2.1")
"jsp21CompileOnly"("javax.servlet:servlet-api:2.5")

"jsp21TestImplementation"("org.eclipse.jetty:jetty-server:${jettyVersion}")
"jsp21TestImplementation"("org.eclipse.jetty:jetty-webapp:${jettyVersion}")
"jsp21TestImplementation"("org.eclipse.jetty:jetty-jsp:${jettyVersion}")
"jsp21TestImplementation"("org.eclipse.jetty:jetty-util:${jettyVersion}")
"jsp21TestImplementation"("org.springframework:spring-core:${springVersion}") {
exclude(group = "commons-logging", module = "commons-logging")
}
"jsp21TestImplementation"("org.springframework:spring-test:${springVersion}") {
exclude(group = "commons-logging", module = "commons-logging")
}

"jython20CompileOnly"("jython:jython:2.1")

"jython22CompileOnly"(sourceSets["jython20"].output)
Expand All @@ -575,27 +521,19 @@ dependencies {
"jython25CompileOnly"(sourceSets["jython20"].output)
"jython25CompileOnly"("org.python:jython:2.5.0")

testImplementation("com.google.code.findbugs:annotations:3.0.0")
testImplementation("junit:junit:4.12")
testImplementation("org.hamcrest:hamcrest-library:1.3")
testImplementation("ch.qos.logback:logback-classic:1.1.2")
testImplementation("commons-io:commons-io:2.7")
testImplementation("com.google.guava:guava:29.0-jre")
testImplementation("org.eclipse.jetty:jetty-server:${jettyVersion}")
testImplementation("org.eclipse.jetty:jetty-webapp:${jettyVersion}")
testImplementation("org.eclipse.jetty:jetty-jsp:${jettyVersion}")
testImplementation("org.eclipse.jetty:jetty-util:${jettyVersion}")
testImplementation("displaytag:displaytag:1.2") {
"testUtilsImplementation"("displaytag:displaytag:1.2") {
exclude(group = "com.lowagie", module = "itext")
exclude(group = "org.slf4j", module = "slf4j-log4j12")
exclude(group = "rg.slf4j", module = "jcl104-over-slf4j")
exclude(group = "log4j", module = "log4j")
}
testImplementation("commons-lang:commons-lang:2.6")
testImplementation("org.springframework:spring-core:${springVersion}") {
exclude(group = "commons-logging", module = "commons-logging")
}
testImplementation("org.springframework:spring-test:${springVersion}") {
exclude(group = "commons-logging", module = "commons-logging")
}
"testUtilsImplementation"(sourceSets.main.get().output)
"testUtilsImplementation"("com.google.code.findbugs:annotations:3.0.0")
"testUtilsImplementation"(libs.junit)
"testUtilsImplementation"("org.hamcrest:hamcrest-library:1.3")
"testUtilsImplementation"("ch.qos.logback:logback-classic:1.1.2")
"testUtilsImplementation"("commons-io:commons-io:2.7")
"testUtilsImplementation"("com.google.guava:guava:29.0-jre")
"testUtilsImplementation"("commons-collections:commons-collections:3.1")
"testUtilsImplementation"("commons-lang:commons-lang:2.6")
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ open class CompileJavaccTask @Inject constructor(
}

private fun withProcessJavaccRunner(action: JavaccRunner.() -> Unit) {
action.invoke { actionArgs ->
action { actionArgs ->
val execResult = execOps.javaexec {
classpath = javaccClasspath
mainClass.set(JAVACC_MAIN_CLASS)
Expand All @@ -203,7 +203,7 @@ open class CompileJavaccTask @Inject constructor(

private fun withClasspathJavaccRunner(action: JavaccRunner.() -> Unit) {
val workQueue = exec.classLoaderIsolation { classpath.from(javaccClasspath) }
action.invoke { actionArgs ->
action { actionArgs ->
workQueue.submit(JavaccRunnerWorkAction::class) { arguments.set(actionArgs) }
}
workQueue.await()
Expand Down
Loading

0 comments on commit 2bd1907

Please sign in to comment.