Skip to content

Commit

Permalink
java plug - class autodetect + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Aug 3, 2020
1 parent 38161cf commit 0b542cc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ You can also hide test execution from event history/stats.
![image](https://user-images.githubusercontent.com/31977106/88609937-554a0a00-d053-11ea-871c-5cbaa4e3d670.png)

## Event Dashboard
A custom implementation of Event History using DataTables.net, it pulls last 1000 jobs and adds some better filtering options. It's also a demo of custom UI complonent (independent from default framework). To open it - go to history page and click on **Event Dashboard** link
A custom implementation of Event History using DataTables.net, it pulls last 1000 jobs and adds some extra filtering options. It's also a demo of custom UI component (independent from default framework). To open it - go to history page and click on **Event Dashboard** link
![image](https://user-images.githubusercontent.com/31977106/88610206-0ea8df80-d054-11ea-938c-29d7dcf74b8d.png)

## Java plugin
If open jdk is installed on your machine you can run java classes as scripts (plugin will take care of creating/compiling/removing temp files). You can also customize classpath and JAVA_HOME (custom java version) using plugin parameters. By default you can put dependency jars (e.g. jdbc drivers) in bin/jars folder.
![image](https://user-images.githubusercontent.com/31977106/89139670-74daaa00-d50d-11ea-91d6-45572e162843.png)

## Minor updates:
- **edit** button added on completed job detail page (for easy back and forth navigation)
- last N occurences filter on history page (**Max rows per event**)
Expand Down
6 changes: 4 additions & 2 deletions bin/java-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ process.stdout.setEncoding('utf8');
var stream = new JSONStream( process.stdin, process.stdout );
stream.on('json', function(job) {
// got job from parent

var className = job.params.class_name || job.event_title;
var commentRg = /\/\*[^]*?\*\/\s*/g ;
var classNameRg = /(?<=^\s*(?:public\s+)?class\s+)(\w+?)(?=[\s|{])/gm
// get class name from parameter, then autodetect from script then event name
var className = job.params.class_name || (job.params.script.replace(commentRg, '').match(classNameRg) || [job.event_title])[0];
var tmpDir = fs.mkdtempSync(path.join(os.tmpdir(),job.id))
var classPath = (job.params.classpath || path.join(__dirname, 'jars/*')) + ':' + tmpDir;
process.env['CLASSPATH'] = classPath;
Expand Down
5 changes: 2 additions & 3 deletions htdocs/js/pages/Schedule.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1604,14 +1604,13 @@ Class.subclass(Page.Base, "Page.Schedule", {
html += '<div class="plugin_params_label">' + param.title + '</div>';
html += '<div class="plugin_params_content"><input type="text" id="fe_ee_pp_' + param.id + '" size="' + param.size + '" value="' + escape_text_field_value(value) + '" spellcheck="false"/></div>';
if(param.id == 'classpath') {
html += '<script>document.getElementById("fe_ee_pp_classpath").title="[optional] Specify jar file or folder to extend default classpath (use * wildcard for folders, e.g. /my/dir/*). By default you can use bin/jars directory to add extra jars to your script"</script>'

html += '<script>document.getElementById("fe_ee_pp_classpath").title="[optional] Specify jar file or folder to override default classpath (use * wildcard for folders, e.g. /my/dir/*). By default you can use bin/jars directory to add extra jars to your script"</script>'
}
if(param.id == 'java_home') {
html += '<script>document.getElementById("fe_ee_pp_java_home").title="[optional] Specify custom JAVA_HOME location to resolve java/javac executables (typically located in JAVA_HOME/bin). This is useful if you only have binaries or multiple java versions. By default it will be resolved from the environment."</script>'
}
if(param.id == 'class_name') {
html += '<script>document.getElementById("fe_ee_pp_class_name").title="Specify which class to run. If not set event name will be used"</script>'
html += '<script>document.getElementById("fe_ee_pp_class_name").title="[optional] Specify which class to run (useful if multiple classes are defined). By default plugin will detect and run first available class, so to be safe place your primary class at the top of the script"</script>'
}
break;

Expand Down
2 changes: 1 addition & 1 deletion sample_conf/setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"modified":1596302507,
"created":1596242530,
"params":[
{"type":"text","id":"class_name","title":"Class Name","size":20,"value":"MyClass"},
{"type":"text","id":"class_name","title":"Class Name","size":20,"value":""},
{"type":"textarea","id":"script","title":"java code:","rows":20,"value":"// jars in bin/jars will be added to classpath\n\nclass MyClass {\n public static void main(String[] args) {\n \n // your code here\n System.out.println(\"Hello from MyClass\");\n \n }\n}"},
{"type":"select","id":"theme","title":"theme","items":["default","darcula"],"value":"default"},
{"type":"hidden","id":"default_lang","title":"def lang","value":"text/x-java"},
Expand Down

0 comments on commit 0b542cc

Please sign in to comment.