Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ class BuildWithoutLicenseTest : AbstractGradleTest() {
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
}

// Copy the flow-build-info.json so that tests can assert on it
// after the build.
// Copy the cached flow-build-info.json so that tests can assert
// on it after the build (the original is deleted by the task so
// IDE runs default to development mode).
tasks.named('vaadinBuildFrontend').configure {
doLast {
def mainResourcesDir = project.sourceSets.main.output.resourcesDir

// Define source file path based on the resources directory
def sourceFile = new File(mainResourcesDir, "META-INF/VAADIN/config/flow-build-info.json")

if (sourceFile.exists()) {
def cachedFile = new File(project.buildDir, "cached-flow-build-info.json")

if (cachedFile.exists()) {
def destFile = project.file("${buildInfo.absolutePath}")
destFile.text = sourceFile.text
logger.lifecycle("Copied flow-build-info.json to temporary file: ${buildInfo.absolutePath}")
destFile.text = cachedFile.text

logger.lifecycle("Copied cached flow-build-info.json to temporary file: ${buildInfo.absolutePath}")
} else {
logger.warn("Could not find flow-build-info.json to copy")
logger.warn("Could not find cached flow-build-info.json to copy")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ class MiscMultiModuleTest : AbstractGradleTest() {
testProject.newFolder("web")

val b: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend", checkTasksSuccessful = false)
b.expectTaskSucceded("web:vaadinPrepareFrontend")
b.expectTaskNotRan("web:vaadinPrepareFrontend")
b.expectTaskSucceded("web:vaadinBuildFrontend")
expect(null) { b.task(":lib:vaadinPrepareFrontend") }
expect(null) { b.task(":lib:vaadinBuildFrontend") }
expect(null) { b.task(":vaadinPrepareFrontend") }
expect(null) { b.task(":vaadinBuildFrontend") }

val tokenFile = File(testProject.dir, "web/build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFile = File(testProject.dir, "web/build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
expect("app-" + StringUtil.getHash("web",
java.nio.charset.StandardCharsets.UTF_8
Expand Down Expand Up @@ -166,14 +166,14 @@ class MiscMultiModuleTest : AbstractGradleTest() {
""".trimIndent())

val b: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend", checkTasksSuccessful = false)
b.expectTaskSucceded("MY_APP_ID:vaadinPrepareFrontend")
b.expectTaskNotRan("MY_APP_ID:vaadinPrepareFrontend")
b.expectTaskSucceded("MY_APP_ID:vaadinBuildFrontend")
expect(null) { b.task(":lib:vaadinPrepareFrontend") }
expect(null) { b.task(":lib:vaadinBuildFrontend") }
expect(null) { b.task(":vaadinPrepareFrontend") }
expect(null) { b.task(":vaadinBuildFrontend") }

val tokenFile = File(testProject.dir, "web/build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFile = File(testProject.dir, "web/build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
expect("app-" + StringUtil.getHash("MY_APP_ID",
java.nio.charset.StandardCharsets.UTF_8
Expand Down Expand Up @@ -218,14 +218,14 @@ class MiscMultiModuleTest : AbstractGradleTest() {
""".trimIndent())

val b: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend", checkTasksSuccessful = false)
b.expectTaskSucceded("web:vaadinPrepareFrontend")
b.expectTaskNotRan("web:vaadinPrepareFrontend")
b.expectTaskSucceded("web:vaadinBuildFrontend")
expect(null) { b.task(":lib:vaadinPrepareFrontend") }
expect(null) { b.task(":lib:vaadinBuildFrontend") }
expect(null) { b.task(":vaadinPrepareFrontend") }
expect(null) { b.task(":vaadinBuildFrontend") }

val tokenFile = File(testProject.dir, "web/build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFile = File(testProject.dir, "web/build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
expect("MY_APP_ID") { tokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ class MiscSingleModuleTest : AbstractGradleTest() {
@Test
fun testWarProjectProductionMode() {
doTestWarProjectProductionMode()
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
// Read from archive since the token file is deleted from the
// filesystem after packaging to avoid stale production tokens
val tokenJson = testProject.builtWar.zipReadEntry("WEB-INF/classes/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = JacksonUtils.readTree(tokenJson!!)
expect("app-" + StringUtil.getHash(testProject.dir.name,
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
Expand All @@ -80,8 +82,8 @@ class MiscSingleModuleTest : AbstractGradleTest() {
fun testWarProjectProductionModeWithCustomName() {
testProject.settingsFile.writeText("rootProject.name = 'my-test-project'")
doTestWarProjectProductionMode()
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
val tokenJson = testProject.builtWar.zipReadEntry("WEB-INF/classes/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = JacksonUtils.readTree(tokenJson!!)
expect("app-" + StringUtil.getHash("my-test-project",
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
Expand Down Expand Up @@ -209,7 +211,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {

val build: BuildResult =
testProject.build("-Pvaadin.productionMode", "build")
build.expectTaskSucceded("vaadinPrepareFrontend")
build.expectTaskNotRan("vaadinPrepareFrontend")
build.expectTaskSucceded("vaadinBuildFrontend")

val jar: File = testProject.builtJar
Expand Down Expand Up @@ -255,7 +257,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {

val build: BuildResult =
testProject.build("-Pvaadin.productionMode", "build")
build.expectTaskSucceded("vaadinPrepareFrontend")
build.expectTaskNotRan("vaadinPrepareFrontend")
build.expectTaskSucceded("vaadinBuildFrontend")

val jar: File = testProject.builtJar
Expand All @@ -268,7 +270,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {

val build: BuildResult =
testProject.build("bootJar")
build.expectTaskSucceded("vaadinPrepareFrontend")
build.expectTaskNotRan("vaadinPrepareFrontend")
build.expectTaskSucceded("vaadinBuildFrontend")

val jar: File = testProject.builtJar
Expand Down Expand Up @@ -445,7 +447,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {

val build: BuildResult =
testProject.build("-Pvaadin.productionMode", "build")
build.expectTaskSucceded("vaadinPrepareFrontend")
build.expectTaskNotRan("vaadinPrepareFrontend")
build.expectTaskSucceded("vaadinBuildFrontend")

val war: File = testProject.builtWar
Expand Down Expand Up @@ -683,7 +685,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {
)

val build: BuildResult = testProject.build("build")
build.expectTaskSucceded("vaadinPrepareFrontend")
build.expectTaskNotRan("vaadinPrepareFrontend")
build.expectTaskSucceded("vaadinBuildFrontend")

val jar: File = testProject.builtJar
Expand Down Expand Up @@ -779,38 +781,35 @@ class MiscSingleModuleTest : AbstractGradleTest() {
""".trimIndent()
)

// First, run prepare and build to ensure everything works normally
// First, run build to ensure everything works normally
val build1: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
build1.expectTaskSucceded("vaadinPrepareFrontend")
build1.expectTaskNotRan("vaadinPrepareFrontend")
build1.expectTaskSucceded("vaadinBuildFrontend")

// Verify token file was created
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
expect(true) { tokenFile.exists() }
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
// Verify token file was packaged in the war archive (the token
// is deleted from the filesystem after packaging to prevent
// stale production tokens when running from an IDE)
val tokenJson = testProject.builtWar.zipReadEntry("WEB-INF/classes/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = JacksonUtils.readTree(tokenJson!!)
expect("app-" + StringUtil.getHash(testProject.dir.name,
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }

// Clean the token file to simulate it not existing
tokenFile.delete()
expect(false) { tokenFile.exists() }

// Also delete the build-frontend marker file so that Gradle's
// up-to-date check detects a missing output and re-executes
// vaadinBuildFrontend (which contains the token file regeneration
// safety net).
val markerFile = File(testProject.dir, "build/vaadin-generated/build-frontend.marker")
// Delete the cached token file so that Gradle's up-to-date check
// detects a missing output and re-executes vaadinBuildFrontend.
val markerFile = File(testProject.dir, "build/cached-flow-build-info.json")
markerFile.delete()

// Run vaadinBuildFrontend again - it should propagate build info
// even though the token file doesn't exist
// Run vaadinBuildFrontend directly (not via build/war) so the
// token file persists on disk for verification
val build2: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend")
build2.expectTaskSucceded("vaadinBuildFrontend")

// Verify token file was re-created by propagation
expect(true) { tokenFile.exists() }
val newTokenFileContent = JacksonUtils.readTree(tokenFile.readText())
// Verify token was re-created (read from the cached copy since
// the build service deletes the original after the build)
val cachedTokenFile = File(testProject.dir, "build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
expect(true) { cachedTokenFile.exists() }
val newTokenFileContent = JacksonUtils.readTree(cachedTokenFile.readText())
expect("app-" + StringUtil.getHash(testProject.dir.name,
java.nio.charset.StandardCharsets.UTF_8
)) { newTokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ private fun File.zipListAllFiles(): List<String> =
zin.fileNameSequence().toList()
}

/**
* Reads the content of a single entry from this zip archive.
* @param entryPath the path inside the archive, e.g. `META-INF/VAADIN/config/flow-build-info.json`
* @return the entry content as a String, or null if not found
*/
fun File.zipReadEntry(entryPath: String): String? =
ZipInputStream(this.inputStream().buffered()).use { zin ->
generateSequence { zin.nextEntry }
.firstOrNull { it.name == entryPath }
?.let { zin.readBytes().toString(Charsets.UTF_8) }
}

/**
* Expects that given archive contains at least one file matching every glob in the [globs] list.
* @param archiveProvider returns the zip file to examine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ class VaadinSmokeTest : AbstractGradleTest() {
@Test
fun testBuildFrontendInProductionMode() {
val result: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend")
// vaadinBuildFrontend depends on vaadinPrepareFrontend
// let's explicitly check that vaadinPrepareFrontend has been run
result.expectTaskSucceded("vaadinPrepareFrontend")
// vaadinBuildFrontend is self-contained in production mode and
// performs its own frontend preparation without depending on
// vaadinPrepareFrontend
result.expectTaskNotRan("vaadinPrepareFrontend")

val build = File(testProject.dir, "build/resources/main/META-INF/VAADIN/webapp/VAADIN/build")
expect(true, build.toString()) { build.isDirectory }
expect(true) { build.listFiles()!!.isNotEmpty() }
build.find("*.br", 4..10)
build.find("*.js", 4..10)
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
// Read from cached copy since the task deletes the original
// token file so IDE runs default to development mode
val tokenFile = File(testProject.dir, "build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
val buildInfo: JsonNode = JacksonUtils.readTree(tokenFile.readText())
expect(true, buildInfo.toString()) { buildInfo.get(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE).booleanValue() }
expect("app-" + StringUtil.getHash(testProject.dir.name,
Expand All @@ -112,11 +115,11 @@ class VaadinSmokeTest : AbstractGradleTest() {
@Test
fun testBuildFrontendInProductionMode_customApplicationIdentifier() {
val result: BuildResult = testProject.build("-Pvaadin.applicationIdentifier=MY_APP_ID", "-Pvaadin.productionMode", "vaadinBuildFrontend", debug = true)
// vaadinBuildFrontend depends on vaadinPrepareFrontend
// let's explicitly check that vaadinPrepareFrontend has been run
result.expectTaskSucceded("vaadinPrepareFrontend")
// vaadinBuildFrontend is self-contained in production mode
result.expectTaskNotRan("vaadinPrepareFrontend")

val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
// Read from cached copy since the task deletes the original
val tokenFile = File(testProject.dir, "build/${VaadinBuildFrontendTask.CACHED_BUILD_INFO_FILE}")
val buildInfo: JsonNode = JacksonUtils.readTree(tokenFile.readText())
expect("MY_APP_ID", buildInfo.toString()) { buildInfo.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
}
Expand All @@ -140,7 +143,7 @@ class VaadinSmokeTest : AbstractGradleTest() {
""".trimIndent())

val result: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
result.expectTaskSucceded("vaadinPrepareFrontend")
result.expectTaskNotRan("vaadinPrepareFrontend")
result.expectTaskSucceded("vaadinBuildFrontend")
val war = testProject.builtWar
expect(true, "$war file doesn't exist") { war.isFile }
Expand Down Expand Up @@ -328,9 +331,8 @@ class VaadinSmokeTest : AbstractGradleTest() {
frontendDirectory = file("src/main/frontend")
}
""")
// let's explicitly check that vaadinPrepareFrontend has been run.
val result: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
result.expectTaskSucceded("vaadinPrepareFrontend")
result.expectTaskNotRan("vaadinPrepareFrontend")
result.expectTaskSucceded("vaadinBuildFrontend")

expect(false) {
Expand Down Expand Up @@ -379,7 +381,7 @@ class VaadinSmokeTest : AbstractGradleTest() {
""".trimIndent())

val result: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
result.expectTaskSucceded("vaadinPrepareFrontend")
result.expectTaskNotRan("vaadinPrepareFrontend")
result.expectTaskSucceded("vaadinBuildFrontend")

val cssFile = File(testProject.dir, FrontendUtils.DEFAULT_PROJECT_FRONTEND_GENERATED_DIR + "jar-resources/mystyle.css")
Expand Down Expand Up @@ -440,7 +442,7 @@ class VaadinSmokeTest : AbstractGradleTest() {
)

val result: BuildResult = testProject.build("-Pvaadin.productionMode", "build", debug = true)
result.expectTaskSucceded("vaadinPrepareFrontend")
result.expectTaskNotRan("vaadinPrepareFrontend")
result.expectTaskSucceded("vaadinBuildFrontend")

val addonFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ internal class BuildFrontendInputProperties(
fun getJavaResourceFolder(): Provider<String> =
config.javaResourceFolder.absolutePath

@Input
fun getGeneratedTsFolder(): Provider<String> =
config.generatedTsFolder.absolutePath

@Input
fun getPostInstallPackages(): ListProperty<String> =
config.postinstallPackages
Expand Down
Loading
Loading