Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #144 from fabianofernandeszup/fix-java8-template-b…
Browse files Browse the repository at this point in the history
…uild-and-add-java11

Fix java8 template and add template java11
  • Loading branch information
fabianofernandeszup authored Aug 19, 2020
2 parents 4e8d7c3 + cdc2e08 commit 28668d8
Show file tree
Hide file tree
Showing 22 changed files with 339 additions and 2 deletions.
13 changes: 13 additions & 0 deletions templates/create_formula/languages/java11/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM cimg/openjdk:11.0.5

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"]
37 changes: 37 additions & 0 deletions templates/create_formula/languages/java11/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"dockerImageBuilder": "cimg/openjdk:11.0.5",
"inputs": [
{
"cache": {
"active": true,
"newLabel": "Type new value. ",
"qty": 6
},
"label": "Type : ",
"name": "sample_text",
"type": "text"
},
{
"default": "in1",
"items": [
"in_list1",
"in_list2",
"in_list3",
"in_listN"
],
"label": "Pick your : ",
"name": "sample_list",
"type": "text"
},
{
"default": "false",
"items": [
"false",
"true"
],
"label": "Pick: ",
"name": "sample_bool",
"type": "bool"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
</properties>

<build>
<finalName>Main</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -31,6 +41,29 @@
</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>
</plugins>
</build>

Expand Down
32 changes: 32 additions & 0 deletions templates/create_formula/languages/java8/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# JAVA
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: java-build sh-unix bat-windows docker
$(CLEAN)

java-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)
11 changes: 11 additions & 0 deletions templates/create_formula/languages/java8/README.md
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
33 changes: 33 additions & 0 deletions templates/create_formula/languages/java8/build.bat
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
17 changes: 17 additions & 0 deletions templates/create_formula/languages/java8/metadata.json
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}"
]
}
78 changes: 78 additions & 0 deletions templates/create_formula/languages/java8/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ritchie</groupId>
<artifactId>formula</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
</properties>

<build>
<finalName>Main</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3 changes: 3 additions & 0 deletions templates/create_formula/languages/java8/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ritchie;

import com.ritchie.formula.Formula;

public class Main {

public static void main(String[] args) {
String input1 = System.getenv("SAMPLE_TEXT");
String input2 = System.getenv("SAMPLE_LIST");
boolean input3 = Boolean.parseBoolean(System.getenv("SAMPLE_BOOL"));
Formula formula = new Formula(input1, input2, input3);
System.out.println(formula.Run());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ritchie.formula;

public class Formula {

private String input1;
private String input2;
private boolean input3;

public String Run() {
return String.format(
"Hello World!\n"
+ "You receive %s in text.\n"
+ "You receive %s in list.\n"
+ "You receive %s in boolean.\n",
input1, input2, input3);
}

public Formula(String input1, String input2, boolean input3) {
this.input1 = input1;
this.input2 = input2;
this.input3 = input3;
}

public String getInput1() {
return input1;
}

public void setInput1(String input1) {
this.input1 = input1;
}

public String getInput2() {
return input2;
}

public void setInput2(String input2) {
this.input2 = input2;
}

public boolean isInput3() {
return input3;
}

public void setInput3(boolean input3) {
this.input3 = input3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ritchie.formula;

import static org.junit.Assert.*;

import org.junit.Test;

public class FormulaTest {

@Test
public void run() {
Formula formula = new Formula("Hello", "World", true);
String excpeted =
"Hello World!\n"
+ "You receive Hello in text.\n"
+ "You receive World in list.\n"
+ "You receive true in boolean.\n";
assertEquals(excpeted, formula.Run());
}
}

0 comments on commit 28668d8

Please sign in to comment.