diff --git a/.gitignore b/.gitignore index e46776d6..bd14b5fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .idea *.iml target +build +.gradle *~ *.versionsBackup **/karma/node_modules @@ -8,3 +10,4 @@ target **/karma/etc js/src/test/karma/package-lock.json + diff --git a/.mvn/maven.config b/.mvn/maven.config deleted file mode 100644 index 854796cd..00000000 --- a/.mvn/maven.config +++ /dev/null @@ -1 +0,0 @@ ---no-snapshot-updates diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index c6feb8bb..00000000 Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index a3f9f187..00000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/js/npm.templates/kotlinx-html/README.md b/README-JS.md similarity index 100% rename from js/npm.templates/kotlinx-html/README.md rename to README-JS.md diff --git a/README.md b/README.md index 76131b6b..7b2163c5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ [![Official JetBrains Project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) -[![Download](https://api.bintray.com/packages/kotlin/kotlinx.html/kotlinx.html/images/download.svg)](https://bintray.com/kotlin/kotlinx.html/kotlinx.html/_latestVersion) [![npm](https://img.shields.io/npm/v/kotlinx-html.svg)](https://www.npmjs.com/package/kotlinx-html) [![TeamCity (simple build status)](https://img.shields.io/teamcity/http/teamcity.jetbrains.com/s/KotlinTools_KotlinxHtml_Build.svg)](https://teamcity.jetbrains.com/viewType.html?buildTypeId=KotlinTools_KotlinxHtml_Build&branch_Kotlin_KotlinX=%3Cdefault%3E&tab=buildTypeStatusDiv&guest=1) [ ![Kotlin](https://img.shields.io/badge/Kotlin-1.2.71-orange.svg) ](https://kotlinlang.org/) [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-green.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0) +[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-green.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0) +[![Kotlin](https://img.shields.io/badge/Kotlin-1.2.71-orange.svg) ](https://kotlinlang.org/)[![Download](https://api.bintray.com/packages/kotlin/kotlinx.html/kotlinx.html/images/download.svg)](https://bintray.com/kotlin/kotlinx.html/kotlinx.html/_latestVersion) +[![npm](https://img.shields.io/npm/v/kotlinx-html.svg)](https://www.npmjs.com/package/kotlinx-html) +[![TeamCity (simple build status)](https://teamcity.jetbrains.com/app/rest/builds/aggregated/strob:\(branch:\(buildType:\(id:KotlinTools_KotlinxHtml_BuildGradleMasterBranch\),policy:active_history_and_active_vcs_branches\),locator:\(buildType:\(id:KotlinTools_KotlinxHtml_BuildGradleMasterBranch\)\)\)/statusIcon.svg)](https://teamcity.jetbrains.com/viewType.html?buildTypeId=KotlinTools_KotlinxHtml_BuildGradleMasterBranch&branch_Kotlin_KotlinX=%3Cdefault%3E&tab=buildTypeStatusDiv&guest=1) # kotlinx.html diff --git a/assembly/pom.xml b/assembly/pom.xml deleted file mode 100644 index b25df02c..00000000 --- a/assembly/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - kotlinx-html - org.jetbrains.kotlinx - 0.6.13-SNAPSHOT - - 4.0.0 - - kotlinx-html-assembly - - - - org.jetbrains.kotlinx - kotlinx-html-jvm - ${project.version} - - - org.jetbrains.kotlinx - kotlinx-html-js - ${project.version} - - - - - - - maven-assembly-plugin - 2.6 - - - jvm-and-webjar - package - - single - - - - src/main/assembly/jvm.xml - src/main/assembly/webjar.xml - - - - - js-only - package - - single - - - src/main/assembly/js.xml - - - true - - - kotlinx-html-js-assembly - - - - - - - kotlinx-html-${project.version} - - - - maven-jar-plugin - - - default-jar - - - true - - - - - - - diff --git a/assembly/src/main/assembly/js.xml b/assembly/src/main/assembly/js.xml deleted file mode 100644 index 3573de4f..00000000 --- a/assembly/src/main/assembly/js.xml +++ /dev/null @@ -1,22 +0,0 @@ - - js - - jar - - false - - - - false - / - 777 - true - - - org.jetbrains.kotlinx:kotlinx-html-js:jar - - - - \ No newline at end of file diff --git a/assembly/src/main/assembly/jvm.xml b/assembly/src/main/assembly/jvm.xml deleted file mode 100644 index b99641fa..00000000 --- a/assembly/src/main/assembly/jvm.xml +++ /dev/null @@ -1,20 +0,0 @@ - - jvm - - zip - - false - - - - false - / - 777 - - org.jetbrains.kotlinx:kotlinx-html-jvm - - - - \ No newline at end of file diff --git a/assembly/src/main/assembly/webjar.xml b/assembly/src/main/assembly/webjar.xml deleted file mode 100644 index 9c81d516..00000000 --- a/assembly/src/main/assembly/webjar.xml +++ /dev/null @@ -1,34 +0,0 @@ - - webjar - - jar - - false - - - - false - META-INF/resources/webjars/kotlinx-html/${project.version} - 777 - - org.jetbrains.kotlinx:kotlinx-html-js - - true - - true - unix - false - - **/*.meta.js - **/META-INF/** - **/kotlinx/** - **/kotlinx-html-js/** - **/*.kotlin_file_table - **/*.js.map - - - - - \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..b8d51dfa --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,385 @@ +import kotlinx.html.js.* +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsSetupTask +import org.apache.tools.ant.taskdefs.condition.Os + +/** + * This build script supports following parameters: + * -Prelease - activates "release" profile (uploading to Bintray "kotlin/kotlinx.html" without publication and + * publication to npmjs "kotlinx-html"). + * -Pbranch-build - activates "branch-build" profile (publication to Bintray "kotlin/kotlin-dev" and to npmjs + * "@kotlinx-branch-build/kotlinx-html"). + * -Pmaster-build - activates "master-build" profile (publication to OSS Sonatype snapshot repository and to npmjs + * "@kotlinx-master-build/kotlinx-html"). + * -PversionTag - works together with "branch-build" profile and overrides "-SNAPSHOT" suffix of the version. + */ +plugins { + kotlin("multiplatform") version "1.3.61" + id("maven-publish") +} + +group = "org.jetbrains.kotlinx" +version = "0.6.13-SNAPSHOT" + +/** + * If "release" profile is used the "-SNAPSHOT" suffix of the version is removed. + */ +if (hasProperty("release")) { + val versionString = version as String + if (versionString.endsWith("-SNAPSHOT")) { + version = versionString.replace("-SNAPSHOT", "") + } +} + +/** + * Handler of "versionTag" property. + * Required to support Bintray and NPM repositories that doesn't support "-SNAPSHOT" versions. To build and publish + * artifacts with specific version run "./gradlew -PversionTag=my-tag" and the final version will be "0.6.13-my-tag". + */ +if (hasProperty("versionTag")) { + val versionString = version as String + val versionTag = properties["versionTag"] + if (versionString.endsWith("-SNAPSHOT")) { + version = versionString.replace("-SNAPSHOT", "-$versionTag") + logger.lifecycle("Project will be built with version '$version'.") + } else { + error("Could not apply 'versionTag' together with non-snapshot version.") + } +} + +publishing { + publications { + repositories { + when { + hasProperty("release") -> { + maven { + url = uri("https://api.bintray.com/maven/kotlin/kotlinx.html/kotlinx.html;publish=0") + credentials { + username = System.getenv("BINTRAY_USERNAME") + password = System.getenv("BINTRAY_PASSWORD") + } + } + } + hasProperty("branch-build") -> { + require(!(version as String).endsWith("-SNAPSHOT")) { + "Profile 'branch-build' assumes non-snapshot version. Use -PversionTag to fix the build." + } + + maven { + url = uri("https://api.bintray.com/maven/kotlin/kotlin-dev/kotlinx.html/;publish=1") + credentials { + username = System.getenv("BINTRAY_USERNAME") + password = System.getenv("BINTRAY_PASSWORD") + } + } + } + hasProperty("master-build") -> { + require((version as String).endsWith("-SNAPSHOT")) { + "Profile 'master-build' assumes snapshot version. Change the version or use another profile." + } + + maven { + url = uri("https://oss.sonatype.org/content/repositories/snapshots") + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_PASSWORD") + } + } + } + } + } + + create("kotlinx-html-assembly") { + artifactId = "kotlinx-html-assembly" + jar("jsWebJar") { + archiveBaseName by "${project.name}-assembly" + archiveClassifier by "webjar" + from("$buildDir/js/packages/${project.name}/kotlin/kotlinx-html.js") + into("META-INF/resources/webjars/${project.name}/${project.version}/") + rename("kotlinx-html.js", "kotlinx-html-js.js") + } + } + } +} + +repositories { + jcenter() + mavenCentral() + + when { + /** Allow all profiles but release to use development and SNAPSHOT dependencies. */ + !hasProperty("release") -> { + maven { url = uri("https://dl.bintray.com/kotlin/kotlin-dev") } + maven { + url = uri("https://oss.sonatype.org/content/repositories/snapshots") + mavenContent { + snapshotsOnly() + } + } + } + } +} + +kotlin { + jvm { + compilations["main"].kotlinOptions.apply { + freeCompilerArgs += "-Xdump-declarations-to=${buildDir}/declarations.json" + } + + mavenPublication { + groupId = group as String + pom.config { name by "${project.name}-jvm" } + + javadocJar("jvmJavadocJar") + jar("jvmTestSourcesJar") { + archiveClassifier by "test-sources" + with(sourceSets["jvmTest"]) { + from(kotlin, resources) + } + } + } + } + + js { + browser { + testTask { + useKarma { + useChromeHeadless() + useConfigDirectory("${project.projectDir}/src/jsTest/karma") + } + } + } + + compilations["main"].packageJson { + main = "kotlin/kotlinx-html-js.js" + name = "kotlinx-html-js" + } + + compilations["main"].kotlinOptions.apply { + outputFile = "$buildDir/js/packages/${project.name}/kotlin/${project.name}-js.js" + moduleKind = "umd" + sourceMap = true + sourceMapEmbedSources = "always" + } + + compilations["test"].kotlinOptions.apply { + moduleKind = "umd" + metaInfo = true + sourceMap = true + } + + mavenPublication { + groupId = group as String + pom.config { name by "${project.name}-js" } + + javadocJar("jsJavadocJar") + jar("jsTestSourcesJar") { + archiveClassifier by "test-sources" + with(sourceSets["jsTest"]) { + from(kotlin, resources) + } + } + } + } + + metadata { + mavenPublication { + groupId = group as String + artifactId = "${project.name}-common" + pom.config { name by "${project.name}-common" } + + javadocJar("commonJavadocJar") + jar("commonTestSourcesJar") { + archiveClassifier by "test-sources" + } + } + } +} + +kotlin { + sourceSets { + commonMain { + dependencies { + implementation(kotlin("stdlib-common")) + } + } + + val jsMain by getting { + dependencies { + implementation(kotlin("stdlib-js")) + } + } + + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + api(npm("puppeteer", "*")) + } + } + + val jvmMain by getting { + dependencies { + implementation(kotlin("stdlib-jdk8")) + } + } + + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit")) + /* Jackson is required to parse declarations.json. */ + implementation("com.fasterxml.jackson.core:jackson-core:2.10.1") + implementation("com.fasterxml.jackson.core:jackson-databind:2.10.1") + } + } + } +} + +tasks.withType { + manifest { + attributes += sortedMapOf( + "Built-By" to System.getProperty("user.name"), + "Build-Jdk" to System.getProperty("java.version"), + "Implementation-Vendor" to "JetBrains s.r.o.", + "Implementation-Version" to archiveVersion.get(), + "Created-By" to org.gradle.util.GradleVersion.current() + ) + } +} + +tasks.register("generate") { + group = "source-generation" + description = "Generate tag-handling code using tags description." + + doLast { + kotlinx.html.generate.generate( + "kotlinx.html", + "src/commonMain/kotlin/generated", + "src/jsMain/kotlin/generated" + ) + } +} + +tasks.register("jsPackagePrepare") { + dependsOn("jsMainClasses") + tasks["assemble"].dependsOn(this) + + group = "build" + description = "Assembles NPM package (result is placed into 'build/tmp/jsPackage')." + + val baseTargetDir = "$buildDir/tmp/jsPackage" + + from("README-JS.md") + from("$buildDir/js/packages/${project.name}/kotlin") + into(baseTargetDir) + + rename("README-JS.md", "README.md") + + doLast { + var npmVersion = version as String + if (npmVersion.endsWith("-SNAPSHOT")) { + npmVersion = npmVersion.replace("-SNAPSHOT", "-${System.currentTimeMillis()}") + } + + val organization = when { + project.hasProperty("branch-build") -> "kotlinx-branch-build" + project.hasProperty("master-build") -> "kotlinx-master-build" + else -> null + } + + File(baseTargetDir, "package.json").writeText(packageJson(npmVersion, organization)) + file("$baseTargetDir/kotlinx-html-js").renameTo(File("$buildDir/js-module/kotlinx-html-js")) + } +} + +tasks.register("publishNpm") { + dependsOn("jsPackagePrepare") + dependsOn("kotlinNodeJsSetup") + + group = "publishing" + description = "Publishes ${project.name} NPM module to 'registry.npmjs.org'." + + val kotlinNodeJsSetupTask = tasks["kotlinNodeJsSetup"] as NodeJsSetupTask + + // For some unknown reason, the node distributive's structure is different on Windows and UNIX. + val node = if (Os.isFamily(Os.FAMILY_WINDOWS)) { + kotlinNodeJsSetupTask.destination + .resolve("node.exe") + } else { + kotlinNodeJsSetupTask.destination + .resolve("bin") + .resolve("node") + } + + val npm = if (Os.isFamily(Os.FAMILY_WINDOWS)) { + kotlinNodeJsSetupTask.destination + .resolve("node_modules") + .resolve("npm") + .resolve("bin") + .resolve("npm-cli.js") + } else { + kotlinNodeJsSetupTask.destination + .resolve("lib") + .resolve("node_modules") + .resolve("npm") + .resolve("bin") + .resolve("npm-cli.js") + } + + commandLine( + node, + npm, + "publish", + "$buildDir/tmp/jsPackage", + "--//registry.npmjs.org/:_authToken=${System.getenv("NPMJS_AUTH")}", + "--access=public" + ) +} + +typealias MavenPomFile = org.gradle.api.publish.maven.MavenPom + +fun MavenPomFile.config(config: MavenPomFile.() -> Unit = {}) { + config() + + url by "https://github.com/Kotlin/kotlinx.html" + + licenses { + license { + name by "The Apache License, Version 2.0" + url by "https://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + + scm { + connection by "scm:git:git@github.com:Kotlin/kotlinx.html.git" + url by "https://github.com/Kotlin/kotlinx.html" + tag by "HEAD" + } + + developers { + developer { + name by "Sergey Mashkov" + organization by "JetBrains s.r.o." + roles to "developer" + } + + developer { + name by "Anton Dmitriev" + organization by "JetBrains s.r.o." + roles to "developer" + } + } +} + +tasks.withType { + enabled = false +} + +fun MavenPublication.jar(taskName: String, config: Action) = artifact(tasks.create(taskName, Jar::class, config)) + +fun MavenPublication.javadocJar(taskName: String, config: Jar.() -> Unit = {}) = jar(taskName) { + archiveClassifier by "javadoc" + config() +} + +infix fun Property.by(value: T) { + set(value) +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..60a2d25e --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("jvm") version "1.3.61" +} + +repositories { + jcenter() + mavenCentral() +} + +dependencies { + implementation(kotlin("stdlib-jdk8")) + implementation("com.sun.xsom:xsom:20140925") +} \ No newline at end of file diff --git a/generate/src/main/kotlin/attributes.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/attributes.kt similarity index 100% rename from generate/src/main/kotlin/attributes.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/attributes.kt diff --git a/generate/src/main/kotlin/codegen.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/codegen.kt similarity index 98% rename from generate/src/main/kotlin/codegen.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/codegen.kt index b18ff41f..b05c0eb5 100644 --- a/generate/src/main/kotlin/codegen.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/codegen.kt @@ -1,7 +1,6 @@ package kotlinx.html.generate -import kotlinx.html.generate.humanize.humanize -import java.util.ArrayList +import java.util.* interface Const data class StringConst(val value : String) : Const diff --git a/generate/src/main/kotlin/enums.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/enums.kt similarity index 97% rename from generate/src/main/kotlin/enums.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/enums.kt index e31f3335..f81e0d6f 100644 --- a/generate/src/main/kotlin/enums.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/enums.kt @@ -1,7 +1,5 @@ package kotlinx.html.generate -import kotlinx.html.generate.humanize.humanize - val reservedNames = setOf("class", "val", "var", "object", "true", "false", "as", "is", "for") fun String.replaceIfReserved() = if (this in reservedNames) "html" + this.capitalize() else this diff --git a/generate/src/main/kotlin/humanizer.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt similarity index 98% rename from generate/src/main/kotlin/humanizer.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt index f6c20a68..3c709217 100644 --- a/generate/src/main/kotlin/humanizer.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/humanizer.kt @@ -1,6 +1,4 @@ -package kotlinx.html.generate.humanize - -import kotlinx.html.generate.* +package kotlinx.html.generate fun String.humanize() : String { if (this.isEmpty()) { diff --git a/generate/src/main/kotlin/kdoc.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/kdoc.kt similarity index 67% rename from generate/src/main/kotlin/kdoc.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/kdoc.kt index 5049bb0f..3f69c4a6 100644 --- a/generate/src/main/kotlin/kdoc.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/kdoc.kt @@ -1,11 +1,11 @@ -import kotlinx.html.generate.TagInfo -import org.w3c.dom.Node -import org.w3c.dom.NodeList -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory +package kotlinx.html.generate -private val HTML_TABLE_PATH = "generate/src/main/resources/htmltable.xml" -private val HTML5_TABLE_PATH = "generate/src/main/resources/html5table.xml" +import org.w3c.dom.* +import java.net.* +import javax.xml.parsers.* + +private val HTML_TABLE_URL = "htmltable.xml".asResourceUrl() +private val HTML5_TABLE_URL = "html5table.xml".asResourceUrl() object KdocRepository { lateinit var tags: Map @@ -18,14 +18,14 @@ fun fillKdocRepositoryExtension() { val TagInfo.kdoc: KDocInfo? get() = KdocRepository.tags[this.name.toLowerCase()] private fun parseDocInfos(): Map { - val html = parseDocInfo(HTML_TABLE_PATH) - val html5 = parseDocInfo(HTML5_TABLE_PATH) + val html = parseDocInfo(HTML_TABLE_URL) + val html5 = parseDocInfo(HTML5_TABLE_URL) return (html + html5).map { it.name to it }.toMap() } -private fun parseDocInfo(xmlPath: String): List { - val xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(File(xmlPath)) +private fun parseDocInfo(xmlPath: URL): List { + val xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlPath.openStream()) xml.documentElement.normalize() return xml.getElementsByTagName("tag").asList().map { node -> diff --git a/generate/src/main/kotlin/main.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt similarity index 94% rename from generate/src/main/kotlin/main.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt index 4ab6a516..ef23d2a3 100644 --- a/generate/src/main/kotlin/main.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt @@ -1,16 +1,11 @@ package kotlinx.html.generate -import fillKdocRepositoryExtension import java.io.* - -fun main(args: Array) { +fun generate(packg: String, todir: String, jsdir: String) { fillRepository() fillKdocRepositoryExtension() - val packg = "kotlinx.html" - val todir = "shared/src/main/kotlin/generated" - val jsdir = "js/src/main/kotlin/generated" File(todir).mkdirs() File(jsdir).mkdirs() @@ -267,13 +262,15 @@ fun main(args: Array) { append("enum ") clazz(Clazz(name = "Entities")) { - File("generate/src/main/resources/entities.txt").readLines().filter { it.isNotEmpty() }.forEachIndexed { idx, ent -> - if (idx > 0) { - append(",") + InputStreamReader("entities.txt".asResourceUrl().openStream()).useLines { lines -> + lines.filter { it.isNotEmpty() }.forEachIndexed { idx, ent -> + if (idx > 0) { + append(",") + } + indent() + append(ent) + emptyLine() } - indent() - append(ent) - emptyLine() } append(";") diff --git a/generate/src/main/kotlin/model.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/model.kt similarity index 97% rename from generate/src/main/kotlin/model.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/model.kt index e4893968..e64f43ab 100644 --- a/generate/src/main/kotlin/model.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/model.kt @@ -1,9 +1,7 @@ package kotlinx.html.generate -import kotlinx.html.generate.humanize.* import java.util.* import kotlin.collections.HashMap -import kotlin.comparisons.thenComparator object Repository { val tags = TreeMap() diff --git a/generate/src/main/kotlin/parent-ifaces-gen.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/parent-ifaces-gen.kt similarity index 98% rename from generate/src/main/kotlin/parent-ifaces-gen.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/parent-ifaces-gen.kt index 63e1b4d8..be361d11 100644 --- a/generate/src/main/kotlin/parent-ifaces-gen.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/parent-ifaces-gen.kt @@ -1,6 +1,5 @@ package kotlinx.html.generate -import kotlinx.html.generate.humanize.* import java.io.* import java.util.* diff --git a/buildSrc/src/main/kotlin/kotlinx/html/generate/resource-loader.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/resource-loader.kt new file mode 100644 index 00000000..5efaa9b4 --- /dev/null +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/resource-loader.kt @@ -0,0 +1,8 @@ +package kotlinx.html.generate + +import java.net.* + +private class ResourceLoader + +internal fun String.asResourceUrl(): URL = ResourceLoader::class.java.classLoader.getResource(this) + ?: throw IllegalArgumentException("Resource $this not found in classpath.") \ No newline at end of file diff --git a/generate/src/main/kotlin/rules.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/rules.kt similarity index 95% rename from generate/src/main/kotlin/rules.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/rules.kt index 777f1f4d..f7b227e0 100644 --- a/generate/src/main/kotlin/rules.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/rules.kt @@ -1,322 +1,322 @@ -package kotlinx.html.generate - -import java.util.regex.Pattern - -val globalSuggestedAttributes = listOf( - "a" to "href", - "a" to "target", - "img" to "src", - "script" to "type", - "script" to "src", - "div" to "class", - "span" to "class", - "meta" to "name", - "meta" to "content", - "meta" to "charset", - "i" to "class", - "input" to "type", - "input" to "name", - "button" to "name", - "link" to "rel", - "link" to "href", - "link" to "type", - "style" to "type", - "head" to "-class", - "html" to "-class", - "link" to "-class", - "script" to "-class", - "style" to "-class", - "meta" to "-class", - "title" to "-class" -).groupBy { it.first }.mapValues { it.value.map { it.second } } - -val tagNamespaces = mapOf( - "svg" to "http://www.w3.org/2000/svg" -) - -val tagsWithCustomizableNamespace = setOf("html") - -val renames = mapOf( - "CommonAttributeGroupFacadePhrasingContent" to "HtmlInlineTag", - "CommonAttributeGroupFacadeFlowContent" to "HtmlBlockTag", - "CommonAttributeGroupFacadeMetaDataContent" to "HtmlHeadTag", - "CommonAttributeGroupFacadeFlowPhrasingContent" to "HtmlBlockInlineTag" -) - -val tagIgnoreList = setOf( - "menu", "menuitem" -) - -fun Iterable.filterIgnored() = filter { it.name.toLowerCase() !in tagIgnoreList } - -val globalSuggestedAttributeNames = setOf("class") - -val specialTypes = listOf( - "*.class" to AttributeType.STRING_SET -).groupBy { it.first }.mapValues { it.value.single().second } - -fun specialTypeFor(tagName: String, attributeName: String): AttributeType? = - specialTypes[tagName + "." + attributeName] ?: specialTypes["*." + attributeName] - -val wellKnownWords = listOf("span", "class", "enabled?", "edit(able)?", - "^on", "encoded?", "form", "type", - "run", "href", "drag(gable)?", - "over", "mouse", - "start(ed)?", "legend", "end(ed)?", "stop", "key", "load(ed)?", "check(ed)?", - "time", "ready", "content", "changed?", - "click", "play(ing)?", "context", - "rows?", "cols?", "group(ed)?", "auto", - "list", "field", "data", "block", "scripts?", - "item", "area", "length", "colors?", "suspend", "focus", "touch" -).map { it.toRegex(RegexOption.IGNORE_CASE) } - -val excludeAttributes = listOf("^item$").map { Pattern.compile(it, Pattern.CASE_INSENSITIVE) } -fun isAttributeExcluded(name: String) = excludeAttributes.any { it.matcher(name).find() } - -val excludedEnums = listOf("Lang$").map { it.toRegex(RegexOption.IGNORE_CASE) } -fun isEnumExcluded(name: String) = excludedEnums.any { it.containsMatchIn(name) } - -val contentlessTags = setOf("html", "head", "script", "style") - -val deprecated = listOf(".*FormMethod#(put|patch|delete)" to "method is not allowed in browsers") - .map { it.first.toRegex(RegexOption.IGNORE_CASE) to it.second } - -fun findEnumDeprecation(attribute: AttributeInfo, value: AttributeEnumValue): String? { - return deprecated.firstOrNull { p -> p.first.matches("""${attribute.enumTypeName}#${value.realName}""") }?.second -} - -val knownTagClasses = """ -HTMLElement -HTMLUnknownElement -HTMLHtmlElement -HTMLHeadElement -HTMLTitleElement -HTMLBaseElement -HTMLLinkElement -HTMLMetaElement -HTMLStyleElement -HTMLBodyElement -HTMLHeadingElement -HTMLParagraphElement -HTMLHRElement -HTMLPreElement -HTMLQuoteElement -HTMLOListElement -HTMLUListElement -HTMLLIElement -HTMLDListElement -HTMLDivElement -HTMLAnchorElement -HTMLDataElement -HTMLTimeElement -HTMLSpanElement -HTMLBRElement -HTMLModElement -HTMLIFrameElement -HTMLEmbedElement -HTMLObjectElement -HTMLParamElement -HTMLVideoElement -HTMLAudioElement -HTMLSourceElement -HTMLTrackElement -HTMLMediaElement -HTMLMapElement -HTMLAreaElement -HTMLTableElement -HTMLTableCaptionElement -HTMLTableColElement -HTMLTableSectionElement -HTMLTableRowElement -HTMLTableDataCellElement -HTMLTableHeaderCellElement -HTMLTableCellElement -HTMLFormElement -HTMLLabelElement -HTMLInputElement -HTMLButtonElement -HTMLSelectElement -HTMLDataListElement -HTMLOptGroupElement -HTMLOptionElement -HTMLTextAreaElement -HTMLKeygenElement -HTMLOutputElement -HTMLProgressElement -HTMLMeterElement -HTMLFieldSetElement -HTMLLegendElement -HTMLDetailsElement -HTMLMenuElement -HTMLMenuItemElement -HTMLDialogElement -HTMLScriptElement -HTMLTemplateElement -HTMLCanvasElement -HTMLAppletElement -HTMLMarqueeElement -HTMLFrameSetElement -HTMLFrameElement -HTMLAnchorElement -HTMLAreaElement -HTMLBodyElement -HTMLBRElement -HTMLTableCaptionElement -HTMLTableColElement -HTMLDirectoryElement -HTMLDivElement -HTMLDListElement -HTMLEmbedElement -HTMLFontElement -HTMLHeadingElement -HTMLHRElement -HTMLHtmlElement -HTMLIFrameElement -HTMLImageElement -HTMLInputElement -HTMLLegendElement -HTMLLIElement -HTMLLinkElement -HTMLMenuElement -HTMLMetaElement -HTMLObjectElement -HTMLOListElement -HTMLParagraphElement -HTMLParamElement -HTMLPreElement -HTMLScriptElement -HTMLTableElement -HTMLTableSectionElement -HTMLTableCellElement -HTMLTableDataCellElement -HTMLTableRowElement -HTMLUListElement -HTMLElement -HTMLUnknownElement -HTMLHtmlElement -HTMLHeadElement -HTMLTitleElement -HTMLBaseElement -HTMLLinkElement -HTMLMetaElement -HTMLStyleElement -HTMLBodyElement -HTMLHeadingElement -HTMLParagraphElement -HTMLHRElement -HTMLPreElement -HTMLQuoteElement -HTMLOListElement -HTMLUListElement -HTMLLIElement -HTMLDListElement -HTMLDivElement -HTMLAnchorElement -HTMLDataElement -HTMLTimeElement -HTMLSpanElement -HTMLBRElement -HTMLModElement -HTMLPictureElement -HTMLSourceElement -HTMLImageElement -HTMLIFrameElement -HTMLEmbedElement -HTMLObjectElement -HTMLParamElement -HTMLVideoElement -HTMLAudioElement -HTMLSourceElement -HTMLTrackElement -HTMLMediaElement -HTMLMapElement -HTMLAreaElement -HTMLTableElement -HTMLTableCaptionElement -HTMLTableColElement -HTMLTableSectionElement -HTMLTableRowElement -HTMLTableDataCellElement -HTMLTableHeaderCellElement -HTMLTableCellElement -HTMLFormElement -HTMLLabelElement -HTMLInputElement -HTMLButtonElement -HTMLSelectElement -HTMLDataListElement -HTMLOptGroupElement -HTMLOptionElement -HTMLTextAreaElement -HTMLKeygenElement -HTMLOutputElement -HTMLProgressElement -HTMLMeterElement -HTMLFieldSetElement -HTMLLegendElement -HTMLDetailsElement -HTMLMenuElement -HTMLMenuItemElement -HTMLDialogElement -HTMLScriptElement -HTMLTemplateElement -HTMLCanvasElement -HTMLAppletElement -HTMLMarqueeElement -HTMLFrameSetElement -HTMLFrameElement -HTMLAnchorElement -HTMLAreaElement -HTMLBodyElement -HTMLBRElement -HTMLTableCaptionElement -HTMLTableColElement -HTMLDirectoryElement -HTMLDivElement -HTMLDListElement -HTMLEmbedElement -HTMLFontElement -HTMLHeadingElement -HTMLHRElement -HTMLHtmlElement -HTMLIFrameElement -HTMLImageElement -HTMLInputElement -HTMLLegendElement -HTMLLIElement -HTMLLinkElement -HTMLMenuElement -HTMLMetaElement -HTMLObjectElement -HTMLOListElement -HTMLParagraphElement -HTMLParamElement -HTMLPreElement -HTMLScriptElement -HTMLTableElement -HTMLTableSectionElement -HTMLTableCellElement -HTMLTableDataCellElement -HTMLTableRowElement -HTMLUListElement -""".split("\\s+".toRegex()).toSet() - -val tagReplacements = listOf( - "img" to "image", - "h\\d" to "heading", - "p" to "paragraph", - "a" to "anchor", - "blockquote" to "quote", - "td" to "TableCell", - "tr" to "TableRow", - "th" to "TableCell", - "col" to "TableCol", - "colGroup" to "TableCol", - "thead" to "TableSection", - "tbody" to "TableSection", - "tfoot" to "TableSection" -) - -val attributeReplacements = listOf( - "class" to "classes" +package kotlinx.html.generate + +import java.util.regex.* + +val globalSuggestedAttributes = listOf( + "a" to "href", + "a" to "target", + "img" to "src", + "script" to "type", + "script" to "src", + "div" to "class", + "span" to "class", + "meta" to "name", + "meta" to "content", + "meta" to "charset", + "i" to "class", + "input" to "type", + "input" to "name", + "button" to "name", + "link" to "rel", + "link" to "href", + "link" to "type", + "style" to "type", + "head" to "-class", + "html" to "-class", + "link" to "-class", + "script" to "-class", + "style" to "-class", + "meta" to "-class", + "title" to "-class" +).groupBy { it.first }.mapValues { it.value.map { it.second } } + +val tagNamespaces = mapOf( + "svg" to "http://www.w3.org/2000/svg" +) + +val tagsWithCustomizableNamespace = setOf("html") + +val renames = mapOf( + "CommonAttributeGroupFacadePhrasingContent" to "HtmlInlineTag", + "CommonAttributeGroupFacadeFlowContent" to "HtmlBlockTag", + "CommonAttributeGroupFacadeMetaDataContent" to "HtmlHeadTag", + "CommonAttributeGroupFacadeFlowPhrasingContent" to "HtmlBlockInlineTag" +) + +val tagIgnoreList = setOf( + "menu", "menuitem" +) + +fun Iterable.filterIgnored() = filter { it.name.toLowerCase() !in tagIgnoreList } + +val globalSuggestedAttributeNames = setOf("class") + +val specialTypes = listOf( + "*.class" to AttributeType.STRING_SET +).groupBy { it.first }.mapValues { it.value.single().second } + +fun specialTypeFor(tagName: String, attributeName: String): AttributeType? = + specialTypes[tagName + "." + attributeName] ?: specialTypes["*." + attributeName] + +val wellKnownWords = listOf("span", "class", "enabled?", "edit(able)?", + "^on", "encoded?", "form", "type", + "run", "href", "drag(gable)?", + "over", "mouse", + "start(ed)?", "legend", "end(ed)?", "stop", "key", "load(ed)?", "check(ed)?", + "time", "ready", "content", "changed?", + "click", "play(ing)?", "context", + "rows?", "cols?", "group(ed)?", "auto", + "list", "field", "data", "block", "scripts?", + "item", "area", "length", "colors?", "suspend", "focus", "touch" +).map { it.toRegex(RegexOption.IGNORE_CASE) } + +val excludeAttributes = listOf("^item$").map { Pattern.compile(it, Pattern.CASE_INSENSITIVE) } +fun isAttributeExcluded(name: String) = excludeAttributes.any { it.matcher(name).find() } + +val excludedEnums = listOf("Lang$").map { it.toRegex(RegexOption.IGNORE_CASE) } +fun isEnumExcluded(name: String) = excludedEnums.any { it.containsMatchIn(name) } + +val contentlessTags = setOf("html", "head", "script", "style") + +val deprecated = listOf(".*FormMethod#(put|patch|delete)" to "method is not allowed in browsers") + .map { it.first.toRegex(RegexOption.IGNORE_CASE) to it.second } + +fun findEnumDeprecation(attribute: AttributeInfo, value: AttributeEnumValue): String? { + return deprecated.firstOrNull { p -> p.first.matches("""${attribute.enumTypeName}#${value.realName}""") }?.second +} + +val knownTagClasses = """ +HTMLElement +HTMLUnknownElement +HTMLHtmlElement +HTMLHeadElement +HTMLTitleElement +HTMLBaseElement +HTMLLinkElement +HTMLMetaElement +HTMLStyleElement +HTMLBodyElement +HTMLHeadingElement +HTMLParagraphElement +HTMLHRElement +HTMLPreElement +HTMLQuoteElement +HTMLOListElement +HTMLUListElement +HTMLLIElement +HTMLDListElement +HTMLDivElement +HTMLAnchorElement +HTMLDataElement +HTMLTimeElement +HTMLSpanElement +HTMLBRElement +HTMLModElement +HTMLIFrameElement +HTMLEmbedElement +HTMLObjectElement +HTMLParamElement +HTMLVideoElement +HTMLAudioElement +HTMLSourceElement +HTMLTrackElement +HTMLMediaElement +HTMLMapElement +HTMLAreaElement +HTMLTableElement +HTMLTableCaptionElement +HTMLTableColElement +HTMLTableSectionElement +HTMLTableRowElement +HTMLTableDataCellElement +HTMLTableHeaderCellElement +HTMLTableCellElement +HTMLFormElement +HTMLLabelElement +HTMLInputElement +HTMLButtonElement +HTMLSelectElement +HTMLDataListElement +HTMLOptGroupElement +HTMLOptionElement +HTMLTextAreaElement +HTMLKeygenElement +HTMLOutputElement +HTMLProgressElement +HTMLMeterElement +HTMLFieldSetElement +HTMLLegendElement +HTMLDetailsElement +HTMLMenuElement +HTMLMenuItemElement +HTMLDialogElement +HTMLScriptElement +HTMLTemplateElement +HTMLCanvasElement +HTMLAppletElement +HTMLMarqueeElement +HTMLFrameSetElement +HTMLFrameElement +HTMLAnchorElement +HTMLAreaElement +HTMLBodyElement +HTMLBRElement +HTMLTableCaptionElement +HTMLTableColElement +HTMLDirectoryElement +HTMLDivElement +HTMLDListElement +HTMLEmbedElement +HTMLFontElement +HTMLHeadingElement +HTMLHRElement +HTMLHtmlElement +HTMLIFrameElement +HTMLImageElement +HTMLInputElement +HTMLLegendElement +HTMLLIElement +HTMLLinkElement +HTMLMenuElement +HTMLMetaElement +HTMLObjectElement +HTMLOListElement +HTMLParagraphElement +HTMLParamElement +HTMLPreElement +HTMLScriptElement +HTMLTableElement +HTMLTableSectionElement +HTMLTableCellElement +HTMLTableDataCellElement +HTMLTableRowElement +HTMLUListElement +HTMLElement +HTMLUnknownElement +HTMLHtmlElement +HTMLHeadElement +HTMLTitleElement +HTMLBaseElement +HTMLLinkElement +HTMLMetaElement +HTMLStyleElement +HTMLBodyElement +HTMLHeadingElement +HTMLParagraphElement +HTMLHRElement +HTMLPreElement +HTMLQuoteElement +HTMLOListElement +HTMLUListElement +HTMLLIElement +HTMLDListElement +HTMLDivElement +HTMLAnchorElement +HTMLDataElement +HTMLTimeElement +HTMLSpanElement +HTMLBRElement +HTMLModElement +HTMLPictureElement +HTMLSourceElement +HTMLImageElement +HTMLIFrameElement +HTMLEmbedElement +HTMLObjectElement +HTMLParamElement +HTMLVideoElement +HTMLAudioElement +HTMLSourceElement +HTMLTrackElement +HTMLMediaElement +HTMLMapElement +HTMLAreaElement +HTMLTableElement +HTMLTableCaptionElement +HTMLTableColElement +HTMLTableSectionElement +HTMLTableRowElement +HTMLTableDataCellElement +HTMLTableHeaderCellElement +HTMLTableCellElement +HTMLFormElement +HTMLLabelElement +HTMLInputElement +HTMLButtonElement +HTMLSelectElement +HTMLDataListElement +HTMLOptGroupElement +HTMLOptionElement +HTMLTextAreaElement +HTMLKeygenElement +HTMLOutputElement +HTMLProgressElement +HTMLMeterElement +HTMLFieldSetElement +HTMLLegendElement +HTMLDetailsElement +HTMLMenuElement +HTMLMenuItemElement +HTMLDialogElement +HTMLScriptElement +HTMLTemplateElement +HTMLCanvasElement +HTMLAppletElement +HTMLMarqueeElement +HTMLFrameSetElement +HTMLFrameElement +HTMLAnchorElement +HTMLAreaElement +HTMLBodyElement +HTMLBRElement +HTMLTableCaptionElement +HTMLTableColElement +HTMLDirectoryElement +HTMLDivElement +HTMLDListElement +HTMLEmbedElement +HTMLFontElement +HTMLHeadingElement +HTMLHRElement +HTMLHtmlElement +HTMLIFrameElement +HTMLImageElement +HTMLInputElement +HTMLLegendElement +HTMLLIElement +HTMLLinkElement +HTMLMenuElement +HTMLMetaElement +HTMLObjectElement +HTMLOListElement +HTMLParagraphElement +HTMLParamElement +HTMLPreElement +HTMLScriptElement +HTMLTableElement +HTMLTableSectionElement +HTMLTableCellElement +HTMLTableDataCellElement +HTMLTableRowElement +HTMLUListElement +""".split("\\s+".toRegex()).toSet() + +val tagReplacements = listOf( + "img" to "image", + "h\\d" to "heading", + "p" to "paragraph", + "a" to "anchor", + "blockquote" to "quote", + "td" to "TableCell", + "tr" to "TableRow", + "th" to "TableCell", + "col" to "TableCol", + "colGroup" to "TableCol", + "thead" to "TableSection", + "tbody" to "TableSection", + "tfoot" to "TableSection" +) + +val attributeReplacements = listOf( + "class" to "classes" ).map { Pair(it.first.toRegex(), it.second) } \ No newline at end of file diff --git a/generate/src/main/kotlin/tag-builders.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt similarity index 100% rename from generate/src/main/kotlin/tag-builders.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/tag-builders.kt diff --git a/generate/src/main/kotlin/tag-unions.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-unions.kt similarity index 97% rename from generate/src/main/kotlin/tag-unions.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/tag-unions.kt index 479d977d..9dc29273 100644 --- a/generate/src/main/kotlin/tag-unions.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/tag-unions.kt @@ -1,7 +1,5 @@ package kotlinx.html.generate -import kotlinx.html.generate.humanize.* - fun tagUnions() { val groupings = Repository.groupsByTags.filter { it.value.size > 1 } val groups = groupings.values.map { it.map { it.name }.toHashSet() }.distinct().sortedByDescending { it.size } diff --git a/generate/src/main/kotlin/tagsgen.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/tagsgen.kt similarity index 96% rename from generate/src/main/kotlin/tagsgen.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/tagsgen.kt index 86e3b5c0..2654a937 100644 --- a/generate/src/main/kotlin/tagsgen.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/tagsgen.kt @@ -1,429 +1,427 @@ -package kotlinx.html.generate - -import kdoc -import kotlinx.html.generate.humanize.* -import java.util.* - -fun Appendable.tagClass(tag : TagInfo, excludeAttributes : Set) { - val parentAttributeIfaces = tag.attributeGroups.map {it.name.capitalize() + "Facade"} - val parentElementIfaces = tag.tagGroupNames.map { it.humanize().capitalize() } - val allParentIfaces = parentAttributeIfaces + parentElementIfaces - val betterParentIfaces = humanizeJoin(allParentIfaces) - - val namespace = tagNamespaces[tag.name.toLowerCase()] - val customizableNamespace = tag.name.toLowerCase() in tagsWithCustomizableNamespace - - val parameters = mutableListOf( - Var("initialAttributes", "Map", false, false, true), - Var("consumer", "TagConsumer<*>", false, true) - ) - val superConstructorArguments = mutableListOf( - tag.name.quote(), - "consumer", - "initialAttributes", - namespace?.quote().toString(), - (tag.name in inlineTags).toString(), - (tag.name in emptyTags).toString() - ) - - if (customizableNamespace) { - parameters.add(Var("namespace", "String?", false, false, true, namespace?.quote() ?: "null")) - superConstructorArguments[3] = "namespace" - } - - appendln("@Suppress(\"unused\")") - clazz(Clazz( - name = tag.className, - variables = parameters, - parents = listOf( - buildString { - functionCall("HTMLTag", superConstructorArguments) - } - ) + when { - allParentIfaces.isNotEmpty() -> listOf(betterParentIfaces).map { renames[it] ?: it } - else -> emptyList() - }, - isOpen = true - )) { - val lowerCasedNames = tag.attributes.map {it.name.toLowerCase()}.toSet() - val attributes = tag.attributes.filter {it.name !in excludeAttributes} - - attributes.filter {!isAttributeExcluded(it.name) }.forEach { attribute -> - if (attribute.name[0].isLowerCase() || attribute.name.toLowerCase() !in lowerCasedNames) { - attributeProperty(attribute) - } - } - - fun contentlessTagDeprecation() { - indent() - appendln("@Deprecated(\"This tag most likely doesn't support text content or requires unsafe content (try unsafe {}\")") - } - - if (tag.name.toLowerCase() in contentlessTags) { - contentlessTagDeprecation() - - indent() - function("unaryPlus", modifiers = listOf("override", "operator"), receiver = "Entities") - block { - indent(2) - append("@Suppress(\"DEPRECATION\") ") - functionCall("entity", listOf("this")) - appendln() - indent() - } - - appendln() - contentlessTagDeprecation() - - indent() - function("unaryPlus", modifiers = listOf("override", "operator"), receiver = "String") - block { - indent(2) - append("@Suppress(\"DEPRECATION\") ") - functionCall("text", listOf("this")) - appendln() - indent() - } - - appendln() - contentlessTagDeprecation() - - indent() - function("text", arguments = listOf(Var("s", "String")), modifiers = listOf("override")) - block { - indent(2) - receiverDot("super") - functionCall("text", listOf("s")) - appendln() - indent() - } - - appendln() - contentlessTagDeprecation() - - indent() - function("text", arguments = listOf(Var("n", "Number")), modifiers = listOf("override")) - block { - indent(2) - receiverDot("super") - functionCall("text", listOf("n")) - appendln() - indent() - } - - appendln() - contentlessTagDeprecation() - - indent() - function("entity", arguments = listOf(Var("e", "Entities")), modifiers = listOf("override")) - block { - indent(2) - receiverDot("super") - functionCall("entity", listOf("e")) - appendln() - indent() - } - } - - emptyLine() - } - - tag.directChildren.map {Repository.tags[it]}.filterNotNull().filterIgnored().forEach { children -> - htmlTagBuilders(tag.className, children) - } - - if (parentElementIfaces.size > 1) { - val commons = tag.tagGroupNames.map {Repository.tagGroups[it]?.tags?.toSet()}.filterNotNull().reduce { a, b -> a.intersect(b) } - if (commons.isNotEmpty()) { - parentElementIfaces.forEach { group -> - variable(Var(name = "as" + group, type = group), receiver = tag.className) - appendln() - getter() - defineIs("this") - emptyLine() - } - } - } - - emptyLine() -} - -internal fun Appendable.tagAttributeVar(attribute: AttributeInfo, receiver: String?, indent: Int = 1): AttributeRequest { - val options = LinkedList>() - - if (attribute.type == AttributeType.ENUM) { - options.add(ReferenceConst(attribute.enumTypeName.decapitalize() + "Values")) - } else if (attribute.type == AttributeType.BOOLEAN && attribute.trueFalse.isNotEmpty()) { - options.addAll(attribute.trueFalse.map(::StringConst)) - } - - val attributeRequest = AttributeRequest(attribute.type, if (attribute.type == AttributeType.ENUM) attribute.enumTypeName else "", options) - Repository.attributeDelegateRequests.add(attributeRequest) - - indent(indent) - variable(Var(attribute.fieldName, attribute.typeName, true), receiver = receiver ?: "") - return attributeRequest -} - -fun probeType(htmlClassName : String) : Boolean = htmlClassName in knownTagClasses - -private fun tagCandidates(tag : TagInfo) = (listOf(tag.memberName) + tagReplacements.map { tag.memberName.replace(it.first.toRegex(), it.second) }).flatMap { listOf(it.capitalize(), it.toUpperCase()) }.distinct() - -fun getTagResultClass(tag: TagInfo) = - tagCandidates(tag) - .map { "HTML${it}Element" } - .firstOrNull { probeType(it) } ?: "HTMLElement" - -fun contentArgumentValue(tag : TagInfo, blockOrContent : Boolean) = when { - tag.name.toLowerCase() in emptyTags -> "block" - blockOrContent -> "block" - else -> "{+content}" -} - -fun Appendable.consumerBuilderJS(tag : TagInfo, blockOrContent : Boolean) { - val resultType = getTagResultClass(tag) - - val constructorArgs = mutableListOf( - buildSuggestedAttributesArgument(tag), - "this" - ) - - if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { - constructorArgs.add("namespace") - } - - tagKdoc(tag) - htmlDslMarker() - append("public ") - function(tag.memberName, tagBuilderFunctionArguments(tag, blockOrContent), resultType, receiver = "TagConsumer") - defineIs(buildString { - functionCall(tag.className, constructorArgs) - append(".") - functionCall("visitAndFinalize", listOf( - "this", - contentArgumentValue(tag, blockOrContent) - )) - - if (resultType != "HTMLElement") { - append(" as ") - append(resultType) - } - }) -} - -fun Appendable.consumerBuilderShared(tag : TagInfo, blockOrContent : Boolean) { - val constructorArgs = mutableListOf( - buildSuggestedAttributesArgument(tag), - "this" - ) - - if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { - constructorArgs.add("namespace") - } - - tagKdoc(tag) - htmlDslMarker() - function(tag.memberName, tagBuilderFunctionArguments(tag, blockOrContent), "T", listOf("T", "C : TagConsumer"), "C") - defineIs(buildString { - functionCall(tag.className, constructorArgs) - append(".") - functionCall("visitAndFinalize", listOf( - "this", - contentArgumentValue(tag, blockOrContent) - )) - }) -} - -fun Appendable.htmlTagBuilderMethod(receiver : String, tag : TagInfo, blockOrContent : Boolean) { - val arguments = tagBuilderFunctionArguments(tag, blockOrContent) - - val constructorArgs = mutableListOf( - buildSuggestedAttributesArgument(tag), - "consumer" - ) - - if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { - constructorArgs.add("namespace") - } - - tagKdoc(tag) - htmlDslMarker() - function(tag.memberName, arguments, "Unit", receiver = receiver) - defineIs(buildString { - functionCall(tag.className, constructorArgs) - append(".") - functionCall("visit", listOf(contentArgumentValue(tag, blockOrContent))) - }) -} - -fun Appendable.htmlTagEnumBuilderMethod(receiver : String, tag : TagInfo, blockOrContent : Boolean, enumAttribute : AttributeInfo, indent : Int) { - require(enumAttribute.enumValues.isNotEmpty()) - - val arguments = tagBuilderFunctionArguments(tag, blockOrContent).filter {it.name != enumAttribute.fieldName} - - enumAttribute.enumValues.forEach { enumValue -> - val deprecation = findEnumDeprecation(enumAttribute, enumValue) - - val constructorArgs = mutableListOf( - buildSuggestedAttributesArgument(tag, mapOf(enumAttribute.fieldName to enumAttribute.typeName + "." + enumValue.fieldName + ".realValue")), - "consumer" - ) - if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { - constructorArgs.add("namespace") - } - - if (deprecation != null) { - indent(indent) - suppress("DEPRECATION") - } - - indent(indent) - htmlDslMarker() - function(enumValue.fieldName + tag.memberName.capitalize(), arguments, "Unit", receiver = receiver) - defineIs(buildString { - functionCall(tag.className, constructorArgs) - append(".") - functionCall("visit", listOf(contentArgumentValue(tag, blockOrContent))) - }) - } -} - -fun Appendable.indent(stops : Int = 1) { - for (i in 0 until stops) { - append(" ") - } -} - -private fun buildSuggestedAttributesArgument(tag: TagInfo, predefinedValues : Map = emptyMap()) : String = - tag.mergeAttributes().filter {it.name in tag.suggestedAttributes}.map { attribute -> - val name = attribute.fieldName - - val encoded = if (name in predefinedValues) predefinedValues[name] else when (attribute.type) { - AttributeType.STRING -> name - AttributeType.BOOLEAN -> "$name?.booleanEncode()" - AttributeType.ENUM -> "$name?.enumEncode()" - AttributeType.TICKER -> "$name?.tickerEncode(${attribute.name.quote()})" - AttributeType.STRING_SET -> name - } - - "${attribute.name.quote()}, $encoded" - }.let { attributeArgs -> - when (attributeArgs.size) { - 0 -> "emptyMap" - else -> attributeArgs.joinToString(",", "attributesMapOf(", ")") - } - } - -private fun tagBuilderFunctionArguments(tag: TagInfo, blockOrContent : Boolean) : ArrayList { - val arguments = ArrayList() - val customizableNamespace = tag.name.toLowerCase() in tagsWithCustomizableNamespace - val defaultNamespace: String = tagNamespaces[tag.name.toLowerCase()]?.quote().toString() - - tag.mergeAttributes().filter {it.name in tag.suggestedAttributes}.forEach { attribute -> - val type = when (attribute.type) { - AttributeType.STRING_SET -> "String" - else -> attribute.typeName - } - arguments.add(Var(attribute.fieldName, type + "?", defaultValue = "null")) - } - - fun addNamespaceParameter() { - if (customizableNamespace) { - arguments.add(Var("namespace", "String?", false, false, true, defaultNamespace)) - } - } - - fun addBlockParameter() { - arguments.add(Var("block", "${tag.className}.() -> Unit", defaultValue = "{}")) - } - - fun addContentParameter() { - arguments.add(Var("content", "String", defaultValue = "\"\"")) - } - - when { - tag.name.toLowerCase() in emptyTags || blockOrContent -> { - addNamespaceParameter() - addBlockParameter() - } - else -> { - addContentParameter() - addNamespaceParameter() - } - } - - return arguments -} - -private fun Appendable.htmlDslMarker() { - appendln("@HtmlTagMarker") -} - -private fun Appendable.tagKdoc(tag: TagInfo) { - val kdoc = tag.kdoc ?: return - appendln("/**") - appendln(" * ${kdoc.description}") - appendln(" */") -} - -private val inlineTags = """a -abbr -acronym -area -b -base -basefont -bdi -bdo -bgsound -big -br -button -cite -code -command -data -datalist -device -dfn -em -embed -font -i -iframe -img -input -kbd -keygen -label -legend -map -mark -menuitem -meter -object -optgroup -option -output -param -progress -q -rp -rt -ruby -samp -select -small -source -span -strong -sub -summary -sup -textarea -time -track -tt -u -var -wbr""".lines().toSet() +package kotlinx.html.generate + +import java.util.* + +fun Appendable.tagClass(tag : TagInfo, excludeAttributes : Set) { + val parentAttributeIfaces = tag.attributeGroups.map {it.name.capitalize() + "Facade"} + val parentElementIfaces = tag.tagGroupNames.map { it.humanize().capitalize() } + val allParentIfaces = parentAttributeIfaces + parentElementIfaces + val betterParentIfaces = humanizeJoin(allParentIfaces) + + val namespace = tagNamespaces[tag.name.toLowerCase()] + val customizableNamespace = tag.name.toLowerCase() in tagsWithCustomizableNamespace + + val parameters = mutableListOf( + Var("initialAttributes", "Map", false, false, true), + Var("consumer", "TagConsumer<*>", false, true) + ) + val superConstructorArguments = mutableListOf( + tag.name.quote(), + "consumer", + "initialAttributes", + namespace?.quote().toString(), + (tag.name in inlineTags).toString(), + (tag.name in emptyTags).toString() + ) + + if (customizableNamespace) { + parameters.add(Var("namespace", "String?", false, false, true, namespace?.quote() ?: "null")) + superConstructorArguments[3] = "namespace" + } + + appendln("@Suppress(\"unused\")") + clazz(Clazz( + name = tag.className, + variables = parameters, + parents = listOf( + buildString { + functionCall("HTMLTag", superConstructorArguments) + } + ) + when { + allParentIfaces.isNotEmpty() -> listOf(betterParentIfaces).map { renames[it] ?: it } + else -> emptyList() + }, + isOpen = true + )) { + val lowerCasedNames = tag.attributes.map {it.name.toLowerCase()}.toSet() + val attributes = tag.attributes.filter {it.name !in excludeAttributes} + + attributes.filter {!isAttributeExcluded(it.name) }.forEach { attribute -> + if (attribute.name[0].isLowerCase() || attribute.name.toLowerCase() !in lowerCasedNames) { + attributeProperty(attribute) + } + } + + fun contentlessTagDeprecation() { + indent() + appendln("@Deprecated(\"This tag most likely doesn't support text content or requires unsafe content (try unsafe {}\")") + } + + if (tag.name.toLowerCase() in contentlessTags) { + contentlessTagDeprecation() + + indent() + function("unaryPlus", modifiers = listOf("override", "operator"), receiver = "Entities") + block { + indent(2) + append("@Suppress(\"DEPRECATION\") ") + functionCall("entity", listOf("this")) + appendln() + indent() + } + + appendln() + contentlessTagDeprecation() + + indent() + function("unaryPlus", modifiers = listOf("override", "operator"), receiver = "String") + block { + indent(2) + append("@Suppress(\"DEPRECATION\") ") + functionCall("text", listOf("this")) + appendln() + indent() + } + + appendln() + contentlessTagDeprecation() + + indent() + function("text", arguments = listOf(Var("s", "String")), modifiers = listOf("override")) + block { + indent(2) + receiverDot("super") + functionCall("text", listOf("s")) + appendln() + indent() + } + + appendln() + contentlessTagDeprecation() + + indent() + function("text", arguments = listOf(Var("n", "Number")), modifiers = listOf("override")) + block { + indent(2) + receiverDot("super") + functionCall("text", listOf("n")) + appendln() + indent() + } + + appendln() + contentlessTagDeprecation() + + indent() + function("entity", arguments = listOf(Var("e", "Entities")), modifiers = listOf("override")) + block { + indent(2) + receiverDot("super") + functionCall("entity", listOf("e")) + appendln() + indent() + } + } + + emptyLine() + } + + tag.directChildren.map {Repository.tags[it]}.filterNotNull().filterIgnored().forEach { children -> + htmlTagBuilders(tag.className, children) + } + + if (parentElementIfaces.size > 1) { + val commons = tag.tagGroupNames.map {Repository.tagGroups[it]?.tags?.toSet()}.filterNotNull().reduce { a, b -> a.intersect(b) } + if (commons.isNotEmpty()) { + parentElementIfaces.forEach { group -> + variable(Var(name = "as" + group, type = group), receiver = tag.className) + appendln() + getter() + defineIs("this") + emptyLine() + } + } + } + + emptyLine() +} + +internal fun Appendable.tagAttributeVar(attribute: AttributeInfo, receiver: String?, indent: Int = 1): AttributeRequest { + val options = LinkedList>() + + if (attribute.type == AttributeType.ENUM) { + options.add(ReferenceConst(attribute.enumTypeName.decapitalize() + "Values")) + } else if (attribute.type == AttributeType.BOOLEAN && attribute.trueFalse.isNotEmpty()) { + options.addAll(attribute.trueFalse.map(::StringConst)) + } + + val attributeRequest = AttributeRequest(attribute.type, if (attribute.type == AttributeType.ENUM) attribute.enumTypeName else "", options) + Repository.attributeDelegateRequests.add(attributeRequest) + + indent(indent) + variable(Var(attribute.fieldName, attribute.typeName, true), receiver = receiver ?: "") + return attributeRequest +} + +fun probeType(htmlClassName : String) : Boolean = htmlClassName in knownTagClasses + +private fun tagCandidates(tag : TagInfo) = (listOf(tag.memberName) + tagReplacements.map { tag.memberName.replace(it.first.toRegex(), it.second) }).flatMap { listOf(it.capitalize(), it.toUpperCase()) }.distinct() + +fun getTagResultClass(tag: TagInfo) = + tagCandidates(tag) + .map { "HTML${it}Element" } + .firstOrNull { probeType(it) } ?: "HTMLElement" + +fun contentArgumentValue(tag : TagInfo, blockOrContent : Boolean) = when { + tag.name.toLowerCase() in emptyTags -> "block" + blockOrContent -> "block" + else -> "{+content}" +} + +fun Appendable.consumerBuilderJS(tag : TagInfo, blockOrContent : Boolean) { + val resultType = getTagResultClass(tag) + + val constructorArgs = mutableListOf( + buildSuggestedAttributesArgument(tag), + "this" + ) + + if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { + constructorArgs.add("namespace") + } + + tagKdoc(tag) + htmlDslMarker() + append("public ") + function(tag.memberName, tagBuilderFunctionArguments(tag, blockOrContent), resultType, receiver = "TagConsumer") + defineIs(buildString { + functionCall(tag.className, constructorArgs) + append(".") + functionCall("visitAndFinalize", listOf( + "this", + contentArgumentValue(tag, blockOrContent) + )) + + if (resultType != "HTMLElement") { + append(" as ") + append(resultType) + } + }) +} + +fun Appendable.consumerBuilderShared(tag : TagInfo, blockOrContent : Boolean) { + val constructorArgs = mutableListOf( + buildSuggestedAttributesArgument(tag), + "this" + ) + + if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { + constructorArgs.add("namespace") + } + + tagKdoc(tag) + htmlDslMarker() + function(tag.memberName, tagBuilderFunctionArguments(tag, blockOrContent), "T", listOf("T", "C : TagConsumer"), "C") + defineIs(buildString { + functionCall(tag.className, constructorArgs) + append(".") + functionCall("visitAndFinalize", listOf( + "this", + contentArgumentValue(tag, blockOrContent) + )) + }) +} + +fun Appendable.htmlTagBuilderMethod(receiver : String, tag : TagInfo, blockOrContent : Boolean) { + val arguments = tagBuilderFunctionArguments(tag, blockOrContent) + + val constructorArgs = mutableListOf( + buildSuggestedAttributesArgument(tag), + "consumer" + ) + + if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { + constructorArgs.add("namespace") + } + + tagKdoc(tag) + htmlDslMarker() + function(tag.memberName, arguments, "Unit", receiver = receiver) + defineIs(buildString { + functionCall(tag.className, constructorArgs) + append(".") + functionCall("visit", listOf(contentArgumentValue(tag, blockOrContent))) + }) +} + +fun Appendable.htmlTagEnumBuilderMethod(receiver : String, tag : TagInfo, blockOrContent : Boolean, enumAttribute : AttributeInfo, indent : Int) { + require(enumAttribute.enumValues.isNotEmpty()) + + val arguments = tagBuilderFunctionArguments(tag, blockOrContent).filter {it.name != enumAttribute.fieldName} + + enumAttribute.enumValues.forEach { enumValue -> + val deprecation = findEnumDeprecation(enumAttribute, enumValue) + + val constructorArgs = mutableListOf( + buildSuggestedAttributesArgument(tag, mapOf(enumAttribute.fieldName to enumAttribute.typeName + "." + enumValue.fieldName + ".realValue")), + "consumer" + ) + if (tag.name.toLowerCase() in tagsWithCustomizableNamespace) { + constructorArgs.add("namespace") + } + + if (deprecation != null) { + indent(indent) + suppress("DEPRECATION") + } + + indent(indent) + htmlDslMarker() + function(enumValue.fieldName + tag.memberName.capitalize(), arguments, "Unit", receiver = receiver) + defineIs(buildString { + functionCall(tag.className, constructorArgs) + append(".") + functionCall("visit", listOf(contentArgumentValue(tag, blockOrContent))) + }) + } +} + +fun Appendable.indent(stops : Int = 1) { + for (i in 0 until stops) { + append(" ") + } +} + +private fun buildSuggestedAttributesArgument(tag: TagInfo, predefinedValues : Map = emptyMap()) : String = + tag.mergeAttributes().filter {it.name in tag.suggestedAttributes}.map { attribute -> + val name = attribute.fieldName + + val encoded = if (name in predefinedValues) predefinedValues[name] else when (attribute.type) { + AttributeType.STRING -> name + AttributeType.BOOLEAN -> "$name?.booleanEncode()" + AttributeType.ENUM -> "$name?.enumEncode()" + AttributeType.TICKER -> "$name?.tickerEncode(${attribute.name.quote()})" + AttributeType.STRING_SET -> name + } + + "${attribute.name.quote()}, $encoded" + }.let { attributeArgs -> + when (attributeArgs.size) { + 0 -> "emptyMap" + else -> attributeArgs.joinToString(",", "attributesMapOf(", ")") + } + } + +private fun tagBuilderFunctionArguments(tag: TagInfo, blockOrContent : Boolean) : ArrayList { + val arguments = ArrayList() + val customizableNamespace = tag.name.toLowerCase() in tagsWithCustomizableNamespace + val defaultNamespace: String = tagNamespaces[tag.name.toLowerCase()]?.quote().toString() + + tag.mergeAttributes().filter {it.name in tag.suggestedAttributes}.forEach { attribute -> + val type = when (attribute.type) { + AttributeType.STRING_SET -> "String" + else -> attribute.typeName + } + arguments.add(Var(attribute.fieldName, type + "?", defaultValue = "null")) + } + + fun addNamespaceParameter() { + if (customizableNamespace) { + arguments.add(Var("namespace", "String?", false, false, true, defaultNamespace)) + } + } + + fun addBlockParameter() { + arguments.add(Var("block", "${tag.className}.() -> Unit", defaultValue = "{}")) + } + + fun addContentParameter() { + arguments.add(Var("content", "String", defaultValue = "\"\"")) + } + + when { + tag.name.toLowerCase() in emptyTags || blockOrContent -> { + addNamespaceParameter() + addBlockParameter() + } + else -> { + addContentParameter() + addNamespaceParameter() + } + } + + return arguments +} + +private fun Appendable.htmlDslMarker() { + appendln("@HtmlTagMarker") +} + +private fun Appendable.tagKdoc(tag: TagInfo) { + val kdoc = tag.kdoc ?: return + appendln("/**") + appendln(" * ${kdoc.description}") + appendln(" */") +} + +private val inlineTags = """a +abbr +acronym +area +b +base +basefont +bdi +bdo +bgsound +big +br +button +cite +code +command +data +datalist +device +dfn +em +embed +font +i +iframe +img +input +kbd +keygen +label +legend +map +mark +menuitem +meter +object +optgroup +option +output +param +progress +q +rp +rt +ruby +samp +select +small +source +span +strong +sub +summary +sup +textarea +time +track +tt +u +var +wbr""".lines().toSet() diff --git a/generate/src/main/kotlin/xsdparser.kt b/buildSrc/src/main/kotlin/kotlinx/html/generate/xsdparser.kt similarity index 98% rename from generate/src/main/kotlin/xsdparser.kt rename to buildSrc/src/main/kotlin/kotlinx/html/generate/xsdparser.kt index 45174786..0f3e1fb3 100644 --- a/generate/src/main/kotlin/xsdparser.kt +++ b/buildSrc/src/main/kotlin/kotlinx/html/generate/xsdparser.kt @@ -2,12 +2,11 @@ package kotlinx.html.generate import com.sun.xml.xsom.* import com.sun.xml.xsom.parser.* -import kotlinx.html.generate.humanize.* import java.util.* import javax.xml.parsers.* -val SCHEME_URL = "generate/src/main/resources/html_5.xsd" -val HTML_NAMESPACE = "html-5" +val SCHEME_URL = "html_5.xsd".asResourceUrl() +const val HTML_NAMESPACE = "html-5" private fun flattenTerm(term: XSTerm, result: MutableCollection, visitedModelNames: MutableSet) { if (term.isElementDecl) { diff --git a/buildSrc/src/main/kotlin/kotlinx/html/js/package.kt b/buildSrc/src/main/kotlin/kotlinx/html/js/package.kt new file mode 100644 index 00000000..cf9f5074 --- /dev/null +++ b/buildSrc/src/main/kotlin/kotlinx/html/js/package.kt @@ -0,0 +1,35 @@ +package kotlinx.html.js + +import org.gradle.api.* + +private const val GITHUB_ORGANIZATION = "Kotlin" +private const val GITHUB_REPOSITORY = "kotlin.html" + +private const val GIT_URL = "git+https://github.com/$GITHUB_ORGANIZATION/$GITHUB_REPOSITORY.git" +private const val GITHUB_BUGS_URL = "https://github.com/$GITHUB_ORGANIZATION/$GITHUB_REPOSITORY/issues" +private const val GITHUB_WIKI_URL = "https://github.com/$GITHUB_ORGANIZATION/$GITHUB_REPOSITORY/wiki" + +fun Project.packageJson(version: String, organization: String? = null): String = """{ + "name": "${organization?.let { "@$it/" } ?: ""}${project.name}", + "version": "$version", + "description": "Library for building HTML in Kotlin", + "main": "${project.name}-js.js", + "repository": { + "type": "git", + "url": "$GIT_URL" + }, + "keywords": [ + "Kotlin", + "Language", + "HTML", + "JavaScript", + "JetBrains" + ], + "author": "JetBrains", + "license": "Apache-2.0", + "bugs": { + "url": "$GITHUB_BUGS_URL" + }, + "homepage": "$GITHUB_WIKI_URL" +} +""" \ No newline at end of file diff --git a/generate/src/main/resources/entities.txt b/buildSrc/src/main/resources/entities.txt similarity index 100% rename from generate/src/main/resources/entities.txt rename to buildSrc/src/main/resources/entities.txt diff --git a/generate/src/main/resources/html5table.xml b/buildSrc/src/main/resources/html5table.xml similarity index 100% rename from generate/src/main/resources/html5table.xml rename to buildSrc/src/main/resources/html5table.xml diff --git a/generate/src/main/resources/html_5.xsd b/buildSrc/src/main/resources/html_5.xsd similarity index 100% rename from generate/src/main/resources/html_5.xsd rename to buildSrc/src/main/resources/html_5.xsd diff --git a/generate/src/main/resources/htmltable.xml b/buildSrc/src/main/resources/htmltable.xml similarity index 100% rename from generate/src/main/resources/htmltable.xml rename to buildSrc/src/main/resources/htmltable.xml diff --git a/generate/src/main/resources/i18Languages.xsd b/buildSrc/src/main/resources/i18Languages.xsd similarity index 100% rename from generate/src/main/resources/i18Languages.xsd rename to buildSrc/src/main/resources/i18Languages.xsd diff --git a/generate/pom.xml b/generate/pom.xml deleted file mode 100644 index 05a7ea58..00000000 --- a/generate/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - kotlinx-html - org.jetbrains.kotlinx - 0.6.13-SNAPSHOT - - 4.0.0 - - generate - - - - org.jetbrains.kotlin - kotlin-stdlib - - - com.sun.xsom - xsom - 20140925 - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - - - - compile - compile - - compile - - - - - test-compile - test-compile - - test-compile - - - - - activate-profile - none - - script - - - - ../scripts/activate-profile.kts - - - - - - - - maven-deploy-plugin - 2.8.2 - - - none - - - - true - - - - - diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..24b55e47 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +# The following property is required to mitigate issue https://github.com/gradle/gradle/issues/11412. +systemProp.org.gradle.internal.publish.checksums.insecure=true +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..cc4fdc29 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..0ebb3108 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..2fe81a7d --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed 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 +# +# https://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 KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..9618d8d9 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/js/npm.templates/kotlinx-html/package.json b/js/npm.templates/kotlinx-html/package.json deleted file mode 100644 index 0756a2e8..00000000 --- a/js/npm.templates/kotlinx-html/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "kotlinx-html", - "version": "1.0.0", - "description": "Library for building HTML in Kotlin", - "main": "kotlinx-html-js.js", - "repository": { - "type": "git", - "url": "git+https://github.com/Kotlin/kotlinx.html.git" - }, - "keywords": [ - "Kotlin", - "Language", - "HTML", - "JavaScript", - "JetBrains" - ], - "author": "JetBrains", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/Kotlin/kotlinx.html/issues" - }, - "homepage": "https://github.com/kotlin/kotlinx.html/wiki" -} diff --git a/js/pom.xml b/js/pom.xml deleted file mode 100644 index 928aa539..00000000 --- a/js/pom.xml +++ /dev/null @@ -1,232 +0,0 @@ - - - - kotlinx-html - org.jetbrains.kotlinx - 0.6.13-SNAPSHOT - - 4.0.0 - - org.jetbrains.kotlinx - kotlinx-html-js - 0.6.13-SNAPSHOT - - kotlinx.html JS - kotlinx.html JS implementation - - - - The Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - Sergey Mashkov - JetBrains s.r.o. - - developer - - - - - https://github.com/Kotlin/kotlinx.html - - scm:git:git@github.com:Kotlin/kotlinx.html.git - https://github.com/Kotlin/kotlinx.html - HEAD - - - - - org.jetbrains.kotlin - kotlin-stdlib-js - - - org.jetbrains.kotlinx - kotlinx-html-common - ${project.version} - - - test - org.jetbrains.kotlin - kotlin-test-js - ${kotlin.version} - true - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - - compile - compile - - js - - - umd - true - always - ./ - ${project.build.outputDirectory}/${project.artifactId}.js - true - - - - compile-js-tests - test-compile - - test-js - - - ${project.basedir}/target/test-js/${project.artifactId}-tests.js - true - true - umd - true - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - add-source - prepare-package - - add-source - - - - ../shared/src/main/kotlin - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - true - ${project.build.outputDirectory} - - **/*.js - **/*.js.map - **/*.kjsm - **/*.kotlin_classes - **/*.kotlin_string_table - **/*.kotlin_file_table - - - - - ${user.name} - - JetBrains s.r.o. - ${project.version} - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.jetbrains.dokka - dokka-maven-plugin - - - maven-dependency-plugin - 2.10 - - - - unpack-dependencies - - test-compile - - test - kotlinx-html-common - jar - ${project.basedir}/target/test-js - *.js - *.meta.js - - - - - - com.github.eirslett - frontend-maven-plugin - 1.6 - - - - install node and npm - generate-test-resources - - install-node-and-npm - - - ${maven.test.skip} - - - - - npm install - generate-test-resources - - npm - - - - install - ${maven.test.skip} - - - - - javascript tests - - karma - - - ${project.basedir}/src/test/karma/karma.conf.js - ${maven.test.skip} - ${maven.test.skip} - - - - - - v8.9.4 - 5.6.0 - - ${project.basedir}/src/test/karma - - - - - diff --git a/jvm/pom.xml b/jvm/pom.xml deleted file mode 100644 index 2cb1180b..00000000 --- a/jvm/pom.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - kotlinx-html - org.jetbrains.kotlinx - 0.6.13-SNAPSHOT - - 4.0.0 - - org.jetbrains.kotlinx - kotlinx-html-jvm - 0.6.13-SNAPSHOT - - kotlinx.html JVM - kotlinx.html JVM implementation - - - - The Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - Sergey Mashkov - JetBrains s.r.o. - - developer - - - - - https://github.com/Kotlin/kotlinx.html - - scm:git:git@github.com:Kotlin/kotlinx.html.git - https://github.com/Kotlin/kotlinx.html - HEAD - - - - - junit - junit - test - - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-test-junit - test - - - org.jetbrains.kotlinx - kotlinx-html-common - ${project.version} - true - - - org.jetbrains.kotlin - kotlin-stdlib-common - - - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - - - - compile - compile - - compile - - - - -Xdump-declarations-to=${build.directory}/declarations.json - - - - - - test-compile - test-compile - - test-compile - - - - - - true - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - add-source - prepare-package - - add-source - - - - ../shared/src/main/kotlin - - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - - attach-sources - prepare-package - - jar-no-fork - test-jar-no-fork - - - - - - - org.jetbrains.dokka - dokka-maven-plugin - - - - - diff --git a/jvm/src/test/kotlin/compatibility.kt b/jvm/src/test/kotlin/compatibility.kt deleted file mode 100644 index e785b3aa..00000000 --- a/jvm/src/test/kotlin/compatibility.kt +++ /dev/null @@ -1,16 +0,0 @@ -package kotlinx.html.tests - -import java.io.* -import kotlin.test.* - -class CompatibilityTest { - // NOTE: this test shouldn't be started from IDEA because incremental compiler will only dump - // changed declarations - @Test - fun binaryCompatibilityTest() { - val expected = this::class.java.classLoader.getResourceAsStream("declarations.json")!!.reader().readText() - val actual = File("target/declarations.json").readText() - - assertEquals(expected, actual) - } -} diff --git a/mvnw b/mvnw deleted file mode 100755 index fc7efd17..00000000 --- a/mvnw +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# 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 -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # - # Look for the Apple JDKs first to preserve the existing behaviour, and then look - # for the new JDKs provided by Oracle. - # - if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then - # - # Apple JDKs - # - export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then - # - # Apple JDKs - # - export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then - # - # Oracle JDKs - # - export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then - # - # Apple JDKs - # - export JAVA_HOME=`/usr/libexec/java_home` - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Migwn, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` -fi - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - local basedir=$(pwd) - local wdir=$(pwd) - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - wdir=$(cd "$wdir/.."; pwd) - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CMD_LINE_ARGS - diff --git a/mvnw.cmd b/mvnw.cmd deleted file mode 100644 index 00104808..00000000 --- a/mvnw.cmd +++ /dev/null @@ -1,145 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - -set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/npm_publish.xml b/npm_publish.xml deleted file mode 100644 index 7d7e6600..00000000 --- a/npm_publish.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 4ecdeaf0..00000000 --- a/pom.xml +++ /dev/null @@ -1,304 +0,0 @@ - - - 4.0.0 - - org.jetbrains.kotlinx - kotlinx-html - pom - 0.6.13-SNAPSHOT - - kotlinx.html root module - A root module for all kotlinx.html components - - - - The Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - shared - jvm - js - generate - assembly - - - https://github.com/Kotlin/kotlinx.html - - scm:git:git@github.com:Kotlin/kotlinx.html.git - https://github.com/Kotlin/kotlinx.html - HEAD - - - - - Sergey Mashkov - JetBrains s.r.o. - - developer - - - - - - UTF-8 - - - - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-stdlib-common - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-stdlib-js - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - - - junit - junit - 4.12 - test - - - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - - attach-sources - prepare-package - - jar-no-fork - test-jar-no-fork - - - true - - - - - - maven-release-plugin - 2.5.3 - - - true - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - - empty-javadoc-jar - prepare-package - - jar - - - javadoc - ${build.dir}/empty - true - - - - - - maven-surefire-plugin - 2.18.1 - - 2C - true - - - - com.devexperts.bintray - bintray-maven-plugin - 1.3 - - - bintray-deploy - - publish - - - bintray - ${bintray.url} - - - - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - - org.jetbrains.dokka - dokka-maven-plugin - 0.9.1 - - - pre-site - - dokka - - - - - - - - ${project.basedir}/src/main/kotlin - https://github.com/Kotlin/kotlinx.html/ - - - - - - - - - - - jcenter - JCenter - https://jcenter.bintray.com/ - - - - - - bintray - ${bintray.url} - - - - - - kotlin-latest - - true - - - 1.3.40 - https://api.bintray.com/maven/kotlin/kotlinx.html/kotlinx.html - - - - kotlin-snapshot - - false - - - 1.2-SNAPSHOT - https://api.bintray.com/maven/kotlin/kotlin-dev/kotlinx.html - - - - - sonatype.oss.snapshots - Sonatype OSS Snapshot Repository - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - sonatype.oss.snapshots - Sonatype OSS Snapshot Repository - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - kotlin-dev - - false - - - 1.3.40 - https://api.bintray.com/maven/kotlin/kotlin-dev/kotlinx.html - - - - - - false - - bintray-kotlin-kotlin-dev - bintray - https://dl.bintray.com/kotlin/kotlin-dev - - - - false - - bintray-kotlin-kotlin-eap - bintray - https://dl.bintray.com/kotlin/kotlin-eap-1.1 - - - - - - false - - bintray-kotlin-plugin-kotlin-dev - bintray-plugins - https://dl.bintray.com/kotlin/kotlin-dev - - - - false - - bintray-kotlin-plugin-kotlin-eap - bintray-plugins - https://dl.bintray.com/kotlin/kotlin-eap-1.1 - - - - - diff --git a/scripts/activate-profile.kts b/scripts/activate-profile.kts deleted file mode 100644 index 420033ba..00000000 --- a/scripts/activate-profile.kts +++ /dev/null @@ -1,53 +0,0 @@ -import java.io.* -import kotlin.system.* - -// activate profiles from -DactivateProfile -val profileToActivate = System.getProperty("activateProfile") -if (profileToActivate == null) { - System.err.println("No property activateProfile specified, -DactivateProfile=someProfile") - exitProcess(1) -} - -val file = File("../pom.xml") -val pom = file.readText() - -val profilesReg = ".*?()".toRegex(RegexOption.DOT_MATCHES_ALL) -val profileId = "(.*?)".toRegex(RegexOption.DOT_MATCHES_ALL) -val activeByDefault = "(.*?)".toRegex(RegexOption.DOT_MATCHES_ALL) - -val profiles = profilesReg.findAll(pom).toList() - -if (profiles.isEmpty()) { - System.err.println("No profiles were found in ${file.absolutePath}") - exitProcess(1) -} - -val result = buildString { - append(pom, 0, profiles.first().range.start) - - profiles.forEachIndexed { index, profileMatch -> - val id = profileId.find(profileMatch.value)?.groupValues?.get(1) - val activated = activeByDefault.find(profileMatch.value) - val activatedValue = activated?.groups?.get(1)?.range - - if (id != null && activatedValue != null) { - val newValue = if (id == profileToActivate) "true" else "false" - - append(profileMatch.value, 0, activatedValue.start) - append(newValue) - append(profileMatch.value, activatedValue.endInclusive + 1, profileMatch.value.length) - } else { - append(profileMatch.value) - } - - if (index != profiles.lastIndex) { - append(pom, profileMatch.range.endInclusive + 1, profiles[index + 1].range.start) - } - } - - append(pom, profiles.last().range.endInclusive + 1, pom.length) -} - -file.writeText(result) - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..52648267 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "kotlinx-html" \ No newline at end of file diff --git a/shared/pom.xml b/shared/pom.xml deleted file mode 100644 index 70da85b1..00000000 --- a/shared/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - kotlinx-html - org.jetbrains.kotlinx - 0.6.13-SNAPSHOT - - 4.0.0 - - kotlinx-html-common - - - - org.jetbrains.kotlin - kotlin-stdlib-common - ${kotlin.version} - - - - - - - maven-resources-plugin - 3.0.2 - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - - metadata - - metadata - - - - - - org.jetbrains.dokka - dokka-maven-plugin - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - true - - - - ${user.name} - - JetBrains s.r.o. - ${project.version} - - - - - - default-jar - none - - - pack-meta - package - - jar - - - ${project.build.outputDirectory} - - - - - - - diff --git a/shared/src/main/kotlin/Event.kt b/src/commonMain/kotlin/Event.kt similarity index 100% rename from shared/src/main/kotlin/Event.kt rename to src/commonMain/kotlin/Event.kt diff --git a/shared/src/main/kotlin/api.kt b/src/commonMain/kotlin/api.kt similarity index 100% rename from shared/src/main/kotlin/api.kt rename to src/commonMain/kotlin/api.kt diff --git a/shared/src/main/kotlin/attributes.kt b/src/commonMain/kotlin/attributes.kt similarity index 100% rename from shared/src/main/kotlin/attributes.kt rename to src/commonMain/kotlin/attributes.kt diff --git a/shared/src/main/kotlin/compatibility.kt b/src/commonMain/kotlin/compatibility.kt similarity index 100% rename from shared/src/main/kotlin/compatibility.kt rename to src/commonMain/kotlin/compatibility.kt diff --git a/shared/src/main/kotlin/delayed-consumer.kt b/src/commonMain/kotlin/delayed-consumer.kt similarity index 93% rename from shared/src/main/kotlin/delayed-consumer.kt rename to src/commonMain/kotlin/delayed-consumer.kt index 5d61971b..4a2cb971 100644 --- a/shared/src/main/kotlin/delayed-consumer.kt +++ b/src/commonMain/kotlin/delayed-consumer.kt @@ -1,10 +1,7 @@ package kotlinx.html.consumers -import kotlinx.html.Entities -import kotlinx.html.Tag -import kotlinx.html.TagConsumer -import kotlinx.html.Unsafe -import org.w3c.dom.events.Event +import kotlinx.html.* +import org.w3c.dom.events.* class DelayedConsumer(val downstream : TagConsumer) : TagConsumer { private var delayed : Tag? = null diff --git a/shared/src/main/kotlin/delegating-map.kt b/src/commonMain/kotlin/delegating-map.kt similarity index 97% rename from shared/src/main/kotlin/delegating-map.kt rename to src/commonMain/kotlin/delegating-map.kt index d5d8679a..25d39f75 100644 --- a/shared/src/main/kotlin/delegating-map.kt +++ b/src/commonMain/kotlin/delegating-map.kt @@ -1,7 +1,6 @@ package kotlinx.html.impl -import kotlinx.html.Tag -import kotlinx.html.TagConsumer +import kotlinx.html.* class DelegatingMap(initialValues : Map, private val tag : Tag, private val consumer : () -> TagConsumer<*>) : MutableMap { private var backing: Map = initialValues diff --git a/shared/src/main/kotlin/exception-consumer.kt b/src/commonMain/kotlin/exception-consumer.kt similarity index 91% rename from shared/src/main/kotlin/exception-consumer.kt rename to src/commonMain/kotlin/exception-consumer.kt index de5cd374..381ad93c 100644 --- a/shared/src/main/kotlin/exception-consumer.kt +++ b/src/commonMain/kotlin/exception-consumer.kt @@ -1,7 +1,6 @@ package kotlinx.html.consumers -import kotlinx.html.Tag -import kotlinx.html.TagConsumer +import kotlinx.html.* private class DelegatingExceptionConsumer( val underlying: TagConsumer, diff --git a/shared/src/main/kotlin/filter-consumer.kt b/src/commonMain/kotlin/filter-consumer.kt similarity index 94% rename from shared/src/main/kotlin/filter-consumer.kt rename to src/commonMain/kotlin/filter-consumer.kt index 49110f51..2e3d95d5 100644 --- a/shared/src/main/kotlin/filter-consumer.kt +++ b/src/commonMain/kotlin/filter-consumer.kt @@ -1,10 +1,7 @@ package kotlinx.html.consumers -import kotlinx.html.Entities -import kotlinx.html.Tag -import kotlinx.html.TagConsumer -import kotlinx.html.Unsafe -import org.w3c.dom.events.Event +import kotlinx.html.* +import org.w3c.dom.events.* object PredicateResults { val PASS = PredicateResult.PASS diff --git a/shared/src/main/kotlin/finalize-consumer.kt b/src/commonMain/kotlin/finalize-consumer.kt similarity index 91% rename from shared/src/main/kotlin/finalize-consumer.kt rename to src/commonMain/kotlin/finalize-consumer.kt index b0f6d332..96768b22 100644 --- a/shared/src/main/kotlin/finalize-consumer.kt +++ b/src/commonMain/kotlin/finalize-consumer.kt @@ -1,10 +1,7 @@ package kotlinx.html.consumers -import kotlinx.html.Entities -import kotlinx.html.Tag -import kotlinx.html.TagConsumer -import kotlinx.html.Unsafe -import org.w3c.dom.events.Event +import kotlinx.html.* +import org.w3c.dom.events.* class FinalizeConsumer(val downstream : TagConsumer, val block : (F, Boolean) -> T) : TagConsumer { private var level = 0 diff --git a/shared/src/main/kotlin/generated/gen-attr-traits.kt b/src/commonMain/kotlin/generated/gen-attr-traits.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-attr-traits.kt rename to src/commonMain/kotlin/generated/gen-attr-traits.kt diff --git a/shared/src/main/kotlin/generated/gen-attributes.kt b/src/commonMain/kotlin/generated/gen-attributes.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-attributes.kt rename to src/commonMain/kotlin/generated/gen-attributes.kt diff --git a/shared/src/main/kotlin/generated/gen-consumer-tags.kt b/src/commonMain/kotlin/generated/gen-consumer-tags.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-consumer-tags.kt rename to src/commonMain/kotlin/generated/gen-consumer-tags.kt diff --git a/shared/src/main/kotlin/generated/gen-entities.kt b/src/commonMain/kotlin/generated/gen-entities.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-entities.kt rename to src/commonMain/kotlin/generated/gen-entities.kt diff --git a/shared/src/main/kotlin/generated/gen-enums.kt b/src/commonMain/kotlin/generated/gen-enums.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-enums.kt rename to src/commonMain/kotlin/generated/gen-enums.kt diff --git a/shared/src/main/kotlin/generated/gen-parent-traits.kt b/src/commonMain/kotlin/generated/gen-parent-traits.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-parent-traits.kt rename to src/commonMain/kotlin/generated/gen-parent-traits.kt diff --git a/shared/src/main/kotlin/generated/gen-tag-groups.kt b/src/commonMain/kotlin/generated/gen-tag-groups.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tag-groups.kt rename to src/commonMain/kotlin/generated/gen-tag-groups.kt diff --git a/shared/src/main/kotlin/generated/gen-tag-unions.kt b/src/commonMain/kotlin/generated/gen-tag-unions.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tag-unions.kt rename to src/commonMain/kotlin/generated/gen-tag-unions.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-a.kt b/src/commonMain/kotlin/generated/gen-tags-a.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-a.kt rename to src/commonMain/kotlin/generated/gen-tags-a.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-b.kt b/src/commonMain/kotlin/generated/gen-tags-b.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-b.kt rename to src/commonMain/kotlin/generated/gen-tags-b.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-c.kt b/src/commonMain/kotlin/generated/gen-tags-c.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-c.kt rename to src/commonMain/kotlin/generated/gen-tags-c.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-d.kt b/src/commonMain/kotlin/generated/gen-tags-d.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-d.kt rename to src/commonMain/kotlin/generated/gen-tags-d.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-e.kt b/src/commonMain/kotlin/generated/gen-tags-e.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-e.kt rename to src/commonMain/kotlin/generated/gen-tags-e.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-f.kt b/src/commonMain/kotlin/generated/gen-tags-f.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-f.kt rename to src/commonMain/kotlin/generated/gen-tags-f.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-h.kt b/src/commonMain/kotlin/generated/gen-tags-h.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-h.kt rename to src/commonMain/kotlin/generated/gen-tags-h.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-i.kt b/src/commonMain/kotlin/generated/gen-tags-i.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-i.kt rename to src/commonMain/kotlin/generated/gen-tags-i.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-k.kt b/src/commonMain/kotlin/generated/gen-tags-k.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-k.kt rename to src/commonMain/kotlin/generated/gen-tags-k.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-l.kt b/src/commonMain/kotlin/generated/gen-tags-l.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-l.kt rename to src/commonMain/kotlin/generated/gen-tags-l.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-m.kt b/src/commonMain/kotlin/generated/gen-tags-m.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-m.kt rename to src/commonMain/kotlin/generated/gen-tags-m.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-n.kt b/src/commonMain/kotlin/generated/gen-tags-n.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-n.kt rename to src/commonMain/kotlin/generated/gen-tags-n.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-o.kt b/src/commonMain/kotlin/generated/gen-tags-o.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-o.kt rename to src/commonMain/kotlin/generated/gen-tags-o.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-p.kt b/src/commonMain/kotlin/generated/gen-tags-p.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-p.kt rename to src/commonMain/kotlin/generated/gen-tags-p.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-q.kt b/src/commonMain/kotlin/generated/gen-tags-q.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-q.kt rename to src/commonMain/kotlin/generated/gen-tags-q.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-r.kt b/src/commonMain/kotlin/generated/gen-tags-r.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-r.kt rename to src/commonMain/kotlin/generated/gen-tags-r.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-s.kt b/src/commonMain/kotlin/generated/gen-tags-s.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-s.kt rename to src/commonMain/kotlin/generated/gen-tags-s.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-t.kt b/src/commonMain/kotlin/generated/gen-tags-t.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-t.kt rename to src/commonMain/kotlin/generated/gen-tags-t.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-u.kt b/src/commonMain/kotlin/generated/gen-tags-u.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-u.kt rename to src/commonMain/kotlin/generated/gen-tags-u.kt diff --git a/shared/src/main/kotlin/generated/gen-tags-v.kt b/src/commonMain/kotlin/generated/gen-tags-v.kt similarity index 100% rename from shared/src/main/kotlin/generated/gen-tags-v.kt rename to src/commonMain/kotlin/generated/gen-tags-v.kt diff --git a/shared/src/main/kotlin/htmltag.kt b/src/commonMain/kotlin/htmltag.kt similarity index 100% rename from shared/src/main/kotlin/htmltag.kt rename to src/commonMain/kotlin/htmltag.kt diff --git a/shared/src/main/kotlin/measure-consumer.kt b/src/commonMain/kotlin/measure-consumer.kt similarity index 97% rename from shared/src/main/kotlin/measure-consumer.kt rename to src/commonMain/kotlin/measure-consumer.kt index c054e7c1..7307bbd4 100644 --- a/shared/src/main/kotlin/measure-consumer.kt +++ b/src/commonMain/kotlin/measure-consumer.kt @@ -1,7 +1,7 @@ package kotlinx.html.consumers import kotlinx.html.* -import org.w3c.dom.events.Event +import org.w3c.dom.events.* data class TimedResult(val result: T, val time: Long) val TimedResult.out: O diff --git a/shared/src/main/kotlin/stream.kt b/src/commonMain/kotlin/stream.kt similarity index 99% rename from shared/src/main/kotlin/stream.kt rename to src/commonMain/kotlin/stream.kt index 4fe09996..ae8f8962 100644 --- a/shared/src/main/kotlin/stream.kt +++ b/src/commonMain/kotlin/stream.kt @@ -2,7 +2,7 @@ package kotlinx.html.stream import kotlinx.html.* import kotlinx.html.consumers.* -import org.w3c.dom.events.Event +import org.w3c.dom.events.* class HTMLStreamBuilder(val out : O, val prettyPrint : Boolean, val xhtmlCompatible: Boolean) : TagConsumer { private var level = 0 diff --git a/shared/src/main/kotlin/trace-consumer.kt b/src/commonMain/kotlin/trace-consumer.kt similarity index 100% rename from shared/src/main/kotlin/trace-consumer.kt rename to src/commonMain/kotlin/trace-consumer.kt diff --git a/shared/src/main/kotlin/util.kt b/src/commonMain/kotlin/util.kt similarity index 100% rename from shared/src/main/kotlin/util.kt rename to src/commonMain/kotlin/util.kt diff --git a/js/src/main/kotlin/compatibility-js.kt b/src/jsMain/kotlin/compatibility-js.kt similarity index 100% rename from js/src/main/kotlin/compatibility-js.kt rename to src/jsMain/kotlin/compatibility-js.kt diff --git a/js/src/main/kotlin/dom-js.kt b/src/jsMain/kotlin/dom-js.kt similarity index 99% rename from js/src/main/kotlin/dom-js.kt rename to src/jsMain/kotlin/dom-js.kt index ef44968b..7892cbe1 100644 --- a/js/src/main/kotlin/dom-js.kt +++ b/src/jsMain/kotlin/dom-js.kt @@ -4,7 +4,6 @@ import kotlinx.html.* import kotlinx.html.consumers.* import org.w3c.dom.* import org.w3c.dom.events.* -import kotlin.dom.* @Suppress("NOTHING_TO_INLINE") private inline fun HTMLElement.setEvent(name: String, noinline callback : (Event) -> Unit) : Unit { diff --git a/js/src/main/kotlin/generated/gen-consumer-tags-js.kt b/src/jsMain/kotlin/generated/gen-consumer-tags-js.kt similarity index 100% rename from js/src/main/kotlin/generated/gen-consumer-tags-js.kt rename to src/jsMain/kotlin/generated/gen-consumer-tags-js.kt diff --git a/js/src/main/kotlin/generated/gen-event-attrs-js.kt b/src/jsMain/kotlin/generated/gen-event-attrs-js.kt similarity index 100% rename from js/src/main/kotlin/generated/gen-event-attrs-js.kt rename to src/jsMain/kotlin/generated/gen-event-attrs-js.kt diff --git a/js/src/main/kotlin/injector.kt b/src/jsMain/kotlin/injector.kt similarity index 100% rename from js/src/main/kotlin/injector.kt rename to src/jsMain/kotlin/injector.kt diff --git a/js/src/main/kotlin/trace-js.kt b/src/jsMain/kotlin/trace-js.kt similarity index 100% rename from js/src/main/kotlin/trace-js.kt rename to src/jsMain/kotlin/trace-js.kt diff --git a/js/src/main/kotlin/utilsImpl-js.kt b/src/jsMain/kotlin/utilsImpl-js.kt similarity index 80% rename from js/src/main/kotlin/utilsImpl-js.kt rename to src/jsMain/kotlin/utilsImpl-js.kt index 3dc8bacb..c39bd7e7 100644 --- a/js/src/main/kotlin/utilsImpl-js.kt +++ b/src/jsMain/kotlin/utilsImpl-js.kt @@ -1,5 +1,5 @@ package kotlinx.html -import kotlin.js.Date +import kotlin.js.* actual fun currentTimeMillis(): Long = Date().getTime().toLong() diff --git a/js/src/test/karma/karma.conf.js b/src/jsTest/karma/karma.conf.js similarity index 87% rename from js/src/test/karma/karma.conf.js rename to src/jsTest/karma/karma.conf.js index 2ba29746..fd0dced7 100644 --- a/js/src/test/karma/karma.conf.js +++ b/src/jsTest/karma/karma.conf.js @@ -20,11 +20,6 @@ module.exports = function (config) { config.set({ frameworks: ['qunit'], reporters: ['progress', 'junit'], - files: [ - '../../../target/test-js/kotlin.js', - '../../../target/classes/kotlinx-html-js.js', - '../../../target/test-js/*.js' - ], exclude: [], port: 9876, runnerPort: 9100, diff --git a/js/src/test/karma/package.json b/src/jsTest/karma/package.json similarity index 100% rename from js/src/test/karma/package.json rename to src/jsTest/karma/package.json diff --git a/js/src/test/kotlin/exceptions.kt b/src/jsTest/kotlin/exceptions.kt similarity index 75% rename from js/src/test/kotlin/exceptions.kt rename to src/jsTest/kotlin/exceptions.kt index 43f51d85..47a83545 100644 --- a/js/src/test/kotlin/exceptions.kt +++ b/src/jsTest/kotlin/exceptions.kt @@ -1,11 +1,9 @@ -import kotlinx.html.consumers.catch -import kotlinx.html.dom.append -import kotlinx.html.h1 -import kotlinx.html.h2 -import kotlinx.html.js.div -import kotlin.test.Test -import kotlin.browser.document -import kotlin.test.assertEquals +import kotlinx.html.* +import kotlinx.html.consumers.* +import kotlinx.html.dom.* +import kotlinx.html.js.* +import kotlin.browser.* +import kotlin.test.* class TestExceptions { diff --git a/js/src/test/kotlin/injector.kt b/src/jsTest/kotlin/injector.kt similarity index 97% rename from js/src/test/kotlin/injector.kt rename to src/jsTest/kotlin/injector.kt index 558980b5..64d19d14 100644 --- a/js/src/test/kotlin/injector.kt +++ b/src/jsTest/kotlin/injector.kt @@ -4,8 +4,7 @@ import kotlinx.html.* import kotlinx.html.dom.* import kotlinx.html.injector.* import kotlinx.html.js.* -import org.w3c.dom.HTMLDivElement -import org.w3c.dom.HTMLParagraphElement +import org.w3c.dom.* import kotlin.browser.* import kotlin.properties.* import kotlin.test.* diff --git a/js/src/test/kotlin/trees.kt b/src/jsTest/kotlin/trees.kt similarity index 99% rename from js/src/test/kotlin/trees.kt rename to src/jsTest/kotlin/trees.kt index 3105ce9b..8e3507e0 100644 --- a/js/src/test/kotlin/trees.kt +++ b/src/jsTest/kotlin/trees.kt @@ -6,7 +6,6 @@ import kotlinx.html.dom.* import kotlinx.html.js.* import org.w3c.dom.* import kotlin.browser.* -import kotlin.dom.* import kotlin.test.* import kotlin.test.Test as test diff --git a/js/src/test/kotlin/unsafe.kt b/src/jsTest/kotlin/unsafe.kt similarity index 97% rename from js/src/test/kotlin/unsafe.kt rename to src/jsTest/kotlin/unsafe.kt index f425ffd8..b558d32c 100644 --- a/js/src/test/kotlin/unsafe.kt +++ b/src/jsTest/kotlin/unsafe.kt @@ -3,7 +3,6 @@ package kotlinx.html.tests.unsafes import kotlinx.html.* import kotlinx.html.dom.* import kotlinx.html.stream.* -import kotlin.test.Test import kotlin.browser.* import kotlin.test.* diff --git a/jvm/src/main/kotlin/dom-jvm.kt b/src/jvmMain/kotlin/dom-jvm.kt similarity index 99% rename from jvm/src/main/kotlin/dom-jvm.kt rename to src/jvmMain/kotlin/dom-jvm.kt index 87cf0bcb..6de00345 100644 --- a/jvm/src/main/kotlin/dom-jvm.kt +++ b/src/jvmMain/kotlin/dom-jvm.kt @@ -4,7 +4,7 @@ import kotlinx.html.* import kotlinx.html.consumers.* import org.w3c.dom.* import org.w3c.dom.events.* -import org.xml.sax.InputSource +import org.xml.sax.* import java.io.* import java.util.* import javax.xml.parsers.* diff --git a/jvm/src/main/kotlin/trace-jvm.kt b/src/jvmMain/kotlin/trace-jvm.kt similarity index 100% rename from jvm/src/main/kotlin/trace-jvm.kt rename to src/jvmMain/kotlin/trace-jvm.kt diff --git a/jvm/src/main/kotlin/utilsImpl-jvm.kt b/src/jvmMain/kotlin/utilsImpl-jvm.kt similarity index 100% rename from jvm/src/main/kotlin/utilsImpl-jvm.kt rename to src/jvmMain/kotlin/utilsImpl-jvm.kt diff --git a/src/jvmTest/kotlin/compatibility.kt b/src/jvmTest/kotlin/compatibility.kt new file mode 100644 index 00000000..510736aa --- /dev/null +++ b/src/jvmTest/kotlin/compatibility.kt @@ -0,0 +1,32 @@ +package kotlinx.html.tests + +import com.fasterxml.jackson.databind.* +import com.fasterxml.jackson.databind.node.* +import java.io.* +import kotlin.test.* + +class CompatibilityTest { + // NOTE: this test shouldn't be started from IDEA because incremental compiler will only dump + // changed declarations + @Test + fun binaryCompatibilityTest() { + val objectMapper = ObjectMapper() + + val expectedJson = objectMapper.readTree(loadResource("declarations.json")) + val actualJson = objectMapper.readTree(File("build/declarations.json").readText()) + + val expected = objectMapper.sortByClass(expectedJson) + val actual = objectMapper.sortByClass(actualJson) + + if (expected != actual) { + // Show text diff. + assertEquals(expected.toPrettyString(), actual.toPrettyString()) + } + } + + private fun loadResource(path: String): InputStreamReader + = this::class.java.classLoader.getResourceAsStream(path)!!.reader() + + private fun ObjectMapper.sortByClass(node: JsonNode): JsonNode + = createArrayNode().addAll((node as ArrayNode).sortedBy { (it["class"] as TextNode).textValue() }) +} diff --git a/jvm/src/test/kotlin/custom-tag.kt b/src/jvmTest/kotlin/custom-tag.kt similarity index 100% rename from jvm/src/test/kotlin/custom-tag.kt rename to src/jvmTest/kotlin/custom-tag.kt diff --git a/jvm/src/test/kotlin/dom-trees.kt b/src/jvmTest/kotlin/dom-trees.kt similarity index 93% rename from jvm/src/test/kotlin/dom-trees.kt rename to src/jvmTest/kotlin/dom-trees.kt index a8cb0841..97eb80a3 100644 --- a/jvm/src/test/kotlin/dom-trees.kt +++ b/src/jvmTest/kotlin/dom-trees.kt @@ -1,230 +1,232 @@ -package kotlinx.html.tests - -import kotlinx.html.* -import kotlinx.html.consumers.filter -import kotlinx.html.dom.* -import kotlinx.html.dom.createHTMLDocument -import kotlin.test.assertEquals -import org.junit.Test as test - -class TestDOMTrees { - @test fun `able to create simple tree`() { - val tree = createHTMLDocument().div { - id = "test-node" - +"content" - } - - assertEquals("div", tree.getElementById("test-node")?.tagName?.toLowerCase()) - } - - @test fun `able to create complex tree and render it with pretty print`() { - val tree = createHTMLDocument().html { - body { - h1 { - +"header" - } - div { - +"content" - span { - +"yo" - } - } - } - } - - assertEquals("\n

header

contentyo
", tree.serialize(false)) - assertEquals(""" - - - -

header

-
contentyo -
- - """.trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n")) - } - - @test fun `vals create and append support`() { - val document = createHTMLDocument().html { - body { - div { - id = "content" - } - } - } - - val contentNode = document.getElementById("content")!! - contentNode.append.p { - +"p1" - } - - val p2 = document.create.p { - +"p2" - } - contentNode.appendChild(p2) - - assertEquals(""" - - -
-

p1

-

p2

-
- - - """.trim().replace("\r\n", "\n"), document.serialize(true).trim().replace("\r\n", "\n")) - } - - @test fun `append function support`() { - val document = createHTMLDocument().html { - body { - div { - id = "content" - } - } - } - - val contentNode = document.getElementById("content")!! - - val nodes = contentNode.append { - p { - +"p1" - } - p { - +"p2" - p { - +"p3" - } - } - } - - assertEquals(2, nodes.size) - - assertEquals(""" - - -
-

p1

-

p2

p3

-

-
- - - """.trim().replace("\r\n", "\n"), document.serialize(true).trim().replace("\r\n", "\n")) - } - - @test fun `should compile wiki example`() { - println(document { - append.filter { if (it.tagName == "div") SKIP else PASS }.html { - body { - div { - a { +"link1" } - } - a { +"link2" } - } - } - }.serialize()) - } - - @test fun `svg should have namespace`() { - val d = document { - append.html { - body { - svg { - } - } - } - } - - assertEquals("\n", - d.serialize(false).trim().replace("\r\n", "\n")) - } - - @test fun `generalize tests`() { - fun T.genericFlow() where T : HtmlBlockTag { - classes += "aha" - +"content" - +Entities.nbsp - div { - } - } - - fun T.genericPhrasing() where T : HtmlInlineTag { - classes += "aha" - +"content" - +Entities.nbsp - span { } - } - - fun T.genericMetaData() where T : HtmlHeadTag { - classes += "aha" - +"content" - +Entities.nbsp - meta("a") - script(ScriptType.textJavaScript) { } - } - - document { - append.html { - head { - genericMetaData() - } - body { - div { - genericFlow() - p { - genericPhrasing() - } - } - } - } - } - } - - @test fun `script content`() { - val document = document { - append.html { - head { - script(ScriptType.textJavaScript) { - unsafe { - raw("fun f() { return 1; }") - } - } - } - } - } - - - assertEquals("\n" + - "", - document.serialize(false).trim().replace("\r\n", "\n")) - } - - @test fun testPrepend() { - val document = createHTMLDocument().html { - body { - a { text("aaa") } - } - } - - document.getElementsByTagName("body").item(0).prepend { - p { - text("OK") - } - } - - assertEquals("\n" + - "

OK

aaa", - document.serialize(false).trim().replace("\r\n", "\n")) - } - - @test fun testComment() { - val document = createHTMLDocument().html { - comment("commented") - } - - assertEquals("\n" + - "", - document.serialize(false).trim().replace("\r\n", "\n")) - } +package kotlinx.html.tests + +import kotlinx.html.* +import kotlinx.html.consumers.* +import kotlinx.html.dom.* +import kotlin.test.* +import org.junit.Test as test + +class TestDOMTrees { + @test fun `able to create simple tree`() { + val tree = createHTMLDocument().div { + id = "test-node" + +"content" + } + + assertEquals("div", tree.getElementById("test-node")?.tagName?.toLowerCase()) + } + + @test fun `able to create complex tree and render it with pretty print`() { + val tree = createHTMLDocument().html { + body { + h1 { + +"header" + } + div { + +"content" + span { + +"yo" + } + } + } + } + + assertEquals("\n

header

contentyo
", tree.serialize(false)) + assertEquals(""" + + + +

header

+
+ contentyo +
+ + """.trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n")) + } + + @test fun `vals create and append support`() { + val document = createHTMLDocument().html { + body { + div { + id = "content" + } + } + } + + val contentNode = document.getElementById("content")!! + contentNode.append.p { + +"p1" + } + + val p2 = document.create.p { + +"p2" + } + contentNode.appendChild(p2) + + assertEquals(""" + + +
+

p1

+

p2

+
+ + + """.trim().replace("\r\n", "\n"), document.serialize(true).trim().replace("\r\n", "\n")) + } + + @test fun `append function support`() { + val document = createHTMLDocument().html { + body { + div { + id = "content" + } + } + } + + val contentNode = document.getElementById("content")!! + + val nodes = contentNode.append { + p { + +"p1" + } + p { + +"p2" + p { + +"p3" + } + } + } + + assertEquals(2, nodes.size) + + assertEquals(""" + + +
+

p1

+

+ p2 +

p3

+

+
+ + + """.trim().replace("\r\n", "\n"), document.serialize(true).trim().replace("\r\n", "\n")) + } + + @test fun `should compile wiki example`() { + println(document { + append.filter { if (it.tagName == "div") SKIP else PASS }.html { + body { + div { + a { +"link1" } + } + a { +"link2" } + } + } + }.serialize()) + } + + @test fun `svg should have namespace`() { + val d = document { + append.html { + body { + svg { + } + } + } + } + + assertEquals("\n", + d.serialize(false).trim().replace("\r\n", "\n")) + } + + @test fun `generalize tests`() { + fun T.genericFlow() where T : HtmlBlockTag { + classes += "aha" + +"content" + +Entities.nbsp + div { + } + } + + fun T.genericPhrasing() where T : HtmlInlineTag { + classes += "aha" + +"content" + +Entities.nbsp + span { } + } + + fun T.genericMetaData() where T : HtmlHeadTag { + classes += "aha" + +"content" + +Entities.nbsp + meta("a") + script(ScriptType.textJavaScript) { } + } + + document { + append.html { + head { + genericMetaData() + } + body { + div { + genericFlow() + p { + genericPhrasing() + } + } + } + } + } + } + + @test fun `script content`() { + val document = document { + append.html { + head { + script(ScriptType.textJavaScript) { + unsafe { + raw("fun f() { return 1; }") + } + } + } + } + } + + + assertEquals("\n" + + "", + document.serialize(false).trim().replace("\r\n", "\n")) + } + + @test fun testPrepend() { + val document = createHTMLDocument().html { + body { + a { text("aaa") } + } + } + + document.getElementsByTagName("body").item(0).prepend { + p { + text("OK") + } + } + + assertEquals("\n" + + "

OK

aaa", + document.serialize(false).trim().replace("\r\n", "\n")) + } + + @test fun testComment() { + val document = createHTMLDocument().html { + comment("commented") + } + + assertEquals("\n" + + "", + document.serialize(false).trim().replace("\r\n", "\n")) + } } \ No newline at end of file diff --git a/jvm/src/test/kotlin/exceptions.kt b/src/jvmTest/kotlin/exceptions.kt similarity index 92% rename from jvm/src/test/kotlin/exceptions.kt rename to src/jvmTest/kotlin/exceptions.kt index b89046df..88c0eb71 100644 --- a/jvm/src/test/kotlin/exceptions.kt +++ b/src/jvmTest/kotlin/exceptions.kt @@ -1,9 +1,8 @@ import kotlinx.html.* -import kotlinx.html.consumers.catch -import kotlinx.html.stream.appendHTML +import kotlinx.html.consumers.* +import kotlinx.html.stream.* import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue +import kotlin.test.* class TestExceptions { @Test fun `default exception must result in empty tag`() { diff --git a/jvm/src/test/kotlin/html5-tags.kt b/src/jvmTest/kotlin/html5-tags.kt similarity index 90% rename from jvm/src/test/kotlin/html5-tags.kt rename to src/jvmTest/kotlin/html5-tags.kt index 712b55fc..9b84f760 100644 --- a/jvm/src/test/kotlin/html5-tags.kt +++ b/src/jvmTest/kotlin/html5-tags.kt @@ -1,11 +1,8 @@ package kotlinx.html.tests import kotlinx.html.* -import kotlinx.html.consumers.filter import kotlinx.html.dom.* -import kotlinx.html.dom.createHTMLDocument -import kotlin.test.Test -import kotlin.test.assertEquals +import kotlin.test.* import org.junit.Test as test class Html5TagsTest { @@ -54,7 +51,8 @@ class Html5TagsTest {

header

-
contentyo +
+ contentyo
""".trimIndent(), tree.serialize(true).trim().replace("\r\n", "\n")) diff --git a/jvm/src/test/kotlin/huge.kt b/src/jvmTest/kotlin/huge.kt similarity index 99% rename from jvm/src/test/kotlin/huge.kt rename to src/jvmTest/kotlin/huge.kt index 1ac950b6..56bd3554 100644 --- a/jvm/src/test/kotlin/huge.kt +++ b/src/jvmTest/kotlin/huge.kt @@ -9,7 +9,7 @@ open class HugeStreamingBenchmark { @Test fun testName() { val sb = StringBuilder(8192) - val count = 10000000 + val count = 100 val time = measureTimeMillis { for (i in 1..count) { testHuge(sb) diff --git a/jvm/src/test/kotlin/streaming.kt b/src/jvmTest/kotlin/streaming.kt similarity index 95% rename from jvm/src/test/kotlin/streaming.kt rename to src/jvmTest/kotlin/streaming.kt index 57bd1d06..44d575de 100644 --- a/jvm/src/test/kotlin/streaming.kt +++ b/src/jvmTest/kotlin/streaming.kt @@ -232,16 +232,31 @@ class TestStreaming { @test fun `test measure consumer with loop inside`() { val count = 1000 - val rs = StringBuilder(26 * (count + 1)).appendHTML(false).measureTime().div { + val builder = StringBuilder(26 * (count + 1)).appendHTML(false) + + var minStart = 0L + var maxStart = 0L + var minEnd = 0L + var maxEnd = 0L + + minStart = currentTimeMillis() + val rs = builder.measureTime().div { + maxStart = currentTimeMillis() for (i in 1..count) { div { p { +"node$i" } } } + minEnd = currentTimeMillis() } + maxEnd = currentTimeMillis() + + val maxTime = maxEnd - minStart + val minTime = minEnd - maxStart - assertTrue(rs.time > 0) - assertTrue(rs.time < count.toLong()) + val errorMessage = "Expected time should be between $minTime and $maxTime ms, but actual is ${rs.time} ms" + assertTrue(errorMessage) { rs.time >= minTime } + assertTrue(errorMessage) { rs.time <= maxTime } val expected = StringBuilder().apply { append("
") diff --git a/jvm/src/test/kotlin/unsafe.kt b/src/jvmTest/kotlin/unsafe.kt similarity index 100% rename from jvm/src/test/kotlin/unsafe.kt rename to src/jvmTest/kotlin/unsafe.kt diff --git a/jvm/src/test/resources/declarations.json b/src/jvmTest/resources/declarations.json similarity index 100% rename from jvm/src/test/resources/declarations.json rename to src/jvmTest/resources/declarations.json