13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package org .culturegraph .mf ;
17
-
18
- import java .io .File ;
19
- import java .io .FilenameFilter ;
20
- import java .io .IOException ;
21
- import java .io .InputStream ;
22
- import java .net .URL ;
23
- import java .net .URLClassLoader ;
24
- import java .util .HashMap ;
25
- import java .util .LinkedList ;
26
- import java .util .List ;
27
- import java .util .Map ;
28
- import java .util .regex .Matcher ;
29
- import java .util .regex .Pattern ;
30
-
31
- import org .antlr .runtime .ANTLRInputStream ;
32
- import org .antlr .runtime .CommonTokenStream ;
33
- import org .antlr .runtime .RecognitionException ;
34
- import org .antlr .runtime .tree .CommonTreeNodeStream ;
35
- import org .culturegraph .mf .flux .Flow ;
36
- import org .culturegraph .mf .flux .parser .FlowBuilder ;
37
- import org .culturegraph .mf .flux .parser .FluxLexer ;
38
- import org .culturegraph .mf .flux .parser .FluxParser ;
39
- import org .culturegraph .mf .util .ResourceUtil ;
40
-
41
-
42
- /**
43
- * @author Markus Michael Geipel
44
- *
45
- */
46
- public final class Flux {
47
- public static final String MODULES_DIR = "modules" ;
48
- private static final Pattern VAR_PATTERN = Pattern .compile ("([^=]*)=(.*)" );
49
- private static final String SCRIPT_HOME = "FLUX_DIR" ;
50
-
51
- private Flux () {
52
- // no instances
53
- }
54
-
55
- /**
56
- * @param args
57
- * @throws IOException
58
- * @throws RecognitionException
59
- */
60
- public static void main (final String [] args ) throws IOException , RecognitionException {
61
-
62
- final File modulesDir = new File (MODULES_DIR );
63
- if (modulesDir .exists ()) {
64
- final FilenameFilter filter = new FilenameFilter () {
65
- @ Override
66
- public boolean accept (final File dir , final String name ) {
67
- return name .endsWith (".jar" ) || name .endsWith (".class" );
68
- }
69
- };
70
- final List <URL > moduleURLs = new LinkedList <URL >();
71
- for (File file : modulesDir .listFiles (filter )) {
72
- moduleURLs .add (file .getAbsoluteFile ().toURI ().toURL ());
73
- }
74
- final URLClassLoader moduleLoader = new URLClassLoader (moduleURLs .toArray (new URL [0 ]), Thread
75
- .currentThread ().getContextClassLoader ());
76
- Thread .currentThread ().setContextClassLoader (moduleLoader );
77
- }
78
-
79
- if (args .length < 1 ) {
80
- Flow .printHelp ();
81
- System .exit (2 );
82
- return ;
83
- }
84
-
85
- final File fluxFile = new File (args [0 ]);
86
- if (!fluxFile .exists ()){
87
- System .err .println ("File not found: " + args [0 ]);
88
- System .exit (1 );
89
- return ;
90
- }
91
-
92
-
93
- // get variable assignments
94
- final Map <String , String > vars = new HashMap <String , String >();
95
- vars .put (SCRIPT_HOME , fluxFile .getAbsoluteFile ().getParent () + System .getProperty ("file.separator" ));
96
-
97
-
98
- for (int i = 1 ; i < args .length ; ++i ) {
99
- final Matcher matcher = VAR_PATTERN .matcher (args [i ]);
100
- if (!matcher .find ()) {
101
- Flow .printHelp ();
102
- return ;
103
- }
104
- vars .put (matcher .group (1 ), matcher .group (2 ));
105
- }
106
-
107
- // run parser and builder
108
- final Flow flow = compileFlow (compileAst (ResourceUtil .getStream (fluxFile )), vars );
109
- flow .start ();
110
- }
111
-
112
- public static CommonTreeNodeStream compileAst (final InputStream flowDef ) throws IOException , RecognitionException {
113
- final FluxParser parser = new FluxParser (new CommonTokenStream (new FluxLexer (new ANTLRInputStream (
114
- flowDef ))));
115
- return new CommonTreeNodeStream (parser .flux ().getTree ());
116
- }
117
-
118
- public static Flow compileFlow (final CommonTreeNodeStream treeNodes , final Map <String , String > vars )
119
- throws RecognitionException {
120
- final FlowBuilder flowBuilder = new FlowBuilder (treeNodes );
121
- flowBuilder .addVaribleAssignements (vars );
122
- final Flow flow = flowBuilder .flux ();
123
- return flow ;
124
- }
16
+ package org .culturegraph .mf ;
17
+
18
+ import java .io .File ;
19
+ import java .io .FilenameFilter ;
20
+ import java .io .IOException ;
21
+ import java .io .InputStream ;
22
+ import java .net .URL ;
23
+ import java .net .URLClassLoader ;
24
+ import java .util .HashMap ;
25
+ import java .util .LinkedList ;
26
+ import java .util .List ;
27
+ import java .util .Map ;
28
+ import java .util .regex .Matcher ;
29
+ import java .util .regex .Pattern ;
30
+
31
+ import org .antlr .runtime .ANTLRInputStream ;
32
+ import org .antlr .runtime .CommonTokenStream ;
33
+ import org .antlr .runtime .RecognitionException ;
34
+ import org .antlr .runtime .tree .CommonTreeNodeStream ;
35
+ import org .culturegraph .mf .flux .Flow ;
36
+ import org .culturegraph .mf .flux .parser .FlowBuilder ;
37
+ import org .culturegraph .mf .flux .parser .FluxLexer ;
38
+ import org .culturegraph .mf .flux .parser .FluxParser ;
39
+ import org .culturegraph .mf .util .ResourceUtil ;
40
+
41
+ /**
42
+ * @author Markus Michael Geipel
43
+ *
44
+ */
45
+ public final class Flux {
46
+ public static final String MODULES_DIR = "modules" ;
47
+ private static final Pattern VAR_PATTERN = Pattern .compile ("([^=]*)=(.*)" );
48
+ private static final String SCRIPT_HOME = "FLUX_DIR" ;
49
+
50
+ private Flux () {
51
+ // no instances
52
+ }
53
+
54
+ /**
55
+ * @param args
56
+ * @throws IOException
57
+ * @throws RecognitionException
58
+ */
59
+ public static void main (final String [] args ) throws IOException , RecognitionException {
60
+
61
+ final File modulesDir = new File (MODULES_DIR );
62
+ if (modulesDir .exists ()) {
63
+ final FilenameFilter filter = new FilenameFilter () {
64
+ @ Override
65
+ public boolean accept (final File dir , final String name ) {
66
+ return name .endsWith (".jar" ) || name .endsWith (".class" );
67
+ }
68
+ };
69
+ final List <URL > moduleURLs = new LinkedList <URL >();
70
+ for (File file : modulesDir .listFiles (filter )) {
71
+ moduleURLs .add (file .getAbsoluteFile ().toURI ().toURL ());
72
+ }
73
+ final URLClassLoader moduleLoader = new URLClassLoader (moduleURLs .toArray (new URL [0 ]), Thread
74
+ .currentThread ().getContextClassLoader ());
75
+ Thread .currentThread ().setContextClassLoader (moduleLoader );
76
+ }
77
+
78
+ if (args .length < 1 ) {
79
+ Flow .printHelp (System .out );
80
+ System .exit (2 );
81
+ } else {
82
+
83
+ final File fluxFile = new File (args [0 ]);
84
+ if (!fluxFile .exists ()) {
85
+ System .err .println ("File not found: " + args [0 ]);
86
+ System .exit (1 );
87
+ return ;
88
+ }
89
+
90
+ // get variable assignments
91
+ final Map <String , String > vars = new HashMap <String , String >();
92
+ vars .put (SCRIPT_HOME , fluxFile .getAbsoluteFile ().getParent () + System .getProperty ("file.separator" ));
93
+
94
+ for (int i = 1 ; i < args .length ; ++i ) {
95
+ final Matcher matcher = VAR_PATTERN .matcher (args [i ]);
96
+ if (!matcher .find ()) {
97
+ Flow .printHelp (System .err );
98
+ return ;
99
+ }
100
+ vars .put (matcher .group (1 ), matcher .group (2 ));
101
+ }
102
+
103
+ // run parser and builder
104
+ final Flow flow = compileFlow (compileAst (ResourceUtil .getStream (fluxFile )), vars );
105
+ flow .start ();
106
+ }
107
+ }
108
+
109
+ public static CommonTreeNodeStream compileAst (final InputStream flowDef ) throws IOException , RecognitionException {
110
+ final FluxParser parser = new FluxParser (new CommonTokenStream (new FluxLexer (new ANTLRInputStream (flowDef ))));
111
+ return new CommonTreeNodeStream (parser .flux ().getTree ());
112
+ }
113
+
114
+ public static Flow compileFlow (final CommonTreeNodeStream treeNodes , final Map <String , String > vars )
115
+ throws RecognitionException {
116
+ final FlowBuilder flowBuilder = new FlowBuilder (treeNodes );
117
+ flowBuilder .addVaribleAssignements (vars );
118
+ final Flow flow = flowBuilder .flux ();
119
+ return flow ;
120
+ }
125
121
}
0 commit comments