This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[39955] Create template Kotlin (#334)
* [39955] Create template Kotlin Signed-off-by: Finzi <andressa.abreu@zup.com.br> * Pre-commit updates Signed-off-by: Finzi <andressa.abreu@zup.com.br> * [39955] Code review corrections Signed-off-by: Finzi <andressa.abreu@zup.com.br> * Pre-Commit Fixes Signed-off-by: maurineimirandazup <maurinei.miranda@zup.com.br> Signed-off-by: Finzi <andressa.abreu@zup.com.br> * [39955] Regex corrections Signed-off-by: Finzi <andressa.abreu@zup.com.br> Co-authored-by: Antonio Oliveira <antonio.filho@zup.com.br> Co-authored-by: maurineimirandazup <maurinei.miranda@zup.com.br>
- Loading branch information
1 parent
12411c1
commit 4757cf0
Showing
22 changed files
with
734 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
templates/create_formula/languages/kotlin-jdk11/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM ritclizup/rit-kotlin-jdk8-runner | ||
|
||
USER root | ||
|
||
RUN mkdir /rit | ||
COPY . /rit | ||
RUN sed -i 's/\r//g' /rit/set_umask.sh | ||
RUN sed -i 's/\r//g' /rit/run.sh | ||
RUN chmod +x /rit/set_umask.sh | ||
|
||
WORKDIR /app | ||
ENTRYPOINT ["/rit/set_umask.sh"] | ||
CMD ["/rit/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# KOTLIN | ||
BIN_FOLDER=bin | ||
SH=$(BIN_FOLDER)/run.sh | ||
BAT=$(BIN_FOLDER)/run.bat | ||
BUILD=mvn clean install | ||
CLEAN=mvn clean | ||
JAR_FILE=Main.jar | ||
TARGET=target | ||
|
||
build: kotlin-build sh-unix bat-windows docker | ||
$(CLEAN) | ||
|
||
kotlin-build: | ||
mkdir -p $(BIN_FOLDER) | ||
$(BUILD) | ||
mv $(TARGET)/$(JAR_FILE) $(BIN_FOLDER) | ||
rm -Rf $(TARGET) | ||
|
||
sh-unix: | ||
echo '#!/bin/sh' > $(SH) | ||
echo 'java -jar "$$(dirname "$$0")"/$(JAR_FILE)' >> $(SH) | ||
chmod +x $(SH) | ||
|
||
bat-windows: | ||
echo '@ECHO OFF' > $(BAT) | ||
echo 'java -jar $(JAR_FILE)' >> $(BAT) | ||
|
||
test: | ||
mvn clean install | ||
|
||
docker: | ||
cp Dockerfile set_umask.sh $(BIN_FOLDER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Ritchie Formula | ||
|
||
## command | ||
|
||
```bash | ||
#rit-replace{formulaCmd} | ||
``` | ||
|
||
## description | ||
|
||
description of formula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
:: Java parameters | ||
echo off | ||
SETLOCAL | ||
SET BIN_FOLDER=bin | ||
SET BIN_NAME=Main.jar | ||
SET BAT_FILE=%BIN_FOLDER%\run.bat | ||
SET SH_FILE=%BIN_FOLDER%\run.sh | ||
:build | ||
call mvn clean install 1>&2 | ||
if %errorlevel% neq 0 exit /b %errorlevel% | ||
mkdir %BIN_FOLDER% | ||
copy target\%BIN_NAME% %BIN_FOLDER%\%BIN_NAME% | ||
rmdir /Q /S target | ||
CALL :BAT_WINDOWS | ||
CALL :SH_LINUX | ||
CALL :CP_DOCKER | ||
GOTO DONE | ||
|
||
:BAT_WINDOWS | ||
echo @ECHO OFF > %BAT_FILE% | ||
echo java -jar %BIN_NAME% >> %BAT_FILE% | ||
GOTO DONE | ||
|
||
:SH_LINUX | ||
echo java -jar "$(dirname "$0")"/%BIN_NAME% > %SH_FILE% | ||
GOTO DONE | ||
|
||
:CP_DOCKER | ||
copy Dockerfile %BIN_FOLDER% | ||
copy set_umask.sh %BIN_FOLDER% | ||
GOTO DONE | ||
|
||
:DONE |
46 changes: 46 additions & 0 deletions
46
templates/create_formula/languages/kotlin-jdk11/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"dockerImageBuilder": "ritclizup/rit-kotlin-jdk8-builder", | ||
"inputs": [ | ||
{ | ||
"cache": { | ||
"active": true, | ||
"newLabel": "Type new value. ", | ||
"qty": 3 | ||
}, | ||
"label": "Type your name: ", | ||
"name": "rit_input_text", | ||
"required": true, | ||
"type": "text" | ||
}, | ||
{ | ||
"default": "false", | ||
"items": [ | ||
"false", | ||
"true" | ||
], | ||
"label": "Have you ever used Ritchie? ", | ||
"name": "rit_input_boolean", | ||
"required": false, | ||
"type": "bool" | ||
}, | ||
{ | ||
"default": "everything", | ||
"items": [ | ||
"daily tasks", | ||
"workflows", | ||
"toils", | ||
"everything" | ||
], | ||
"label": "What do you want to automate? ", | ||
"name": "rit_input_list", | ||
"required": false, | ||
"type": "text" | ||
}, | ||
{ | ||
"label": "Tell us a secret: ", | ||
"name": "rit_input_password", | ||
"required": true, | ||
"type": "password" | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
templates/create_formula/languages/kotlin-jdk11/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"execution": [ | ||
"local", | ||
"docker" | ||
], | ||
"os": { | ||
"deps": [], | ||
"support": [ | ||
"windows", | ||
"mac", | ||
"linux" | ||
] | ||
}, | ||
"tags": [ | ||
"#rit-replace{formulaTags}" | ||
] | ||
} |
129 changes: 129 additions & 0 deletions
129
templates/create_formula/languages/kotlin-jdk11/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>formula</artifactId> | ||
<groupId>com.ritchie</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<kotlin.code.style>official</kotlin.code.style> | ||
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget> | ||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>mavenCentral</id> | ||
<url>https://repo1.maven.org/maven2/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<finalName>Main</finalName> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<!-- Build an executable JAR --> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>${maven-jar-plugin.version}</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<!-- <addClasspath>true</addClasspath> --> | ||
<mainClass>com.ritchie.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.ritchie.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>1.4.10</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>testCompile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit</artifactId> | ||
<version>1.4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>1.4.10</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomas-langer</groupId> | ||
<artifactId>chalk</artifactId> | ||
<version>1.0.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
umask 0011 | ||
$1 |
15 changes: 15 additions & 0 deletions
15
templates/create_formula/languages/kotlin-jdk11/src/main/kotlin/com/ritchie/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ritchie | ||
|
||
import com.ritchie.formula.Formula | ||
|
||
object Main { | ||
@JvmStatic | ||
fun main(args: Array<String?>?) { | ||
val inputText: String = System.getenv("RIT_INPUT_TEXT") | ||
val inputBoolean: Boolean = (System.getenv("RIT_INPUT_BOOLEAN").toBoolean()) | ||
val inputList: String = System.getenv("RIT_INPUT_LIST") | ||
val inputPassword: String = System.getenv("RIT_INPUT_PASSWORD") | ||
val formula = Formula(inputText, inputBoolean, inputList, inputPassword) | ||
formula.Run() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ates/create_formula/languages/kotlin-jdk11/src/main/kotlin/com/ritchie/formula/Formula.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.ritchie.formula | ||
import com.github.tomaslanger.chalk.Chalk; | ||
|
||
class Formula(private val inputText: String, private val inputBoolean: Boolean, private val inputList: String, private val inputPassword: String) { | ||
fun Run() { | ||
println("Hello World!") | ||
println(Chalk.on(String.format("My name is %s.", inputText)).green()) | ||
if (inputBoolean) { | ||
println(Chalk.on("I've already created formulas using Ritchie.").cyan()) | ||
} else { | ||
println(Chalk.on("I'm excited in creating new formulas using Ritchie.").red()) | ||
} | ||
println(Chalk.on(String.format("Today, I want to automate %s.", inputList)).yellow()) | ||
println(Chalk.on(String.format("My secret is %s.", inputPassword)).magenta()) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../create_formula/languages/kotlin-jdk11/src/test/kotlin/com/ritchie/formula/FormulaTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.ritchie.formula | ||
|
||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintStream | ||
import kotlin.test.assertEquals | ||
|
||
class FormulaTest { | ||
private val outContent: ByteArrayOutputStream = ByteArrayOutputStream() | ||
private val originalOut: PrintStream = System.out | ||
@Before | ||
fun setUpStreams() { | ||
System.setOut(PrintStream(outContent)) | ||
} | ||
|
||
@After | ||
fun restoreStreams() { | ||
System.setOut(originalOut) | ||
} | ||
|
||
@Test | ||
fun runTrueInput() { | ||
Formula("Hello", true, "world", "pass").Run() | ||
assertEquals("Hello World!" + | ||
"My name is Hello." + | ||
"I've already created formulas using Ritchie." + | ||
"Today, I want to automate world." + | ||
"My secret is pass.", outContent.toString().replace(Regex("\\r|\\n"), "").replace(Regex("\u001B\\[[;\\d]*m"), "")) | ||
} | ||
|
||
@Test | ||
fun runFalseInput() { | ||
Formula("Hello", false, "world", "pass").Run() | ||
assertEquals("Hello World!" + | ||
"My name is Hello." + | ||
"I'm excited in creating new formulas using Ritchie." + | ||
"Today, I want to automate world." + | ||
"My secret is pass.", outContent.toString().replace(Regex("\\r|\\n"), "").replace(Regex("\u001B\\[[;\\d]*m"), "")) | ||
} | ||
|
||
@Test | ||
fun runNoSecretsInput() { | ||
Formula("Hello", false, "world", "").Run() | ||
assertEquals("Hello World!" + | ||
"My name is Hello." + | ||
"I'm excited in creating new formulas using Ritchie." + | ||
"Today, I want to automate world." + | ||
"My secret is .", outContent.toString().replace(Regex("\\r|\\n"), "").replace(Regex("\u001B\\[[;\\d]*m"), "")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM ritclizup/rit-kotlin-jdk8-runner | ||
|
||
USER root | ||
|
||
RUN mkdir /rit | ||
COPY . /rit | ||
RUN sed -i 's/\r//g' /rit/set_umask.sh | ||
RUN sed -i 's/\r//g' /rit/run.sh | ||
RUN chmod +x /rit/set_umask.sh | ||
|
||
WORKDIR /app | ||
ENTRYPOINT ["/rit/set_umask.sh"] | ||
CMD ["/rit/run.sh"] |
Oops, something went wrong.