1 | #!/bin/bash |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # RAPPTURE 2 CISHELL |
---|
4 | # |
---|
5 | # Developed this script as part of the 2012 JSMF Workshop on |
---|
6 | # Plug-and-Play Macroscopes, Nov 16-17 at Indiana University. |
---|
7 | # |
---|
8 | # Takes a Rappture tool.xml files and updates an existing CIShell |
---|
9 | # project. General workflow is: |
---|
10 | # 1) Create a new project for the plug-in in CIShell |
---|
11 | # 2) Run this script: rp2ci tool.xml projectName |
---|
12 | # 3) Export the project from Eclipse into CIShell |
---|
13 | # |
---|
14 | # ====================================================================== |
---|
15 | # AUTHOR: Michael McLennan, Purdue University |
---|
16 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
17 | # |
---|
18 | # See the file "license.terms" for information on usage and |
---|
19 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
20 | # ====================================================================== |
---|
21 | #\ |
---|
22 | exec tclsh "$0" "$@" |
---|
23 | |
---|
24 | package require Rappture |
---|
25 | |
---|
26 | if {$argc != 2} { |
---|
27 | puts stderr "usage: rp2ci tool.xml projectName" |
---|
28 | exit 1 |
---|
29 | } |
---|
30 | set rpFile [lindex $argv 0] |
---|
31 | set projName [lindex $argv 1] |
---|
32 | |
---|
33 | if {[catch {Rappture::library $rpFile} tool]} { |
---|
34 | puts stderr "can't load tool.xml from $rpFile" |
---|
35 | exit 1 |
---|
36 | } |
---|
37 | |
---|
38 | if {![file isdirectory $projName]} { |
---|
39 | puts stderr "can't find project $projName" |
---|
40 | exit 1 |
---|
41 | } |
---|
42 | if {![file exists [file join $projName META-INF]]} { |
---|
43 | puts stderr "not a CIShell project: $projName" |
---|
44 | exit 1 |
---|
45 | } |
---|
46 | |
---|
47 | # build up a string of inputs for METADATA.XML |
---|
48 | set ADs "" |
---|
49 | set inputs "" |
---|
50 | foreach path [Rappture::entities -as path $tool input] { |
---|
51 | set name [$tool element -as id $path] |
---|
52 | set label [$tool get $path.about.label] |
---|
53 | set desc [$tool get $path.about.description] |
---|
54 | set default [$tool get $path.default] |
---|
55 | append ADs "<AD name=\"$label\" id=\"$name\" type=\"String\" description=\"$desc\" default=\"$default\"/>\n" |
---|
56 | append inputs "String $name = (String) parameters.get(\"$name\");\n" |
---|
57 | } |
---|
58 | |
---|
59 | set fid [open [file join $projName OSGI-INF metatype METADATA.XML] r] |
---|
60 | set info [read $fid] |
---|
61 | close $fid |
---|
62 | |
---|
63 | if {[regsub {>[ \t\n]*</OCD>} $info ">\n$ADs</OCD>" info] != 1} { |
---|
64 | error "failed to add inputs to METADATA.XML" |
---|
65 | } |
---|
66 | set fid [open [file join $projName OSGI-INF metatype METADATA.XML] w] |
---|
67 | puts -nonewline $fid $info |
---|
68 | close $fid |
---|
69 | |
---|
70 | # Find the algorithm code |
---|
71 | set dir [file join $projName src] |
---|
72 | set found 0 |
---|
73 | while {!$found} { |
---|
74 | foreach fname [glob [file join $dir *]] { |
---|
75 | if {[string match *Algorithm.java $fname]} { |
---|
76 | set found 1 |
---|
77 | break |
---|
78 | } elseif {[file isdirectory $fname]} { |
---|
79 | set dir $fname |
---|
80 | break |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | # Find stuff in the file... |
---|
86 | set fid [open $fname r] |
---|
87 | set algorithm [read $fid] |
---|
88 | close $fid |
---|
89 | |
---|
90 | if {![regexp {package org\.([^;]+);} $algorithm match pkg]} { |
---|
91 | error "can't find package name in algorithm" |
---|
92 | } |
---|
93 | if {![regexp {public +class +([^ ]+)} $algorithm match class]} { |
---|
94 | error "can't find class name in algorithm" |
---|
95 | } |
---|
96 | |
---|
97 | # Make substitutions... |
---|
98 | set template { |
---|
99 | package org.@@PACKAGE@@; |
---|
100 | |
---|
101 | import java.util.Dictionary; |
---|
102 | |
---|
103 | import org.cishell.framework.CIShellContext; |
---|
104 | import org.cishell.framework.algorithm.Algorithm; |
---|
105 | import org.cishell.framework.algorithm.AlgorithmExecutionException; |
---|
106 | import org.cishell.framework.data.Data; |
---|
107 | import org.osgi.service.log.LogService; |
---|
108 | |
---|
109 | public class @@CLASS@@ implements Algorithm { |
---|
110 | private Data[] data; |
---|
111 | private Dictionary parameters; |
---|
112 | private CIShellContext ciShellContext; |
---|
113 | private LogService logger; |
---|
114 | |
---|
115 | public @@CLASS@@(Data[] data, |
---|
116 | Dictionary parameters, |
---|
117 | CIShellContext ciShellContext) { |
---|
118 | this.data = data; |
---|
119 | this.parameters = parameters; |
---|
120 | this.ciShellContext = ciShellContext; |
---|
121 | this.logger = (LogService) ciShellContext.getService(LogService.class.getName()); |
---|
122 | } |
---|
123 | |
---|
124 | public Data[] execute() throws AlgorithmExecutionException { |
---|
125 | @@INPUTS@@ |
---|
126 | this.logger.log(LogService.LOG_INFO, "Rappture tool: @@TOOL@@"); |
---|
127 | |
---|
128 | // |
---|
129 | // Fix this to exec tool and return output... |
---|
130 | // |
---|
131 | return null; |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | set newalg [string map [list \ |
---|
137 | @@PACKAGE@@ $pkg \ |
---|
138 | @@CLASS@@ $class \ |
---|
139 | @@INPUTS@@ $inputs \ |
---|
140 | @@TOOL@@ [$tool get tool.title] \ |
---|
141 | ] $template] |
---|
142 | |
---|
143 | set fid [open $fname w] |
---|
144 | puts -nonewline $fid $newalg |
---|
145 | close $fid |
---|