diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 95e377018b..0000000000 --- a/build.gradle +++ /dev/null @@ -1,325 +0,0 @@ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform - -plugins { - id 'application' - id 'checkstyle' - id 'idea' - id 'jacoco' - id 'java' - id 'com.github.johnrengelman.shadow' version '7.1.2' - id 'com.liferay.node' version '7.2.18' - id 'com.github.psxpaul.execfork' version '0.2.0' - id 'com.palantir.git-version' version '0.13.0' -} - -OperatingSystem os = DefaultNativePlatform.currentOperatingSystem; - -mainClassName = 'reposense.RepoSense' - -node.download = false // The Liferay Node Gradle Plugin will use the system PATH to find the Node/npm executable. - -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - -repositories { - mavenCentral() -} - -configurations { - systemtestImplementation.extendsFrom testImplementation - systemtestRuntime.extendsFrom testRuntime -} - -dependencies { - String jUnitVersion = '5.8.2' - implementation group: 'com.google.code.gson' ,name: 'gson', version:'2.9.0' - implementation group: 'net.freeutils', name: 'jlhttp', version: '2.6' - implementation group: 'net.sourceforge.argparse4j', name: 'argparse4j', version: '0.9.0' - implementation group: 'org.apache.ant', name: 'ant', version: '1.10.12' - implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.9.0' - implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0' - - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion -} - -sourceSets { - systemtest { - compileClasspath += main.output + test.output - runtimeClasspath += main.output + test.output - java.srcDir file('src/systemtest/java') - resources.srcDir file('src/systemtest/resources') - } -} - -def installFrontend = tasks.register('installFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - workingDir 'frontend/' - args = ['ci'] -} - -def buildFrontend = tasks.register('buildFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - dependsOn installFrontend - workingDir 'frontend/' - args = ['run', 'devbuild'] -} - -def zipReport = tasks.register('zipReport', Zip) { - dependsOn buildFrontend - from 'frontend/build/' - archiveBaseName = 'templateZip' - destinationDirectory = file('src/main/resources') -} - -def copyCypressConfig = tasks.register('copyCypressConfig', Copy) { - description 'Copies the config files used by the backend to generate the test report for Cypress testing into an isolated working directory' - from 'frontend/cypress/config' - into 'build/serveTestReport/exampleconfig' -} - -def copyMainClasses = tasks.register('copyMainClasses', Copy) { - description 'Copies the backend classes used to generate the test report for Cypress testing into an isolated working directory' - dependsOn classes - from 'build/classes/java/main' - into 'build/serveTestReport/java/main' -} - -def compileJava = tasks.compileJava - -tasks.named("processSystemtestResources").configure { - duplicatesStrategy = DuplicatesStrategy.INCLUDE -} - -tasks.run.dependsOn(zipReport); - -run { - //the second arguments indicates the default value associated with the property. - tasks.compileJava.mustRunAfter(zipReport) - args System.getProperty('args', '').split() - systemProperty "version", getRepoSenseVersion() -} - -checkstyle { - toolVersion = '9.3' - getConfigDirectory().set(file("$rootProject.projectDir/config/checkstyle")) -} - -idea { - module { - sourceSets.systemtest.allSource.srcDirs.each { srcDir -> module.testSourceDirs += srcDir } - } -} - -test { - environment("REPOSENSE_ENVIRONMENT", "TEST") - - testLogging { - events 'passed', 'skipped', 'failed' - showStandardStreams = true - } - - doFirst { - deleteReposAddressDirectory() - } - - useJUnitPlatform() - - doLast { - deleteReposAddressDirectory() - } -} - -tasks.shadowJar.dependsOn(zipReport); - -shadowJar { - tasks.compileJava.mustRunAfter(zipReport) - tasks.processResources.mustRunAfter(zipReport) - archiveFileName = 'RepoSense.jar' - destinationDirectory = file("${buildDir}/jar/") - - manifest { - attributes 'Implementation-Version': getRepoSenseVersion() - } -} - -tasks.register('lintFrontend', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - dependsOn installFrontend - workingDir 'frontend/' - args = ['run', 'lint'] -} - -def checkstyleMain = tasks.checkstyleMain -def checkstyleTest = tasks.checkstyleTest -def checkstyleSystemtest = tasks.checkstyleSystemtest - -tasks.register('checkstyleAll', Checkstyle) { - dependsOn checkstyleMain, checkstyleTest, checkstyleSystemtest - tasks.checkstyleTest.mustRunAfter('checkstyleMain') - tasks.checkstyleSystemtest.mustRunAfter('checkstyleTest') -} - -tasks.register('environmentalChecks', Exec) { - workingDir 'config/checks/' - if (os.isWindows()){ - commandLine 'cmd', '/c', 'run-checks.bat' - } else { - commandLine 'sh', './run-checks.sh' - } -} - - -tasks.register('systemtest', Test) { - testClassesDirs = sourceSets.systemtest.output.classesDirs - classpath = sourceSets.systemtest.runtimeClasspath - environment("REPOSENSE_ENVIRONMENT", "TEST") - - testLogging { - events 'passed', 'skipped', 'failed' - showStandardStreams = true - } - - doFirst { - deleteReposAddressDirectory() - } - - useJUnitPlatform() - - doLast { - deleteReposAddressDirectory() - } -} - -def serveTestReportInBackground = tasks.register('serveTestReportInBackground', com.github.psxpaul.task.JavaExecFork) { - description 'Creates a background server process for the test report that is to be used by Cypress' - dependsOn zipReport, compileJava, processResources, copyCypressConfig, copyMainClasses - tasks.compileJava.mustRunAfter(zipReport) - tasks.processResources.mustRunAfter(zipReport) - workingDir = 'build/serveTestReport' - main = mainClassName - classpath = sourceSets.main.runtimeClasspath - args = ['--config', './exampleconfig', '--since', 'd1', '--view'] - String versionJvmArgs = '-Dversion=' + getRepoSenseVersion() - jvmArgs = [ versionJvmArgs ] - killDescendants = false // Kills descendants of started process using methods only found in Java 9 and beyond. - // Above flag is set to true by default but is incompatible with Java 8. It should be removed from this file if we fully migrate to Java 11. - waitForPort = 9000 -} - -def installCypress = tasks.register('installCypress', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - workingDir 'frontend/cypress/' - args = ['ci'] -} - -tasks.register('cypress', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - dependsOn installCypress, serveTestReportInBackground - tasks.serveTestReportInBackground.mustRunAfter(installCypress) - - workingDir = file('frontend/cypress/') - args = ["run-script", "debug"] -} - -tasks.register('frontendTest', com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask) { - dependsOn installCypress, serveTestReportInBackground - tasks.serveTestReportInBackground.mustRunAfter(installCypress) - - workingDir = file('frontend/cypress/') - args = ["run-script", "tests"] - - // Run tests in CI without slow motion - if (project.hasProperty('ci')) { - args = ["run-script", "ci"] - } -} - -tasks.withType(Copy) { - includeEmptyDirs = true -} - -jacoco { - toolVersion = "0.8.7" -} - -jacocoTestReport { - reports { - html.required = true - xml.required = true - csv.required = false - html.destination file("${buildDir}/jacocoHtml") - } - - executionData systemtest, frontendTest -} - -tasks.register('coverage', JacocoReport) - -coverage.configure { - sourceDirectories.from files(sourceSets.main.allSource.srcDirs) - classDirectories.from files(sourceSets.main.output) - executionData.from files(jacocoTestReport.executionData) - - afterEvaluate { - classDirectories.from files(classDirectories.files.collect { - fileTree(dir: it, exclude: ['**/*.jar']) - }) - } - - reports { - html.required = true - xml.required = true - } -} - -String getRepoSenseVersion() { - String repoSenseVersion = project.property("version") - if (repoSenseVersion.equals("unspecified")) { - repoSenseVersion = versionDetails().commitDistance == 0 ? versionDetails().lastTag : versionDetails().gitHash - } - return repoSenseVersion -} - -def syncFrontendPublic = tasks.register('syncFrontendPublic', Sync) { - from 'reposense-report' - into 'frontend/public/' - include '**/*.json' - includeEmptyDirs = false - preserve { - include 'index.html' - include 'favicon.ico' - } -} - -def macHotReloadFrontend = tasks.register('macHotReloadFrontend', Exec) { - dependsOn installFrontend - onlyIf {os.isMacOsX()} - workingDir 'frontend/' - commandLine 'npm', 'run', 'serveOpen' -} - -def windowsHotReloadFrontend = tasks.register('windowsHotReloadFrontend', Exec) { - dependsOn installFrontend - onlyIf {os.isWindows()} - workingDir 'frontend/' - commandLine 'cmd','/c', 'START', '"hotreload RepoSense frontend"', 'npm', 'run', 'serveOpen' -} - -def linuxHotReloadFrontend = tasks.register('linuxHotReloadFrontend', Exec) { - dependsOn installFrontend - onlyIf {os.isLinux()} - workingDir 'frontend/' - commandLine 'npm', 'run', 'serveOpen' -} - -tasks.register('hotReloadFrontend') { - dependsOn syncFrontendPublic - finalizedBy windowsHotReloadFrontend - finalizedBy macHotReloadFrontend - finalizedBy linuxHotReloadFrontend -} -// End of hot reload Tasks - -void deleteReposAddressDirectory() { - final String REPOS_ADDRESS = "repos" - def reposDirectory = new File(REPOS_ADDRESS) - reposDirectory.deleteDir() -} - -defaultTasks 'clean', 'build', 'systemtest', 'frontendTest', 'coverage' diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..8b5299ca06 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,354 @@ +import com.github.psxpaul.task.JavaExecFork +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import com.liferay.gradle.plugins.node.tasks.ExecutePackageManagerTask +import com.palantir.gradle.gitversion.VersionDetails +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform +import groovy.lang.Closure + +plugins { + application + checkstyle + idea + jacoco + java + id("com.github.johnrengelman.shadow") version("7.1.2") + id("com.liferay.node") version("7.2.18") + id("com.github.psxpaul.execfork") version("0.2.0") + id("com.palantir.git-version") version("0.13.0") +} + +val os = DefaultNativePlatform.getCurrentOperatingSystem() + +application { + mainClassName = "reposense.RepoSense" +} + +node { + setDownload(false) // The Liferay Node Gradle Plugin will use the system PATH to find the Node/npm executable. +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} +repositories { + mavenCentral() +} + +configurations { + create("systemtestImplementation").extendsFrom(getByName("testImplementation")) + create("systemtestRuntime").extendsFrom(getByName("testRuntimeClasspath")) +} + +dependencies { + val jUnitVersion = "5.8.2" + implementation(group = "com.google.code.gson", name = "gson", version = "2.9.0") + implementation(group = "net.freeutils", name = "jlhttp", version = "2.6") + implementation(group = "net.sourceforge.argparse4j", name = "argparse4j", version = "0.9.0") + implementation(group = "org.apache.ant", name = "ant", version = "1.10.12") + implementation(group = "org.apache.commons", name = "commons-csv", version = "1.9.0") + implementation(group = "org.fusesource.jansi", name = "jansi", version = "2.4.0") + + testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = jUnitVersion) + testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = jUnitVersion) +} + +sourceSets { + create("systemtest") { + compileClasspath += main.get().output + test.get().output + runtimeClasspath += main.get().output + test.get().output + java.srcDir(file("src/systemtest/java")) + resources.srcDir(file("src/systemtest/resources")) + } +} + +val installFrontend = tasks.register("installFrontend") { + setWorkingDir("frontend/") + setArgs(listOf("ci")) +} + +val buildFrontend = tasks.register("buildFrontend") { + dependsOn(installFrontend) + setWorkingDir("frontend/") + setArgs(listOf("run", "devbuild")) +} + +val zipReport = tasks.register("zipReport") { + dependsOn(buildFrontend) + from("frontend/build/") + archiveBaseName.set("templateZip") + destinationDirectory.set(file("src/main/resources")) +} + +val copyCypressConfig = tasks.register("copyCypressConfig") { + description = "Copies the config files used by the backend to generate the test report for Cypress testing into an isolated working directory" + from("frontend/cypress/config") + into("build/serveTestReport/exampleconfig") +} + +val copyMainClasses = tasks.register("copyMainClasses") { + description = "Copies the backend classes used to generate the test report for Cypress testing into an isolated working directory" + dependsOn(tasks.named("classes")) + from("build/classes/java/main") + into("build/serveTestReport/java/main") +} + +val compileJava = tasks.getByName("compileJava") + +tasks.named("processSystemtestResources") { // removed the .configure from here + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + +tasks.getByName("run").dependsOn(zipReport); + +tasks.named("run") { + // The second arguments indicates the default value associated with the property. + compileJava.mustRunAfter(zipReport) + args = System.getProperty("args", "").split(" ") + systemProperty("version", getRepoSenseVersion()) +} + +checkstyle { + toolVersion = "9.3" + configDirectory.set(file("${rootProject.projectDir}/config/checkstyle")) +} + +idea { + module { + sourceSets.getByName("systemtest").allSource.srcDirs.forEach { + srcDir: File -> testSourceDirs.add(srcDir) + } + } +} + +tasks.named("test") { + environment("REPOSENSE_ENVIRONMENT", "TEST") + + testLogging { + events("passed", "skipped", "failed") + showStandardStreams = true + } + + doFirst { + deleteReposAddressDirectory() + } + + useJUnitPlatform() + + doLast { + deleteReposAddressDirectory() + } +} + +val processResources = tasks.getByName("processResources") + +tasks.getByName("shadowJar").dependsOn(zipReport); + +tasks.named("shadowJar") { + compileJava.mustRunAfter(zipReport) + processResources.mustRunAfter(zipReport) + archiveFileName.set("RepoSense.jar") + destinationDirectory.set(file("${buildDir}/jar/")) + + manifest { + attributes("Implementation-Version" to getRepoSenseVersion()) + } +} + +tasks.register("lintFrontend") { + dependsOn(installFrontend) + setWorkingDir("frontend/") + setArgs(listOf("run", "lint")) +} + +val checkstyleMain = tasks.getByName("checkstyleMain") +val checkstyleTest = tasks.getByName("checkstyleTest") +val checkstyleSystemtest = tasks.getByName("checkstyleSystemtest") + +tasks.register("checkstyleAll") { + dependsOn(checkstyleMain, checkstyleTest, checkstyleSystemtest) + checkstyleTest.mustRunAfter("checkstyleMain") + checkstyleSystemtest.mustRunAfter("checkstyleTest") +} + +tasks.register("environmentalChecks") { + setWorkingDir("config/checks/") + if (os.isWindows()){ + commandLine("cmd", "/c", "run-checks.bat") + } else { + commandLine("sh", "./run-checks.sh") + } +} + + +val systemtest = tasks.register("systemtest") { + testClassesDirs = sourceSets.getByName("systemtest").output.classesDirs + classpath = sourceSets.getByName("systemtest").runtimeClasspath + environment("REPOSENSE_ENVIRONMENT", "TEST") + + testLogging { + events("passed", "skipped", "failed") + showStandardStreams = true + } + + doFirst { + deleteReposAddressDirectory() + } + + useJUnitPlatform() + + doLast { + deleteReposAddressDirectory() + } + + finalizedBy(tasks.getByName("jacocoTestReport")) +} + +val serveTestReportInBackground = tasks.register("serveTestReportInBackground") { + description = "Creates a background server process for the test report that is to be used by Cypress" + dependsOn(zipReport, compileJava, processResources, copyCypressConfig, copyMainClasses) + compileJava.mustRunAfter(zipReport) + processResources.mustRunAfter(zipReport) + workingDir = file("build/serveTestReport") + main = application.mainClassName + classpath = sourceSets.getByName("main").runtimeClasspath + args = listOf("--config", "./exampleconfig", "--since", "d1", "--view").toMutableList() + val versionJvmArgs = "-Dversion=" + getRepoSenseVersion() + jvmArgs = listOf(versionJvmArgs) + killDescendants = false // Kills descendants of started process using methods only found in Java 9 and beyond. + // Above flag is set to true by default but is incompatible with Java 8. It should be removed from this file if we fully migrate to Java 11. + waitForPort = 9000 + timeout = 120 +} + +val installCypress = tasks.register("installCypress") { + setWorkingDir("frontend/cypress/") + setArgs(listOf("ci")) +} + +tasks.register("cypress") { + dependsOn(installCypress, serveTestReportInBackground) + tasks.getByName("serveTestReportInBackground").mustRunAfter(installCypress) + + setWorkingDir("frontend/cypress/") + setArgs(listOf("run-script", "debug")) +} + +val frontendTest = tasks.register("frontendTest") { + dependsOn(installCypress, serveTestReportInBackground) + tasks.getByName("serveTestReportInBackground").mustRunAfter(installCypress) + + setWorkingDir("frontend/cypress/") + setArgs(listOf("run-script", "tests")) + + // Run tests in CI without slow motion + if (project.hasProperty("ci")) { + setArgs(listOf("run-script", "ci")) + } + + finalizedBy(tasks.getByName("jacocoTestReport")) +} + +tasks.withType { + includeEmptyDirs = true +} + +jacoco { + toolVersion = "0.8.7" +} + +tasks.named("jacocoTestReport") { + dependsOn(systemtest, frontendTest) + + reports { + html.required.set(true) + xml.required.set(true) + csv.required.set(false) + html.outputLocation.set(file("${buildDir}/jacocoHtml")) + + } + + executionData(tasks.run.get()) +} + +tasks.register("coverage") + +tasks.getByName("coverage") { + sourceDirectories.from(files(sourceSets.getByName("main").allSource.srcDirs)) + classDirectories.from(files(sourceSets.getByName("main").output)) + executionData(fileTree("${buildDir}/jacoco").include("*.exec")) + + afterEvaluate { + classDirectories.from(classDirectories.files.map { + fileTree(it) { + exclude("**/*.jar") + } + }) + } + + reports { + html.required.set(true) + xml.required.set(true) + } +} + +fun getRepoSenseVersion(): String { + val repoSenseVersion: String = project.findProperty("version")?.toString() ?: "" + if (repoSenseVersion == "unspecified") { + val versionDetails: Closure by extra + if (versionDetails().commitDistance == 0) { + return versionDetails().lastTag + } else { + return versionDetails().gitHash + } + } + return repoSenseVersion +} + +val syncFrontendPublic = tasks.register("syncFrontendPublic") { + from("reposense-report") + into("frontend/public/") + include("**/*.json") + includeEmptyDirs = false + preserve { + include("index.html") + include("favicon.ico") + } +} + +val macHotReloadFrontend = tasks.register("macHotReloadFrontend") { + dependsOn(installFrontend) + onlyIf {os.isMacOsX()} + setWorkingDir("frontend/") + commandLine("npm", "run", "serveOpen") +} + +val windowsHotReloadFrontend = tasks.register("windowsHotReloadFrontend") { + dependsOn(installFrontend) + onlyIf {os.isWindows()} + workingDir("frontend/") + commandLine("cmd", "/c", "START", "'hotreload RepoSense frontend'", "npm", "run", "serveOpen") +} + +val linuxHotReloadFrontend = tasks.register("linuxHotReloadFrontend") { + dependsOn(installFrontend) + onlyIf {os.isLinux()} + setWorkingDir("frontend/") + commandLine("npm", "run", "serveOpen") +} + +tasks.register("hotReloadFrontend") { + dependsOn(syncFrontendPublic) + finalizedBy(windowsHotReloadFrontend) + finalizedBy(macHotReloadFrontend) + finalizedBy(linuxHotReloadFrontend) +} +// End of hot reload Tasks + +fun deleteReposAddressDirectory() { + val REPOS_ADDRESS : String = "repos" + val reposDirectory = File(REPOS_ADDRESS) + reposDirectory.deleteRecursively() +} + +defaultTasks("clean", "build", "systemtest", "frontendTest", "coverage")