package correction
[idea/community.git] / update-server-mock / src / main / java / com / intellij / updater / mock / Generator.kt
1 /*
2  * Copyright (c) 2016 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.updater.mock
17
18 class Generator {
19   private val patch = this.javaClass.classLoader.getResourceAsStream("patch/patch.jar").use { it.readBytes() }
20
21   fun generateXml(productCode: String, buildId: String, eap: Boolean): String {
22     val status = if (eap) "eap" else "release"
23     return """
24       <!DOCTYPE products SYSTEM "updates.dtd">
25       <products>
26         <product name="Mock Product">
27           <code>$productCode</code>
28           <channel id="MOCK" status="$status" licensing="$status">
29             <build number="9999.0.0" version="Mock">
30               <message><![CDATA[A mock update. For testing purposes only.]]></message>
31               <button name="Download" url="https://www.jetbrains.com/" download="true"/>
32               <patch from="$buildId" size="from 0 to ∞"/>
33             </build>
34           </channel>
35         </product>
36       </products>""".trimIndent()
37   }
38
39   fun generatePatch(): ByteArray = patch
40 }