├── .gitignore ├── gradle.properties ├── src └── macosMain │ ├── kotlin │ └── com │ │ └── jetbrains │ │ └── handson │ │ └── handson │ │ └── init │ │ ├── ConfigurationException.kt │ │ ├── FileIOException.kt │ │ ├── Configuration.kt │ │ ├── ConfigurationFile.kt │ │ ├── Main.kt │ │ ├── FileIO.kt │ │ └── HandsOnInitiator.kt │ └── resources │ └── config.json ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── settings.gradle ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | /out 4 | /build 5 | *.iml 6 | *.ipr 7 | *.iws 8 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | kotlin.import.noCommonSourceSets=true 3 | 4 | -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/ConfigurationException.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | class ConfigurationException(override val message: String) : Throwable(message) 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/FileIOException.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlinx.cinterop.toKString 4 | import platform.posix.strerror 5 | 6 | class FileIOException(errorCode: Int) : Throwable(strerror(errorCode)?.toKString() ?: "Error: $errorCode") 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | maven { url "https://kotlin.bintray.com/kotlinx" } 6 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } 7 | } 8 | } 9 | rootProject.name = 'hands-on-init' 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/macosMain/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Introduction to Ktor", 3 | "projectName": "introduction-to-ktor", 4 | "pathHandsOn": "./hands-on", 5 | "pathProject": "./", 6 | "pre": [ 7 | { 8 | "text": "How to set up a project", 9 | "link": "https://play.kotlinlang.org/hands-on/how-to" 10 | }, 11 | { 12 | "text": "How to start a server", 13 | "link": "https://play.kotlinlang.org/hands-on/start-server" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/Configuration.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class Configuration( 7 | val title: String, 8 | val projectName: String, 9 | val pathHandsOn: String, 10 | val pathProject: String, 11 | val pre: List 12 | ) 13 | 14 | @Serializable 15 | data class PreRequisite( 16 | val text: String, 17 | val link: String 18 | ) 19 | -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/ConfigurationFile.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlinx.serialization.json.Json 4 | import kotlinx.serialization.json.JsonConfiguration 5 | 6 | 7 | class ConfigurationFile { 8 | fun load(fileName: String): Configuration { 9 | val fileReader = FileIO() 10 | try { 11 | val contents = fileReader.readFile(fileName) 12 | val json = Json(JsonConfiguration.Default) 13 | return json.parse(Configuration.serializer(), contents) 14 | } catch (e: FileIOException) { 15 | throw ConfigurationException(e.message!!) 16 | } 17 | } 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/Main.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlin.system.exitProcess 4 | 5 | 6 | fun hello(): String = "Hello, Kotlin/Native!" 7 | 8 | fun main(args: Array) { 9 | if (args.isEmpty()) { 10 | println("\n usage: hands-on-init {config.json}") 11 | exitProcess(-1) 12 | } 13 | val configurationFile = ConfigurationFile() 14 | try { 15 | val config = configurationFile.load(args[0]) 16 | val handsOnInitiator = HandsOnInitiator(config) 17 | handsOnInitiator.createFolderStructure() 18 | handsOnInitiator.createMarkdownFiles() 19 | handsOnInitiator.createLicenseFile() 20 | handsOnInitiator.createGitIgnoreFile() 21 | handsOnInitiator.outputInstructions() 22 | } catch (e: Exception) { 23 | printErrorMessage(e) 24 | exitProcess(-1) 25 | } 26 | } 27 | 28 | fun printErrorMessage(e: Throwable) { 29 | println("\n An error occurred: ${e.message}") 30 | } -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/FileIO.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlinx.cinterop.ByteVar 4 | import kotlinx.cinterop.allocArray 5 | import kotlinx.cinterop.memScoped 6 | import kotlinx.cinterop.toKString 7 | import platform.posix.* 8 | 9 | class FileIO() { 10 | 11 | fun readFile(filename: String): String { 12 | val file = fopen(filename, "r") 13 | ?: throw FileIOException(errno) 14 | var contents = "" 15 | try { 16 | memScoped { 17 | val bufferLength = 64 * 1024 18 | val buffer = allocArray(bufferLength) 19 | var nextLine = fgets(buffer, bufferLength, file)?.toKString() 20 | while (nextLine != null) { 21 | contents += nextLine 22 | nextLine = fgets(buffer, bufferLength, file)?.toKString() 23 | } 24 | } 25 | } finally{ 26 | fclose(file) 27 | } 28 | return contents 29 | } 30 | 31 | fun createFolder(folderName: String) { 32 | val result = mkdir(folderName, S_IRWXU) 33 | if (result != 0 && result != -1) { 34 | throw FileIOException(errno) 35 | } 36 | } 37 | 38 | fun createFile(fileName: String, contents: String) { 39 | val file = fopen(fileName, "w") ?: throw FileIOException(errno) 40 | try { 41 | fprintf(file, contents) 42 | } finally { 43 | fclose(file) 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) 2 | [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0) 3 | 4 | 5 | # Hands-On Initiator Command Line Tool 6 | 7 | A simple command line tool (currently only works on macOS) to create the necessary structure for new 8 | Hands-On tutorials. 9 | 10 | ## Usage 11 | 12 | Configure the parameters for your hands-on tutorial using a JSON configuration file with the following format 13 | 14 | ```json 15 | { 16 | "title": "Introduction to Ktor", 17 | "projectName": "introduction-to-ktor", 18 | "pathHandsOn": "./hands-on", 19 | "pathProject": "./hands-on-project", 20 | "pre": [ 21 | { 22 | "text": "How to set up a project", 23 | "link": "https://play.kotlinlang.org/hands-on/how-to" 24 | }, 25 | { 26 | "text": "How to start a server", 27 | "link": "https://play.kotlinlang.org/hands-on/start-server" 28 | } 29 | ] 30 | } 31 | ``` 32 | 33 | It will create all the necessary files for you and all you need to do is to fill in some TODOs and push to GitHub. Of course, you'll 34 | also need to write the contents and projects! 35 | 36 | ## Building the project 37 | 38 | This is a Kotlin/Native project that targets macOS. To build it, simply run 39 | 40 | `gradle macosBinaries` 41 | 42 | ## Binaries 43 | 44 | You can binaries on the [Releases](https://github.com/kotlin-hands-on/hands-on-init/releases) page. 45 | 46 | ## License 47 | 48 | Apache 2.0 49 | 50 | 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of resources Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by resources 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as resources whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not resources Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom resources Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You resources perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You resources perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including resources 83 | cross-claim or counterclaim in resources lawsuit) alleging that the Work 84 | or resources Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (resources) You must give any other recipients of the Work or 95 | Derivative Works resources copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes resources "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include resources readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within resources NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within resources display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as resources whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as resources 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge resources fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that resources 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain resources copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /src/macosMain/kotlin/com/jetbrains/handson/handson/init/HandsOnInitiator.kt: -------------------------------------------------------------------------------- 1 | package com.jetbrains.handson.handson.init 2 | 3 | import kotlinx.serialization.PrimitiveKind 4 | 5 | class HandsOnInitiator(private val configuration: Configuration) { 6 | private val fileIO = FileIO() 7 | 8 | fun createFolderStructure() { 9 | println("\nCreating folder structure...") 10 | println("Folder for hands-on tutorial") 11 | fileIO.createFolder(configuration.pathHandsOn) 12 | fileIO.createFolder("${configuration.pathHandsOn}/${configuration.title}") 13 | fileIO.createFolder("${configuration.pathHandsOn}/${configuration.title}/assets") 14 | println("Folder for associated project") 15 | fileIO.createFolder(configuration.pathProject) 16 | fileIO.createFolder("${configuration.pathProject}/${configuration.projectName}") 17 | } 18 | 19 | fun createMarkdownFiles() { 20 | println("\nCreating markdown files...") 21 | println("Description file") 22 | 23 | fileIO.createFile("${configuration.pathHandsOn}/${configuration.title}/00_description.md", generateDescriptionContent()) 24 | println("Introduction file") 25 | fileIO.createFile("${configuration.pathHandsOn}/${configuration.title}/01_introduction.md", generateIntroductionContent()) 26 | println("Project README file") 27 | fileIO.createFile("${configuration.pathProject}/${configuration.projectName}/README.md", generateREADMEContent()) 28 | } 29 | 30 | fun createLicenseFile() { 31 | println("\nCreating license file") 32 | fileIO.createFile("${configuration.pathProject}/${configuration.projectName}/LICENSE", generateLicenseContent()) 33 | } 34 | 35 | fun createGitIgnoreFile() { 36 | println("\nCreating .gitignore file") 37 | fileIO.createFile("${configuration.pathProject}/${configuration.projectName}/.gitignore", generateGitIgnoreContent()) 38 | } 39 | 40 | private fun generateGitIgnoreContent(): String { 41 | return "/.gradle\n" + 42 | "/.idea\n" + 43 | "/out\n" + 44 | "/build\n" + 45 | "*.iml\n" + 46 | "*.ipr\n" + 47 | "*.iws" 48 | } 49 | 50 | private fun generateLicenseContent(): String { 51 | return " Apache License\n" + 52 | " Version 2.0, January 2004\n" + 53 | " http://www.apache.org/licenses/\n" + 54 | "\n" + 55 | " TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n" + 56 | "\n" + 57 | " 1. Definitions.\n" + 58 | "\n" + 59 | " \"License\" shall mean the terms and conditions for use, reproduction,\n" + 60 | " and distribution as defined by Sections 1 through 9 of this document.\n" + 61 | "\n" + 62 | " \"Licensor\" shall mean the copyright owner or entity authorized by\n" + 63 | " the copyright owner that is granting the License.\n" + 64 | "\n" + 65 | " \"Legal Entity\" shall mean the union of the acting entity and all\n" + 66 | " other entities that control, are controlled by, or are under common\n" + 67 | " control with that entity. For the purposes of this definition,\n" + 68 | " \"control\" means (i) the power, direct or indirect, to cause the\n" + 69 | " direction or management of such entity, whether by contract or\n" + 70 | " otherwise, or (ii) ownership of fifty percent (50%) or more of the\n" + 71 | " outstanding shares, or (iii) beneficial ownership of such entity.\n" + 72 | "\n" + 73 | " \"You\" (or \"Your\") shall mean an individual or Legal Entity\n" + 74 | " exercising permissions granted by this License.\n" + 75 | "\n" + 76 | " \"Source\" form shall mean the preferred form for making modifications,\n" + 77 | " including but not limited to software source code, documentation\n" + 78 | " source, and configuration files.\n" + 79 | "\n" + 80 | " \"Object\" form shall mean any form resulting from mechanical\n" + 81 | " transformation or translation of resources Source form, including but\n" + 82 | " not limited to compiled object code, generated documentation,\n" + 83 | " and conversions to other media types.\n" + 84 | "\n" + 85 | " \"Work\" shall mean the work of authorship, whether in Source or\n" + 86 | " Object form, made available under the License, as indicated by resources\n" + 87 | " copyright notice that is included in or attached to the work\n" + 88 | " (an example is provided in the Appendix below).\n" + 89 | "\n" + 90 | " \"Derivative Works\" shall mean any work, whether in Source or Object\n" + 91 | " form, that is based on (or derived from) the Work and for which the\n" + 92 | " editorial revisions, annotations, elaborations, or other modifications\n" + 93 | " represent, as resources whole, an original work of authorship. For the purposes\n" + 94 | " of this License, Derivative Works shall not include works that remain\n" + 95 | " separable from, or merely link (or bind by name) to the interfaces of,\n" + 96 | " the Work and Derivative Works thereof.\n" + 97 | "\n" + 98 | " \"Contribution\" shall mean any work of authorship, including\n" + 99 | " the original version of the Work and any modifications or additions\n" + 100 | " to that Work or Derivative Works thereof, that is intentionally\n" + 101 | " submitted to Licensor for inclusion in the Work by the copyright owner\n" + 102 | " or by an individual or Legal Entity authorized to submit on behalf of\n" + 103 | " the copyright owner. For the purposes of this definition, \"submitted\"\n" + 104 | " means any form of electronic, verbal, or written communication sent\n" + 105 | " to the Licensor or its representatives, including but not limited to\n" + 106 | " communication on electronic mailing lists, source code control systems,\n" + 107 | " and issue tracking systems that are managed by, or on behalf of, the\n" + 108 | " Licensor for the purpose of discussing and improving the Work, but\n" + 109 | " excluding communication that is conspicuously marked or otherwise\n" + 110 | " designated in writing by the copyright owner as \"Not resources Contribution.\"\n" + 111 | "\n" + 112 | " \"Contributor\" shall mean Licensor and any individual or Legal Entity\n" + 113 | " on behalf of whom resources Contribution has been received by Licensor and\n" + 114 | " subsequently incorporated within the Work.\n" + 115 | "\n" + 116 | " 2. Grant of Copyright License. Subject to the terms and conditions of\n" + 117 | " this License, each Contributor hereby grants to You resources perpetual,\n" + 118 | " worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n" + 119 | " copyright license to reproduce, prepare Derivative Works of,\n" + 120 | " publicly display, publicly perform, sublicense, and distribute the\n" + 121 | " Work and such Derivative Works in Source or Object form.\n" + 122 | "\n" + 123 | " 3. Grant of Patent License. Subject to the terms and conditions of\n" + 124 | " this License, each Contributor hereby grants to You resources perpetual,\n" + 125 | " worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n" + 126 | " (except as stated in this section) patent license to make, have made,\n" + 127 | " use, offer to sell, sell, import, and otherwise transfer the Work,\n" + 128 | " where such license applies only to those patent claims licensable\n" + 129 | " by such Contributor that are necessarily infringed by their\n" + 130 | " Contribution(s) alone or by combination of their Contribution(s)\n" + 131 | " with the Work to which such Contribution(s) was submitted. If You\n" + 132 | " institute patent litigation against any entity (including resources\n" + 133 | " cross-claim or counterclaim in resources lawsuit) alleging that the Work\n" + 134 | " or resources Contribution incorporated within the Work constitutes direct\n" + 135 | " or contributory patent infringement, then any patent licenses\n" + 136 | " granted to You under this License for that Work shall terminate\n" + 137 | " as of the date such litigation is filed.\n" + 138 | "\n" + 139 | " 4. Redistribution. You may reproduce and distribute copies of the\n" + 140 | " Work or Derivative Works thereof in any medium, with or without\n" + 141 | " modifications, and in Source or Object form, provided that You\n" + 142 | " meet the following conditions:\n" + 143 | "\n" + 144 | " (resources) You must give any other recipients of the Work or\n" + 145 | " Derivative Works resources copy of this License; and\n" + 146 | "\n" + 147 | " (b) You must cause any modified files to carry prominent notices\n" + 148 | " stating that You changed the files; and\n" + 149 | "\n" + 150 | " (c) You must retain, in the Source form of any Derivative Works\n" + 151 | " that You distribute, all copyright, patent, trademark, and\n" + 152 | " attribution notices from the Source form of the Work,\n" + 153 | " excluding those notices that do not pertain to any part of\n" + 154 | " the Derivative Works; and\n" + 155 | "\n" + 156 | " (d) If the Work includes resources \"NOTICE\" text file as part of its\n" + 157 | " distribution, then any Derivative Works that You distribute must\n" + 158 | " include resources readable copy of the attribution notices contained\n" + 159 | " within such NOTICE file, excluding those notices that do not\n" + 160 | " pertain to any part of the Derivative Works, in at least one\n" + 161 | " of the following places: within resources NOTICE text file distributed\n" + 162 | " as part of the Derivative Works; within the Source form or\n" + 163 | " documentation, if provided along with the Derivative Works; or,\n" + 164 | " within resources display generated by the Derivative Works, if and\n" + 165 | " wherever such third-party notices normally appear. The contents\n" + 166 | " of the NOTICE file are for informational purposes only and\n" + 167 | " do not modify the License. You may add Your own attribution\n" + 168 | " notices within Derivative Works that You distribute, alongside\n" + 169 | " or as an addendum to the NOTICE text from the Work, provided\n" + 170 | " that such additional attribution notices cannot be construed\n" + 171 | " as modifying the License.\n" + 172 | "\n" + 173 | " You may add Your own copyright statement to Your modifications and\n" + 174 | " may provide additional or different license terms and conditions\n" + 175 | " for use, reproduction, or distribution of Your modifications, or\n" + 176 | " for any such Derivative Works as resources whole, provided Your use,\n" + 177 | " reproduction, and distribution of the Work otherwise complies with\n" + 178 | " the conditions stated in this License.\n" + 179 | "\n" + 180 | " 5. Submission of Contributions. Unless You explicitly state otherwise,\n" + 181 | " any Contribution intentionally submitted for inclusion in the Work\n" + 182 | " by You to the Licensor shall be under the terms and conditions of\n" + 183 | " this License, without any additional terms or conditions.\n" + 184 | " Notwithstanding the above, nothing herein shall supersede or modify\n" + 185 | " the terms of any separate license agreement you may have executed\n" + 186 | " with Licensor regarding such Contributions.\n" + 187 | "\n" + 188 | " 6. Trademarks. This License does not grant permission to use the trade\n" + 189 | " names, trademarks, service marks, or product names of the Licensor,\n" + 190 | " except as required for reasonable and customary use in describing the\n" + 191 | " origin of the Work and reproducing the content of the NOTICE file.\n" + 192 | "\n" + 193 | " 7. Disclaimer of Warranty. Unless required by applicable law or\n" + 194 | " agreed to in writing, Licensor provides the Work (and each\n" + 195 | " Contributor provides its Contributions) on an \"AS IS\" BASIS,\n" + 196 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n" + 197 | " implied, including, without limitation, any warranties or conditions\n" + 198 | " of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n" + 199 | " PARTICULAR PURPOSE. You are solely responsible for determining the\n" + 200 | " appropriateness of using or redistributing the Work and assume any\n" + 201 | " risks associated with Your exercise of permissions under this License.\n" + 202 | "\n" + 203 | " 8. Limitation of Liability. In no event and under no legal theory,\n" + 204 | " whether in tort (including negligence), contract, or otherwise,\n" + 205 | " unless required by applicable law (such as deliberate and grossly\n" + 206 | " negligent acts) or agreed to in writing, shall any Contributor be\n" + 207 | " liable to You for damages, including any direct, indirect, special,\n" + 208 | " incidental, or consequential damages of any character arising as resources\n" + 209 | " result of this License or out of the use or inability to use the\n" + 210 | " Work (including but not limited to damages for loss of goodwill,\n" + 211 | " work stoppage, computer failure or malfunction, or any and all\n" + 212 | " other commercial damages or losses), even if such Contributor\n" + 213 | " has been advised of the possibility of such damages.\n" + 214 | "\n" + 215 | " 9. Accepting Warranty or Additional Liability. While redistributing\n" + 216 | " the Work or Derivative Works thereof, You may choose to offer,\n" + 217 | " and charge resources fee for, acceptance of support, warranty, indemnity,\n" + 218 | " or other liability obligations and/or rights consistent with this\n" + 219 | " License. However, in accepting such obligations, You may act only\n" + 220 | " on Your own behalf and on Your sole responsibility, not on behalf\n" + 221 | " of any other Contributor, and only if You agree to indemnify,\n" + 222 | " defend, and hold each Contributor harmless for any liability\n" + 223 | " incurred by, or claims asserted against, such Contributor by reason\n" + 224 | " of your accepting any such warranty or additional liability.\n" + 225 | "\n" + 226 | " END OF TERMS AND CONDITIONS\n" + 227 | "\n" + 228 | " APPENDIX: How to apply the Apache License to your work.\n" + 229 | "\n" + 230 | " To apply the Apache License to your work, attach the following\n" + 231 | " boilerplate notice, with the fields enclosed by brackets \"[]\"\n" + 232 | " replaced with your own identifying information. (Don't include\n" + 233 | " the brackets!) The text should be enclosed in the appropriate\n" + 234 | " comment syntax for the file format. We also recommend that resources\n" + 235 | " file or class name and description of purpose be included on the\n" + 236 | " same \"printed page\" as the copyright notice for easier\n" + 237 | " identification within third-party archives.\n" + 238 | "\n" + 239 | " Copyright [yyyy] [name of copyright owner]\n" + 240 | "\n" + 241 | " Licensed under the Apache License, Version 2.0 (the \"License\");\n" + 242 | " you may not use this file except in compliance with the License.\n" + 243 | " You may obtain resources copy of the License at\n" + 244 | "\n" + 245 | " http://www.apache.org/licenses/LICENSE-2.0\n" + 246 | "\n" + 247 | " Unless required by applicable law or agreed to in writing, software\n" + 248 | " distributed under the License is distributed on an \"AS IS\" BASIS,\n" + 249 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + 250 | " See the License for the specific language governing permissions and\n" + 251 | " limitations under the License." 252 | } 253 | 254 | private fun generateREADMEContent(): String { 255 | return "[![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)\n" + 256 | "[![GitHub license](https://img.shields.io/badge/license-Apache%%20License%%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)\n" + 257 | "\n" + 258 | "\n" + 259 | "# ${configuration.title}\n" + 260 | "\n" + 261 | "This repository is the code corresponding to the hands-on lab [${configuration.title}](https://play.kotlinlang.org/hands-on/${configuration.title.replace(" ", "%%20")}/01_Introduction). \n" 262 | } 263 | 264 | private fun generatePrerequisites(): String { 265 | var topics = "" 266 | configuration.pre.forEach { 267 | topics += "* [${it.text}](${it.link.replace("%20", "%%20").replace(" ", "%%20")})\n" 268 | } 269 | 270 | return "This tutorial assumes that you're already familiar with the following topics:\n" + 271 | "\n" + 272 | topics + 273 | "\n" 274 | } 275 | 276 | private fun generateIntroductionContent(): String { 277 | val prereq = generatePrerequisites() 278 | return "# Introduction\n" + 279 | "\n" + 280 | prereq + 281 | "\n" + 282 | "TODO - Provide introduction here" + 283 | "\n" + 284 | "[Source code on GitHub](https://github.com/kotlin-hands-on/${configuration.projectName})\n" 285 | } 286 | 287 | private fun generateDescriptionContent(): String { 288 | return "# ${configuration.title}\n" + 289 | "\n" + 290 | "TODO - Provide short description here\n" 291 | } 292 | 293 | fun outputInstructions() { 294 | println("\nSuccessfully generated all the required folders and files") 295 | println("\nNext steps:") 296 | println("\n 1. Fill in the corresponding TODO's in 00_description.md, 01_introduction.md") 297 | println("\n 2. Create repository on GitHub for project and upload project") 298 | println("\n 3. Push changes to Hands-On repository on GitHub") 299 | } 300 | } --------------------------------------------------------------------------------