Dynamic calls from java to Groovy workspace DSL

This commit is contained in:
darksnake 2016-08-17 16:43:46 +03:00
parent 867ace2d79
commit 154ff33bbd
9 changed files with 79 additions and 29 deletions

View File

@ -32,3 +32,12 @@ task listActions(dependsOn: classes, type: JavaExec) {
description "print a list of available actions as via -lc command line parameter" description "print a list of available actions as via -lc command line parameter"
group "numass" group "numass"
} }
task workspace(dependsOn: classes, type: JavaExec) {
main 'inr.numass.workspace.NumassGrindLauncher'
classpath = sourceSets.main.runtimeClasspath
args "-c \"D:\\Work\\Numass\\sterile2016\\workspace.groovy\" numass.fitsum sum".split()
description "Run workspace task"
group "numass"
}

View File

@ -18,10 +18,10 @@ package inr.numass
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import hep.dataforge.grind.WorkspaceSpec import hep.dataforge.grind.WorkspaceSpec
import inr.numass.tasks.NumassFitScanSummaryTask import inr.numass.workspace.NumassFitScanSummaryTask
import inr.numass.tasks.NumassFitScanTask import inr.numass.workspace.NumassFitScanTask
import inr.numass.tasks.NumassPrepareTask import inr.numass.workspace.NumassPrepareTask
import inr.numass.tasks.NumassTableFilterTask import inr.numass.workspace.NumassTableFilterTask
/** /**
* Created by darksnake on 16-Aug-16. * Created by darksnake on 16-Aug-16.

View File

@ -1,18 +0,0 @@
package inr.numass.tasks;
import hep.dataforge.grind.JavaGrindLauncher;
import inr.numass.NumassWorkspaceSpec;
import java.io.File;
/**
* Created by darksnake on 12-Aug-16.
*/
public class NumassGrindLauncher {
public static void main(String[] args) throws Exception {
JavaGrindLauncher.buildWorkspace(new File("D:\\Work\\Numass\\sterile2016\\workspace.groovy"), NumassWorkspaceSpec.class)
.runTask("numass.fitsum", "fill_3").computeAll();
}
}

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package inr.numass.tasks; package inr.numass.workspace;
import hep.dataforge.actions.Action; import hep.dataforge.actions.Action;
import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.actions.ManyToOneAction;

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package inr.numass.tasks; package inr.numass.workspace;
import hep.dataforge.actions.Action; import hep.dataforge.actions.Action;
import hep.dataforge.computation.WorkManager; import hep.dataforge.computation.WorkManager;

View File

@ -0,0 +1,59 @@
package inr.numass.workspace;
import hep.dataforge.data.DataNode;
import hep.dataforge.grind.JavaGrindLauncher;
import hep.dataforge.meta.Meta;
import hep.dataforge.workspace.Workspace;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by darksnake on 12-Aug-16.
*/
public class NumassGrindLauncher {
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption("c", "config", true, "Configuration file for workspace");
options.addOption("o", "overlay", false, "If meta with the same name as parameter exist in the workspace, use it as lower layer");
CommandLine cli = new DefaultParser().parse(options, args);
String cfgPath = cli.getOptionValue('c', "workspace.groovy");
List<String> arglist = cli.getArgList();
Workspace workspace = JavaGrindLauncher.buildWorkspace(new File(cfgPath), "inr.numass.NumassWorkspaceSpec");
if (arglist.size() == 0) {
new HelpFormatter().printHelp("launcher [opts] <task name> <meta name / meta>", options);
return;
} else if (arglist.size() == 1) {
String taskName = arglist.get(0);
workspace.runTask(taskName, taskName);
} else {
String taskName = arglist.get(0);
String theRest = arglist.stream().skip(1).collect(Collectors.joining());
DataNode node;
if (theRest.contains("{") || theRest.contains("(")) {
Meta meta = JavaGrindLauncher.buildMeta(theRest);
boolean overlay = cli.hasOption("o");
node = workspace.runTask(taskName, meta, overlay);
} else {
node = workspace.runTask(taskName, theRest);
}
node.computeAll();
}
//
// JavaGrindLauncher.buildWorkspace(new File(cfgPath), NumassWorkspaceSpec.class)
// .runTask("numass.fitsum", "sum").computeAll();
}
}

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package inr.numass.tasks; package inr.numass.workspace;
import hep.dataforge.actions.Action; import hep.dataforge.actions.Action;
import hep.dataforge.computation.WorkManager; import hep.dataforge.computation.WorkManager;

View File

@ -1,4 +1,4 @@
package inr.numass.tasks; package inr.numass.workspace;
import hep.dataforge.actions.OneToOneAction; import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.computation.WorkManager; import hep.dataforge.computation.WorkManager;

View File

@ -19,7 +19,7 @@ includeProjects(rootDir, '')
File dataforgeDir = new File(rootDir,'../dataforge'); File dataforgeDir = new File(rootDir,'../dataforge');
if(dataforgeDir.exists()){ if(dataforgeDir.exists()){
// include 'dataforge' includeFlat "dataforge"
// project(':dataforge').projectDir = dataforgeDir
includeProjects(dataforgeDir,'') includeProjects(dataforgeDir,'')
} }