Revision 1159
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.scripting</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<version>2.3.81</version> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description>Scripting Framework for gvSIG</description> |
|
10 |
<url>http://devel.gvsig.org/sites/org.gvsig.scripting/${project.version}</url> |
|
11 |
|
|
12 |
<parent> |
|
13 |
<groupId>org.gvsig</groupId> |
|
14 |
<artifactId>org.gvsig.desktop</artifactId> |
|
15 |
<version>2.0.256</version> |
|
16 |
</parent> |
|
17 |
|
|
18 |
<scm> |
|
19 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81</url> |
|
22 |
</scm> |
|
23 |
<developers> |
|
24 |
<developer> |
|
25 |
<id>jjdelcerro</id> |
|
26 |
<name>Joaquín José del Cerro</name> |
|
27 |
<email>jjdelcerro@gvsig.org</email> |
|
28 |
<roles> |
|
29 |
<role>Architect</role> |
|
30 |
<role>Developer</role> |
|
31 |
</roles> |
|
32 |
</developer> |
|
33 |
<developer> |
|
34 |
<id>jbadia</id> |
|
35 |
<name>José Badía</name> |
|
36 |
<email>badia_jos@gva.es</email> |
|
37 |
<roles> |
|
38 |
<role>Developer</role> |
|
39 |
</roles> |
|
40 |
</developer> |
|
41 |
</developers> |
|
42 |
|
|
43 |
<distributionManagement> |
|
44 |
<site> |
|
45 |
<id>gvsig-repository</id> |
|
46 |
<url>dav:https://devel.gvsig.org/sites/org.gvsig.scripting/${project.version}</url> |
|
47 |
</site> |
|
48 |
</distributionManagement> |
|
49 |
<repositories> |
|
50 |
<repository> |
|
51 |
<id>gvsig-public-http-repository</id> |
|
52 |
<name>gvSIG maven public HTTP repository</name> |
|
53 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
54 |
<releases> |
|
55 |
<enabled>true</enabled> |
|
56 |
<updatePolicy>daily</updatePolicy> |
|
57 |
<checksumPolicy>warn</checksumPolicy> |
|
58 |
</releases> |
|
59 |
<snapshots> |
|
60 |
<enabled>true</enabled> |
|
61 |
<updatePolicy>daily</updatePolicy> |
|
62 |
<checksumPolicy>warn</checksumPolicy> |
|
63 |
</snapshots> |
|
64 |
</repository> |
|
65 |
<repository> |
|
66 |
<id>bedatadriven</id> |
|
67 |
<name>bedatadriven public repo</name> |
|
68 |
<url>http://nexus.bedatadriven.com/content/groups/public/</url> |
|
69 |
</repository> |
|
70 |
</repositories> |
|
71 |
<build> |
|
72 |
<plugins> |
|
73 |
<plugin> |
|
74 |
<groupId>org.apache.maven.plugins</groupId> |
|
75 |
<artifactId>maven-release-plugin</artifactId> |
|
76 |
<configuration> |
|
77 |
<tagBase>https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags</tagBase> |
|
78 |
</configuration> |
|
79 |
</plugin> |
|
80 |
|
|
81 |
</plugins> |
|
82 |
</build> |
|
83 |
|
|
84 |
<dependencyManagement> |
|
85 |
<dependencies> |
|
86 |
<dependency> |
|
87 |
<groupId>org.gvsig</groupId> |
|
88 |
<artifactId>org.gvsig.scripting.lib.api</artifactId> |
|
89 |
<version>2.3.81</version> |
|
90 |
</dependency> |
|
91 |
<dependency> |
|
92 |
<groupId>org.gvsig</groupId> |
|
93 |
<artifactId>org.gvsig.scripting.swing.api</artifactId> |
|
94 |
<version>2.3.81</version> |
|
95 |
</dependency> |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.scripting.lib.impl</artifactId> |
|
99 |
<version>2.3.81</version> |
|
100 |
</dependency> |
|
101 |
<dependency> |
|
102 |
<groupId>org.gvsig</groupId> |
|
103 |
<artifactId>org.gvsig.scripting.swing.impl</artifactId> |
|
104 |
<version>2.3.81</version> |
|
105 |
</dependency> |
|
106 |
|
|
107 |
<dependency> |
|
108 |
<groupId>org.gvsig</groupId> |
|
109 |
<artifactId>org.gvsig.scripting.main</artifactId> |
|
110 |
<version>2.3.81</version> |
|
111 |
</dependency> |
|
112 |
|
|
113 |
<dependency> |
|
114 |
<groupId>org.gvsig</groupId> |
|
115 |
<artifactId>org.gvsig.scripting.thing</artifactId> |
|
116 |
<version>2.3.81</version> |
|
117 |
</dependency> |
|
118 |
|
|
119 |
<dependency> |
|
120 |
<groupId>org.gvsig</groupId> |
|
121 |
<artifactId>org.gvsig.scripting.app.mainplugin</artifactId> |
|
122 |
<version>2.3.81</version> |
|
123 |
</dependency> |
|
124 |
|
|
125 |
<dependency> |
|
126 |
<groupId>com.github.tbekolay.jnumeric</groupId> |
|
127 |
<artifactId>jnumeric</artifactId> |
|
128 |
<version>0.1</version> |
|
129 |
</dependency> |
|
130 |
|
|
131 |
<dependency> |
|
132 |
<groupId>org.renjin</groupId> |
|
133 |
<artifactId>renjin-script-engine</artifactId> |
|
134 |
<version>0.9.2644</version> |
|
135 |
<classifier>jar-with-dependencies</classifier> |
|
136 |
</dependency> |
|
137 |
|
|
138 |
<!-- |
|
139 |
<dependency> |
|
140 |
<groupId>org.scala-lang</groupId> |
|
141 |
<artifactId>scala-dist</artifactId> |
|
142 |
<version>2.12.0-M2</version> |
|
143 |
<scope>runtime</scope> |
|
144 |
<exclusions> |
|
145 |
<exclusion> |
|
146 |
<groupId>org.scala-lang</groupId> |
|
147 |
<artifactId>scala-library-all</artifactId> |
|
148 |
</exclusion> |
|
149 |
</exclusions> |
|
150 |
</dependency> |
|
151 |
<dependency> |
|
152 |
<groupId>org.scala-lang</groupId> |
|
153 |
<artifactId>scala-compiler</artifactId> |
|
154 |
<version>2.12.0-M2</version> |
|
155 |
</dependency> |
|
156 |
<dependency> |
|
157 |
<groupId>org.scala-lang</groupId> |
|
158 |
<artifactId>scala-library</artifactId> |
|
159 |
<version>2.12.0-M2</version> |
|
160 |
</dependency> |
|
161 |
<dependency> |
|
162 |
<groupId>org.scala-lang</groupId> |
|
163 |
<artifactId>scala-reflect</artifactId> |
|
164 |
<version>2.12.0-M2</version> |
|
165 |
</dependency> |
|
166 |
<dependency> |
|
167 |
<groupId>org.scala-lang</groupId> |
|
168 |
<artifactId>scalap</artifactId> |
|
169 |
<version>2.12.0-M2</version> |
|
170 |
</dependency> |
|
171 |
<dependency> |
|
172 |
<groupId>jline</groupId> |
|
173 |
<artifactId>jline</artifactId> |
|
174 |
<version>2.12.1</version> |
|
175 |
</dependency> |
|
176 |
--> |
|
177 |
|
|
178 |
<dependency> |
|
179 |
<groupId>com.jeta</groupId> |
|
180 |
<artifactId>abeille</artifactId> |
|
181 |
<version>2.1.0.M3</version> |
|
182 |
<type>tar.gz</type> |
|
183 |
</dependency> |
|
184 |
|
|
185 |
<dependency> |
|
186 |
<groupId>org.apache.tika</groupId> |
|
187 |
<artifactId>tika-core</artifactId> |
|
188 |
<version>1.12</version> |
|
189 |
</dependency> |
|
190 |
<dependency> |
|
191 |
<groupId>net.sf.cssbox</groupId> |
|
192 |
<artifactId>swingbox</artifactId> |
|
193 |
<version>1.1</version> |
|
194 |
</dependency> |
|
195 |
<dependency> |
|
196 |
<groupId>net.sf.cssbox</groupId> |
|
197 |
<artifactId>cssbox</artifactId> |
|
198 |
<version>4.7</version> |
|
199 |
</dependency> |
|
200 |
<dependency> |
|
201 |
<groupId>net.sourceforge.nekohtml</groupId> |
|
202 |
<artifactId>nekohtml</artifactId> |
|
203 |
<version>1.9.21</version> |
|
204 |
</dependency> |
|
205 |
<dependency> |
|
206 |
<groupId>net.sf.cssbox</groupId> |
|
207 |
<artifactId>jstyleparser</artifactId> |
|
208 |
<version>1.18</version> |
|
209 |
</dependency> |
|
210 |
<dependency> |
|
211 |
<groupId>org.eclipse.jgit</groupId> |
|
212 |
<artifactId>org.eclipse.jgit</artifactId> |
|
213 |
<version>4.9.0.201710071750-r</version> |
|
214 |
</dependency> |
|
215 |
|
|
216 |
</dependencies> |
|
217 |
</dependencyManagement> |
|
218 |
|
|
219 |
<modules> |
|
220 |
<module>org.gvsig.scripting.thing</module> |
|
221 |
<module>org.gvsig.scripting.lib</module> |
|
222 |
<module>org.gvsig.scripting.swing</module> |
|
223 |
<module>org.gvsig.scripting.main</module> |
|
224 |
<module>org.gvsig.scripting.app</module> |
|
225 |
</modules> |
|
226 |
</project> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestDialog.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.BufferedWriter; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileWriter; |
|
6 |
import java.io.IOException; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import junit.framework.Assert; |
|
11 |
|
|
12 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
13 |
|
|
14 |
public abstract class TestDialog extends AbstractLibraryAutoInitTestCase { |
|
15 |
|
|
16 |
protected ScriptingManager manager; |
|
17 |
|
|
18 |
@Override |
|
19 |
protected void doSetUp() throws Exception { |
|
20 |
manager = ScriptingLocator.getManager(); |
|
21 |
} |
|
22 |
|
|
23 |
public void setWorkingFolder(){ |
|
24 |
File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile()); |
|
25 |
|
|
26 |
// FIXME: hay que sustituirlo por manager.setHomeFolder(home) |
|
27 |
// manager.setRootUserFolder(file.getAbsolutePath()); |
|
28 |
} |
|
29 |
|
|
30 |
public File getFile(String name){ |
|
31 |
return new File(manager.getRootUserFolder()+File.separator+name); |
|
32 |
} |
|
33 |
|
|
34 |
public void deleteFolderContent(ScriptingFolder folder){ |
|
35 |
List<ScriptingUnit> units = folder.getUnits(); |
|
36 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
37 |
while(it.hasNext()){ |
|
38 |
ScriptingUnit unit = it.next(); |
|
39 |
if(unit instanceof ScriptingFolder){ |
|
40 |
deleteFolderContent((ScriptingFolder)unit); |
|
41 |
folder.remove(unit); |
|
42 |
}else{ |
|
43 |
folder.remove(unit); |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public void deleteWorkingFolderContent(){ |
|
49 |
setWorkingFolder(); |
|
50 |
ScriptingFolder folder = manager.getUserFolder(); |
|
51 |
deleteFolderContent(folder); |
|
52 |
} |
|
53 |
|
|
54 |
public void checkFile(String fName){ |
|
55 |
File fscript = getFile(fName); |
|
56 |
Assert.assertTrue(fscript.exists()); |
|
57 |
} |
|
58 |
|
|
59 |
public void checkScriptDefaultValues(ScriptingDialog script){ |
|
60 |
Assert.assertEquals("test_dialog", script.getId()); |
|
61 |
Assert.assertEquals("test_dialog", script.getName()); |
|
62 |
Assert.assertEquals("python", script.getLangName()); |
|
63 |
Assert.assertEquals("main", script.getMainName()); |
|
64 |
} |
|
65 |
|
|
66 |
public void checkScriptNewValues(ScriptingDialog script){ |
|
67 |
Assert.assertEquals("test_dialog", script.getId()); |
|
68 |
Assert.assertEquals("TestDialog", script.getName()); |
|
69 |
Assert.assertEquals("Tests sobre dialogs", script.getDescription()); |
|
70 |
Assert.assertEquals("python", script.getLangName()); |
|
71 |
Assert.assertEquals("main", script.getMainName()); |
|
72 |
Assert.assertEquals("creator", script.getCreatedBy()); |
|
73 |
Assert.assertEquals("v1.0", script.getVersion()); |
|
74 |
Assert.assertEquals("def hola():\n return 'hola mundo'\n",script.getCode()); |
|
75 |
} |
|
76 |
|
|
77 |
public void testCreation(){ |
|
78 |
deleteWorkingFolderContent(); |
|
79 |
setWorkingFolder(); |
|
80 |
ScriptingDialog script = (ScriptingDialog) manager.createUnit(ScriptingManager.UNIT_DIALOG,manager.getUserFolder(),"test_dialog.py"); |
|
81 |
|
|
82 |
script.save(); |
|
83 |
checkFile("test_dialog.py"); |
|
84 |
checkFile("test_dialog.dlg"); |
|
85 |
checkFile("test_dialog.inf"); |
|
86 |
|
|
87 |
checkScriptDefaultValues(script); |
|
88 |
} |
|
89 |
|
|
90 |
public void testOpen(){ |
|
91 |
testCreation(); |
|
92 |
ScriptingDialog script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
93 |
|
|
94 |
checkScriptDefaultValues(script); |
|
95 |
deleteWorkingFolderContent(); |
|
96 |
} |
|
97 |
|
|
98 |
public void testSave(){ |
|
99 |
testCreation(); |
|
100 |
ScriptingDialog script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
101 |
|
|
102 |
script.setName("TestDialog"); |
|
103 |
script.setDescription("Tests sobre dialogs"); |
|
104 |
script.setCode("def hola():\n return 'hola mundo'\n"); |
|
105 |
script.setCreatedBy("creator"); |
|
106 |
script.setVersion("v1.0"); |
|
107 |
script.save(); |
|
108 |
|
|
109 |
File f = script.getDialogFile(); |
|
110 |
try { |
|
111 |
BufferedWriter bw = new BufferedWriter(new FileWriter(f)); |
|
112 |
bw.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + |
|
113 |
"<panel columns=\"1\">\n" + |
|
114 |
"\t<button action=\"hola\" text=\"press\"/>\n" + |
|
115 |
"</panel>"); |
|
116 |
} catch (IOException e) { |
|
117 |
// TODO Auto-generated catch block |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
120 |
|
|
121 |
script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
122 |
checkScriptNewValues(script); |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
public void testRename(){ |
|
127 |
deleteWorkingFolderContent(); |
|
128 |
testCreation(); |
|
129 |
ScriptingDialog script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
130 |
|
|
131 |
Assert.assertFalse(script.rename("test_dialog")); |
|
132 |
Assert.assertTrue(script.rename("test_dialog2")); |
|
133 |
|
|
134 |
script = (ScriptingDialog) manager.getScript(getFile("test_dialog2.py")); |
|
135 |
Assert.assertEquals("test_dialog2", script.getId()); |
|
136 |
|
|
137 |
File f = getFile("test_dialog.py"); |
|
138 |
Assert.assertFalse(f.exists()); |
|
139 |
f = getFile("test_dialog2.py"); |
|
140 |
Assert.assertTrue(f.exists()); |
|
141 |
|
|
142 |
deleteWorkingFolderContent(); |
|
143 |
} |
|
144 |
|
|
145 |
public void testMove(){ |
|
146 |
testCreation(); |
|
147 |
ScriptingFolder folderDestination = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(), "other folder"); |
|
148 |
checkFile("other folder"); |
|
149 |
ScriptingDialog script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
150 |
|
|
151 |
script.move(folderDestination); |
|
152 |
Assert.assertEquals(script.getParent().getFile().getAbsolutePath(),folderDestination.getFile().getAbsolutePath()); |
|
153 |
deleteWorkingFolderContent(); |
|
154 |
} |
|
155 |
|
|
156 |
public void testRun(){ |
|
157 |
/* testSave(); |
|
158 |
ScriptingDialog script = (ScriptingDialog) manager.getScript(getFile("test_dialog.py")); |
|
159 |
|
|
160 |
Assert.assertEquals("hola mundo", script.run()); |
|
161 |
|
|
162 |
//setMainName |
|
163 |
|
|
164 |
//invokeMethod |
|
165 |
|
|
166 |
//invokeFunction |
|
167 |
deleteWorkingFolderContent();*/ |
|
168 |
} |
|
169 |
|
|
170 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestScript.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import junit.framework.Assert; |
|
8 |
|
|
9 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
10 |
|
|
11 |
public abstract class TestScript extends AbstractLibraryAutoInitTestCase { |
|
12 |
|
|
13 |
protected ScriptingManager manager; |
|
14 |
|
|
15 |
@Override |
|
16 |
protected void doSetUp() throws Exception { |
|
17 |
ScriptingLocator locator = new ScriptingLocator(); |
|
18 |
Assert.assertNotNull(locator); |
|
19 |
manager = ScriptingLocator.getManager(); |
|
20 |
Assert.assertNotNull(manager); |
|
21 |
} |
|
22 |
|
|
23 |
public void setWorkingFolder(){ |
|
24 |
File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile()); |
|
25 |
if(file.exists()){ |
|
26 |
file.mkdir(); |
|
27 |
} |
|
28 |
// FIXME: hay que sustituirlo por manager.setHomeFolder(home) |
|
29 |
// manager.setRootUserFolder(file.getAbsolutePath()); |
|
30 |
} |
|
31 |
|
|
32 |
public void deleteFolderContent(ScriptingFolder folder){ |
|
33 |
List<ScriptingUnit> units = folder.getUnits(); |
|
34 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
35 |
while(it.hasNext()){ |
|
36 |
ScriptingUnit unit = it.next(); |
|
37 |
if(unit instanceof ScriptingFolder){ |
|
38 |
deleteFolderContent((ScriptingFolder)unit); |
|
39 |
folder.remove(unit); |
|
40 |
}else{ |
|
41 |
folder.remove(unit); |
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
public void deleteWorkingFolderContent(){ |
|
47 |
setWorkingFolder(); |
|
48 |
ScriptingFolder folder = manager.getUserFolder(); |
|
49 |
deleteFolderContent(folder); |
|
50 |
} |
|
51 |
|
|
52 |
public File getFile(ScriptingFolder folder, String name){ |
|
53 |
return new File(folder.getFile(),name); |
|
54 |
} |
|
55 |
|
|
56 |
public void checkFile(ScriptingFolder folder, String fName){ |
|
57 |
File fscript = getFile(folder, fName); |
|
58 |
Assert.assertTrue(fscript.exists()); |
|
59 |
} |
|
60 |
|
|
61 |
public void checkScriptDefaultValues(ScriptingScript script){ |
|
62 |
Assert.assertEquals(manager.getUserFolder().getFile().getAbsolutePath(), script.getParent().getFile().getAbsolutePath()); |
|
63 |
|
|
64 |
Assert.assertEquals("test_script", script.getId()); |
|
65 |
Assert.assertEquals("test_script", script.getName()); |
|
66 |
Assert.assertEquals("python", script.getLangName()); |
|
67 |
Assert.assertEquals("main", script.getMainName()); |
|
68 |
} |
|
69 |
|
|
70 |
public void checkScriptNewValues(ScriptingScript script){ |
|
71 |
Assert.assertEquals("test_script", script.getId()); |
|
72 |
Assert.assertEquals("TestScript", script.getName()); |
|
73 |
Assert.assertEquals("Tests sobre scripts", script.getDescription()); |
|
74 |
Assert.assertEquals("python", script.getLangName()); |
|
75 |
Assert.assertEquals("main", script.getMainName()); |
|
76 |
Assert.assertEquals("creator", script.getCreatedBy()); |
|
77 |
Assert.assertEquals("v1.0", script.getVersion()); |
|
78 |
Assert.assertEquals("def main():\n return 'hola mundo'\n",script.getCode()); |
|
79 |
} |
|
80 |
|
|
81 |
public void testCreation(){ |
|
82 |
setWorkingFolder(); |
|
83 |
ScriptingScript previous = (ScriptingScript) manager.getScript(new File(manager.getRootUserFolder()+File.separator+"test_script.py")); |
|
84 |
if (previous!=null){ |
|
85 |
manager.getUserFolder().remove(previous); |
|
86 |
} |
|
87 |
ScriptingScript script = (ScriptingScript) manager.createUnit(ScriptingManager.UNIT_SCRIPT,manager.getUserFolder(),"test_script.py"); |
|
88 |
|
|
89 |
script.save(); |
|
90 |
|
|
91 |
checkFile(manager.getUserFolder(),"test_script.py"); |
|
92 |
checkFile(manager.getUserFolder(),"test_script.inf"); |
|
93 |
|
|
94 |
checkScriptDefaultValues(script); |
|
95 |
} |
|
96 |
|
|
97 |
public void testOpen(){ |
|
98 |
testCreation(); |
|
99 |
ScriptingScript script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
100 |
|
|
101 |
checkScriptDefaultValues(script); |
|
102 |
deleteWorkingFolderContent(); |
|
103 |
} |
|
104 |
|
|
105 |
public void testSave(){ |
|
106 |
testCreation(); |
|
107 |
ScriptingScript script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
108 |
|
|
109 |
script.setName("TestScript"); |
|
110 |
script.setDescription("Tests sobre scripts"); |
|
111 |
script.setCode("def main():\n return 'hola mundo'\n"); |
|
112 |
script.setCreatedBy("creator"); |
|
113 |
script.setVersion("v1.0"); |
|
114 |
script.save(); |
|
115 |
|
|
116 |
script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
117 |
checkScriptNewValues(script); |
|
118 |
} |
|
119 |
|
|
120 |
public void testRename(){ |
|
121 |
testSave(); |
|
122 |
ScriptingScript script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
123 |
|
|
124 |
Assert.assertFalse(script.rename("test_script")); |
|
125 |
Assert.assertTrue(script.rename("test_script2")); |
|
126 |
|
|
127 |
script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script2.py")); |
|
128 |
|
|
129 |
Assert.assertEquals("test_script2", script.getId()); |
|
130 |
deleteWorkingFolderContent(); |
|
131 |
} |
|
132 |
|
|
133 |
public void testMove(){ |
|
134 |
setWorkingFolder(); |
|
135 |
ScriptingFolder folderDestination = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(), "other folder"); |
|
136 |
checkFile(manager.getUserFolder(),"other folder"); |
|
137 |
|
|
138 |
ScriptingScript previous = (ScriptingScript) manager.getScript(new File(folderDestination.getFile(),"test_script.py")); |
|
139 |
if (previous!=null){ |
|
140 |
folderDestination.remove(previous); |
|
141 |
} |
|
142 |
|
|
143 |
testSave(); |
|
144 |
ScriptingScript script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
145 |
|
|
146 |
script.move(folderDestination); |
|
147 |
System.out.println(script.getParent() + " " + folderDestination); |
|
148 |
Assert.assertEquals(script.getParent(),folderDestination); |
|
149 |
deleteWorkingFolderContent(); |
|
150 |
} |
|
151 |
|
|
152 |
public void testRun() throws NoSuchMethodException{ |
|
153 |
testSave(); |
|
154 |
ScriptingScript script = (ScriptingScript) manager.getScript(getFile(manager.getUserFolder(),"test_script.py")); |
|
155 |
Assert.assertEquals("hola mundo", script.run()); |
|
156 |
|
|
157 |
script.setCode("def hola():\n return 'hola mundo'\n"); |
|
158 |
//setMainName |
|
159 |
script.setMainName("hola"); |
|
160 |
Assert.assertEquals("hola mundo", script.run()); |
|
161 |
|
|
162 |
//invokeMethod |
|
163 |
|
|
164 |
//invokeFunction |
|
165 |
Assert.assertEquals("hola mundo", script.invokeFunction("hola", null)); |
|
166 |
deleteWorkingFolderContent(); |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestManager.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.Set; |
|
8 |
|
|
9 |
import junit.framework.Assert; |
|
10 |
|
|
11 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
12 |
|
|
13 |
public abstract class TestManager extends AbstractLibraryAutoInitTestCase { |
|
14 |
|
|
15 |
protected ScriptingManager manager; |
|
16 |
|
|
17 |
@Override |
|
18 |
protected void doSetUp() throws Exception { |
|
19 |
manager = ScriptingLocator.getManager(); |
|
20 |
} |
|
21 |
|
|
22 |
public void setWorkingFolder(){ |
|
23 |
File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile()); |
|
24 |
// FIXME: hay que sustituirlo por manager.setHomeFolder(home) |
|
25 |
// manager.setRootUserFolder(file.getAbsolutePath()); |
|
26 |
} |
|
27 |
|
|
28 |
public void deleteFolderContent(ScriptingFolder folder){ |
|
29 |
List<ScriptingUnit> units = folder.getUnits(); |
|
30 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
31 |
while(it.hasNext()){ |
|
32 |
ScriptingUnit unit = it.next(); |
|
33 |
if(unit instanceof ScriptingFolder){ |
|
34 |
deleteFolderContent((ScriptingFolder)unit); |
|
35 |
folder.remove(unit); |
|
36 |
}else{ |
|
37 |
folder.remove(unit); |
|
38 |
} |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
public void deleteWorkingFolderContent(){ |
|
43 |
setWorkingFolder(); |
|
44 |
ScriptingFolder folder = manager.getUserFolder(); |
|
45 |
deleteFolderContent(folder); |
|
46 |
} |
|
47 |
|
|
48 |
public void testUserFolderPath(){ |
|
49 |
setWorkingFolder(); |
|
50 |
Assert.assertEquals(manager.getRootUserFolder().getAbsolutePath(), manager.getUserFolder().getFile().getAbsolutePath()); |
|
51 |
} |
|
52 |
|
|
53 |
public void testExistsScriptId(){ |
|
54 |
setWorkingFolder(); |
|
55 |
manager.createUnit(ScriptingManager.UNIT_SCRIPT,manager.getUserFolder(),"test_script.py"); |
|
56 |
|
|
57 |
Assert.assertEquals(false, manager.validateUnitId(manager.getUserFolder(),"test_script")); |
|
58 |
Assert.assertEquals(true, manager.validateUnitId(manager.getUserFolder(),"test_script2")); |
|
59 |
deleteWorkingFolderContent(); |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
public void checkUnitValues(ScriptingUnit unit1, ScriptingUnit unit2){ |
|
64 |
Assert.assertEquals(unit1.getId(),unit2.getId()); |
|
65 |
Assert.assertEquals(unit1.getName(),unit2.getName()); |
|
66 |
} |
|
67 |
|
|
68 |
public void testRegisteringSystemFolders(){ |
|
69 |
ScriptingFolder folder_parent = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(), "test"); |
|
70 |
ScriptingFolder folder = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,folder_parent, "test"); |
|
71 |
ScriptingScript script = (ScriptingScript)manager.createUnit(ScriptingManager.UNIT_SCRIPT,folder, "test_script.py"); |
|
72 |
|
|
73 |
manager.registerSystemFolder("test", folder.getFile()); |
|
74 |
|
|
75 |
List<ScriptingUnit> units = manager.getSystemFolder().getUnits(); |
|
76 |
|
|
77 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
78 |
ScriptingUnit unit = null; |
|
79 |
while(it.hasNext()){ |
|
80 |
unit = it.next(); |
|
81 |
checkUnitValues(unit, folder); |
|
82 |
} |
|
83 |
Assert.assertNotNull(unit); |
|
84 |
|
|
85 |
ScriptingScript script2 = (ScriptingScript) manager.getScript(new File(((ScriptingFolder)unit).getFile(),script.getId()+".py")); |
|
86 |
checkUnitValues(script,script2); |
|
87 |
deleteWorkingFolderContent(); |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestFolder.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import junit.framework.Assert; |
|
8 |
|
|
9 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
10 |
|
|
11 |
public abstract class TestFolder extends AbstractLibraryAutoInitTestCase { |
|
12 |
|
|
13 |
protected ScriptingManager manager; |
|
14 |
|
|
15 |
@Override |
|
16 |
protected void doSetUp() throws Exception { |
|
17 |
manager = ScriptingLocator.getManager(); |
|
18 |
} |
|
19 |
|
|
20 |
public void setWorkingFolder(){ |
|
21 |
File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile()); |
|
22 |
if(file.exists()){ |
|
23 |
file.mkdir(); |
|
24 |
} |
|
25 |
// FIXME: hay que sustituirlo por manager.setHomeFolder(home) |
|
26 |
// manager.setRootUserFolder(file.getAbsolutePath()); |
|
27 |
} |
|
28 |
|
|
29 |
public void deleteFolderContent(ScriptingFolder folder){ |
|
30 |
List<ScriptingUnit> units = folder.getUnits(); |
|
31 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
32 |
while(it.hasNext()){ |
|
33 |
ScriptingUnit unit = it.next(); |
|
34 |
if(unit instanceof ScriptingFolder){ |
|
35 |
deleteFolderContent((ScriptingFolder)unit); |
|
36 |
folder.remove(unit); |
|
37 |
}else{ |
|
38 |
folder.remove(unit); |
|
39 |
} |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
public void deleteWorkingFolderContent(){ |
|
44 |
setWorkingFolder(); |
|
45 |
ScriptingFolder folder = manager.getUserFolder(); |
|
46 |
deleteFolderContent(folder); |
|
47 |
} |
|
48 |
|
|
49 |
public File getFile(ScriptingFolder folder, String name){ |
|
50 |
return new File(folder.getFile(),name); |
|
51 |
} |
|
52 |
|
|
53 |
public void checkFolder(ScriptingFolder folder, String fName){ |
|
54 |
File ffolder = getFile(folder, fName); |
|
55 |
Assert.assertTrue(ffolder.exists()); |
|
56 |
Assert.assertTrue(ffolder.isDirectory()); |
|
57 |
} |
|
58 |
|
|
59 |
public void checkScriptDefaultValues(ScriptingScript script){ |
|
60 |
Assert.assertEquals("test_script", script.getId()); |
|
61 |
Assert.assertEquals("test_script", script.getName()); |
|
62 |
Assert.assertEquals("python", script.getLangName()); |
|
63 |
Assert.assertEquals("main", script.getMainName()); |
|
64 |
} |
|
65 |
|
|
66 |
public void testCreation(){ |
|
67 |
deleteWorkingFolderContent(); |
|
68 |
ScriptingFolder folder = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(),"test_folder"); |
|
69 |
|
|
70 |
checkFolder(manager.getUserFolder(),folder.getId()); |
|
71 |
} |
|
72 |
|
|
73 |
public void testList(){ |
|
74 |
testCreation(); |
|
75 |
ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder")); |
|
76 |
|
|
77 |
ScriptingScript script = (ScriptingScript) manager.createUnit(ScriptingManager.UNIT_SCRIPT,folder, "test_script.py"); |
|
78 |
|
|
79 |
List<ScriptingUnit> units = folder.getUnits(); |
|
80 |
Iterator<ScriptingUnit> it = units.iterator(); |
|
81 |
while(it.hasNext()){ |
|
82 |
ScriptingUnit unit = it.next(); |
|
83 |
checkScriptDefaultValues((ScriptingScript) unit); |
|
84 |
} |
|
85 |
|
|
86 |
folder.remove(script); |
|
87 |
Assert.assertTrue(folder.getUnits().isEmpty()); |
|
88 |
} |
|
89 |
|
|
90 |
public void testRename(){ |
|
91 |
testCreation(); |
|
92 |
ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder")); |
|
93 |
|
|
94 |
Assert.assertFalse(folder.rename("test_folder")); |
|
95 |
Assert.assertTrue(folder.rename("test_folder2")); |
|
96 |
|
|
97 |
Assert.assertEquals("test_folder2", folder.getName()); |
|
98 |
deleteWorkingFolderContent(); |
|
99 |
} |
|
100 |
|
|
101 |
public void testMove(){ |
|
102 |
testCreation(); |
|
103 |
ScriptingScript script = (ScriptingScript) manager.createUnit(ScriptingManager.UNIT_SCRIPT,manager.getUserFolder(), "test_script.py"); |
|
104 |
ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder")); |
|
105 |
Assert.assertEquals(script.getParent().getFile().getAbsolutePath(),manager.getUserFolder().getFile().getAbsolutePath()); |
|
106 |
|
|
107 |
folder.add(script); |
|
108 |
Assert.assertEquals(script.getParent(),folder); |
|
109 |
deleteWorkingFolderContent(); |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
For each class you are going to test, create one Test class with the same |
|
5 |
name as the class to test, ending with Test. |
|
6 |
|
|
7 |
For example, the unit tests of the "ExampleLibrary" class are performed |
|
8 |
by the "ExampleLibraryTest" class. |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/resources/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
Put into this folder the resources needed by your test classes. |
|
5 |
|
|
6 |
This folder is added to the Tests classpath, so you can load any resources |
|
7 |
through the ClassLoader. |
|
8 |
|
|
9 |
By default, in this folder you can find an example of log4j configuration, |
|
10 |
prepared to log messages through the console, so logging works when you |
|
11 |
run your tests classes. |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
DefaultExampleManager class. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.scripting.impl.DefaultExampleManager"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
|
|
26 |
<!-- |
|
27 |
By default, show only logging messages of INFO level or higher, |
|
28 |
through the previously configured CONSOLE appender. |
|
29 |
--> |
|
30 |
<root> |
|
31 |
<priority value="INFO" /> |
|
32 |
<appender-ref ref="CONSOLE" /> |
|
33 |
</root> |
|
34 |
</log4j:configuration> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingNotification.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
/** |
|
4 |
* Interface to support the notifications in the application |
|
5 |
* |
|
6 |
*/ |
|
7 |
public interface ScriptingNotification { |
|
8 |
|
|
9 |
/** |
|
10 |
* Gets the type of ScriptingNotification |
|
11 |
* |
|
12 |
* @return An integer with the type. |
|
13 |
*/ |
|
14 |
public int getType(); |
|
15 |
|
|
16 |
/** |
|
17 |
* Gets the ScriptingNotification's id |
|
18 |
* |
|
19 |
* @return a String with the id |
|
20 |
*/ |
|
21 |
public String getId(); |
|
22 |
|
|
23 |
/** |
|
24 |
* Get the {@link ScriptingUnit} which send the notification |
|
25 |
* |
|
26 |
* @return {@link ScriptingUnit |
|
27 |
*/ |
|
28 |
public ScriptingUnit getUnit(); |
|
29 |
|
|
30 |
/** |
|
31 |
* Gets the cause of the ScriptingNotification |
|
32 |
* |
|
33 |
* @return Exception |
|
34 |
*/ |
|
35 |
public Exception getException(); |
|
36 |
|
|
37 |
|
|
38 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.scripting package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>TODO: Example library description.</p> |
|
11 |
|
|
12 |
<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#packagecomment">Javadoc Tool documentation about the package file</a></p> |
|
13 |
|
|
14 |
</body> |
|
15 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/CompileErrorException.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
public class CompileErrorException extends ScriptingErrorException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -7829204331513125285L; |
|
11 |
|
|
12 |
public CompileErrorException(String msg, File name, int line, int column) { |
|
13 |
super(msg, name, line, column); |
|
14 |
} |
|
15 |
|
|
16 |
public CompileErrorException(String msg, File name, int line, int column, Throwable cause) { |
|
17 |
this(msg, name, line, column); |
|
18 |
this.initCause(cause); |
|
19 |
} |
|
20 |
|
|
21 |
public CompileErrorException(String msg, File name, Throwable cause) { |
|
22 |
this(msg, name, -1, -1); |
|
23 |
this.initCause(cause); |
|
24 |
} |
|
25 |
} |
|
0 | 26 |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingBaseScript.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.Writer; |
|
5 |
|
|
6 |
import org.gvsig.tools.observer.WeakReferencingObservable; |
|
7 |
|
|
8 |
/** |
|
9 |
* <p> |
|
10 |
* Interface that represents Scripting elements.</p> |
|
11 |
* |
|
12 |
* @see ScriptingUnit |
|
13 |
* |
|
14 |
* @see ScriptingScript |
|
15 |
* @see ScriptingDialog |
|
16 |
* @see ScriptingProject |
|
17 |
*/ |
|
18 |
public interface ScriptingBaseScript extends ScriptingUnit, WeakReferencingObservable { |
|
19 |
|
|
20 |
public static final int ISOLATION_LOW = 0; |
|
21 |
public static final int ISOLATION_HIGH = 10; |
|
22 |
|
|
23 |
/** |
|
24 |
* Check if the script execution is enabled. |
|
25 |
* |
|
26 |
* @return if the script is enabled. |
|
27 |
*/ |
|
28 |
public boolean isEnabled(); |
|
29 |
|
|
30 |
/** |
|
31 |
* Enable or disable the sript execution. |
|
32 |
* |
|
33 |
* @param enabled |
|
34 |
*/ |
|
35 |
public void setEnabled(boolean enabled); |
|
36 |
|
|
37 |
/** |
|
38 |
* Executes the code of a ScriptBaseScript. |
|
39 |
* |
|
40 |
* @return |
|
41 |
*/ |
|
42 |
public Object run(); |
|
43 |
|
|
44 |
/** |
|
45 |
* Executes the code of a ScriptBaseScript. |
|
46 |
* |
|
47 |
* @param args Contains the input parameters to run the ScriptBaseScript. |
|
48 |
* @return |
|
49 |
*/ |
|
50 |
public Object run(Object args[]); |
|
51 |
|
|
52 |
/** |
|
53 |
* Executes the code of a ScriptBaseScript in a separated thread |
|
54 |
* |
|
55 |
* @param args Contains the input parameters to run the ScriptBaseScript. |
|
56 |
*/ |
|
57 |
public void runAsTask(Object args[]); |
|
58 |
|
|
59 |
public void compile() throws ScriptingRunningException; |
|
60 |
|
|
61 |
public void put(String name, Object value); |
|
62 |
|
|
63 |
/** |
|
64 |
* Return a resource File that is beside this script. |
|
65 |
* |
|
66 |
* @param filename |
|
67 |
* @return the file which is beside this script |
|
68 |
*/ |
|
69 |
public File getResource(String filename); |
|
70 |
|
|
71 |
public File getScriptFile(); |
|
72 |
|
|
73 |
public String getLibrarySuffix(); |
|
74 |
|
|
75 |
public void setLibrarySuffix(String librarySuffix); |
|
76 |
|
|
77 |
public void addStdoutWriter(Writer out); |
|
78 |
|
|
79 |
public void addStderrWriter(Writer err); |
|
80 |
|
|
81 |
public void removeStdoutWriter(Writer out); |
|
82 |
|
|
83 |
public void removeStderrWriter(Writer err); |
|
84 |
|
|
85 |
public void setIsolationGroup(String group); |
|
86 |
|
|
87 |
public String getIsolationGroup(); |
|
88 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingDialog.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
/** |
|
6 |
* <p> Interface that represents a single script with window dialog.</p> |
|
7 |
* |
|
8 |
* @see ScriptingUnit |
|
9 |
* @see ScriptingBaseScript |
|
10 |
*/ |
|
11 |
public interface ScriptingDialog extends ScriptingScript{ |
|
12 |
|
|
13 |
public static final int MODE_DIALOG=1; |
|
14 |
public static final int MODE_WINDOW=2; |
|
15 |
public static final int MODE_TOOL=3; |
|
16 |
|
|
17 |
/** |
|
18 |
* Returns the file where is the window dialog's gui. |
|
19 |
* |
|
20 |
* @return a File with the code of the window dialog. |
|
21 |
*/ |
|
22 |
public File getDialogFile(); |
|
23 |
|
|
24 |
/** |
|
25 |
* Returns the type of the window dialog associated with the ScriptingDialog. |
|
26 |
* |
|
27 |
* @return an int with the window mode. |
|
28 |
*/ |
|
29 |
public int getShowMode(); |
|
30 |
|
|
31 |
/** |
|
32 |
* Sets the window mode associated with a ScriptingDialog. |
|
33 |
* |
|
34 |
* @param mode |
|
35 |
* int that contains the window mode. |
|
36 |
*/ |
|
37 |
public void setShowMode(int mode); |
|
38 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingRunningException.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
public class ScriptingRunningException extends Exception { |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
*/ |
|
8 |
private static final long serialVersionUID = 4327337186862453971L; |
|
9 |
|
|
10 |
private String message; |
|
11 |
private String fileName; |
|
12 |
private int lineNunber; |
|
13 |
private int columnNumber; |
|
14 |
|
|
15 |
public ScriptingRunningException(String message, String fileName, |
|
16 |
int lineNumber, int columnNumber) { |
|
17 |
this.message = message; |
|
18 |
this.fileName = fileName; |
|
19 |
this.lineNunber = lineNumber; |
|
20 |
this.columnNumber = columnNumber; |
|
21 |
} |
|
22 |
|
|
23 |
public ScriptingRunningException(String message, String fileName) { |
|
24 |
this(message, fileName, -1, -1); |
|
25 |
} |
|
26 |
|
|
27 |
public int getLineNumber() { |
|
28 |
return this.lineNunber; |
|
29 |
} |
|
30 |
|
|
31 |
public int getColumnNumber() { |
|
32 |
return this.columnNumber; |
|
33 |
} |
|
34 |
|
|
35 |
public String getFileName() { |
|
36 |
return this.fileName; |
|
37 |
} |
|
38 |
|
|
39 |
public String getMessage() { |
|
40 |
return this.message; |
|
41 |
} |
|
42 |
} |
|
0 | 43 |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingLocator.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import org.gvsig.tools.locator.BaseLocator; |
|
4 |
import org.gvsig.tools.locator.Locator; |
|
5 |
import org.gvsig.tools.locator.LocatorException; |
|
6 |
|
|
7 |
public class ScriptingLocator extends BaseLocator { |
|
8 |
|
|
9 |
private static final String LOCATOR_NAME = "ScriptingLocator"; |
|
10 |
|
|
11 |
public static final String MANAGER_NAME = "scriptinglocator.manager"; |
|
12 |
|
|
13 |
public static final String MANAGER_DESCRIPTION = "Scripting Manager"; |
|
14 |
|
|
15 |
/** |
|
16 |
* Unique instance. |
|
17 |
*/ |
|
18 |
private static final ScriptingLocator instance = new ScriptingLocator(); |
|
19 |
|
|
20 |
/** |
|
21 |
* Return the singleton instance. |
|
22 |
* |
|
23 |
* @return the singleton instance |
|
24 |
*/ |
|
25 |
public static ScriptingLocator getInstance() { |
|
26 |
return instance; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Return the Locator's name |
|
31 |
* |
|
32 |
* @return a String with the Locator's name |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public String getLocatorName() { |
|
36 |
return LOCATOR_NAME; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* Return a reference to ScriptManager. |
|
41 |
* |
|
42 |
* @return a reference to ScriptManager |
|
43 |
* @throws LocatorException |
|
44 |
* if there is no access to the class or the class cannot be |
|
45 |
* instantiated |
|
46 |
* @see Locator#get(String) |
|
47 |
*/ |
|
48 |
public static ScriptingManager getManager() throws LocatorException { |
|
49 |
return (ScriptingManager) getInstance().get(MANAGER_NAME); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Registers the Class implementing the ScriptManager interface. |
|
54 |
* |
|
55 |
* @param clazz |
|
56 |
* implementing the ScriptManager interface |
|
57 |
*/ |
|
58 |
public static void registerManager(Class<? extends ScriptingManager> clazz) { |
|
59 |
getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
60 |
} |
|
61 |
|
|
62 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingLibrary.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import org.gvsig.tools.library.AbstractLibrary; |
|
4 |
import org.gvsig.tools.library.LibraryException; |
|
5 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
6 |
|
|
7 |
public class ScriptingLibrary extends AbstractLibrary { |
|
8 |
|
|
9 |
@Override |
|
10 |
public void doRegistration() { |
|
11 |
registerAsAPI(ScriptingLibrary.class); |
|
12 |
} |
|
13 |
|
|
14 |
@Override |
|
15 |
protected void doInitialize() throws LibraryException { |
|
16 |
// Nothing to do |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void doPostInitialize() throws LibraryException { |
|
21 |
// Validate there is any implementation registered. |
|
22 |
ScriptingManager manager = ScriptingLocator.getManager(); |
|
23 |
|
|
24 |
if (manager == null) { |
|
25 |
throw new ReferenceNotRegisteredException( |
|
26 |
ScriptingLocator.MANAGER_NAME, ScriptingLocator.getInstance()); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingScript.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import org.gvsig.tools.script.Script; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* <p> Interface that represents a single script without window dialog.</p> |
|
8 |
* |
|
9 |
* @see ScriptingUnit |
|
10 |
* @see ScriptingBaseScript |
|
11 |
*/ |
|
12 |
public interface ScriptingScript extends ScriptingBaseScript, Script { |
|
13 |
|
|
14 |
/** |
|
15 |
* Returns the languange in which the ScriptingScript is written. |
|
16 |
* |
|
17 |
* @return a String containing the name of the language |
|
18 |
*/ |
|
19 |
public String getLangName(); |
|
20 |
|
|
21 |
/** |
|
22 |
* Returns the ScriptingScript's code. |
|
23 |
* |
|
24 |
* @return a String with the code of the script. |
|
25 |
*/ |
|
26 |
@Override |
|
27 |
public String getCode(); |
|
28 |
|
|
29 |
/** |
|
30 |
* Sets a the code associated with a ScriptingScript. |
|
31 |
* |
|
32 |
* @param code |
|
33 |
* String that contains the new code. |
|
34 |
*/ |
|
35 |
public void setCode(String code); |
|
36 |
|
|
37 |
/** |
|
38 |
* Returns the name of the main function in the ScriptingScript's code |
|
39 |
* |
|
40 |
* @return a String with main function (default main name is 'main'). |
|
41 |
*/ |
|
42 |
public String getMainName(); |
|
43 |
|
|
44 |
/** |
|
45 |
* Stablishes a new main main function in the ScriptingScript's code. |
|
46 |
* |
|
47 |
* @param mainName |
|
48 |
* String that contains the new main function name. |
|
49 |
*/ |
|
50 |
public void setMainName(String mainName); |
|
51 |
|
|
52 |
/** |
|
53 |
* Persists the current status of a ScriptingScript with the content associated. |
|
54 |
*/ |
|
55 |
public void save(); |
|
56 |
|
|
57 |
/** |
|
58 |
* Executes a method from the Script's code |
|
59 |
* |
|
60 |
* @param obj this Object represents the script's code |
|
61 |
* @param name method's name to execute |
|
62 |
* @param args input parameters of the method |
|
63 |
* |
|
64 |
* @return An Object that represents the execution |
|
65 |
* |
|
66 |
* @throws NoSuchMethodException If there isn't a main function to begin the execution |
|
67 |
*/ |
|
68 |
public Object invokeMethod(Object obj, String name, Object[] args) throws NoSuchMethodException; |
|
69 |
|
|
70 |
/** |
|
71 |
* Executes a function from the Script's code |
|
72 |
* |
|
73 |
* @param name method's name to execute |
|
74 |
* @param args input parameters of the method |
|
75 |
* |
|
76 |
* @return An Object that represents the execution |
|
77 |
* |
|
78 |
* @throws NoSuchMethodException If there isn't a main function to begin the execution |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public Object invokeFunction(String name, Object[] args) throws NoSuchMethodException; |
|
82 |
|
|
83 |
public String getMimeType(); |
|
84 |
|
|
85 |
public void registerDataFolder(String id); |
|
86 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ExecuteErrorException.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
public class ExecuteErrorException extends ScriptingErrorException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = 3733567933742742587L; |
|
11 |
|
|
12 |
public ExecuteErrorException(String msg, File name, int line, int column) { |
|
13 |
super(msg, name, line, column); |
|
14 |
} |
|
15 |
|
|
16 |
public ExecuteErrorException(String msg, File name, int line, int column, Throwable cause) { |
|
17 |
this(msg, name, line, column); |
|
18 |
this.initCause(cause); |
|
19 |
} |
|
20 |
|
|
21 |
public ExecuteErrorException(String msg, File name, Throwable cause) { |
|
22 |
this(msg, name, -1, -1); |
|
23 |
this.initCause(cause); |
|
24 |
} |
|
25 |
|
|
26 |
} |
|
0 | 27 |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingErrorException.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.scripting; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import org.apache.commons.io.FilenameUtils; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author jjdelcerro |
|
14 |
*/ |
|
15 |
public class ScriptingErrorException extends RuntimeException { |
|
16 |
private static final long serialVersionUID = -3489829775437358107L; |
|
17 |
private final File name; |
|
18 |
private final int line; |
|
19 |
private final int column; |
|
20 |
|
|
21 |
public ScriptingErrorException(String msg, File name, int line, int column) { |
|
22 |
super(msg); |
|
23 |
this.name = name; |
|
24 |
this.line = line; |
|
25 |
this.column = column; |
|
26 |
} |
|
27 |
|
|
28 |
public int getLineNumber() { |
|
29 |
return this.line; |
|
30 |
} |
|
31 |
|
|
32 |
public int getColumnNumber() { |
|
33 |
return this.column; |
|
34 |
} |
|
35 |
|
|
36 |
public String getScriptName() { |
|
37 |
return FilenameUtils.getBaseName(this.name.getName()); |
|
38 |
} |
|
39 |
|
|
40 |
public File getScriptFile() { |
|
41 |
return this.name; |
|
42 |
} |
|
43 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.81/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingManager.java | ||
---|---|---|
1 |
package org.gvsig.scripting; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Set; |
|
7 |
import org.gvsig.tools.packageutils.Version; |
|
8 |
import org.gvsig.tools.service.spi.ProviderFactory; |
|
9 |
import org.gvsig.tools.script.ScriptManager; |
|
10 |
import org.gvsig.tools.util.FolderSet; |
|
11 |
|
|
12 |
/** |
|
13 |
* There are two top level management roles within ScriptingFramework: logical |
|
14 |
* and User's Interface (UI) management. |
|
15 |
* |
|
16 |
* This class is responsible of the logical role. It provides all the services |
|
17 |
* to manage the information used in ScriptingFramework. |
|
18 |
*/ |
|
19 |
public interface ScriptingManager extends ScriptManager { |
|
20 |
|
|
21 |
public static final String INSTALLER_PROVIDER_NAME = "Script"; |
|
22 |
public static final String INSTALLER_PROVIDER_DESCRIPTION = "Provider to install scripts"; |
|
23 |
|
|
24 |
public static final String PYTHON_LANGUAGE_NAME = "python"; |
|
25 |
// public static final String SCALA_LANGUAGE_NAME = "scala"; |
|
26 |
public static final String DEFAULT_ISOLATION_GROUP = "default"; |
|
27 |
|
|
28 |
public static final String UNIT_SCRIPT = "Script"; |
|
29 |
public static final String UNIT_DIALOG = "Dialog"; |
|
30 |
public static final String UNIT_FOLDER = "Folder"; |
|
31 |
public static final String UNIT_EXTERNALFILE = "ExternalFile"; |
|
32 |
|
|
33 |
public void setHomeFolder(File home); |
|
34 |
|
|
35 |
public File getHomeFolder(); |
|
36 |
|
|
37 |
public File getDataFolder(String id); |
|
38 |
|
|
39 |
public void registerDataFolder(ScriptingFolder folderScript, String id); |
|
40 |
|
|
41 |
public List<DataFolderFound> searchOldVersions(Version currentVersion, FolderSet folder); |
|
42 |
|
|
43 |
/** |
|
44 |
* Returns the System's Folder |
|
45 |
* |
|
46 |
* @return a {@link ScriptingFolder} with the System's Folder. |
|
47 |
*/ |
|
48 |
public ScriptingFolder getSystemFolder(); |
|
49 |
|
|
50 |
/** |
|
51 |
* Returns the User's Folder |
|
52 |
* |
|
53 |
* @return a {@link ScriptingFolder} with the User's Folder. |
|
54 |
*/ |
|
55 |
public ScriptingFolder getUserFolder(); |
|
56 |
|
|
57 |
public List<ScriptingFolder> getAlternativeUserFolders(); |
|
58 |
|
|
59 |
public void addAlternativeUserFolder(File f, String name, String description); |
|
60 |
|
|
61 |
public ScriptingUnit createUnit(String unitType, ScriptingFolder folder, String id); |
|
62 |
|
Also available in: Unified diff