-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from kuzzleio/1.3.3-proposal
Release 1.3.3
- Loading branch information
Showing
42 changed files
with
680 additions
and
501 deletions.
There are no files selected for viewing
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,8 @@ | ||
FROM node:14.18.2 | ||
|
||
COPY . /var/app | ||
WORKDIR /var/app | ||
|
||
RUN npm install | ||
|
||
CMD [ "node /var/app/builder.js" ] |
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,90 @@ | ||
const yaml = require('js-yaml'); | ||
const fs = require('fs'); | ||
const Path = require('path'); | ||
const glob = require('glob'); | ||
|
||
const javaSnippetPath = '/mnt/doc/**/snippets/*-java.test.yml'; | ||
const kotlinSnippetPath = '/mnt/doc/**/snippets/*-kotlin.test.yml'; | ||
const snippetTemplatesPath = '/mnt/snippet-templates/*'; | ||
const buildDir = '/mnt/build'; | ||
|
||
/** | ||
* Extract code from balises @start and @stop | ||
* If one of the balise is missing, the whole file is returned | ||
* | ||
* @param {String} code | ||
* @returns | ||
*/ | ||
function extractCode(code) { | ||
const lines = code.split('\n'); | ||
const start = lines.findIndex(line => line.includes('// @start')); | ||
const end = lines.findIndex(line => line.includes('// @end')); | ||
|
||
if (start === -1 || end === -1) { | ||
return code; | ||
} | ||
|
||
return lines.slice(start, end).join('\n'); | ||
} | ||
|
||
/** | ||
* Go over each file and build the snippet with the right template | ||
* then build the method that encapsulate the snippet | ||
* | ||
* @param {String[]} paths | ||
* @param {String} ext | ||
* @param {*} templates | ||
* @returns | ||
*/ | ||
function buildSnippetMethods(paths, ext, templates) { | ||
const methodTemplate = fs.readFileSync(`./templates/method.${ext}`, 'utf-8'); | ||
|
||
const methods = {}; | ||
for (const path of paths) { | ||
const testConfig = yaml.load(fs.readFileSync(path, 'utf8')); | ||
|
||
const template = templates[`${testConfig.template}.tpl.${ext}`]; | ||
|
||
const snippetName = testConfig.name.toLowerCase().replace(/ /g, '_').replace(/-/g, '_').replace(/#/g,''); | ||
|
||
const snippetCode = extractCode(fs.readFileSync(path.replace('.test.yml', `.${ext}`), 'utf8')); | ||
|
||
const snippet = template.replace('[snippet-code]', snippetCode); | ||
methods[snippetName] = methodTemplate.replace('[snippet-name]', snippetName).replace('[snippet-code]', snippet); | ||
} | ||
|
||
return methods; | ||
} | ||
|
||
/** | ||
* Build each snippet in a static method and bundle every method in a single file | ||
* ready to be compiled | ||
* | ||
* @param {*} paths | ||
* @param {*} ext | ||
* @param {*} templates | ||
*/ | ||
function bundleAndBuildTests(paths, ext, templates) { | ||
const methods = buildSnippetMethods(paths, ext, templates); | ||
|
||
const mainTemplate = fs.readFileSync(`./templates/main.${ext}`, 'utf8'); | ||
|
||
const buildedSnippets = Object.keys(methods).map(key => methods[key]).join('\n'); | ||
|
||
|
||
const program = mainTemplate.replace('[builded-snippets]', buildedSnippets); | ||
fs.writeFileSync(`${buildDir}/SnippetTest.${ext}`, program); | ||
} | ||
|
||
async function main() { | ||
const templatesPath = glob.sync(snippetTemplatesPath); | ||
const templates = {} | ||
for (const path of templatesPath) { | ||
templates[Path.basename(path)] = fs.readFileSync(path, 'utf8'); | ||
} | ||
|
||
bundleAndBuildTests(glob.sync(javaSnippetPath), 'java', templates); | ||
bundleAndBuildTests(glob.sync(kotlinSnippetPath), 'kt', templates); | ||
} | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "builder", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "builder.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"glob": "^7.2.0", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
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,39 @@ | ||
import io.kuzzle.sdk.Kuzzle; | ||
import io.kuzzle.sdk.protocol.*; | ||
import io.kuzzle.sdk.coreClasses.responses.Response; | ||
import io.kuzzle.sdk.coreClasses.SearchResult; | ||
import io.kuzzle.sdk.coreClasses.lang.Lang; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.*; | ||
|
||
public class SnippetTest { | ||
|
||
[builded-snippets] | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 1) { | ||
System.err.println("Missing snippet name to execute"); | ||
System.exit(1); | ||
} | ||
|
||
// Format the snippet name into the method name | ||
// Convert "java-searchresultscroll_3e8f25b" into "java_searchresultscroll" | ||
String methodName = args[0].toLowerCase().replace("-","_").substring(0, args[0].length() - 8); | ||
|
||
try { | ||
// Find the static method that has the given name using reflection | ||
Method method = SnippetTest.class.getMethod(methodName); | ||
// Execute the static method | ||
method.invoke(null); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
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,30 @@ | ||
import io.kuzzle.sdk.Kuzzle | ||
import io.kuzzle.sdk.protocol.* | ||
import io.kuzzle.sdk.coreClasses.responses.Response | ||
import io.kuzzle.sdk.coreClasses.SearchResult | ||
import io.kuzzle.sdk.coreClasses.lang.Lang | ||
import io.kuzzle.sdk.coreClasses.maps.KuzzleMap | ||
import java.lang.reflect.Method | ||
import java.util.*; | ||
import kotlin.system.exitProcess | ||
|
||
public class Snippets { | ||
[builded-snippets] | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
if (args.isEmpty()) { | ||
println("Missing snippet name to execute") | ||
exitProcess(1) | ||
} | ||
|
||
// Format the snippet name into the method name | ||
// Convert "kotlin-searchresultscroll_3e8f25b" into "kotlin_searchresultscroll" | ||
val methodName: String = args[0].lowercase().replace('-', '_').substring(0, args[0].length - 8) | ||
|
||
var snippets: Snippets = Snippets() | ||
// Find the method that has the given name using reflection | ||
var method: Method = snippets.javaClass.getMethod(methodName) | ||
// execute method | ||
method.invoke(snippets) | ||
} |
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,4 @@ | ||
public static void [snippet-name]() { | ||
Kuzzle kuzzle = null; | ||
[snippet-code] | ||
} |
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 @@ | ||
fun [snippet-name]() { | ||
[snippet-code] | ||
} |
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
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
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,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "Wait for Snippets to be built and bundled" | ||
timeout 600 bash -c 'until stat /mnt/build/SnippetTest.java > /dev/null && stat /mnt/build/SnippetTest.kt > /dev/null; do sleep 1; done' | ||
echo "Building SDK" | ||
cd /mnt && ./gradlew jar | ||
echo "Copying SDK" | ||
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/java-project/libs/sdk-jvm-without-dependencies.jar | ||
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/kotlin-project/libs/sdk-jvm-without-dependencies.jar | ||
echo "Copying Java Snippets" | ||
cp /mnt/build/SnippetTest.java /mnt/.ci/doc/java-project/src/main/java/SnippetTest.java | ||
echo "Copying Kotlin Snippets" | ||
cp /mnt/build/SnippetTest.kt /mnt/.ci/doc/kotlin-project/src/main/java/SnippetTest.kt | ||
echo "Building Java executable" | ||
cd /mnt/.ci/doc/java-project/ && ./gradlew build | ||
echo "Building Kotlin executable" | ||
cd /mnt/.ci/doc/kotlin-project/ && ./gradlew build | ||
echo "Wait for Kuzzle to be ready" | ||
timeout 600 bash -c 'until stat /tmp/runner_is_ready && curl -f -s -o /dev/null http://kuzzle:7512/_now; do sleep 1; done' |
Oops, something went wrong.