Revision 1248

View differences:

org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<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">
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.scripting.app.mainplugin</artifactId>
6
    <packaging>jar</packaging>
7
    <name>${project.artifactId}</name>
8
    <description><![CDATA[
9
This plugin provides support for scripting to gvSIG.
10
Among other things it contains:
11

  
12
- The gvSIG scripting engine
13
- The gvSIG script editor
14
- Script engines for:
15
   - Jython
16
   - Groovy
17
   - javascript
18
   - Renjin
19

  
20
- The script install module for the add-on manager.
21
- Utilities to generate packages of complements with our scripts.
22
- Python libraries as:
23
   - Six - Utilities for writing code that runs on Python 2 and 3
24
   - PyLint - Python source code analyzer
25
   - Pygments - syntax highlighting package
26
   - CSSUtils - CSS Cascading Style Sheets library
27
   - Docutils - Python Documentation Utilities
28
   - geopy - client for several popular geocoding web services
29
   - PyInliner - CSS-to-inline-styles conversion tool for HTML
30
   - Statistics - functions for calculating statistics of data
31
   - Cartodb - simple CartoDB client to perform requests against the CartoDB API
32

  
33
- Java libraries to use from scripting like:
34
   - Abeille forms deseigner
35
   - jOpenDocument
36
   - JNumeric
37
   - CSSBox
38

  
39

  
40
This plugin can be configured to be preinstalled automatically, allowing 
41
"Script" type plugins to be installed during the application installation process. 
42
To do this, the following entries must be added to the "packages.properties" 
43
of gvspks::
44

  
45
    installers=scripts
46
    installer.scripts.initializer=org.gvsig.scripting.app.extension.ScriptsInstallerInitializer
47
    installer.scripts.package.code=org.gvsig.scripting.app.mainplugin
48
    installer.scripts.factory.name=Script
49
    installer.scripts.libs=lib
50

  
51
If the "installers" entry already exists, add "scripts" to the end separating 
52
it with a space.    
53
                            
54
]]></description>
55
    <parent>
56
        <groupId>org.gvsig</groupId>
57
        <artifactId>org.gvsig.scripting.app</artifactId>
58
        <version>2.3.95</version>
59
    </parent>
60
    <dependencies>
61
        <dependency>
62
            <groupId>org.gvsig</groupId>
63
            <artifactId>org.gvsig.tools.lib</artifactId>
64
            <scope>compile</scope>
65
        </dependency>
66
        <!--
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.tools.lib</artifactId>
70
            <scope>test</scope>
71
        </dependency>
72
        -->
73
        <dependency>
74
            <groupId>org.gvsig</groupId>
75
            <artifactId>org.gvsig.i18n</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
        <dependency>
79
            <groupId>org.gvsig</groupId>
80
            <artifactId>org.gvsig.andami</artifactId>
81
            <scope>compile</scope>
82
        </dependency>
83
        <dependency>
84
            <groupId>org.gvsig</groupId>
85
            <artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId>
86
            <scope>compile</scope>
87
        </dependency>
88
        <dependency>
89
            <groupId>org.gvsig</groupId>
90
            <artifactId>org.gvsig.app.mainplugin</artifactId>
91
            <scope>compile</scope>
92
        </dependency>
93
        <dependency>
94
            <groupId>org.gvsig</groupId>
95
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
96
            <scope>compile</scope>
97
        </dependency>
98
        <dependency>
99
            <groupId>org.gvsig</groupId>
100
            <artifactId>org.gvsig.about.api</artifactId>
101
            <scope>compile</scope>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.gvsig</groupId>
105
            <artifactId>org.gvsig.scripting.lib.api</artifactId>
106
            <scope>compile</scope>
107
        </dependency>
108
        <dependency>
109
            <groupId>org.gvsig</groupId>
110
            <artifactId>org.gvsig.scripting.swing.api</artifactId>
111
            <scope>compile</scope>
112
        </dependency>
113
        <dependency>
114
            <groupId>org.gvsig</groupId>
115
            <artifactId>org.gvsig.scripting.lib.impl</artifactId>
116
            <scope>compile</scope>
117
        </dependency>
118
        <dependency>
119
            <groupId>org.gvsig</groupId>
120
            <artifactId>org.gvsig.scripting.swing.impl</artifactId>
121
            <scope>compile</scope>
122
        </dependency>
123

  
124
        <!-- force adding -->
125
        <dependency>
126
            <groupId>org.ini4j</groupId>
127
            <artifactId>ini4j</artifactId>
128
            <scope>runtime</scope>
129
        </dependency>
130
        <dependency>
131
            <groupId>net.sourceforge.thinlet</groupId>
132
            <artifactId>thinlet</artifactId>
133
            <scope>runtime</scope>
134
        </dependency>
135
        <dependency>
136
            <groupId>org.gvsig</groupId>
137
            <artifactId>org.gvsig.scripting.thing</artifactId>
138
            <scope>runtime</scope>
139
        </dependency>
140
        <dependency>
141
            <groupId>com.jeta</groupId>
142
            <artifactId>abeille</artifactId>
143
            <type>tar.gz</type>
144
            <scope>runtime</scope>
145
        </dependency>
146
        <dependency>
147
            <groupId>org.jopendocument</groupId>
148
            <artifactId>jOpenDocument</artifactId>
149
            <scope>runtime</scope>
150
        </dependency>
151
        <dependency>
152
            <groupId>com.github.tbekolay.jnumeric</groupId>
153
            <artifactId>jnumeric</artifactId>
154
            <scope>runtime</scope>
155
        </dependency>
156
 
157
        <dependency>
158
            <groupId>org.apache.tika</groupId>
159
            <artifactId>tika-core</artifactId>
160
            <scope>runtime</scope>
161
        </dependency>
162

  
163
        <dependency>
164
            <groupId>org.python</groupId>
165
            <artifactId>${jython.artifactId}</artifactId>
166
            <scope>runtime</scope>
167
        </dependency>
168
        <dependency>
169
            <groupId>org.codehaus.groovy</groupId>
170
            <artifactId>groovy-all</artifactId>
171
            <scope>runtime</scope>
172
        </dependency>
173
        <dependency>
174
            <groupId>org.renjin</groupId>
175
            <artifactId>renjin-script-engine</artifactId>
176
            <classifier>jar-with-dependencies</classifier>
177
            <scope>runtime</scope>
178
        </dependency>      
179
        
180
        <!--
181
        <dependency>
182
            <groupId>org.scala-lang</groupId>
183
            <artifactId>scala-dist</artifactId>
184
            <scope>runtime</scope>
185
        </dependency>
186
        <dependency>
187
            <groupId>org.scala-lang</groupId>
188
            <artifactId>scala-compiler</artifactId>
189
            <scope>runtime</scope>
190
        </dependency>
191
        <dependency>
192
            <groupId>org.scala-lang</groupId>
193
            <artifactId>scala-library</artifactId>
194
            <scope>runtime</scope>
195
        </dependency>
196
        <dependency>
197
            <groupId>org.scala-lang</groupId>
198
            <artifactId>scala-reflect</artifactId>
199
            <scope>runtime</scope>
200
        </dependency>
201
        <dependency>
202
            <groupId>org.scala-lang</groupId>
203
            <artifactId>scalap</artifactId>
204
            <scope>runtime</scope>
205
        </dependency>
206
        <dependency>
207
            <groupId>jline</groupId>
208
            <artifactId>jline</artifactId>
209
            <scope>runtime</scope>
210
        </dependency>
211
        -->
212
        <dependency>
213
            <groupId>net.sf.cssbox</groupId>
214
            <artifactId>swingbox</artifactId>
215
            <scope>runtime</scope>
216
        </dependency>
217
        <dependency>
218
            <groupId>net.sf.cssbox</groupId>
219
            <artifactId>cssbox</artifactId>
220
            <scope>runtime</scope>
221
        </dependency>
222
        
223
        <dependency>
224
            <groupId>net.sourceforge.nekohtml</groupId>
225
            <artifactId>nekohtml</artifactId>
226
            <scope>runtime</scope>
227
        </dependency>
228
        <dependency>
229
            <groupId>net.sf.cssbox</groupId>
230
            <artifactId>jstyleparser</artifactId>
231
            <scope>runtime</scope>
232
        </dependency>
233
        <dependency>
234
            <groupId>org.antlr</groupId>
235
            <artifactId>antlr-runtime</artifactId>
236
            <!-- Ojo que forzamos una version en concreto -->
237
            <version>3.5.2</version>
238
        </dependency>     
239
        
240
        <!-- JGit runtime dependencies -->   
241
        <dependency>
242
            <groupId>org.eclipse.jgit</groupId>
243
            <artifactId>org.eclipse.jgit</artifactId>
244
            <scope>runtime</scope>
245
        </dependency>                    
246
        
247
        <dependency>
248
            <groupId>org.icepdf.os</groupId>
249
            <artifactId>icepdf-viewer</artifactId>
250
            <version>6.2.2</version>
251
            <exclusions>
252
                <exclusion>
253
                    <groupId>batik</groupId>
254
                    <artifactId>batik-awt-util</artifactId>
255
                </exclusion>        
256
                <exclusion>
257
                    <groupId>batik</groupId>
258
                    <artifactId>batik-dom</artifactId>
259
                </exclusion>        
260
                <exclusion>
261
                    <groupId>batik</groupId>
262
                    <artifactId>batik-svg-dom</artifactId>
263
                </exclusion>        
264
                <exclusion>
265
                    <groupId>batik</groupId>
266
                    <artifactId>batik-svggen</artifactId>
267
                </exclusion>        
268
                <exclusion>
269
                    <groupId>batik</groupId>
270
                    <artifactId>batik-util</artifactId>
271
                </exclusion>        
272
                <exclusion>
273
                    <groupId>batik</groupId>
274
                    <artifactId>batik-xml</artifactId>
275
                </exclusion>        
276
            </exclusions>
277
                
278
        </dependency>
279
                
280
<!--        <dependency>
281
            <groupId>com.vladsch.flexmark</groupId>
282
            <artifactId>flexmark-all</artifactId>
283
            <version>0.60.2</version>
284
        </dependency>-->
285
        <dependency>
286
            <groupId>com.vladsch.flexmark</groupId>
287
            <artifactId>flexmark-all</artifactId>
288
            <version>0.60.2</version>
289
            <scope>runtime</scope>
290
        </dependency>
291
        <dependency>
292
          <groupId>org.apache.pdfbox</groupId>
293
          <artifactId>pdfbox</artifactId>
294
          <version>2.0.16</version>
295
          <scope>runtime</scope>
296
        </dependency>
297
        <dependency>
298
          <groupId>org.apache.pdfbox</groupId>
299
          <artifactId>fontbox</artifactId>
300
          <version>2.0.16</version>
301
          <scope>runtime</scope>
302
        </dependency>
303

  
304
    </dependencies>
305

  
306

  
307
    <properties>
308
        <gvsig.package.info.name>Scripting framework</gvsig.package.info.name>
309
        <gvsig.package.info.dependencies>required: org.gvsig.app.document.table.app.mainplugin -ge 2</gvsig.package.info.dependencies>
310
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-scripting/pool</gvsig.package.info.poolURL>
311
        <gvsig.package.info.sourcesURL>https://devel.gvsig.org/svn/gvsig-scripting</gvsig.package.info.sourcesURL>
312
        <gvsig.package.info.state>testing</gvsig.package.info.state>
313
        <gvsig.package.info.categories>Development</gvsig.package.info.categories>
314
        <gvsig.package.info.official>true</gvsig.package.info.official>
315

  
316
    </properties>
317

  
318
    <build>
319
        <plugins>
320

  
321
            <plugin>
322
                <groupId>org.apache.maven.plugins</groupId>
323
                <artifactId>maven-dependency-plugin</artifactId>
324
                <executions>
325
                    <execution>
326
                        <id>unpack</id>
327
                        <phase>process-sources</phase>
328
                        <goals>
329
                            <goal>unpack</goal>
330
                        </goals>
331
                        <configuration>
332
                            <artifactItems>
333
                                <artifactItem>
334
                                    <groupId>com.jeta</groupId>
335
                                    <artifactId>abeille</artifactId>
336
                                    <version>2.1.0.M3</version>
337
                                    <type>tar.gz</type>
338
                                    <overWrite>true</overWrite>
339
                                    <outputDirectory>target/abeille</outputDirectory>
340
                                </artifactItem>
341
                            </artifactItems>
342
                        </configuration>
343
                    </execution>
344
                </executions>
345
            </plugin>
346

  
347
        </plugins>
348
    </build>
349

  
350
</project>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/buildNumber.properties
1
#Sun Apr 26 17:31:28 CEST 2020
2
buildNumber=175
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
        <fileSet>
24
            <directory>target/abeille</directory>
25
            <outputDirectory>.</outputDirectory>
26
        </fileSet>
27
  </fileSets>
28

  
29
  <dependencySets>
30

  
31
    <dependencySet>
32
      <useProjectArtifact>false</useProjectArtifact>
33
      <useTransitiveDependencies>false</useTransitiveDependencies>
34
      <outputDirectory>lib</outputDirectory>
35
      <includes>
36
        <!--
37
            Plugin libraries
38
        -->  
39
        <include>org.ini4j:ini4j</include>
40
        <include>net.sourceforge.thinlet:thinlet</include>
41
        <include>org.gvsig:org.gvsig.scripting.thing</include>
42
        <include>org.gvsig:org.gvsig.scripting.lib.api</include>
43
        <include>org.gvsig:org.gvsig.scripting.swing.api</include>
44
        <include>org.gvsig:org.gvsig.scripting.lib.impl</include>
45
        <include>org.gvsig:org.gvsig.scripting.swing.impl</include>
46
        <include>org.apache.tika:tika-core</include>        
47
        
48
        <!--
49
            Utility libraries
50
        -->
51
        <!-- JOpenDocument -->    
52
        <include>org.jopendocument:jOpenDocument</include>
53
        
54
        <!-- CSSBox webbrowser -->
55
        <include>net.sf.cssbox:cssbox</include>
56
        <include>net.sf.cssbox:swingbox</include>
57
        <include>net.sf.cssbox:jstyleparser</include>
58
        <include>net.sourceforge.nekohtml:nekohtml</include>
59
        <include>org.antlr:antlr-runtime</include>
60
                                
61
        <!--
62
            Script engines libraries
63
        -->
64

  
65
        <include>org.codehaus.groovy:groovy-all</include>
66

  
67
        <!--
68
        <include>org.renjin:renjin-script-engine:jar:jar-with-dependencies</include>
69
        -->
70
        
71
        <include>org.python:${jython.artifactId}</include>
72
        <include>com.github.tbekolay.jnumeric:jnumeric</include>
73
        
74
      </includes>
75
    </dependencySet>
76

  
77
    <dependencySet>
78
      <useProjectArtifact>false</useProjectArtifact>
79
      <useTransitiveDependencies>true</useTransitiveDependencies>
80
      <outputDirectory>lib</outputDirectory>
81
      <includes>
82
        <!--
83
            JGit support runtime libraries
84
        -->        
85
        <include>org.eclipse.jgit:org.eclipse.jgit</include>
86
        <include>com.jcraft:jsch</include>
87
        <include>com.googlecode.javaewah:JavaEWAH</include>
88
        <include>org.apache.httpcomponents:httpclient</include>
89
        <include>org.apache.httpcomponents:httpcore</include>
90
      </includes>
91
    </dependencySet>
92

  
93
    <dependencySet>
94
      <useProjectArtifact>false</useProjectArtifact>
95
      <useTransitiveDependencies>true</useTransitiveDependencies>
96
      <outputDirectory>lib</outputDirectory>
97
      <includes>
98
        <!--
99
            ICEPDF support runtime libraries
100
        -->        
101
        <include>org.icepdf.os:icepdf-viewer</include>
102
        <include>org.icepdf.os:icepdf-core</include>
103
      </includes>
104
    </dependencySet>
105

  
106
    <dependencySet>
107
      <useProjectArtifact>false</useProjectArtifact>
108
      <useTransitiveDependencies>true</useTransitiveDependencies>
109
      <outputDirectory>lib</outputDirectory>
110
      <includes>
111
        <!--
112
            flexmark-java, Markdown support libraries
113
        -->        
114
        <include>com.vladsch.flexmark:flexmark-all</include>
115
        <include>com.vladsch.flexmark:flexmark</include>
116
        <include>com.vladsch.flexmark:flexmark-ext-abbreviation</include>
117
        <include>com.vladsch.flexmark:flexmark-util</include>
118
        <include>com.vladsch.flexmark:flexmark-ext-admonition</include>
119
        <include>com.vladsch.flexmark:flexmark-ext-anchorlink</include>
120
        <include>com.vladsch.flexmark:flexmark-ext-aside</include>
121
        <include>com.vladsch.flexmark:flexmark-ext-attributes</include>
122
        <include>com.vladsch.flexmark:flexmark-ext-autolink</include>
123
        <include>org.nibor.autolink:autolink</include>
124
        <include>com.vladsch.flexmark:flexmark-ext-definition</include>
125
        <include>com.vladsch.flexmark:flexmark-ext-emoji</include>
126
        <include>com.vladsch.flexmark:flexmark-ext-enumerated-reference</include>
127
        <include>com.vladsch.flexmark:flexmark-ext-escaped-character</include>
128
        <include>com.vladsch.flexmark:flexmark-ext-footnotes</include>
129
        <include>com.vladsch.flexmark:flexmark-ext-gfm-issues</include>
130
        <include>com.vladsch.flexmark:flexmark-ext-gfm-strikethrough</include>
131
        <include>com.vladsch.flexmark:flexmark-ext-gfm-tasklist</include>
132
        <include>com.vladsch.flexmark:flexmark-ext-gfm-users</include>
133
        <include>com.vladsch.flexmark:flexmark-ext-gitlab</include>
134
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-front-matter</include>
135
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-tag</include>
136
        <include>com.vladsch.flexmark:flexmark-ext-media-tags</include>
137
        <include>com.vladsch.flexmark:flexmark-ext-macros</include>
138
        <include>com.vladsch.flexmark:flexmark-ext-ins</include>
139
        <include>com.vladsch.flexmark:flexmark-ext-xwiki-macros</include>
140
        <include>com.vladsch.flexmark:flexmark-ext-superscript</include>
141
        <include>com.vladsch.flexmark:flexmark-ext-tables</include>
142
        <include>com.vladsch.flexmark:flexmark-ext-toc</include>
143
        <include>com.vladsch.flexmark:flexmark-ext-typographic</include>
144
        <include>com.vladsch.flexmark:flexmark-ext-wikilink</include>
145
        <include>com.vladsch.flexmark:flexmark-ext-yaml-front-matter</include>
146
        <include>com.vladsch.flexmark:flexmark-ext-youtube-embedded</include>
147
        <include>com.vladsch.flexmark:flexmark-html2md-converter</include>
148
        <include>org.jsoup:jsoup</include>
149
        <include>com.vladsch.flexmark:flexmark-jira-converter</include>
150
        <include>com.vladsch.flexmark:flexmark-pdf-converter</include>
151
        <include>com.openhtmltopdf:openhtmltopdf-core</include>
152
        <include>com.openhtmltopdf:openhtmltopdf-pdfbox</include>
153
        <include>org.apache.pdfbox:xmpbox</include>
154
        <include>de.rototor.pdfbox:graphics2d</include>
155
        <include>com.openhtmltopdf:openhtmltopdf-rtl-support</include>
156
        <include>com.ibm.icu:icu4j</include>
157
        <include>com.openhtmltopdf:openhtmltopdf-jsoup-dom-converter</include>
158
        <include>com.vladsch.flexmark:flexmark-profile-pegdown</include>
159
        <include>com.vladsch.flexmark:flexmark-util-ast</include>
160
        <include>org.jetbrains:annotations</include>
161
        <include>com.vladsch.flexmark:flexmark-util-builder</include>
162
        <include>com.vladsch.flexmark:flexmark-util-collection</include>
163
        <include>com.vladsch.flexmark:flexmark-util-data</include>
164
        <include>com.vladsch.flexmark:flexmark-util-dependency</include>
165
        <include>com.vladsch.flexmark:flexmark-util-format</include>
166
        <include>com.vladsch.flexmark:flexmark-util-html</include>
167
        <include>com.vladsch.flexmark:flexmark-util-misc</include>
168
        <include>com.vladsch.flexmark:flexmark-util-options</include>
169
        <include>com.vladsch.flexmark:flexmark-util-sequence</include>
170
        <include>com.vladsch.flexmark:flexmark-util-visitor</include>
171
        <include>com.vladsch.flexmark:flexmark-youtrack-converter</include>
172
        <include>org.apache.pdfbox:pdfbox</include>
173
        <include>org.apache.pdfbox:fontbox</include>
174
        <include>commons-logging:commons-logging</include>
175
      </includes>
176
    </dependencySet>
177
    
178
  </dependencySets>
179

  
180
</assembly>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptingUtils.java
1
package org.gvsig.scripting.app.extension;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.io.File;
6
import java.io.IOException;
7
import java.nio.file.FileVisitOption;
8
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
9
import java.nio.file.FileVisitResult;
10
import java.nio.file.Files;
11
import java.nio.file.Path;
12
import java.nio.file.Paths;
13
import java.nio.file.SimpleFileVisitor;
14
import java.nio.file.attribute.BasicFileAttributes;
15
import java.text.MessageFormat;
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.Collections;
19
import java.util.Comparator;
20
import java.util.EnumSet;
21
import java.util.List;
22
import java.util.function.Predicate;
23
import javax.swing.JOptionPane;
24
import javax.swing.SwingUtilities;
25
import org.apache.commons.io.FileUtils;
26
import org.apache.commons.io.FilenameUtils;
27
import org.apache.commons.io.IOCase;
28
import org.apache.commons.lang3.BooleanUtils;
29
import org.gvsig.scripting.DataFolderFound;
30
import org.gvsig.scripting.ScriptingBaseScript;
31
import org.gvsig.scripting.ScriptingFolder;
32
import org.gvsig.scripting.ScriptingLocator;
33
import org.gvsig.scripting.ScriptingManager;
34
import org.gvsig.scripting.ScriptingScript;
35
import org.gvsig.scripting.ScriptingUnit;
36
import org.gvsig.scripting.app.extension.messagewait.MessageWait;
37
import org.gvsig.scripting.swing.api.JScriptingComposer;
38
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
39
import org.gvsig.scripting.swing.api.ScriptingUIManager;
40
import static org.gvsig.scripting.swing.api.ScriptingUIManager.SCRIPT_COMPOSER_AUTORUN;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.exception.BaseException;
43
import org.gvsig.tools.i18n.I18nManager;
44
import org.gvsig.tools.packageutils.PackageManager;
45
import org.gvsig.tools.packageutils.Version;
46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
47
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
48
import org.gvsig.tools.swing.api.windowmanager.Dialog;
49
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
50
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
51
import org.gvsig.tools.task.SimpleTaskStatus;
52
import org.gvsig.tools.visitor.VisitCanceledException;
53
import org.gvsig.tools.visitor.Visitor;
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56
import org.gvsig.tools.util.FolderSet;
57
import org.gvsig.tools.util.impl.DefaultFolderSet;
58
/**
59
 *
60
 * @author jjdelcerro
61
 */
62
@SuppressWarnings("UseSpecificCatch")
63
public class ScriptingUtils {
64
    
65
    public static final String SKIP_AUTORUNS = "skipAutoruns";
66
    
67
    private static final Logger LOGGER = LoggerFactory.getLogger(ScriptingExtension.class);
68

  
69
    private boolean executingAutorunScripts = false;
70
    private static boolean composer_initialized = false;
71
    private final MessageWait message;
72

  
73
    /*
74
     * la funcion log y las constantes estan pensadas para usarlas desde los scripts.
75
     */
76
    public static final int INFO = 0;
77
    public static final int TRACE = 1;
78
    public static final int WARN = 2;
79
    public static final int ERROR = 3;
80

  
81
    public static void log(String message) {
82
        log(INFO, message, null);
83
    }
84

  
85
    public static void log(int level, String message) {
86
        log(level, message, null);
87
    }
88

  
89
    public static void log(int level, String message, Throwable th) {
90
        switch( level ) {
91
        case TRACE:
92
            LOGGER.trace(message, th);
93
            break;
94
        case ERROR:
95
            LOGGER.error(message, th);
96
            break;
97
        case WARN:
98
            LOGGER.warn(message, th);
99
            break;
100
        default:
101
        case INFO:
102
            LOGGER.info(message, th);
103
            break;
104
        }
105
    }
106
    private String appversion;
107
    private File pluginHomeFolder;
108

  
109
    public ScriptingUtils() {
110
        message = new MessageWait();
111
    }
112
    
113
    public static File getScriptsHomeFolder(File pluginHomeFolder, String appversion) {
114
        File scriptsHomeFolder;
115
        File f = FileUtils.getFile(pluginHomeFolder, "scripts-folder.txt");
116
        if( f.exists() ) {
117
            try {
118
                List<String> lines = FileUtils.readLines(f);
119
                for( String line : lines ) {
120
                    line = line.trim();
121
                    if( !line.startsWith("#") ) {
122
                        scriptsHomeFolder = new File(line);
123
                        if( !scriptsHomeFolder.isAbsolute() ) {
124
                            scriptsHomeFolder = new File(pluginHomeFolder, line);
125
                        }
126
                        scriptsHomeFolder = new File(
127
                            FilenameUtils.normalizeNoEndSeparator(
128
                                scriptsHomeFolder.getAbsolutePath(),
129
                                true
130
                            )
131
                        );
132
                        if( scriptsHomeFolder.exists() ) {
133
                            return scriptsHomeFolder;
134
                        }
135
                    }
136
                }
137
            } catch (IOException ex) {
138
            }
139
        } else {
140
            try {
141
                FileUtils.touch(f);
142
            } catch (IOException ex) {
143
            }
144
        }
145
        scriptsHomeFolder = FileUtils.getFile(pluginHomeFolder, appversion) ;
146
        return scriptsHomeFolder;
147
    }
148
    
149
    public void initializaPaths(List<File> pluginsFolder, File installFolder, File pluginHoneFolder, String appversion) {
150

  
151
        this.appversion = appversion;
152
        this.pluginHomeFolder = pluginHoneFolder;
153
        ScriptingManager manager = ScriptingLocator.getManager();
154
        manager.setHomeFolder(getScriptsHomeFolder(pluginHoneFolder, appversion));
155

  
156
        ScriptingFolder folder = manager.createLink(
157
            "Common",
158
            manager.getUserFolder(), 
159
            "../../scripts"
160
        );
161
        folder.setProperty(ScriptingUtils.SKIP_AUTORUNS, BooleanUtils.toStringTrueFalse(true));
162
        folder.save();
163
//        manager.createLink(
164
//            "Previous version",
165
//            manager.getUserFolder(), 
166
//            "../../../org.gvsig.scripting.app.extension/scripts"
167
//        );
168

  
169
        List<File> pluginsFolders = new ArrayList<>();
170
        for( File f : pluginsFolder ) {
171
            pluginsFolders.addAll(Arrays.asList(f.listFiles()));
172
        }
173

  
174
        for( File pluginFolder : pluginsFolders ) {
175
            File scriptsFolder = new File(pluginFolder, "scripting/scripts");
176
            if( scriptsFolder.exists() ) {
177
                manager.registerSystemFolder(pluginFolder.getName(), scriptsFolder);
178
            }
179
            File libFolder = new File(pluginFolder, "scripting/lib");
180
            if( libFolder.exists() ) {
181
                manager.addLibFolder(libFolder);
182
            }
183
        }
184
        manager.setPackagesFolder(installFolder);
185

  
186
        File localAddonRepositoryFolder = new File(manager.getRootUserFolder(), "addons");
187
        if( !localAddonRepositoryFolder.exists() ) {
188
            try {
189
                FileUtils.forceMkdir(localAddonRepositoryFolder);
190
            } catch (IOException ex) {
191
                LOGGER.info("Can't create addons folder in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
192
            }
193
        }
194
        File initAddonFile = new File(localAddonRepositoryFolder, "__init__.py");
195
        if( !initAddonFile.exists() ) {
196
            try {
197
                FileUtils.touch(initAddonFile);
198
            } catch (IOException ex) {
199
                LOGGER.info("Can't create addons __init__ file in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
200
            }
201
        }
202
    }
203
    
204
    
205
    public void runScript(String name, Object[] args) {
206
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
207
        WindowManager winmanager = ToolsSwingLocator.getWindowManager();        
208

  
209
        ScriptingBaseScript script = uimanager.getManager().getScript(name);
210
        if( script != null ) {
211
            script.run(args);
212
        } else {
213
            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
214
            dialogs.messageDialog(
215
                    "Can't locate script '" + name + "'.", 
216
                    "ScriptLaunch", 
217
                    JOptionPane.OK_OPTION
218
            );
219
        }
220
    }
221
    
222
    public void runLauncher() {
223
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
224
        WindowManager winmanager = ToolsSwingLocator.getWindowManager();        
225
        winmanager.showWindow(uimanager.createLauncher().asJComponent(), uimanager.getTranslation("Scripting_Launcher"), WindowManager.MODE.TOOL);        
226
    }
227
    
228
    public void runComposer() {
229
        I18nManager i18n = ToolsLocator.getI18nManager();
230
        message.showMessage(
231
                i18n.getTranslation("_notice"),
232
                i18n.getTranslation("_Initializing_the_scripting_plugin_Xhorizontal_ellipsisX") + "\n"
233
                + i18n.getTranslation("_Waiting_to_terminate"),
234
                new MessageWait.WaitingCondition() {
235
            private Thread th = null;
236

  
237
            @Override
238
            public boolean stopWaiting() {
239
                if (executingAutorunScripts) {
240
                    return false;
241
                }
242
                if (composer_initialized) {
243
                    return true;
244
                }
245
                if (th == null) {
246
                    th = new Thread(new ExecuteScriptsFromScriptingFolders(null, "scautorun", SCRIPT_COMPOSER_AUTORUN), "StartupScriptingComposer");
247
                    th.start();
248
                }
249
                return false;
250
            }
251
        },
252
                new Runnable() {
253
            @Override
254
            public void run() {
255
                showScriptingComposer();
256
            }
257
        }
258
        );
259

  
260
    }
261
    
262
    public Runnable getAutorunScriptsOnStartup(List<File> pluginsFolders) {
263
        return new ExecuteAutorunScriptsOnStartup(pluginsFolders);
264
    }
265
    
266
    private void showScriptingComposer() {
267
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
268
        JScriptingComposer composer = uimanager.createComposer();
269
        uimanager.showWindow(
270
            composer.asJComponent(),
271
            uimanager.getTranslation("Scripting_Composer")
272
        );
273
    }
274

  
275
    private class ExecuteScriptsFromScriptingFolders extends AbstractExecuteScripts {
276
        
277
        public ExecuteScriptsFromScriptingFolders(List<File> pluginsFolders, String title, String patternName) {
278
            super(pluginsFolders, title, patternName);
279
        }
280
        
281
        @Override
282
        public void run() {            
283
            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
284
            SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Scripts startup");
285
            status.setIndeterminate();
286
            status.setAutoremove(true);
287
            status.add();
288
            final I18nManager i18nManager = ToolsLocator.getI18nManager();            
289
            try {
290
                LOGGER.info("Searching "+title+" scripts...");
291
                dialogs.message(
292
                    i18nManager.getTranslation("_Searching_autorun_scripts_Xhorizontal_ellipsisX"),
293
                    JOptionPane.INFORMATION_MESSAGE
294
                );
295
                ScriptingManager manager = ScriptingLocator.getManager();
296
                final List<ScriptingScript> scripts = new ArrayList<>();
297
                
298
                Visitor visitor = new Visitor() {
299
                    @Override
300
                    public void visit(Object o) throws VisitCanceledException, BaseException {
301
                        ScriptingUnit unit = (ScriptingUnit) o;
302
                        if( unit instanceof ScriptingScript && 
303
                            FilenameUtils.wildcardMatch(unit.getName(), patternName, IOCase.INSENSITIVE) ) {
304
                            ScriptingScript script = (ScriptingScript) unit;
305
                            if( script.isEnabled() ) {
306
                                scripts.add(script);
307
                            } else {
308
                                LOGGER.info("Skip "+title+" script '" + script.getFile().getAbsolutePath() + "'.");
309
                            }
310
                        }
311
                    }
312
                };
313
                Predicate<ScriptingUnit> includeFilter = new Predicate<ScriptingUnit>() {
314
                    @Override
315
                    public boolean test(ScriptingUnit unit) {
316
                        if( unit instanceof ScriptingFolder ) {
317
                            return !BooleanUtils.toBoolean(unit.getProperty(SKIP_AUTORUNS));
318
                        }
319
                        return false;
320
                    }
321
                };
322
                manager.getSystemFolder().accept(visitor, includeFilter);
323
                manager.getUserFolder().accept(visitor, includeFilter);
324
                sortScripts(scripts);
325
                executeScripts(scripts, status);
326
            } catch(Throwable th) {
327
                
328
            } finally {
329
                composer_initialized = true;
330
                LOGGER.info("Running "+title+" scripts terminated.");
331
                dialogs.message("", JOptionPane.INFORMATION_MESSAGE);
332
                status.terminate();
333
            }
334
        }
335
    }
336

  
337
    public class ExecuteAutorunScriptsOnStartup implements Runnable {
338

  
339
        private final List<File> pluginsFolders;
340

  
341
        public ExecuteAutorunScriptsOnStartup(List<File> pluginsFolders) {
342
            this.pluginsFolders = pluginsFolders;
343
        }
344
        
345
        @Override
346
        public void run() {
347
            Runnable process = new ExecuteScriptsFromFilesystem(
348
                    this.pluginsFolders,
349
                    "autorun", 
350
                    "autorun.inf"
351
            );
352
            process.run();
353
        }
354
    }
355

  
356
    private abstract class AbstractExecuteScripts implements Runnable {
357

  
358
        protected String patternName;
359
        protected String title;
360
        private final List<File> pluginsFolders;
361

  
362
        public AbstractExecuteScripts(List<File> pluginsFolders, String title, String patternName) {
363
            if( pluginsFolders==null ) {
364
                this.pluginsFolders = Collections.EMPTY_LIST;
365
            } else {
366
                this.pluginsFolders = pluginsFolders;
367
            }
368
            this.patternName = patternName;
369
            this.title = title;
370
        }
371
        
372
        protected List<File> getPluginsFolders() {
373
            return this.pluginsFolders;
374
        }
375
        
376
        private String getScriptOrderKey(ScriptingBaseScript o) {
377
            int groupOrder = 500;
378
            String groupName = "default";
379
            int scriptOrder = 500;
380
            String s = o.getProperty("autorun.group.order");
381
            if (s != null) {
382
                try {
383
                    groupOrder = Integer.parseInt(s);
384
                } catch (Exception ex) {
385
                    // Do nothing.
386
                }
387
            }
388
            s = o.getProperty("autorun.group.name");
389
            if (s != null) {
390
                groupName = s;
391
            }
392
            s = o.getProperty("autorun.order");
393
            if (s != null) {
394
                try {
395
                    scriptOrder = Integer.parseInt(s);
396
                } catch (Exception ex) {
397
                    // Do nothing.
398
                }
399
            }
400
            String key = MessageFormat.format(
401
                    "{0,number,000000}.{1}.{2,number,000000}",
402
                    groupOrder,
403
                    groupName,
404
                    scriptOrder
405
            );
406
            return key;
407
        }
408

  
409
        protected void sortScripts(List<ScriptingScript> scripts) {
410
            Collections.sort(scripts, new Comparator<ScriptingBaseScript>() {
411

  
412
                @Override
413
                public int compare(ScriptingBaseScript o1, ScriptingBaseScript o2) {
414
                    return getScriptOrderKey(o2).compareToIgnoreCase(getScriptOrderKey(o1));
415
                }
416
            });
417
        }
418

  
419
        protected void executeScripts(List<ScriptingScript> scripts, SimpleTaskStatus status) {
420
            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
421
            final I18nManager i18nManager = ToolsLocator.getI18nManager();
422
            if (scripts != null && !scripts.isEmpty()) {
423
                if (status != null) {
424
                    status.setRangeOfValues(0, scripts.size());
425
                }
426
                int n = 0;
427
                for (ScriptingBaseScript script : scripts) {
428
                    if (status != null) {
429
                        status.setCurValue(n++);
430
                    }
431
                    try {
432
                        LOGGER.info("running " + title + " script '" + script.getFile().getAbsolutePath() + "' (" + getScriptOrderKey(script) + ", " + script.getIsolationGroup() + ").");
433
                        dialogs.message(
434
                                i18nManager.getTranslation(
435
                                        "_Starting_XnameX",
436
                                        new String[]{
437
                                            script.getFile().getParentFile().getName()}
438
                                ),
439
                                JOptionPane.INFORMATION_MESSAGE
440
                        );
441
                    } catch (Exception ex) {
442
                        // Ignore it
443
                    }
444
                    try {
445
                        // Hacemos un reload por si un sript deshabilito a otro.
446
                        script.reload();
447
                        if( script.isEnabled() ) {
448
                            script.run();
449
                        } else {
450
                            LOGGER.info("Skip " + title + " script '" + script.getFile().getAbsolutePath() + "' (" + getScriptOrderKey(script) + ", " + script.getIsolationGroup() + ").");
451
                        }
452
                    } catch (Exception ex) {
453
                        LOGGER.warn("Can't execute " + title + " from '" + script.getFile().getAbsolutePath() + "'.", ex);
454
                    }
455
                }
456
            }
457

  
458
        }
459
    }
460

  
461
    private class ExecuteScriptsFromFilesystem extends AbstractExecuteScripts {
462

  
463
        public ExecuteScriptsFromFilesystem(List<File> pluginsFolder, String title, String patternName) {
464
            super(pluginsFolder, title, patternName);
465
        }
466

  
467
        @Override
468
        public void run() {
469
            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
470
            executingAutorunScripts = true;
471
            try {
472
                final ScriptingManager manager = ScriptingLocator.getManager();
473
                manager.loadEngines();
474

  
475
//                final PluginsManager pluginManager = PluginsLocator.getManager();
476
                final I18nManager i18nManager = ToolsLocator.getI18nManager();
477

  
478
                final List<ScriptingScript> scripts = new ArrayList<>();
479

  
480
                List<File> pluginsFolders = new ArrayList<>();
481
                for (File pluginsFolders2 : this.getPluginsFolders()) {
482
                    for (File pluginFolder : pluginsFolders2.listFiles()) {
483
                        File f = FileUtils.getFile(pluginFolder, "scripting", "scripts");
484
                        if (f.exists()) {
485
                            pluginsFolders.add(f);
486
                        }
487
                    }
488
                }
489

  
490
                dialogs.message(
491
                        i18nManager.getTranslation("_Searching_autorun_scripts_Xhorizontal_ellipsisX"),
492
                        JOptionPane.INFORMATION_MESSAGE
493
                );
494

  
495
                SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
496
                    @Override
497
                    public FileVisitResult visitFile(Path path, BasicFileAttributes bfa) throws IOException {
498
                        File file = path.toFile();
499
                        if (FilenameUtils.wildcardMatch(file.getName(), patternName, IOCase.INSENSITIVE)) {
500
                            if (file.exists()) {
501
                                ScriptingScript script = (ScriptingScript) manager.getScript(file);
502
                                if (script.isEnabled()) {
503
                                    scripts.add(script);
504
                                } else {
505
                                    LOGGER.info("Skip " + title + " script '" + file.getAbsolutePath() + "'.");
506
                                }
507
                            }
508
                        }
509
                        return FileVisitResult.CONTINUE;
510
                    }
511
                };
512
                try {
513
                    EnumSet<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS);
514
                    for (File pluginFolder : pluginsFolders) {
515
                        Files.walkFileTree(Paths.get(pluginFolder.toURI()), opts, Integer.MAX_VALUE, visitor);
516
                    }
517
                    Files.walkFileTree(Paths.get(manager.getRootUserFolder().toURI()), opts, Integer.MAX_VALUE, visitor);
518
                    List<ScriptingFolder> folders = manager.getAlternativeUserFolders();
519
                    for (ScriptingFolder folder : folders) {
520
                        Files.walkFileTree(Paths.get(folder.getFile().toURI()), opts, Integer.MAX_VALUE, visitor);
521
                    }
522
                } catch (Exception ex) {
523
                    LOGGER.warn("Can't execute " + title + " in home.", ex);
524
                }
525
                sortScripts(scripts);
526
                executeScripts(scripts, null);
527

  
528
            } finally {
529
                LOGGER.info("Running " + title + " scripts terminated.");
530
                dialogs.message("", JOptionPane.INFORMATION_MESSAGE);
531
                executingAutorunScripts = false;
532
            }
533
            checkDataFoldersVersions();
534
        }
535

  
536
    }
537
    
538
    private void checkDataFoldersVersions() {
539
        final ScriptingManager manager = ScriptingLocator.getManager();
540
        PackageManager versionFactory = ToolsLocator.getPackageManager();
541
        Version currentVersion = versionFactory.createVersion(this.appversion);
542
        FolderSet folders = new DefaultFolderSet();
543
        folders.add(this.pluginHomeFolder);
544
        final List<DataFolderFound> dataFoldersFound = manager.searchOldVersions(currentVersion, folders);
545
        if( dataFoldersFound == null || dataFoldersFound.isEmpty() ) {
546
            return;
547
        }
548
        Runnable askUser = new Runnable() {
549
            @Override
550
            public void run() {
551
                WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
552
                final DataFoldersRecoverPanel panel = new DataFoldersRecoverPanel(dataFoldersFound);
553
                final Dialog dialog = winManager.createDialog(
554
                        panel,
555
                        "Recuperacion de preferencias",
556
                        null,
557
                        WindowManager_v2.BUTTONS_OK_CANCEL
558
                );
559
                dialog.addActionListener(new ActionListener() {
560
                    @Override
561
                    public void actionPerformed(ActionEvent e) {
562
                        if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
563
                            List<DataFolderFound> toRestore = panel.getSelectedDataFolders();
564
                            for (DataFolderFound dataFolderFound : dataFoldersFound) {
565
                                if (toRestore.contains(dataFolderFound)) {
566
                                    dataFolderFound.restore();
567
                                } else {
568
                                    dataFolderFound.leave();
569
                                }
570
                            }
571
                        }
572
                    }
573
                });
574
                dialog.show(WindowManager.MODE.WINDOW);
575
            }
576
        };
577
        if( SwingUtilities.isEventDispatchThread() ) {
578
            askUser.run();
579
        } else {
580
            SwingUtilities.invokeLater(askUser);
581
        }
582
    }
583
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptingMain.java
1
package org.gvsig.scripting.app.extension;
2

  
3
import java.io.File;
4
import java.net.URL;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import javax.swing.UIManager;
10
import org.apache.commons.cli.CommandLine;
11
import org.apache.commons.cli.CommandLineParser;
12
import org.apache.commons.cli.Options;
13
import org.apache.commons.cli.PosixParser;
14
import org.apache.commons.io.FileUtils;
15
import org.gvsig.about.AboutLocator;
16
import org.gvsig.about.AboutManager;
17
import org.gvsig.scripting.ScriptingManager;
18
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
19
import org.gvsig.scripting.swing.api.ScriptingUIManager;
20
import org.gvsig.tools.ToolsLocator;
21
import org.gvsig.tools.exception.BaseException;
22
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
23
import org.gvsig.tools.packageutils.PackageInfo;
24
import org.gvsig.tools.packageutils.PackageManager;
25
import org.gvsig.tools.packageutils.Version;
26

  
27
/**
28
 *
29
 * @author jjdelcerro
30
 */
31
public class ScriptingMain {
32

  
33
    private File applicationFolder = null;
34
    private Version applicacionVersion = null;
35
    private List<File> pluginsFolder = null;
36
    private File applicationHomeFolder;
37
    private File installFolder;
38
    private int applicacionBuildNumber;
39

  
40
    private ScriptingUtils utils;
41

  
42
    public static void main(String args[]) throws Exception {
43
        ScriptingMain main = new ScriptingMain();
44
        main.doMain(args);
45
    }
46
    
47
    public File getApplicationFolder() {
48
        if (applicationFolder == null) {
49
            applicationFolder = new File(System.getProperty("user.dir"));
50
        }
51
        return applicationFolder;
52
    }
53

  
54
    public File getApplicationHomeFolder() {
55
        if (applicationHomeFolder == null) {
56
            applicationHomeFolder = new File(System.getProperty("user.home"));
57
        }
58
        return applicationHomeFolder;
59
    }
60

  
61
    public File getInstallFolder() {
62
        if (installFolder == null) {
63
            installFolder = FileUtils.getFile(getApplicationFolder(), "install");
64
        }
65
        return this.installFolder;
66
    }
67

  
68
    public Version getApplicationVersion() throws BaseException {
69
        if (applicacionVersion == null) {
70
            PackageManager packageManager = ToolsLocator.getPackageManager();
71
            PackageInfo packageInfo = packageManager.createPackageInfo(
72
                    new File(this.applicationFolder, "package.info")
73
            );
74
            applicacionVersion = (Version) packageInfo.getVersion();
75
        }
76
        return applicacionVersion;
77
    }
78

  
79
    public int getApplicationBuildNumber() throws BaseException {
80
        if (applicacionBuildNumber == 0) {
81
            applicacionBuildNumber = getApplicationVersion().getBuild();
82
        }
83
        return this.applicacionBuildNumber;
84
    }
85

  
86
    public List<File> getPluginsFolder() {
87
        List<File> folders = new ArrayList<>();
88
        folders.add(FileUtils.getFile(this.getApplicationFolder(), "gvSIG", "extensiones"));
89
        folders.add(FileUtils.getFile(this.getApplicationHomeFolder(), "gvSIG", "installation", "gvSIG", "extensiones"));
90
        return folders;
91
    }
92

  
93
    public File getPluginHomeFolder() {
94
        File f = this.getApplicationHomeFolder();
95
        f = FileUtils.getFile(f, "gvSIG", "plugins", "org.gvsig.scripting.app.mainplugin");
96
        return f;
97
    }
98

  
99
    private void initializeAbout() throws Exception {
100
        AboutManager aboutManager = AboutLocator.getManager();
101

  
102
        String build = String.valueOf(this.getApplicationBuildNumber());
103
        String version = this.getApplicationVersion().toString();
104
        
105
        Map<String, String> gvsig_vars = new HashMap<>();
106
        gvsig_vars.put("version", version);
107
        gvsig_vars.put("build", build);
108
        aboutManager.setProject(
109
                "gvSIG Desktop", 
110
                getResource("gvsig.html"),
111
                null, 
112
                gvsig_vars);
113
        aboutManager.getProject().set("build", build);
114

  
115
        aboutManager.addSponsor(
116
                "Generalitat Valenciana",
117
                getResource("gva.html"), 
118
                1);
119

  
120
        aboutManager.addDeveloper(
121
                "gvSIG Asocicion",
122
                getResource("gvSIG-asociacion.html"), 
123
                2);
124

  
125
    }
126

  
127
    public void doMain(String args[]) throws Exception {
128

  
129
        String lookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
130
        try {
131
            UIManager.setLookAndFeel(lookAndFeel);
132
        } catch(Throwable th) {
133
            
134
        }
135
        
136
        new DefaultLibrariesInitializer().fullInitialize();
137

  
138
        initializeAbout();
139

  
140
        this.utils = new ScriptingUtils();
141
        this.utils.initializaPaths(
142
                this.getPluginsFolder(),
143
                this.getInstallFolder(),
144
                this.getPluginHomeFolder(),
145
                this.getApplicationVersion().format("%M.%m.%r")
146
        );
147

  
148
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
149
        ScriptingManager manager = uimanager.getManager();
150

  
151
        Options options = new Options();
152
        options.addOption("d",
153
                "debug",
154
                false,
155
                "");
156
        options.addOption("p",
157
                "pause",
158
                false,
159
                "");
160
        options.addOption("l",
161
                "launcher",
162
                false,
163
                "Show the launcher window");
164
        options.addOption("c",
165
                "composer",
166
                false,
167
                "Show the composer window");
168
        options.addOption("r",
169
                "run",
170
                true,
171
                "Run the specified script");
172
        options.addOption("h",
173
                "home",
174
                true,
175
                "Specify for the home of the script framework");
176
        CommandLineParser parser = new PosixParser();
177
        CommandLine line = null;
178
        boolean runLauncherAtEnd = true;
179
        
180
        line = parser.parse(options, args);
181
        if (line.hasOption("home")) {
182
            manager.setHomeFolder(new File(line.getOptionValue("home")));
183
        }
184
        if (line.hasOption("composer")) {
185
            runLauncherAtEnd = false;
186
            utils.runComposer();
187
        }
188
        if (line.hasOption("run")) {
189
            runLauncherAtEnd = false;
190
            utils.runScript(line.getOptionValue("run"), line.getArgs());
191
        }
192
        if( runLauncherAtEnd ) {
193
            utils.runLauncher();
194
        }
195
    }
196

  
197
    private URL getResource(String name) {
198
        URL resource = this.getClass().getResource(name);
199
        return resource;
200
    }
201

  
202
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.95/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/DataFoldersRecoverPanelView.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<object classname="com.jeta.forms.store.memento.FormPackage">
4
 <at name="fileversion">
5
  <object classname="com.jeta.forms.store.memento.FormsVersion2">
6
   <at name="major">2</at>
7
   <at name="minor">0</at>
8
   <at name="sub">0</at>
9
  </object>
10
 </at>
11
 <at name="form">
12
  <object classname="com.jeta.forms.store.memento.FormMemento">
13
   <super classname="com.jeta.forms.store.memento.ComponentMemento">
14
    <at name="cellconstraints">
15
     <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
16
      <at name="column">1</at>
17
      <at name="row">1</at>
18
      <at name="colspan">1</at>
19
      <at name="rowspan">1</at>
20
      <at name="halign">default</at>
21
      <at name="valign">default</at>
22
      <at name="insets" object="insets">0,0,0,0</at>
23
     </object>
24
    </at>
25
    <at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
26
   </super>
27
   <at name="id">/home/jjdelcerro/datos/devel/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/DataFoldersRecoverPanelView.xml</at>
28
   <at name="rowspecs">CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE</at>
29
   <at name="colspecs">FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE</at>
30
   <at name="components">
31
    <object classname="java.util.LinkedList">
32
     <item >
33
      <at name="value">
34
       <object classname="com.jeta.forms.store.memento.BeanMemento">
35
        <super classname="com.jeta.forms.store.memento.ComponentMemento">
36
         <at name="cellconstraints">
37
          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
38
           <at name="column">2</at>
39
           <at name="row">2</at>
40
           <at name="colspan">1</at>
41
           <at name="rowspan">1</at>
42
           <at name="halign">default</at>
43
           <at name="valign">default</at>
44
           <at name="insets" object="insets">0,0,0,0</at>
45
          </object>
46
         </at>
47
         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
48
        </super>
49
        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
50
        <at name="beanclass">com.jeta.forms.components.label.JETALabel</at>
51
        <at name="beanproperties">
52
         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
53
          <at name="classname">com.jeta.forms.components.label.JETALabel</at>
54
          <at name="properties">
55
           <object classname="com.jeta.forms.store.support.PropertyMap">
56
            <at name="border">
57
             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
58
              <super classname="com.jeta.forms.store.properties.BorderProperty">
59
               <at name="name">border</at>
60
              </super>
61
              <at name="borders">
62
               <object classname="java.util.LinkedList">
63
                <item >
64
                 <at name="value">
65
                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
66
                   <super classname="com.jeta.forms.store.properties.BorderProperty">
67
                    <at name="name">border</at>
68
                   </super>
69
                  </object>
70
                 </at>
71
                </item>
72
               </object>
73
              </at>
74
             </object>
75
            </at>
76
            <at name="name">lblMsg1</at>
77
            <at name="width">583</at>
78
            <at name="text">&lt;html&gt;Han sido encontradas preferencias de versiones anteriores para algunos complementos.&lt;/html&gt;</at>
79
            <at name="fill">
80
             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
81
              <at name="name">fill</at>
82
             </object>
83
            </at>
84
            <at name="height">14</at>
85
           </object>
86
          </at>
87
         </object>
88
        </at>
89
       </object>
90
      </at>
91
     </item>
92
     <item >
93
      <at name="value">
94
       <object classname="com.jeta.forms.store.memento.BeanMemento">
95
        <super classname="com.jeta.forms.store.memento.ComponentMemento">
96
         <at name="cellconstraints">
97
          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
98
           <at name="column">2</at>
99
           <at name="row">4</at>
100
           <at name="colspan">1</at>
101
           <at name="rowspan">1</at>
102
           <at name="halign">default</at>
103
           <at name="valign">default</at>
104
           <at name="insets" object="insets">0,0,0,0</at>
105
          </object>
106
         </at>
107
         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
108
        </super>
109
        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
110
        <at name="beanclass">com.jeta.forms.components.label.JETALabel</at>
111
        <at name="beanproperties">
112
         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
113
          <at name="classname">com.jeta.forms.components.label.JETALabel</at>
114
          <at name="properties">
115
           <object classname="com.jeta.forms.store.support.PropertyMap">
116
            <at name="border">
117
             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
118
              <super classname="com.jeta.forms.store.properties.BorderProperty">
119
               <at name="name">border</at>
120
              </super>
121
              <at name="borders">
122
               <object classname="java.util.LinkedList">
123
                <item >
124
                 <at name="value">
125
                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
126
                   <super classname="com.jeta.forms.store.properties.BorderProperty">
127
                    <at name="name">border</at>
128
                   </super>
129
                  </object>
130
                 </at>
131
                </item>
132
               </object>
133
              </at>
134
             </object>
135
            </at>
136
            <at name="name">lblMsg2</at>
137
            <at name="width">583</at>
138
            <at name="text">&lt;html&gt;Seleccione los complementos para los que desea recuperar las preferencias de versiones anteriores&lt;/html&gt;</at>
139
            <at name="fill">
140
             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
141
              <at name="name">fill</at>
142
             </object>
143
            </at>
144
            <at name="height">14</at>
145
           </object>
146
          </at>
147
         </object>
148
        </at>
149
       </object>
150
      </at>
151
     </item>
152
     <item >
153
      <at name="value">
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff