Revision 1516
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/java/org/gvsig/scripting/main/Main.java | ||
---|---|---|
1 |
package org.gvsig.scripting.main; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.event.ActionEvent; |
|
5 |
import java.awt.event.ActionListener; |
|
6 |
import java.io.File; |
|
7 |
import java.net.URL; |
|
8 |
import java.util.Calendar; |
|
9 |
import java.util.Date; |
|
10 |
import java.util.HashMap; |
|
11 |
import java.util.Map; |
|
12 |
import javax.swing.JComponent; |
|
13 |
|
|
14 |
import javax.swing.JFrame; |
|
15 |
import javax.swing.JMenu; |
|
16 |
import javax.swing.JMenuBar; |
|
17 |
import javax.swing.JMenuItem; |
|
18 |
import javax.swing.WindowConstants; |
|
19 |
|
|
20 |
import org.apache.commons.cli.CommandLine; |
|
21 |
import org.apache.commons.cli.CommandLineParser; |
|
22 |
import org.apache.commons.cli.Options; |
|
23 |
import org.apache.commons.cli.ParseException; |
|
24 |
import org.apache.commons.cli.PosixParser; |
|
25 |
import org.gvsig.about.AboutLocator; |
|
26 |
import org.gvsig.about.AboutManager; |
|
27 |
import org.gvsig.scripting.ScriptingDialog; |
|
28 |
import org.gvsig.scripting.ScriptingManager; |
|
29 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
|
30 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
|
31 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
32 |
|
|
33 |
public class Main { |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
*/ |
|
38 |
private static final long serialVersionUID = -6853523688803006280L; |
|
39 |
ScriptingUIManager uimanager; |
|
40 |
AboutManager aboutManager; |
|
41 |
ScriptingManager manager; |
|
42 |
|
|
43 |
public static void main(String args[]) { |
|
44 |
Main main = new Main(); |
|
45 |
main.doMain(args); |
|
46 |
} |
|
47 |
|
|
48 |
private void initializeAbout() { |
|
49 |
aboutManager = AboutLocator.getManager(); |
|
50 |
|
|
51 |
Map<String, String> gvsig_vars = new HashMap<String, String>(); |
|
52 |
gvsig_vars.put("version", "2.0.0"); |
|
53 |
gvsig_vars.put("build", "2020"); |
|
54 |
aboutManager.setProject("gvSIG Desktop", getResource("gvsig.html"), |
|
55 |
null, gvsig_vars); |
|
56 |
aboutManager.getProject().set("build", "2021"); |
|
57 |
|
|
58 |
aboutManager.addSponsor("Generalitat Valenciana", |
|
59 |
getResource("gva.html"), 1); |
|
60 |
|
|
61 |
aboutManager.addDeveloper("gvSIG Asocicion", |
|
62 |
getResource("gvSIG-asociacion.html"), 2); |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
private void registerPluginFolders(File pluginsFolder) { |
|
67 |
|
|
68 |
File[] folders = pluginsFolder.listFiles(); |
|
69 |
for (File folder : folders) { |
|
70 |
File scriptsFolder = new File(folder,"scripting/scripts"); |
|
71 |
if( scriptsFolder.exists() ) { |
|
72 |
manager.registerSystemFolder(folder.getName(), scriptsFolder); |
|
73 |
} |
|
74 |
File libFolder = new File(folder,"scripting/lib"); |
|
75 |
if( libFolder.exists() ) { |
|
76 |
manager.addLibFolder(libFolder); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
public void doMain(String args[]) { |
|
82 |
|
|
83 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
84 |
|
|
85 |
initializeAbout(); |
|
86 |
|
|
87 |
uimanager = ScriptingSwingLocator.getUIManager(); |
|
88 |
manager = uimanager.getManager(); |
|
89 |
|
|
90 |
Options options = new Options(); |
|
91 |
options.addOption("l", "show-launcher", false, |
|
92 |
"Show the launcher window"); |
|
93 |
options.addOption("c", "show-composer", false, |
|
94 |
"Show the composer window"); |
|
95 |
options.addOption("r", "run", true, "Run the specified script"); |
|
96 |
options.addOption("f", "plugins-folder", true, "Register scripts and libs folder in the plugins located in this location"); |
|
97 |
options.addOption("s", "show", true, "Show the specified dialog"); |
|
98 |
options.addOption("h", "home", true, |
|
99 |
"Specify for the home of the script framework"); |
|
100 |
CommandLineParser parser = new PosixParser(); |
|
101 |
CommandLine line = null; |
|
102 |
try { |
|
103 |
line = parser.parse(options, args); |
|
104 |
if (line.hasOption("home")) { |
|
105 |
manager.setHomeFolder(new File(line.getOptionValue("home"))); |
|
106 |
} |
|
107 |
if (line.hasOption("plugins-folder")) { |
|
108 |
registerPluginFolders(new File(line.getOptionValue("plugins-folder"))); |
|
109 |
} |
|
110 |
if (line.hasOption("show-launcher")) { |
|
111 |
showLauncher(); |
|
112 |
} |
|
113 |
if (line.hasOption("show-composer")) { |
|
114 |
showComposer(); |
|
115 |
} |
|
116 |
if (line.hasOption("run")) { |
|
117 |
manager.getScript(new File(line.getOptionValue("run"))).run(); |
|
118 |
} |
|
119 |
if (line.hasOption("show")) { |
|
120 |
showDialog(line.getOptionValue("show")); |
|
121 |
if ( !(line.hasOption("show-launcher") || line.hasOption("show-composer")) ) { |
|
122 |
System.exit(0); |
|
123 |
} |
|
124 |
} |
|
125 |
} catch (ParseException exp) { |
|
126 |
System.out.println("Unexpected exception:" + exp.getMessage()); |
|
127 |
} |
|
128 |
String[] moreArgs = line.getArgs(); |
|
129 |
if( moreArgs.length > 0 ) { |
|
130 |
showDialog(moreArgs[0]); |
|
131 |
System.exit(0); |
|
132 |
} |
|
133 |
showLauncher(); |
|
134 |
} |
|
135 |
|
|
136 |
private void showDialog(String name) { |
|
137 |
if (!name.endsWith(".dlg")) { |
|
138 |
name = name + ".dlg"; |
|
139 |
} |
|
140 |
ScriptingDialog dlg = (ScriptingDialog) manager |
|
141 |
.getScript(new File(name)); |
|
142 |
dlg.setShowMode(ScriptingDialog.MODE_DIALOG); |
|
143 |
dlg.run(); |
|
144 |
} |
|
145 |
|
|
146 |
private void showLauncher() { |
|
147 |
JFrame frame = new JFrame("gvSIG's Script Framework"); |
|
148 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
149 |
|
|
150 |
// Create the menu bar. |
|
151 |
JMenuBar menuBar = new JMenuBar(); |
|
152 |
|
|
153 |
// Build the menu. |
|
154 |
JMenu menu_file = new JMenu("File"); |
|
155 |
|
|
156 |
JMenuItem menuItem_composer = new JMenuItem("Composer"); |
|
157 |
menuItem_composer.addActionListener(new ActionListener() { |
|
158 |
|
|
159 |
public void actionPerformed(ActionEvent e) { |
|
160 |
showComposer(); |
|
161 |
} |
|
162 |
}); |
|
163 |
menu_file.add(menuItem_composer); |
|
164 |
|
|
165 |
JMenuItem menuItem_installer = new JMenuItem("Install package"); |
|
166 |
menuItem_installer.addActionListener(new ActionListener() { |
|
167 |
|
|
168 |
public void actionPerformed(ActionEvent e) { |
|
169 |
showPackageInstaller(manager); |
|
170 |
} |
|
171 |
}); |
|
172 |
menu_file.add(menuItem_installer); |
|
173 |
|
|
174 |
JMenuItem menuItem_installPackage = new JMenuItem("Build package"); |
|
175 |
menuItem_installer.addActionListener(new ActionListener() { |
|
176 |
|
|
177 |
public void actionPerformed(ActionEvent e) { |
|
178 |
showPackageBuilder(manager); |
|
179 |
} |
|
180 |
}); |
|
181 |
menu_file.add(menuItem_installPackage); |
|
182 |
|
|
183 |
menu_file.addSeparator(); |
|
184 |
|
|
185 |
JMenuItem menuItem_exit = new JMenuItem("Exit"); |
|
186 |
menuItem_exit.addActionListener(new ActionListener() { |
|
187 |
|
|
188 |
public void actionPerformed(ActionEvent e) { |
|
189 |
System.exit(0); |
|
190 |
} |
|
191 |
}); |
|
192 |
menu_file.add(menuItem_exit); |
|
193 |
|
|
194 |
menuBar.add(menu_file); |
|
195 |
|
|
196 |
frame.add(menuBar, BorderLayout.NORTH); |
|
197 |
frame.add(uimanager.createLauncher().asJComponent(), BorderLayout.CENTER); |
|
198 |
|
|
199 |
// Display the window. |
|
200 |
frame.pack(); |
|
201 |
frame.setVisible(true); |
|
202 |
|
|
203 |
} |
|
204 |
|
|
205 |
@SuppressWarnings("unused") |
|
206 |
private Date getDate(int year, int month, int day) { |
|
207 |
Calendar cal = Calendar.getInstance(); |
|
208 |
cal.set(year, month, day); |
|
209 |
return cal.getTime(); |
|
210 |
} |
|
211 |
|
|
212 |
private URL getResource(String name) { |
|
213 |
URL resource = this.getClass().getResource(name); |
|
214 |
return resource; |
|
215 |
} |
|
216 |
|
|
217 |
private void showComposer() { |
|
218 |
showWindow(uimanager.createComposer().asJComponent(), "Scripting Composer"); |
|
219 |
} |
|
220 |
|
|
221 |
private void showPackageInstaller(ScriptingManager manager) { |
|
222 |
// not implemented |
|
223 |
} |
|
224 |
|
|
225 |
private void showPackageBuilder(ScriptingManager manager) { |
|
226 |
// not implemented |
|
227 |
} |
|
228 |
|
|
229 |
private void showWindow(JComponent component, String title) { |
|
230 |
JFrame frame = new JFrame(title); |
|
231 |
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
232 |
|
|
233 |
frame.setContentPane(component); |
|
234 |
|
|
235 |
// Display the window. |
|
236 |
frame.pack(); |
|
237 |
frame.setVisible(true); |
|
238 |
} |
|
239 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/javadoc/overview.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 overview.</p> |
|
11 |
|
|
12 |
<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#overviewcomment">Javadoc Tool documentation about the overview file</a></p> |
|
13 |
|
|
14 |
</body> |
|
15 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/impl/scripts/Test.groovy | ||
---|---|---|
1 |
/** |
|
2 |
* package com.disid.groovygis |
|
3 |
*/ |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
*/ |
|
9 |
class Test { |
|
10 |
|
|
11 |
static main(args) { |
|
12 |
println "Hello world" |
|
13 |
} |
|
14 |
} |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/gvsig.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="gvsig-logo1-association.jpg"><br> |
|
5 |
<h2>gvSIG desktop</h2> |
|
6 |
<p> |
|
7 |
A Geographic Information System (GIS) for desktop environments<br> |
|
8 |
<br> |
|
9 |
Version: %(version)<br> |
|
10 |
Build: %(build)<br> |
|
11 |
© Copyright gvSIG Association. All rights reserved.<br> |
|
12 |
<br> |
|
13 |
For more information, contact:<a href="http://www.gvsig.com/contact-info">http://www.gvsig.com/contact-info</a><br> |
|
14 |
Or visit <a href="http://www.gvsig.org">http://www.gvsig.org</a> |
|
15 |
</p> |
|
16 |
<br> |
|
17 |
<br> |
|
18 |
<br> |
|
19 |
<font face="Arial, Helvetica, sans-serif"> |
|
20 |
This program is free software; you can redistribute it and/or |
|
21 |
modify it under the terms of the GNU General Public License |
|
22 |
as published by the Free Software Foundation; either version 2 |
|
23 |
of the License, or (at your option) any later version. |
|
24 |
<br> |
|
25 |
This program is distributed in the hope that it will be useful, |
|
26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
GNU General Public License for more dlogo.jpgetails.<br> |
|
29 |
<br> |
|
30 |
You should have received a copy of the GNU General Public License |
|
31 |
along with this program; if not, write to the Free Software |
|
32 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
33 |
<br> |
|
34 |
|
|
35 |
<p>Agradecimientos:</p> |
|
36 |
<ul> |
|
37 |
<li><a target="blank" href="http://www.gvsig.org/web/community/agradecimientos/traductores/">Traductores</a></li> |
|
38 |
<li><a target="blank" href="http://www.gvsig.org/web/community/agradecimientos/testers/">Testers</a></li> |
|
39 |
<li><a target="blank" href="http://www.gvsig.org/web/community/agradecimientos/otras-colaboraciones/">Otras colaboraciones</a></li> |
|
40 |
</ul> |
|
41 |
|
|
42 |
|
|
43 |
</font> |
|
44 |
</body> |
|
45 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/prodevelop.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="prodevelop-logo.png"><br> |
|
5 |
|
|
6 |
<h2>PRODEVELOP</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/scolab.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="scolab-logo.png"><br> |
|
5 |
|
|
6 |
<h2>Software Colaborativo</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/iver.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="iver-logo.png"><br> |
|
5 |
|
|
6 |
<h2>IVER</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/csgis.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="csgis-logo.gif"><br> |
|
5 |
|
|
6 |
<h2>CSGIS</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/disid.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="disid-logo.jpeg"><br> |
|
5 |
|
|
6 |
<h2>DiSiD Technologies</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/main/gva.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
|
|
4 |
<img src="gva-logo_horiz_bicolor.png"><br> |
|
5 |
|
|
6 |
<h2>GVA</h2> |
|
7 |
<br> |
|
8 |
|
|
9 |
<p>EN CONSTRUCCION</p> |
|
10 |
|
|
11 |
</body> |
|
12 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/help/introduction.html | ||
---|---|---|
1 |
<html> |
|
2 |
<h1>Hola</h1> |
|
3 |
</html> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/help/toc.xml | ||
---|---|---|
1 |
<!DOCTYPE toc |
|
2 |
PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN" |
|
3 |
"http://java.sun.com/products/javahelp/toc_1_0.dtd"> |
|
4 |
|
|
5 |
<toc version="1.0"> |
|
6 |
<tocitem text="gvSIG scripting framework"> |
|
7 |
<tocitem text="Introduction" target="introduction.html"/> |
|
8 |
</tocitem> |
|
9 |
</toc> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/help/help.jhm | ||
---|---|---|
1 |
<?xml version='1.0' encoding='ISO-8859-1' ?> |
|
2 |
<!DOCTYPE map |
|
3 |
PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN" |
|
4 |
"http://java.sun.com/products/javahelp/map_1_0.dtd"> |
|
5 |
|
|
6 |
<map version="1.0"> |
|
7 |
<mapID target="introduction.html" url="introduction.html" /> |
|
8 |
</map> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/org/gvsig/scripting/help/help.hs | ||
---|---|---|
1 |
<?xml version='1.0' encoding='ISO-8859-1' ?> |
|
2 |
<!DOCTYPE helpset |
|
3 |
PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN" |
|
4 |
"http://java.sun.com/products/javahelp/helpset_1_0.dtd"> |
|
5 |
|
|
6 |
<?TestTarget this is data for the test target ?> |
|
7 |
|
|
8 |
<helpset version="1.0"> |
|
9 |
|
|
10 |
<!-- title --> |
|
11 |
<title>ScriptingFramework</title> |
|
12 |
|
|
13 |
<!-- maps --> |
|
14 |
<maps> |
|
15 |
<homeID>main</homeID> |
|
16 |
<mapref location="help.jhm"/> |
|
17 |
</maps> |
|
18 |
|
|
19 |
<!-- views --> |
|
20 |
<view> |
|
21 |
<name>TOC</name> |
|
22 |
<label>TOC</label> |
|
23 |
<type>javax.help.TOCView</type> |
|
24 |
<data>toc.xml</data> |
|
25 |
</view> |
|
26 |
<!-- |
|
27 |
<view> <name>Index</name> |
|
28 |
<label>Indice</label> |
|
29 |
<type>javax.help.IndexView</type> |
|
30 |
<data>index.xml</data> |
|
31 |
</view> |
|
32 |
|
|
33 |
<view> |
|
34 |
<name>Search</name> |
|
35 |
<label>Busqueda</label> |
|
36 |
<type>javax.help.SearchView</type> |
|
37 |
</view> |
|
38 |
|
|
39 |
--> |
|
40 |
<view> |
|
41 |
<name>Favorites</name> |
|
42 |
<label>Favoritos</label> |
|
43 |
<type>javax.help.FavoritesView</type> |
|
44 |
</view> |
|
45 |
|
|
46 |
<presentation default="true" displayviewimages="false"> |
|
47 |
<name>main window</name> |
|
48 |
<size width="700" height="400" /> |
|
49 |
<location x="200" y="200" /> |
|
50 |
<title>gvSIG - Ayuda en linea</title> |
|
51 |
<image>toplevelfolder</image> |
|
52 |
<toolbar> |
|
53 |
<helpaction image="action.back">javax.help.BackAction</helpaction> |
|
54 |
<helpaction image="action.forward">javax.help.ForwardAction</helpaction> |
|
55 |
</toolbar> |
|
56 |
</presentation> |
|
57 |
</helpset> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your library classes. |
|
2 |
|
|
3 |
This folder is added to the runtime classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, into this folder you can find some examples of resource bundle |
|
7 |
property files that may be used by your library classes. |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/src/main/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
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 |
org.gvsig.tools packages. |
|
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.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.scripting"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/org.gvsig.scripting.main/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.147/org.gvsig.scripting.main/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.147/org.gvsig.scripting.main/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.147/org.gvsig.scripting.main/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.main</artifactId> |
|
6 |
<packaging>jar</packaging> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.scripting</artifactId> |
|
11 |
<version>2.3.147</version> |
|
12 |
</parent> |
|
13 |
<dependencies> |
|
14 |
<dependency> |
|
15 |
<groupId>org.gvsig</groupId> |
|
16 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
17 |
<scope>compile</scope> |
|
18 |
</dependency> |
|
19 |
<dependency> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
22 |
<scope>runtime</scope> |
|
23 |
</dependency> |
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.about.api</artifactId> |
|
27 |
<scope>compile</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.about.impl</artifactId> |
|
32 |
<scope>runtime</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.scripting.lib.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.scripting.lib.impl</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>org.gvsig</groupId> |
|
46 |
<artifactId>org.gvsig.scripting.swing.api</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.gvsig</groupId> |
|
51 |
<artifactId>org.gvsig.scripting.swing.impl</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
<!-- |
|
55 |
<dependency> |
|
56 |
<groupId>com.jgoodies</groupId> |
|
57 |
<artifactId>jgoodies-looks</artifactId> |
|
58 |
<scope>compile</scope> |
|
59 |
</dependency> |
|
60 |
--> |
|
61 |
<dependency> |
|
62 |
<groupId>commons-cli</groupId> |
|
63 |
<artifactId>commons-cli</artifactId> |
|
64 |
<scope>compile</scope> |
|
65 |
</dependency> |
|
66 |
</dependencies> |
|
67 |
</project> |
|
0 | 68 |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147/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.147</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.343</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.147</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147</developerConnection> |
|
21 |
<url>https://devel.gvsig.org/svn/gvsig-scripting/org.gvsig.scripting/tags/org.gvsig.scripting-2.3.147</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.147</version> |
|
90 |
</dependency> |
|
91 |
<dependency> |
|
92 |
<groupId>org.gvsig</groupId> |
|
93 |
<artifactId>org.gvsig.scripting.swing.api</artifactId> |
|
94 |
<version>2.3.147</version> |
|
95 |
</dependency> |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.scripting.lib.impl</artifactId> |
|
99 |
<version>2.3.147</version> |
|
100 |
</dependency> |
|
101 |
<dependency> |
|
102 |
<groupId>org.gvsig</groupId> |
|
103 |
<artifactId>org.gvsig.scripting.swing.impl</artifactId> |
|
104 |
<version>2.3.147</version> |
|
105 |
</dependency> |
|
106 |
|
|
107 |
<dependency> |
|
108 |
<groupId>org.gvsig</groupId> |
|
109 |
<artifactId>org.gvsig.scripting.main</artifactId> |
|
110 |
<version>2.3.147</version> |
|
111 |
</dependency> |
|
112 |
|
|
113 |
<dependency> |
|
114 |
<groupId>org.gvsig</groupId> |
|
115 |
<artifactId>org.gvsig.scripting.thing</artifactId> |
|
116 |
<version>2.3.147</version> |
|
117 |
</dependency> |
|
118 |
|
|
119 |
<dependency> |
|
120 |
<groupId>org.gvsig</groupId> |
|
121 |
<artifactId>org.gvsig.scripting.app.mainplugin</artifactId> |
|
122 |
<version>2.3.147</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.147/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.147/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.147/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 |
|
Also available in: Unified diff